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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "gpu/command_buffer/service/gpu_switches.h" | 60 #include "gpu/command_buffer/service/gpu_switches.h" |
61 #include "gpu/config/gpu_driver_bug_list.h" | 61 #include "gpu/config/gpu_driver_bug_list.h" |
62 #include "gpu/ipc/host/shader_disk_cache.h" | 62 #include "gpu/ipc/host/shader_disk_cache.h" |
63 #include "gpu/ipc/service/switches.h" | 63 #include "gpu/ipc/service/switches.h" |
64 #include "ipc/ipc_channel_handle.h" | 64 #include "ipc/ipc_channel_handle.h" |
65 #include "ipc/message_filter.h" | 65 #include "ipc/message_filter.h" |
66 #include "media/base/media_switches.h" | 66 #include "media/base/media_switches.h" |
67 #include "media/media_features.h" | 67 #include "media/media_features.h" |
68 #include "mojo/edk/embedder/embedder.h" | 68 #include "mojo/edk/embedder/embedder.h" |
69 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" | 69 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" |
| 70 #include "services/service_manager/public/cpp/binder_registry.h" |
70 #include "services/service_manager/public/cpp/connection.h" | 71 #include "services/service_manager/public/cpp/connection.h" |
71 #include "services/service_manager/public/cpp/interface_provider.h" | 72 #include "services/service_manager/public/cpp/interface_provider.h" |
72 #include "services/service_manager/public/cpp/interface_registry.h" | |
73 #include "services/service_manager/runner/common/client_util.h" | 73 #include "services/service_manager/runner/common/client_util.h" |
74 #include "ui/display/display_switches.h" | 74 #include "ui/display/display_switches.h" |
75 #include "ui/events/latency_info.h" | 75 #include "ui/events/latency_info.h" |
76 #include "ui/gfx/switches.h" | 76 #include "ui/gfx/switches.h" |
77 #include "ui/gl/gl_switches.h" | 77 #include "ui/gl/gl_switches.h" |
78 | 78 |
79 #if defined(OS_ANDROID) | 79 #if defined(OS_ANDROID) |
80 #include "base/android/build_info.h" | 80 #include "base/android/build_info.h" |
81 #endif | 81 #endif |
82 | 82 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 const std::string& data) { | 328 const std::string& data) { |
329 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 329 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
330 if (host) | 330 if (host) |
331 host->LoadedShader(key, data); | 331 host->LoadedShader(key, data); |
332 } | 332 } |
333 | 333 |
334 } // anonymous namespace | 334 } // anonymous namespace |
335 | 335 |
336 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { | 336 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { |
337 public: | 337 public: |
338 ConnectionFilterImpl(GpuProcessHost* host) : host_(host) {} | 338 ConnectionFilterImpl() { |
339 | 339 registry_.AddInterface( |
340 private: | |
341 // ConnectionFilter: | |
342 bool OnConnect(const service_manager::Identity& remote_identity, | |
343 service_manager::InterfaceRegistry* registry, | |
344 service_manager::Connector* connector) override { | |
345 if (remote_identity.name() != mojom::kGpuServiceName) | |
346 return false; | |
347 | |
348 registry->AddInterface( | |
349 base::Bind( | 340 base::Bind( |
350 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, | 341 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
351 base::Unretained( | 342 base::Unretained( |
352 memory_instrumentation::CoordinatorImpl::GetInstance())), | 343 memory_instrumentation::CoordinatorImpl::GetInstance())), |
353 content::BrowserThread::GetTaskRunnerForThread( | 344 content::BrowserThread::GetTaskRunnerForThread( |
354 content::BrowserThread::UI)); | 345 content::BrowserThread::UI)); |
355 | |
356 GetContentClient()->browser()->ExposeInterfacesToGpuProcess(registry, | |
357 host_); | |
358 | |
359 #if defined(OS_ANDROID) | 346 #if defined(OS_ANDROID) |
360 GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces(registry); | 347 GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces(®istry_); |
361 #endif | 348 #endif |
362 | |
363 return true; | |
364 } | 349 } |
365 | 350 |
366 GpuProcessHost* host_; | 351 private: |
| 352 // ConnectionFilter: |
| 353 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 354 const std::string& interface_name, |
| 355 mojo::ScopedMessagePipeHandle* interface_pipe, |
| 356 service_manager::Connector* connector) override { |
| 357 if (registry_.CanBindInterface(interface_name)) { |
| 358 registry_.BindInterface(source_info.identity, interface_name, |
| 359 std::move(*interface_pipe)); |
| 360 } else { |
| 361 GetContentClient()->browser()->BindInterfaceRequest( |
| 362 source_info, interface_name, interface_pipe); |
| 363 } |
| 364 } |
| 365 |
| 366 service_manager::BinderRegistry registry_; |
367 | 367 |
368 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); | 368 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); |
369 }; | 369 }; |
370 | 370 |
371 // static | 371 // static |
372 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { | 372 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { |
373 // The Gpu process is invalid if it's not using SwiftShader, the card is | 373 // The Gpu process is invalid if it's not using SwiftShader, the card is |
374 // blacklisted, and we can kill it and start over. | 374 // blacklisted, and we can kill it and start over. |
375 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 375 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
376 switches::kSingleProcess) || | 376 switches::kSingleProcess) || |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 bool force_create, | 462 bool force_create, |
463 const base::Callback<void(GpuProcessHost*)>& callback) { | 463 const base::Callback<void(GpuProcessHost*)>& callback) { |
464 #if !defined(OS_WIN) | 464 #if !defined(OS_WIN) |
465 DCHECK_NE(kind, GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED); | 465 DCHECK_NE(kind, GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED); |
466 #endif | 466 #endif |
467 BrowserThread::PostTask( | 467 BrowserThread::PostTask( |
468 BrowserThread::IO, FROM_HERE, | 468 BrowserThread::IO, FROM_HERE, |
469 base::Bind(&RunCallbackOnIO, kind, force_create, callback)); | 469 base::Bind(&RunCallbackOnIO, kind, force_create, callback)); |
470 } | 470 } |
471 | 471 |
472 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { | 472 void GpuProcessHost::BindInterface( |
473 return process_->child_connection()->GetRemoteInterfaces(); | 473 const std::string& interface_name, |
| 474 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 475 process_->child_connection()->BindInterface(interface_name, |
| 476 std::move(interface_pipe)); |
474 } | 477 } |
475 | 478 |
476 // static | 479 // static |
477 GpuProcessHost* GpuProcessHost::FromID(int host_id) { | 480 GpuProcessHost* GpuProcessHost::FromID(int host_id) { |
478 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 481 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
479 | 482 |
480 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { | 483 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { |
481 GpuProcessHost* host = g_gpu_process_hosts[i]; | 484 GpuProcessHost* host = g_gpu_process_hosts[i]; |
482 if (host && host->host_id_ == host_id && ValidateHost(host)) | 485 if (host && host->host_id_ == host_id && ValidateHost(host)) |
483 return host; | 486 return host; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 617 } |
615 | 618 |
616 bool GpuProcessHost::Init() { | 619 bool GpuProcessHost::Init() { |
617 init_start_time_ = base::TimeTicks::Now(); | 620 init_start_time_ = base::TimeTicks::Now(); |
618 | 621 |
619 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 622 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
620 | 623 |
621 // May be null during test execution. | 624 // May be null during test execution. |
622 if (ServiceManagerConnection::GetForProcess()) { | 625 if (ServiceManagerConnection::GetForProcess()) { |
623 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( | 626 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
624 base::MakeUnique<ConnectionFilterImpl>(this)); | 627 base::MakeUnique<ConnectionFilterImpl>()); |
625 } | 628 } |
626 | 629 |
627 process_->GetHost()->CreateChannelMojo(); | 630 process_->GetHost()->CreateChannelMojo(); |
628 | 631 |
629 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); | 632 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); |
630 if (in_process_) { | 633 if (in_process_) { |
631 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 634 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
632 DCHECK(GetGpuMainThreadFactory()); | 635 DCHECK(GetGpuMainThreadFactory()); |
633 in_process_gpu_thread_.reset(GetGpuMainThreadFactory()( | 636 in_process_gpu_thread_.reset(GetGpuMainThreadFactory()( |
634 InProcessChildThreadParams( | 637 InProcessChildThreadParams( |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 GetShaderCacheFactorySingleton()->Get(client_id); | 1251 GetShaderCacheFactorySingleton()->Get(client_id); |
1249 if (!cache.get()) | 1252 if (!cache.get()) |
1250 return; | 1253 return; |
1251 | 1254 |
1252 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); | 1255 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); |
1253 | 1256 |
1254 client_id_to_shader_cache_[client_id] = cache; | 1257 client_id_to_shader_cache_[client_id] = cache; |
1255 } | 1258 } |
1256 | 1259 |
1257 } // namespace content | 1260 } // namespace content |
OLD | NEW |