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/gpu/gpu_child_thread.h" | 5 #include "content/gpu/gpu_child_thread.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "content/child/child_process.h" | 17 #include "content/child/child_process.h" |
18 #include "content/child/thread_safe_sender.h" | 18 #include "content/child/thread_safe_sender.h" |
19 #include "content/common/establish_channel_params.h" | 19 #include "content/common/establish_channel_params.h" |
20 #include "content/common/gpu_host_messages.h" | 20 #include "content/common/gpu_host_messages.h" |
21 #include "content/gpu/gpu_process_control_impl.h" | 21 #include "content/gpu/gpu_process_control_impl.h" |
22 #include "content/gpu/gpu_watchdog_thread.h" | 22 #include "content/gpu/gpu_watchdog_thread.h" |
23 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/mojo_shell_connection.h" | |
26 #include "content/public/gpu/content_gpu_client.h" | 25 #include "content/public/gpu/content_gpu_client.h" |
27 #include "gpu/command_buffer/service/gpu_switches.h" | 26 #include "gpu/command_buffer/service/gpu_switches.h" |
28 #include "gpu/command_buffer/service/sync_point_manager.h" | 27 #include "gpu/command_buffer/service/sync_point_manager.h" |
29 #include "gpu/config/gpu_info_collector.h" | 28 #include "gpu/config/gpu_info_collector.h" |
30 #include "gpu/config/gpu_switches.h" | 29 #include "gpu/config/gpu_switches.h" |
31 #include "gpu/config/gpu_util.h" | 30 #include "gpu/config/gpu_util.h" |
32 #include "gpu/ipc/common/memory_stats.h" | 31 #include "gpu/ipc/common/memory_stats.h" |
33 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 32 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
34 #include "ipc/ipc_channel_handle.h" | 33 #include "ipc/ipc_channel_handle.h" |
35 #include "ipc/ipc_sync_message_filter.h" | 34 #include "ipc/ipc_sync_message_filter.h" |
36 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" | 35 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" |
37 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 36 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
38 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 37 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
39 #include "media/gpu/ipc/service/media_service.h" | 38 #include "media/gpu/ipc/service/media_service.h" |
40 #include "services/shell/public/cpp/interface_registry.h" | |
41 #include "ui/gl/gl_implementation.h" | 39 #include "ui/gl/gl_implementation.h" |
42 #include "ui/gl/gl_switches.h" | 40 #include "ui/gl/gl_switches.h" |
43 #include "ui/gl/gpu_switching_manager.h" | 41 #include "ui/gl/gpu_switching_manager.h" |
44 #include "ui/gl/init/gl_factory.h" | 42 #include "ui/gl/init/gl_factory.h" |
45 #include "url/gurl.h" | 43 #include "url/gurl.h" |
46 | 44 |
47 #if defined(USE_OZONE) | 45 #if defined(USE_OZONE) |
48 #include "ui/ozone/public/gpu_platform_support.h" | 46 #include "ui/ozone/public/gpu_platform_support.h" |
49 #include "ui/ozone/public/ozone_platform.h" | 47 #include "ui/ozone/public/ozone_platform.h" |
50 #endif | 48 #endif |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 #if defined(OS_ANDROID) | 214 #if defined(OS_ANDROID) |
217 // When running in in-process mode, this has been set in the browser at | 215 // When running in in-process mode, this has been set in the browser at |
218 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 216 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
219 if (!in_browser_process_) | 217 if (!in_browser_process_) |
220 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 218 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
221 #endif | 219 #endif |
222 | 220 |
223 // Only set once per process instance. | 221 // Only set once per process instance. |
224 process_control_.reset(new GpuProcessControlImpl()); | 222 process_control_.reset(new GpuProcessControlImpl()); |
225 | 223 |
226 GetInterfaceRegistry()->AddInterface(base::Bind( | |
227 &GpuChildThread::BindProcessControlRequest, base::Unretained(this))); | |
228 | |
229 if (GetContentClient()->gpu()) { // NULL in tests. | |
230 GetContentClient()->gpu()->ExposeInterfacesToBrowser( | |
231 GetInterfaceRegistry()); | |
232 } | |
233 | |
234 // We don't want to process any incoming interface requests until | |
235 // OnInitialize() is invoked. | |
236 GetInterfaceRegistry()->PauseBinding(); | |
237 | |
238 if (GetContentClient()->gpu()) // NULL in tests. | 224 if (GetContentClient()->gpu()) // NULL in tests. |
239 GetContentClient()->gpu()->Initialize(this); | 225 GetContentClient()->gpu()->Initialize(this); |
240 } | 226 } |
241 | 227 |
242 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name, | 228 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name, |
243 const std::string& group_name) { | 229 const std::string& group_name) { |
244 Send(new GpuHostMsg_FieldTrialActivated(trial_name)); | 230 Send(new GpuHostMsg_FieldTrialActivated(trial_name)); |
245 } | 231 } |
246 | 232 |
247 bool GpuChildThread::Send(IPC::Message* msg) { | 233 bool GpuChildThread::Send(IPC::Message* msg) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 OnDestroyingVideoSurface); | 283 OnDestroyingVideoSurface); |
298 #endif | 284 #endif |
299 IPC_MESSAGE_UNHANDLED(handled = false) | 285 IPC_MESSAGE_UNHANDLED(handled = false) |
300 IPC_END_MESSAGE_MAP() | 286 IPC_END_MESSAGE_MAP() |
301 if (handled) | 287 if (handled) |
302 return true; | 288 return true; |
303 | 289 |
304 return false; | 290 return false; |
305 } | 291 } |
306 | 292 |
| 293 bool GpuChildThread::OnConnect(shell::Connection* connection) { |
| 294 // Use of base::Unretained(this) is safe here because |service_registry()| |
| 295 // will be destroyed before GpuChildThread is destructed. |
| 296 connection->GetInterfaceRegistry()->AddInterface(base::Bind( |
| 297 &GpuChildThread::BindProcessControlRequest, base::Unretained(this))); |
| 298 |
| 299 if (GetContentClient()->gpu()) { // NULL in tests. |
| 300 GetContentClient()->gpu()->ExposeInterfacesToBrowser( |
| 301 connection->GetInterfaceRegistry()); |
| 302 } |
| 303 |
| 304 // We don't want to process any incoming interface requests until |
| 305 // OnInitialize(). |
| 306 if (!gpu_channel_manager_) { |
| 307 connection->GetInterfaceRegistry()->PauseBinding(); |
| 308 resume_interface_bindings_callback_ = base::Bind( |
| 309 &shell::InterfaceRegistry::ResumeBinding, |
| 310 connection->GetInterfaceRegistry()->GetWeakPtr()); |
| 311 } |
| 312 |
| 313 return true; |
| 314 } |
| 315 |
| 316 shell::InterfaceRegistry* GpuChildThread::GetInterfaceRegistryForConnection() { |
| 317 return nullptr; |
| 318 } |
| 319 |
| 320 shell::InterfaceProvider* GpuChildThread::GetInterfaceProviderForConnection() { |
| 321 return nullptr; |
| 322 } |
| 323 |
307 void GpuChildThread::SetActiveURL(const GURL& url) { | 324 void GpuChildThread::SetActiveURL(const GURL& url) { |
308 GetContentClient()->SetActiveURL(url); | 325 GetContentClient()->SetActiveURL(url); |
309 } | 326 } |
310 | 327 |
311 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) { | 328 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) { |
312 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url)); | 329 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url)); |
313 } | 330 } |
314 | 331 |
315 void GpuChildThread::DidDestroyChannel(int client_id) { | 332 void GpuChildThread::DidDestroyChannel(int client_id) { |
316 media_service_->RemoveChannel(client_id); | 333 media_service_->RemoveChannel(client_id); |
(...skipping 23 matching lines...) Expand all Loading... |
340 } | 357 } |
341 #endif | 358 #endif |
342 | 359 |
343 void GpuChildThread::StoreShaderToDisk(int32_t client_id, | 360 void GpuChildThread::StoreShaderToDisk(int32_t client_id, |
344 const std::string& key, | 361 const std::string& key, |
345 const std::string& shader) { | 362 const std::string& shader) { |
346 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); | 363 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); |
347 } | 364 } |
348 | 365 |
349 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { | 366 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { |
350 GetInterfaceRegistry()->ResumeBinding(); | 367 if (!resume_interface_bindings_callback_.is_null()) |
| 368 base::ResetAndReturn(&resume_interface_bindings_callback_).Run(); |
351 | 369 |
352 gpu_preferences_ = gpu_preferences; | 370 gpu_preferences_ = gpu_preferences; |
353 | 371 |
354 gpu_info_.video_decode_accelerator_capabilities = | 372 gpu_info_.video_decode_accelerator_capabilities = |
355 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 373 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
356 gpu_info_.video_encode_accelerator_supported_profiles = | 374 gpu_info_.video_encode_accelerator_supported_profiles = |
357 media::GpuVideoEncodeAccelerator::GetSupportedProfiles( | 375 media::GpuVideoEncodeAccelerator::GetSupportedProfiles( |
358 gpu_preferences_); | 376 gpu_preferences_); |
359 gpu_info_.jpeg_decode_accelerator_supported = | 377 gpu_info_.jpeg_decode_accelerator_supported = |
360 media::GpuJpegDecodeAccelerator::IsSupported(); | 378 media::GpuJpegDecodeAccelerator::IsSupported(); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 #endif | 577 #endif |
560 | 578 |
561 void GpuChildThread::OnLoseAllContexts() { | 579 void GpuChildThread::OnLoseAllContexts() { |
562 if (gpu_channel_manager_) { | 580 if (gpu_channel_manager_) { |
563 gpu_channel_manager_->DestroyAllChannels(); | 581 gpu_channel_manager_->DestroyAllChannels(); |
564 media_service_->DestroyAllChannels(); | 582 media_service_->DestroyAllChannels(); |
565 } | 583 } |
566 } | 584 } |
567 | 585 |
568 void GpuChildThread::BindProcessControlRequest( | 586 void GpuChildThread::BindProcessControlRequest( |
569 mojom::ProcessControlRequest request) { | 587 mojo::InterfaceRequest<mojom::ProcessControl> request) { |
570 DVLOG(1) << "GPU: Binding ProcessControl request"; | 588 DVLOG(1) << "GPU: Binding ProcessControl request"; |
571 DCHECK(process_control_); | 589 DCHECK(process_control_); |
572 process_control_bindings_.AddBinding(process_control_.get(), | 590 process_control_bindings_.AddBinding(process_control_.get(), |
573 std::move(request)); | 591 std::move(request)); |
574 } | 592 } |
575 | 593 |
576 } // namespace content | 594 } // namespace content |
OLD | NEW |