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 |
49 bool GpuProcessLogMessageHandler(int severity, | 58 bool GpuProcessLogMessageHandler(int severity, |
50 const char* file, int line, | 59 const char* file, int line, |
51 size_t message_start, | 60 size_t message_start, |
52 const std::string& str) { | 61 const std::string& str) { |
53 std::string header = str.substr(0, message_start); | 62 std::string header = str.substr(0, message_start); |
54 std::string message = str.substr(message_start); | 63 std::string message = str.substr(message_start); |
55 | 64 |
56 g_thread_safe_sender.Get()->Send( | 65 g_thread_safe_sender.Get()->Send( |
57 new GpuHostMsg_OnLogMessage(severity, header, message)); | 66 new GpuHostMsg_OnLogMessage(severity, header, message)); |
58 | 67 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } // namespace | 151 } // namespace |
143 | 152 |
144 GpuChildThread::GpuChildThread( | 153 GpuChildThread::GpuChildThread( |
145 GpuWatchdogThread* watchdog_thread, | 154 GpuWatchdogThread* watchdog_thread, |
146 bool dead_on_arrival, | 155 bool dead_on_arrival, |
147 const gpu::GPUInfo& gpu_info, | 156 const gpu::GPUInfo& gpu_info, |
148 const DeferredMessages& deferred_messages, | 157 const DeferredMessages& deferred_messages, |
149 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 158 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
150 gpu::SyncPointManager* sync_point_manager) | 159 gpu::SyncPointManager* sync_point_manager) |
151 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 160 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
| 161 gpu_preferences_(GetGpuPreferencesFromCommandLine()), |
152 dead_on_arrival_(dead_on_arrival), | 162 dead_on_arrival_(dead_on_arrival), |
153 sync_point_manager_(sync_point_manager), | 163 sync_point_manager_(sync_point_manager), |
154 gpu_info_(gpu_info), | 164 gpu_info_(gpu_info), |
155 deferred_messages_(deferred_messages), | 165 deferred_messages_(deferred_messages), |
156 in_browser_process_(false), | 166 in_browser_process_(false), |
157 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 167 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
158 watchdog_thread_ = watchdog_thread; | 168 watchdog_thread_ = watchdog_thread; |
159 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
160 target_services_ = NULL; | 170 target_services_ = NULL; |
161 #endif | 171 #endif |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 child_window)); | 341 child_window)); |
332 } | 342 } |
333 #endif | 343 #endif |
334 | 344 |
335 void GpuChildThread::StoreShaderToDisk(int32_t client_id, | 345 void GpuChildThread::StoreShaderToDisk(int32_t client_id, |
336 const std::string& key, | 346 const std::string& key, |
337 const std::string& shader) { | 347 const std::string& shader) { |
338 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); | 348 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); |
339 } | 349 } |
340 | 350 |
341 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { | 351 void GpuChildThread::OnInitialize() { |
342 gpu_preferences_ = gpu_preferences; | |
343 // Record initialization only after collecting the GPU info because that can | 352 // Record initialization only after collecting the GPU info because that can |
344 // take a significant amount of time. | 353 // take a significant amount of time. |
345 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; | 354 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; |
346 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); | 355 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); |
347 while (!deferred_messages_.empty()) { | 356 while (!deferred_messages_.empty()) { |
348 Send(deferred_messages_.front()); | 357 Send(deferred_messages_.front()); |
349 deferred_messages_.pop(); | 358 deferred_messages_.pop(); |
350 } | 359 } |
351 | 360 |
352 if (dead_on_arrival_) { | 361 if (dead_on_arrival_) { |
(...skipping 30 matching lines...) Expand all Loading... |
383 // Quit the GPU process | 392 // Quit the GPU process |
384 base::MessageLoop::current()->QuitWhenIdle(); | 393 base::MessageLoop::current()->QuitWhenIdle(); |
385 } | 394 } |
386 | 395 |
387 void GpuChildThread::StopWatchdog() { | 396 void GpuChildThread::StopWatchdog() { |
388 if (watchdog_thread_.get()) { | 397 if (watchdog_thread_.get()) { |
389 watchdog_thread_->Stop(); | 398 watchdog_thread_->Stop(); |
390 } | 399 } |
391 } | 400 } |
392 | 401 |
| 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 |
393 void GpuChildThread::OnCollectGraphicsInfo() { | 466 void GpuChildThread::OnCollectGraphicsInfo() { |
394 #if defined(OS_WIN) | 467 #if defined(OS_WIN) |
395 // GPU full info collection should only happen on un-sandboxed GPU process | 468 // GPU full info collection should only happen on un-sandboxed GPU process |
396 // or single process/in-process gpu mode on Windows. | 469 // or single process/in-process gpu mode on Windows. |
397 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 470 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
398 DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || | 471 DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || |
399 in_browser_process_); | 472 in_browser_process_); |
400 #endif // OS_WIN | 473 #endif // OS_WIN |
401 | 474 |
402 gpu::CollectInfoResult result = | 475 gpu::CollectInfoResult result = |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 614 |
542 void GpuChildThread::BindProcessControlRequest( | 615 void GpuChildThread::BindProcessControlRequest( |
543 mojo::InterfaceRequest<ProcessControl> request) { | 616 mojo::InterfaceRequest<ProcessControl> request) { |
544 DVLOG(1) << "GPU: Binding ProcessControl request"; | 617 DVLOG(1) << "GPU: Binding ProcessControl request"; |
545 DCHECK(process_control_); | 618 DCHECK(process_control_); |
546 process_control_bindings_.AddBinding(process_control_.get(), | 619 process_control_bindings_.AddBinding(process_control_.get(), |
547 std::move(request)); | 620 std::move(request)); |
548 } | 621 } |
549 | 622 |
550 } // namespace content | 623 } // namespace content |
OLD | NEW |