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