| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "ui/ozone/public/gpu_platform_support.h" | 39 #include "ui/ozone/public/gpu_platform_support.h" |
| 40 #include "ui/ozone/public/ozone_platform.h" | 40 #include "ui/ozone/public/ozone_platform.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 namespace content { | 43 namespace content { |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 46 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
| 47 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 47 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
| 48 | 48 |
| 49 bool GetSizeTFromSwitch(const base::CommandLine* command_line, | |
| 50 const base::StringPiece& switch_string, | |
| 51 size_t* value) { | |
| 52 if (!command_line->HasSwitch(switch_string)) | |
| 53 return false; | |
| 54 std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); | |
| 55 return base::StringToSizeT(switch_value, value); | |
| 56 } | |
| 57 | |
| 58 bool GpuProcessLogMessageHandler(int severity, | 49 bool GpuProcessLogMessageHandler(int severity, |
| 59 const char* file, int line, | 50 const char* file, int line, |
| 60 size_t message_start, | 51 size_t message_start, |
| 61 const std::string& str) { | 52 const std::string& str) { |
| 62 std::string header = str.substr(0, message_start); | 53 std::string header = str.substr(0, message_start); |
| 63 std::string message = str.substr(message_start); | 54 std::string message = str.substr(message_start); |
| 64 | 55 |
| 65 g_thread_safe_sender.Get()->Send( | 56 g_thread_safe_sender.Get()->Send( |
| 66 new GpuHostMsg_OnLogMessage(severity, header, message)); | 57 new GpuHostMsg_OnLogMessage(severity, header, message)); |
| 67 | 58 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } // namespace | 142 } // namespace |
| 152 | 143 |
| 153 GpuChildThread::GpuChildThread( | 144 GpuChildThread::GpuChildThread( |
| 154 GpuWatchdogThread* watchdog_thread, | 145 GpuWatchdogThread* watchdog_thread, |
| 155 bool dead_on_arrival, | 146 bool dead_on_arrival, |
| 156 const gpu::GPUInfo& gpu_info, | 147 const gpu::GPUInfo& gpu_info, |
| 157 const DeferredMessages& deferred_messages, | 148 const DeferredMessages& deferred_messages, |
| 158 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 149 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 159 gpu::SyncPointManager* sync_point_manager) | 150 gpu::SyncPointManager* sync_point_manager) |
| 160 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 151 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
| 161 gpu_preferences_(GetGpuPreferencesFromCommandLine()), | |
| 162 dead_on_arrival_(dead_on_arrival), | 152 dead_on_arrival_(dead_on_arrival), |
| 163 sync_point_manager_(sync_point_manager), | 153 sync_point_manager_(sync_point_manager), |
| 164 gpu_info_(gpu_info), | 154 gpu_info_(gpu_info), |
| 165 deferred_messages_(deferred_messages), | 155 deferred_messages_(deferred_messages), |
| 166 in_browser_process_(false), | 156 in_browser_process_(false), |
| 167 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 157 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
| 168 watchdog_thread_ = watchdog_thread; | 158 watchdog_thread_ = watchdog_thread; |
| 169 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 170 target_services_ = NULL; | 160 target_services_ = NULL; |
| 171 #endif | 161 #endif |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 child_window)); | 331 child_window)); |
| 342 } | 332 } |
| 343 #endif | 333 #endif |
| 344 | 334 |
| 345 void GpuChildThread::StoreShaderToDisk(int32_t client_id, | 335 void GpuChildThread::StoreShaderToDisk(int32_t client_id, |
| 346 const std::string& key, | 336 const std::string& key, |
| 347 const std::string& shader) { | 337 const std::string& shader) { |
| 348 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); | 338 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); |
| 349 } | 339 } |
| 350 | 340 |
| 351 void GpuChildThread::OnInitialize() { | 341 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { |
| 342 gpu_preferences_ = gpu_preferences; |
| 352 // Record initialization only after collecting the GPU info because that can | 343 // Record initialization only after collecting the GPU info because that can |
| 353 // take a significant amount of time. | 344 // take a significant amount of time. |
| 354 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; | 345 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; |
| 355 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); | 346 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); |
| 356 while (!deferred_messages_.empty()) { | 347 while (!deferred_messages_.empty()) { |
| 357 Send(deferred_messages_.front()); | 348 Send(deferred_messages_.front()); |
| 358 deferred_messages_.pop(); | 349 deferred_messages_.pop(); |
| 359 } | 350 } |
| 360 | 351 |
| 361 if (dead_on_arrival_) { | 352 if (dead_on_arrival_) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 392 // Quit the GPU process | 383 // Quit the GPU process |
| 393 base::MessageLoop::current()->QuitWhenIdle(); | 384 base::MessageLoop::current()->QuitWhenIdle(); |
| 394 } | 385 } |
| 395 | 386 |
| 396 void GpuChildThread::StopWatchdog() { | 387 void GpuChildThread::StopWatchdog() { |
| 397 if (watchdog_thread_.get()) { | 388 if (watchdog_thread_.get()) { |
| 398 watchdog_thread_->Stop(); | 389 watchdog_thread_->Stop(); |
| 399 } | 390 } |
| 400 } | 391 } |
| 401 | 392 |
| 402 // static | |
| 403 gpu::GpuPreferences GpuChildThread::GetGpuPreferencesFromCommandLine() { | |
| 404 // TODO(penghuang): share below code with | |
| 405 // android_webview/browser/deferred_gpu_command_service.cc | |
| 406 // http://crbug.com/590825 | |
| 407 // For any modification of below code, deferred_gpu_command_service.cc should | |
| 408 // be updated as well. | |
| 409 DCHECK(base::CommandLine::InitializedForCurrentProcess()); | |
| 410 const base::CommandLine* command_line = | |
| 411 base::CommandLine::ForCurrentProcess(); | |
| 412 gpu::GpuPreferences gpu_preferences; | |
| 413 gpu_preferences.single_process = | |
| 414 command_line->HasSwitch(switches::kSingleProcess); | |
| 415 gpu_preferences.in_process_gpu = | |
| 416 command_line->HasSwitch(switches::kInProcessGPU); | |
| 417 gpu_preferences.ui_prioritize_in_gpu_process = | |
| 418 command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess); | |
| 419 gpu_preferences.compile_shader_always_succeeds = | |
| 420 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); | |
| 421 gpu_preferences.disable_gl_error_limit = | |
| 422 command_line->HasSwitch(switches::kDisableGLErrorLimit); | |
| 423 gpu_preferences.disable_glsl_translator = | |
| 424 command_line->HasSwitch(switches::kDisableGLSLTranslator); | |
| 425 gpu_preferences.disable_gpu_driver_bug_workarounds = | |
| 426 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); | |
| 427 gpu_preferences.disable_shader_name_hashing = | |
| 428 command_line->HasSwitch(switches::kDisableShaderNameHashing); | |
| 429 gpu_preferences.enable_gpu_command_logging = | |
| 430 command_line->HasSwitch(switches::kEnableGPUCommandLogging); | |
| 431 gpu_preferences.enable_gpu_debugging = | |
| 432 command_line->HasSwitch(switches::kEnableGPUDebugging); | |
| 433 gpu_preferences.enable_gpu_service_logging_gpu = | |
| 434 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); | |
| 435 gpu_preferences.disable_gpu_program_cache = | |
| 436 command_line->HasSwitch(switches::kDisableGpuProgramCache); | |
| 437 gpu_preferences.enforce_gl_minimums = | |
| 438 command_line->HasSwitch(switches::kEnforceGLMinimums); | |
| 439 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb, | |
| 440 &gpu_preferences.force_gpu_mem_available)) { | |
| 441 gpu_preferences.force_gpu_mem_available *= 1024 * 1024; | |
| 442 } | |
| 443 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, | |
| 444 &gpu_preferences.gpu_program_cache_size)) { | |
| 445 gpu_preferences.gpu_program_cache_size *= 1024; | |
| 446 } | |
| 447 gpu_preferences.enable_share_group_async_texture_upload = | |
| 448 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload); | |
| 449 gpu_preferences.enable_subscribe_uniform_extension = | |
| 450 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); | |
| 451 gpu_preferences.enable_threaded_texture_mailboxes = | |
| 452 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); | |
| 453 gpu_preferences.gl_shader_interm_output = | |
| 454 command_line->HasSwitch(switches::kGLShaderIntermOutput); | |
| 455 gpu_preferences.emulate_shader_precision = | |
| 456 command_line->HasSwitch(switches::kEmulateShaderPrecision); | |
| 457 gpu_preferences.enable_gpu_service_logging = | |
| 458 command_line->HasSwitch(switches::kEnableGPUServiceLogging); | |
| 459 gpu_preferences.enable_gpu_service_tracing = | |
| 460 command_line->HasSwitch(switches::kEnableGPUServiceTracing); | |
| 461 gpu_preferences.enable_unsafe_es3_apis = | |
| 462 command_line->HasSwitch(switches::kEnableUnsafeES3APIs); | |
| 463 return gpu_preferences; | |
| 464 } | |
| 465 | |
| 466 void GpuChildThread::OnCollectGraphicsInfo() { | 393 void GpuChildThread::OnCollectGraphicsInfo() { |
| 467 #if defined(OS_WIN) | 394 #if defined(OS_WIN) |
| 468 // GPU full info collection should only happen on un-sandboxed GPU process | 395 // GPU full info collection should only happen on un-sandboxed GPU process |
| 469 // or single process/in-process gpu mode on Windows. | 396 // or single process/in-process gpu mode on Windows. |
| 470 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 397 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 471 DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || | 398 DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || |
| 472 in_browser_process_); | 399 in_browser_process_); |
| 473 #endif // OS_WIN | 400 #endif // OS_WIN |
| 474 | 401 |
| 475 gpu::CollectInfoResult result = | 402 gpu::CollectInfoResult result = |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 541 |
| 615 void GpuChildThread::BindProcessControlRequest( | 542 void GpuChildThread::BindProcessControlRequest( |
| 616 mojo::InterfaceRequest<ProcessControl> request) { | 543 mojo::InterfaceRequest<ProcessControl> request) { |
| 617 DVLOG(1) << "GPU: Binding ProcessControl request"; | 544 DVLOG(1) << "GPU: Binding ProcessControl request"; |
| 618 DCHECK(process_control_); | 545 DCHECK(process_control_); |
| 619 process_control_bindings_.AddBinding(process_control_.get(), | 546 process_control_bindings_.AddBinding(process_control_.get(), |
| 620 std::move(request)); | 547 std::move(request)); |
| 621 } | 548 } |
| 622 | 549 |
| 623 } // namespace content | 550 } // namespace content |
| OLD | NEW |