| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/gpu/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
| 23 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 24 #include "base/sha1.h" | 24 #include "base/sha1.h" |
| 25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
| 28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 29 #include "components/tracing/common/tracing_switches.h" | 29 #include "components/tracing/common/tracing_switches.h" |
| 30 #include "content/browser/browser_child_process_host_impl.h" | 30 #include "content/browser/browser_child_process_host_impl.h" |
| 31 #include "content/browser/browser_main_loop.h" | 31 #include "content/browser/browser_main_loop.h" |
| 32 #include "content/browser/field_trial_recorder.h" | |
| 33 #include "content/browser/gpu/compositor_util.h" | 32 #include "content/browser/gpu/compositor_util.h" |
| 34 #include "content/browser/gpu/gpu_data_manager_impl.h" | 33 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 35 #include "content/browser/gpu/gpu_main_thread_factory.h" | 34 #include "content/browser/gpu/gpu_main_thread_factory.h" |
| 35 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 36 #include "content/browser/gpu/shader_cache_factory.h" | 36 #include "content/browser/gpu/shader_cache_factory.h" |
| 37 #include "content/browser/service_manager/service_manager_context.h" | 37 #include "content/browser/service_manager/service_manager_context.h" |
| 38 #include "content/common/child_process_host_impl.h" | 38 #include "content/common/child_process_host_impl.h" |
| 39 #include "content/common/in_process_child_thread_params.h" | 39 #include "content/common/in_process_child_thread_params.h" |
| 40 #include "content/common/service_manager/child_connection.h" | 40 #include "content/common/service_manager/child_connection.h" |
| 41 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
| 42 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/content_browser_client.h" | 43 #include "content/public/browser/content_browser_client.h" |
| 44 #include "content/public/browser/gpu_utils.h" | 44 #include "content/public/browser/gpu_utils.h" |
| 45 #include "content/public/common/connection_filter.h" | 45 #include "content/public/common/connection_filter.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 #include "services/service_manager/public/cpp/binder_registry.h" | 64 #include "services/service_manager/public/cpp/binder_registry.h" |
| 65 #include "services/service_manager/public/cpp/interface_provider.h" | 65 #include "services/service_manager/public/cpp/interface_provider.h" |
| 66 #include "services/service_manager/runner/common/client_util.h" | 66 #include "services/service_manager/runner/common/client_util.h" |
| 67 #include "ui/display/display_switches.h" | 67 #include "ui/display/display_switches.h" |
| 68 #include "ui/gfx/switches.h" | 68 #include "ui/gfx/switches.h" |
| 69 #include "ui/gl/gl_switches.h" | 69 #include "ui/gl/gl_switches.h" |
| 70 #include "ui/latency/latency_info.h" | 70 #include "ui/latency/latency_info.h" |
| 71 | 71 |
| 72 #if defined(OS_ANDROID) | 72 #if defined(OS_ANDROID) |
| 73 #include "base/android/build_info.h" | 73 #include "base/android/build_info.h" |
| 74 #include "content/public/browser/android/java_interfaces.h" | |
| 75 #include "media/mojo/interfaces/android_overlay.mojom.h" | |
| 76 #endif | 74 #endif |
| 77 | 75 |
| 78 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
| 79 #include "base/win/windows_version.h" | 77 #include "base/win/windows_version.h" |
| 80 #include "content/common/sandbox_win.h" | 78 #include "content/common/sandbox_win.h" |
| 81 #include "sandbox/win/src/sandbox_policy.h" | 79 #include "sandbox/win/src/sandbox_policy.h" |
| 82 #include "ui/gfx/switches.h" | 80 #include "ui/gfx/switches.h" |
| 83 #include "ui/gfx/win/rendering_window_manager.h" | 81 #include "ui/gfx/win/rendering_window_manager.h" |
| 84 #endif | 82 #endif |
| 85 | 83 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; | 187 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; |
| 190 | 188 |
| 191 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind, | 189 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind, |
| 192 bool force_create, | 190 bool force_create, |
| 193 const base::Callback<void(GpuProcessHost*)>& callback) { | 191 const base::Callback<void(GpuProcessHost*)>& callback) { |
| 194 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create); | 192 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create); |
| 195 callback.Run(host); | 193 callback.Run(host); |
| 196 } | 194 } |
| 197 | 195 |
| 198 #if defined(USE_OZONE) | 196 #if defined(USE_OZONE) |
| 199 // The ozone platform use this callback to send IPC messages to the gpu process. | |
| 200 void SendGpuProcessMessage(base::WeakPtr<GpuProcessHost> host, | 197 void SendGpuProcessMessage(base::WeakPtr<GpuProcessHost> host, |
| 201 IPC::Message* message) { | 198 IPC::Message* message) { |
| 202 if (host) | 199 if (host) |
| 203 host->Send(message); | 200 host->Send(message); |
| 204 else | 201 else |
| 205 delete message; | 202 delete message; |
| 206 } | 203 } |
| 207 | |
| 208 void RouteMessageToOzoneOnUI(const IPC::Message& message) { | |
| 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 210 ui::OzonePlatform::GetInstance() | |
| 211 ->GetGpuPlatformSupportHost() | |
| 212 ->OnMessageReceived(message); | |
| 213 } | |
| 214 | |
| 215 #endif // defined(USE_OZONE) | 204 #endif // defined(USE_OZONE) |
| 216 | 205 |
| 217 void OnGpuProcessHostDestroyedOnUI(int host_id, const std::string& message) { | |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 219 GpuDataManagerImpl::GetInstance()->AddLogMessage( | |
| 220 logging::LOG_ERROR, "GpuProcessHostUIShim", message); | |
| 221 #if defined(USE_OZONE) | |
| 222 ui::OzonePlatform::GetInstance() | |
| 223 ->GetGpuPlatformSupportHost() | |
| 224 ->OnChannelDestroyed(host_id); | |
| 225 #endif | |
| 226 } | |
| 227 | |
| 228 // NOTE: changes to this class need to be reviewed by the security team. | 206 // NOTE: changes to this class need to be reviewed by the security team. |
| 229 class GpuSandboxedProcessLauncherDelegate | 207 class GpuSandboxedProcessLauncherDelegate |
| 230 : public SandboxedProcessLauncherDelegate { | 208 : public SandboxedProcessLauncherDelegate { |
| 231 public: | 209 public: |
| 232 explicit GpuSandboxedProcessLauncherDelegate( | 210 explicit GpuSandboxedProcessLauncherDelegate( |
| 233 const base::CommandLine& cmd_line) | 211 const base::CommandLine& cmd_line) |
| 234 #if defined(OS_WIN) | 212 #if defined(OS_WIN) |
| 235 : cmd_line_(cmd_line) | 213 : cmd_line_(cmd_line) |
| 236 #endif | 214 #endif |
| 237 { | 215 { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 SandboxType GetSandboxType() override { | 299 SandboxType GetSandboxType() override { |
| 322 return SANDBOX_TYPE_GPU; | 300 return SANDBOX_TYPE_GPU; |
| 323 } | 301 } |
| 324 | 302 |
| 325 private: | 303 private: |
| 326 #if defined(OS_WIN) | 304 #if defined(OS_WIN) |
| 327 base::CommandLine cmd_line_; | 305 base::CommandLine cmd_line_; |
| 328 #endif // OS_WIN | 306 #endif // OS_WIN |
| 329 }; | 307 }; |
| 330 | 308 |
| 331 #if defined(OS_ANDROID) | |
| 332 template <typename Interface> | |
| 333 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) { | |
| 334 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 335 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request)); | |
| 336 } | |
| 337 #endif // defined(OS_ANDROID) | |
| 338 | |
| 339 } // anonymous namespace | 309 } // anonymous namespace |
| 340 | 310 |
| 341 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { | 311 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { |
| 342 public: | 312 public: |
| 343 ConnectionFilterImpl() { | 313 ConnectionFilterImpl() { |
| 344 auto task_runner = BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); | 314 GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces(®istry_); |
| 345 registry_.AddInterface(base::Bind(&FieldTrialRecorder::Create), | |
| 346 task_runner); | |
| 347 registry_.AddInterface( | |
| 348 base::Bind( | |
| 349 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, | |
| 350 base::Unretained( | |
| 351 memory_instrumentation::CoordinatorImpl::GetInstance())), | |
| 352 task_runner); | |
| 353 #if defined(OS_ANDROID) | |
| 354 registry_.AddInterface( | |
| 355 base::Bind(&BindJavaInterface<media::mojom::AndroidOverlayProvider>), | |
| 356 task_runner); | |
| 357 #endif | |
| 358 } | 315 } |
| 359 | 316 |
| 360 private: | 317 private: |
| 361 // ConnectionFilter: | 318 // ConnectionFilter: |
| 362 void OnBindInterface(const service_manager::ServiceInfo& source_info, | 319 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 363 const std::string& interface_name, | 320 const std::string& interface_name, |
| 364 mojo::ScopedMessagePipeHandle* interface_pipe, | 321 mojo::ScopedMessagePipeHandle* interface_pipe, |
| 365 service_manager::Connector* connector) override { | 322 service_manager::Connector* connector) override { |
| 366 if (registry_.CanBindInterface(interface_name)) { | 323 if (registry_.CanBindInterface(interface_name)) { |
| 367 registry_.BindInterface(source_info.identity, interface_name, | 324 registry_.BindInterface(source_info.identity, interface_name, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 switches::kInProcessGPU)) { | 459 switches::kInProcessGPU)) { |
| 503 in_process_ = true; | 460 in_process_ = true; |
| 504 } | 461 } |
| 505 | 462 |
| 506 // If the 'single GPU process' policy ever changes, we still want to maintain | 463 // If the 'single GPU process' policy ever changes, we still want to maintain |
| 507 // it for 'gpu thread' mode and only create one instance of host and thread. | 464 // it for 'gpu thread' mode and only create one instance of host and thread. |
| 508 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); | 465 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); |
| 509 | 466 |
| 510 g_gpu_process_hosts[kind] = this; | 467 g_gpu_process_hosts[kind] = this; |
| 511 | 468 |
| 469 // Post a task to create the corresponding GpuProcessHostUIShim. The |
| 470 // GpuProcessHostUIShim will be destroyed when the GpuProcessHost is |
| 471 // destroyed, which happens when the corresponding GPU process terminates or |
| 472 // fails to launch. On browser exit, the shim can be leaked. |
| 473 BrowserThread::PostTask( |
| 474 BrowserThread::UI, |
| 475 FROM_HERE, |
| 476 base::Bind(base::IgnoreResult(&GpuProcessHostUIShim::Create), host_id)); |
| 477 |
| 512 process_.reset(new BrowserChildProcessHostImpl( | 478 process_.reset(new BrowserChildProcessHostImpl( |
| 513 PROCESS_TYPE_GPU, this, mojom::kGpuServiceName)); | 479 PROCESS_TYPE_GPU, this, mojom::kGpuServiceName)); |
| 514 } | 480 } |
| 515 | 481 |
| 516 GpuProcessHost::~GpuProcessHost() { | 482 GpuProcessHost::~GpuProcessHost() { |
| 517 DCHECK(CalledOnValidThread()); | 483 DCHECK(CalledOnValidThread()); |
| 518 | 484 |
| 519 SendOutstandingReplies(); | 485 SendOutstandingReplies(); |
| 520 | 486 |
| 521 // In case we never started, clean up. | 487 // In case we never started, clean up. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 break; | 555 break; |
| 590 } | 556 } |
| 591 } | 557 } |
| 592 | 558 |
| 593 // If there are any remaining offscreen contexts at the point the | 559 // If there are any remaining offscreen contexts at the point the |
| 594 // GPU process exits, assume something went wrong, and block their | 560 // GPU process exits, assume something went wrong, and block their |
| 595 // URLs from accessing client 3D APIs without prompting. | 561 // URLs from accessing client 3D APIs without prompting. |
| 596 if (block_offscreen_contexts) | 562 if (block_offscreen_contexts) |
| 597 BlockLiveOffscreenContexts(); | 563 BlockLiveOffscreenContexts(); |
| 598 | 564 |
| 599 BrowserThread::PostTask( | 565 BrowserThread::PostTask(BrowserThread::UI, |
| 600 BrowserThread::UI, FROM_HERE, | 566 FROM_HERE, |
| 601 base::Bind(&OnGpuProcessHostDestroyedOnUI, host_id_, message)); | 567 base::Bind(&GpuProcessHostUIShim::Destroy, |
| 568 host_id_, |
| 569 message)); |
| 602 } | 570 } |
| 603 | 571 |
| 604 bool GpuProcessHost::Init() { | 572 bool GpuProcessHost::Init() { |
| 605 init_start_time_ = base::TimeTicks::Now(); | 573 init_start_time_ = base::TimeTicks::Now(); |
| 606 | 574 |
| 607 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 575 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
| 608 | 576 |
| 609 // May be null during test execution. | 577 // May be null during test execution. |
| 610 if (ServiceManagerConnection::GetForProcess()) { | 578 if (ServiceManagerConnection::GetForProcess()) { |
| 611 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( | 579 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 gpu_main_ptr_->CreateGpuService( | 612 gpu_main_ptr_->CreateGpuService( |
| 645 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(), | 613 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(), |
| 646 gpu_preferences, activity_flags_.CloneHandle()); | 614 gpu_preferences, activity_flags_.CloneHandle()); |
| 647 | 615 |
| 648 #if defined(USE_OZONE) | 616 #if defined(USE_OZONE) |
| 649 // Ozone needs to send the primary DRM device to GPU process as early as | 617 // Ozone needs to send the primary DRM device to GPU process as early as |
| 650 // possible to ensure the latter always has a valid device. crbug.com/608839 | 618 // possible to ensure the latter always has a valid device. crbug.com/608839 |
| 651 ui::OzonePlatform::GetInstance() | 619 ui::OzonePlatform::GetInstance() |
| 652 ->GetGpuPlatformSupportHost() | 620 ->GetGpuPlatformSupportHost() |
| 653 ->OnGpuProcessLaunched( | 621 ->OnGpuProcessLaunched( |
| 654 host_id_, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 622 host_id_, base::ThreadTaskRunnerHandle::Get(), |
| 655 base::ThreadTaskRunnerHandle::Get(), | |
| 656 base::Bind(&SendGpuProcessMessage, weak_ptr_factory_.GetWeakPtr())); | 623 base::Bind(&SendGpuProcessMessage, weak_ptr_factory_.GetWeakPtr())); |
| 657 #endif | 624 #endif |
| 658 | 625 |
| 659 return true; | 626 return true; |
| 660 } | 627 } |
| 661 | 628 |
| 629 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
| 630 BrowserThread::PostTask( |
| 631 BrowserThread::UI, |
| 632 FROM_HERE, |
| 633 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); |
| 634 } |
| 635 |
| 662 bool GpuProcessHost::Send(IPC::Message* msg) { | 636 bool GpuProcessHost::Send(IPC::Message* msg) { |
| 663 DCHECK(CalledOnValidThread()); | 637 DCHECK(CalledOnValidThread()); |
| 664 if (process_->GetHost()->IsChannelOpening()) { | 638 if (process_->GetHost()->IsChannelOpening()) { |
| 665 queued_messages_.push(msg); | 639 queued_messages_.push(msg); |
| 666 return true; | 640 return true; |
| 667 } | 641 } |
| 668 | 642 |
| 669 bool result = process_->Send(msg); | 643 bool result = process_->Send(msg); |
| 670 if (!result) { | 644 if (!result) { |
| 671 // Channel is hosed, but we may not get destroyed for a while. Send | 645 // Channel is hosed, but we may not get destroyed for a while. Send |
| 672 // outstanding channel creation failures now so that the caller can restart | 646 // outstanding channel creation failures now so that the caller can restart |
| 673 // with a new process/channel without waiting. | 647 // with a new process/channel without waiting. |
| 674 SendOutstandingReplies(); | 648 SendOutstandingReplies(); |
| 675 } | 649 } |
| 676 return result; | 650 return result; |
| 677 } | 651 } |
| 678 | 652 |
| 679 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 653 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 680 DCHECK(CalledOnValidThread()); | 654 DCHECK(CalledOnValidThread()); |
| 681 #if defined(USE_OZONE) | 655 RouteOnUIThread(message); |
| 682 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 683 base::Bind(&RouteMessageToOzoneOnUI, message)); | |
| 684 #endif | |
| 685 return true; | 656 return true; |
| 686 } | 657 } |
| 687 | 658 |
| 688 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { | 659 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { |
| 689 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); | 660 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); |
| 690 | 661 |
| 691 while (!queued_messages_.empty()) { | 662 while (!queued_messages_.empty()) { |
| 692 Send(queued_messages_.front()); | 663 Send(queued_messages_.front()); |
| 693 queued_messages_.pop(); | 664 queued_messages_.pop(); |
| 694 } | 665 } |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 if (!cache.get()) | 1181 if (!cache.get()) |
| 1211 return; | 1182 return; |
| 1212 | 1183 |
| 1213 cache->set_shader_loaded_callback(base::Bind(&GpuProcessHost::LoadedShader, | 1184 cache->set_shader_loaded_callback(base::Bind(&GpuProcessHost::LoadedShader, |
| 1214 weak_ptr_factory_.GetWeakPtr())); | 1185 weak_ptr_factory_.GetWeakPtr())); |
| 1215 | 1186 |
| 1216 client_id_to_shader_cache_[client_id] = cache; | 1187 client_id_to_shader_cache_[client_id] = cache; |
| 1217 } | 1188 } |
| 1218 | 1189 |
| 1219 } // namespace content | 1190 } // namespace content |
| OLD | NEW |