| 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/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "content/child/child_process.h" | 15 #include "content/child/child_process.h" |
| 15 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
| 16 #include "content/common/gpu/establish_channel_params.h" | 17 #include "content/common/gpu/establish_channel_params.h" |
| 17 #include "content/common/gpu/gpu_host_messages.h" | 18 #include "content/common/gpu/gpu_host_messages.h" |
| 18 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 19 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 19 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | 20 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
| 20 #include "content/gpu/gpu_process_control_impl.h" | 21 #include "content/gpu/gpu_process_control_impl.h" |
| 21 #include "content/gpu/gpu_watchdog_thread.h" | 22 #include "content/gpu/gpu_watchdog_thread.h" |
| 22 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
| 23 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/gpu/content_gpu_client.h" | 25 #include "content/public/gpu/content_gpu_client.h" |
| 26 #include "gpu/command_buffer/service/gpu_switches.h" |
| 25 #include "gpu/config/gpu_info_collector.h" | 27 #include "gpu/config/gpu_info_collector.h" |
| 28 #include "gpu/config/gpu_switches.h" |
| 29 #include "gpu/config/gpu_util.h" |
| 26 #include "ipc/ipc_channel_handle.h" | 30 #include "ipc/ipc_channel_handle.h" |
| 27 #include "ipc/ipc_sync_message_filter.h" | 31 #include "ipc/ipc_sync_message_filter.h" |
| 28 #include "ui/gl/gl_implementation.h" | 32 #include "ui/gl/gl_implementation.h" |
| 33 #include "ui/gl/gl_switches.h" |
| 29 #include "ui/gl/gpu_switching_manager.h" | 34 #include "ui/gl/gpu_switching_manager.h" |
| 30 | 35 |
| 31 #if defined(USE_OZONE) | 36 #if defined(USE_OZONE) |
| 32 #include "ui/ozone/public/gpu_platform_support.h" | 37 #include "ui/ozone/public/gpu_platform_support.h" |
| 33 #include "ui/ozone/public/ozone_platform.h" | 38 #include "ui/ozone/public/ozone_platform.h" |
| 34 #endif | 39 #endif |
| 35 | 40 |
| 36 namespace content { | 41 namespace content { |
| 37 namespace { | 42 namespace { |
| 38 | 43 |
| 39 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 44 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
| 40 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 45 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
| 41 | 46 |
| 47 bool GetSizeTFromSwitch(const base::CommandLine* command_line, |
| 48 const base::StringPiece& switch_string, |
| 49 size_t* value) { |
| 50 if (!command_line->HasSwitch(switch_string)) |
| 51 return false; |
| 52 std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 53 return base::StringToSizeT(switch_value, value); |
| 54 } |
| 55 |
| 56 gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { |
| 57 // TODO(penghuang): share below code with |
| 58 // android_webview/browser/deferred_gpu_command_service.cc |
| 59 // http://crbug.com/590825 |
| 60 // For any modification of below code, deferred_gpu_command_service.cc should |
| 61 // be updated as well. |
| 62 DCHECK(base::CommandLine::InitializedForCurrentProcess()); |
| 63 const base::CommandLine* command_line = |
| 64 base::CommandLine::ForCurrentProcess(); |
| 65 gpu::GpuPreferences gpu_preferences; |
| 66 gpu_preferences.single_process = |
| 67 command_line->HasSwitch(switches::kSingleProcess); |
| 68 gpu_preferences.in_process_gpu = |
| 69 command_line->HasSwitch(switches::kInProcessGPU); |
| 70 gpu_preferences.ui_prioritize_in_gpu_process = |
| 71 command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess); |
| 72 gpu_preferences.compile_shader_always_succeeds = |
| 73 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| 74 gpu_preferences.disable_gl_error_limit = |
| 75 command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| 76 gpu_preferences.disable_glsl_translator = |
| 77 command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| 78 gpu_preferences.disable_gpu_driver_bug_workarounds = |
| 79 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); |
| 80 gpu_preferences.disable_shader_name_hashing = |
| 81 command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| 82 gpu_preferences.enable_gpu_command_logging = |
| 83 command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| 84 gpu_preferences.enable_gpu_debugging = |
| 85 command_line->HasSwitch(switches::kEnableGPUDebugging); |
| 86 gpu_preferences.enable_gpu_service_logging_gpu = |
| 87 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| 88 gpu_preferences.disable_gpu_program_cache = |
| 89 command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| 90 gpu_preferences.enforce_gl_minimums = |
| 91 command_line->HasSwitch(switches::kEnforceGLMinimums); |
| 92 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
| 93 &gpu_preferences.force_gpu_mem_available)) { |
| 94 gpu_preferences.force_gpu_mem_available *= 1024 * 1024; |
| 95 } |
| 96 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, |
| 97 &gpu_preferences.gpu_program_cache_size)) { |
| 98 gpu_preferences.gpu_program_cache_size *= 1024; |
| 99 } |
| 100 gpu_preferences.enable_share_group_async_texture_upload = |
| 101 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload); |
| 102 gpu_preferences.enable_subscribe_uniform_extension = |
| 103 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); |
| 104 gpu_preferences.enable_threaded_texture_mailboxes = |
| 105 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); |
| 106 gpu_preferences.gl_shader_interm_output = |
| 107 command_line->HasSwitch(switches::kGLShaderIntermOutput); |
| 108 gpu_preferences.emulate_shader_precision = |
| 109 command_line->HasSwitch(switches::kEmulateShaderPrecision); |
| 110 gpu_preferences.enable_gpu_service_logging = |
| 111 command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| 112 gpu_preferences.enable_gpu_service_tracing = |
| 113 command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| 114 gpu_preferences.enable_unsafe_es3_apis = |
| 115 command_line->HasSwitch(switches::kEnableUnsafeES3APIs); |
| 116 return gpu_preferences; |
| 117 } |
| 118 |
| 42 bool GpuProcessLogMessageHandler(int severity, | 119 bool GpuProcessLogMessageHandler(int severity, |
| 43 const char* file, int line, | 120 const char* file, int line, |
| 44 size_t message_start, | 121 size_t message_start, |
| 45 const std::string& str) { | 122 const std::string& str) { |
| 46 std::string header = str.substr(0, message_start); | 123 std::string header = str.substr(0, message_start); |
| 47 std::string message = str.substr(message_start); | 124 std::string message = str.substr(message_start); |
| 48 | 125 |
| 49 g_thread_safe_sender.Get()->Send( | 126 g_thread_safe_sender.Get()->Send( |
| 50 new GpuHostMsg_OnLogMessage(severity, header, message)); | 127 new GpuHostMsg_OnLogMessage(severity, header, message)); |
| 51 | 128 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } // namespace | 212 } // namespace |
| 136 | 213 |
| 137 GpuChildThread::GpuChildThread( | 214 GpuChildThread::GpuChildThread( |
| 138 GpuWatchdogThread* watchdog_thread, | 215 GpuWatchdogThread* watchdog_thread, |
| 139 bool dead_on_arrival, | 216 bool dead_on_arrival, |
| 140 const gpu::GPUInfo& gpu_info, | 217 const gpu::GPUInfo& gpu_info, |
| 141 const DeferredMessages& deferred_messages, | 218 const DeferredMessages& deferred_messages, |
| 142 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 219 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 143 gpu::SyncPointManager* sync_point_manager) | 220 gpu::SyncPointManager* sync_point_manager) |
| 144 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 221 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
| 222 gpu_preferences_(GetGpuPreferencesFromCommandLine()), |
| 145 dead_on_arrival_(dead_on_arrival), | 223 dead_on_arrival_(dead_on_arrival), |
| 146 sync_point_manager_(sync_point_manager), | 224 sync_point_manager_(sync_point_manager), |
| 147 gpu_info_(gpu_info), | 225 gpu_info_(gpu_info), |
| 148 deferred_messages_(deferred_messages), | 226 deferred_messages_(deferred_messages), |
| 149 in_browser_process_(false), | 227 in_browser_process_(false), |
| 150 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 228 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
| 151 watchdog_thread_ = watchdog_thread; | 229 watchdog_thread_ = watchdog_thread; |
| 152 #if defined(OS_WIN) | 230 #if defined(OS_WIN) |
| 153 target_services_ = NULL; | 231 target_services_ = NULL; |
| 154 #endif | 232 #endif |
| 155 g_thread_safe_sender.Get() = thread_safe_sender(); | 233 g_thread_safe_sender.Get() = thread_safe_sender(); |
| 156 } | 234 } |
| 157 | 235 |
| 158 GpuChildThread::GpuChildThread( | 236 GpuChildThread::GpuChildThread( |
| 237 const gpu::GpuPreferences* gpu_preferences, |
| 159 const InProcessChildThreadParams& params, | 238 const InProcessChildThreadParams& params, |
| 160 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 239 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 161 gpu::SyncPointManager* sync_point_manager) | 240 gpu::SyncPointManager* sync_point_manager) |
| 162 : ChildThreadImpl(ChildThreadImpl::Options::Builder() | 241 : ChildThreadImpl(ChildThreadImpl::Options::Builder() |
| 163 .InBrowserProcess(params) | 242 .InBrowserProcess(params) |
| 164 .AddStartupFilter(new GpuMemoryBufferMessageFilter( | 243 .AddStartupFilter(new GpuMemoryBufferMessageFilter( |
| 165 gpu_memory_buffer_factory)) | 244 gpu_memory_buffer_factory)) |
| 166 .Build()), | 245 .Build()), |
| 246 gpu_preferences_(gpu_preferences ? |
| 247 *gpu_preferences : GetGpuPreferencesFromCommandLine()), |
| 167 dead_on_arrival_(false), | 248 dead_on_arrival_(false), |
| 168 sync_point_manager_(sync_point_manager), | 249 sync_point_manager_(sync_point_manager), |
| 169 in_browser_process_(true), | 250 in_browser_process_(true), |
| 170 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 251 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
| 171 #if defined(OS_WIN) | 252 #if defined(OS_WIN) |
| 172 target_services_ = NULL; | 253 target_services_ = NULL; |
| 173 #endif | 254 #endif |
| 174 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 255 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 175 switches::kSingleProcess) || | 256 switches::kSingleProcess) || |
| 176 base::CommandLine::ForCurrentProcess()->HasSwitch( | 257 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 431 } |
| 351 | 432 |
| 352 // We don't need to pipe log messages if we are running the GPU thread in | 433 // We don't need to pipe log messages if we are running the GPU thread in |
| 353 // the browser process. | 434 // the browser process. |
| 354 if (!in_browser_process_) | 435 if (!in_browser_process_) |
| 355 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 436 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
| 356 | 437 |
| 357 // Defer creation of the render thread. This is to prevent it from handling | 438 // Defer creation of the render thread. This is to prevent it from handling |
| 358 // IPC messages before the sandbox has been enabled and all other necessary | 439 // IPC messages before the sandbox has been enabled and all other necessary |
| 359 // initialization has succeeded. | 440 // initialization has succeeded. |
| 360 gpu_channel_manager_.reset(new GpuChannelManager( | 441 gpu_channel_manager_.reset( |
| 361 this, watchdog_thread_.get(), base::ThreadTaskRunnerHandle::Get().get(), | 442 new GpuChannelManager(gpu_preferences_, this, watchdog_thread_.get(), |
| 362 ChildProcess::current()->io_task_runner(), | 443 base::ThreadTaskRunnerHandle::Get().get(), |
| 363 ChildProcess::current()->GetShutDownEvent(), sync_point_manager_, | 444 ChildProcess::current()->io_task_runner(), |
| 364 gpu_memory_buffer_factory_)); | 445 ChildProcess::current()->GetShutDownEvent(), |
| 446 sync_point_manager_, gpu_memory_buffer_factory_)); |
| 365 | 447 |
| 366 #if defined(USE_OZONE) | 448 #if defined(USE_OZONE) |
| 367 ui::OzonePlatform::GetInstance() | 449 ui::OzonePlatform::GetInstance() |
| 368 ->GetGpuPlatformSupport() | 450 ->GetGpuPlatformSupport() |
| 369 ->OnChannelEstablished(this); | 451 ->OnChannelEstablished(this); |
| 370 #endif | 452 #endif |
| 371 } | 453 } |
| 372 | 454 |
| 373 void GpuChildThread::OnFinalize() { | 455 void GpuChildThread::OnFinalize() { |
| 374 // Quit the GPU process | 456 // Quit the GPU process |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 607 |
| 526 void GpuChildThread::BindProcessControlRequest( | 608 void GpuChildThread::BindProcessControlRequest( |
| 527 mojo::InterfaceRequest<ProcessControl> request) { | 609 mojo::InterfaceRequest<ProcessControl> request) { |
| 528 DVLOG(1) << "GPU: Binding ProcessControl request"; | 610 DVLOG(1) << "GPU: Binding ProcessControl request"; |
| 529 DCHECK(process_control_); | 611 DCHECK(process_control_); |
| 530 process_control_bindings_.AddBinding(process_control_.get(), | 612 process_control_bindings_.AddBinding(process_control_.get(), |
| 531 std::move(request)); | 613 std::move(request)); |
| 532 } | 614 } |
| 533 | 615 |
| 534 } // namespace content | 616 } // namespace content |
| OLD | NEW |