Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: content/gpu/gpu_child_thread.cc

Issue 1716813002: Use GpuPreferences to avoid directly accessing switches in gpu related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // For any modification of below code, deferred_gpu_command_service.cc should
60 // be updated as well.
61 DCHECK(base::CommandLine::InitializedForCurrentProcess());
62 const base::CommandLine* command_line =
63 base::CommandLine::ForCurrentProcess();
64 gpu::GpuPreferences gpu_preferences;
65 gpu_preferences.single_process =
66 command_line->HasSwitch(switches::kSingleProcess);
67 gpu_preferences.in_process_gpu =
68 command_line->HasSwitch(switches::kInProcessGPU);
69 gpu_preferences.ui_prioritize_in_gpu_process =
70 command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess);
71 gpu_preferences.compile_shader_always_succeeds =
72 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
73 gpu_preferences.disable_gl_error_limit =
74 command_line->HasSwitch(switches::kDisableGLErrorLimit);
75 gpu_preferences.disable_glsl_translator =
76 command_line->HasSwitch(switches::kDisableGLSLTranslator);
77 gpu_preferences.disable_gpu_driver_bug_workarounds =
78 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
79 gpu_preferences.disable_shader_name_hashing =
80 command_line->HasSwitch(switches::kDisableShaderNameHashing);
81 gpu_preferences.enable_gpu_command_logging =
82 command_line->HasSwitch(switches::kEnableGPUCommandLogging);
83 gpu_preferences.enable_gpu_debugging =
84 command_line->HasSwitch(switches::kEnableGPUDebugging);
85 gpu_preferences.enable_gpu_service_logging_gpu =
86 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
87 gpu_preferences.disable_gpu_program_cache =
88 command_line->HasSwitch(switches::kDisableGpuProgramCache);
89 gpu_preferences.enforce_gl_minimums =
90 command_line->HasSwitch(switches::kEnforceGLMinimums);
91 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
92 &gpu_preferences.force_gpu_mem_available)) {
93 gpu_preferences.force_gpu_mem_available *= 1024 * 1024;
94 }
95 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
96 &gpu_preferences.gpu_program_cache_size)) {
97 gpu_preferences.gpu_program_cache_size *= 1024;
98 }
99 gpu_preferences.enable_share_group_async_texture_upload =
100 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload);
101 gpu_preferences.enable_subscribe_uniform_extension =
102 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension);
103 gpu_preferences.enable_threaded_texture_mailboxes =
104 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
105 gpu_preferences.gl_shader_interm_output =
106 command_line->HasSwitch(switches::kGLShaderIntermOutput);
107 gpu_preferences.emulate_shader_precision =
108 command_line->HasSwitch(switches::kEmulateShaderPrecision);
109 gpu_preferences.enable_gl_path_rendering =
110 command_line->HasSwitch(switches::kEnableGLPathRendering);
111 gpu_preferences.enable_gpu_service_logging =
112 command_line->HasSwitch(switches::kEnableGPUServiceLogging);
113 gpu_preferences.enable_gpu_service_tracing =
114 command_line->HasSwitch(switches::kEnableGPUServiceTracing);
115 gpu_preferences.enable_unsafe_es3_apis =
116 command_line->HasSwitch(switches::kEnableUnsafeES3APIs);
117 return gpu_preferences;
118 }
119
42 bool GpuProcessLogMessageHandler(int severity, 120 bool GpuProcessLogMessageHandler(int severity,
43 const char* file, int line, 121 const char* file, int line,
44 size_t message_start, 122 size_t message_start,
45 const std::string& str) { 123 const std::string& str) {
46 std::string header = str.substr(0, message_start); 124 std::string header = str.substr(0, message_start);
47 std::string message = str.substr(message_start); 125 std::string message = str.substr(message_start);
48 126
49 g_thread_safe_sender.Get()->Send( 127 g_thread_safe_sender.Get()->Send(
50 new GpuHostMsg_OnLogMessage(severity, header, message)); 128 new GpuHostMsg_OnLogMessage(severity, header, message));
51 129
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (message_filter) 206 if (message_filter)
129 builder.AddStartupFilter(message_filter); 207 builder.AddStartupFilter(message_filter);
130 #endif 208 #endif
131 209
132 return builder.Build(); 210 return builder.Build();
133 } 211 }
134 212
135 } // namespace 213 } // namespace
136 214
137 GpuChildThread::GpuChildThread( 215 GpuChildThread::GpuChildThread(
216 const gpu::GpuPreferences* gpu_preferences,
138 GpuWatchdogThread* watchdog_thread, 217 GpuWatchdogThread* watchdog_thread,
139 bool dead_on_arrival, 218 bool dead_on_arrival,
140 const gpu::GPUInfo& gpu_info, 219 const gpu::GPUInfo& gpu_info,
141 const DeferredMessages& deferred_messages, 220 const DeferredMessages& deferred_messages,
142 GpuMemoryBufferFactory* gpu_memory_buffer_factory, 221 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
143 gpu::SyncPointManager* sync_point_manager) 222 gpu::SyncPointManager* sync_point_manager)
144 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), 223 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)),
224 gpu_preferences_(gpu_preferences ?
225 *gpu_preferences : GetGpuPreferencesFromCommandLine()),
boliu 2016/02/26 22:17:32 Don't do this. Either make the caller construct a
Peng 2016/02/29 16:09:22 Removed the gpu_preferences for this constructor.
boliu 2016/02/29 16:26:40 const* is generally against the style guide. Eithe
Peng 2016/02/29 19:29:50 https://google.github.io/styleguide/cppguide.html#
boliu 2016/02/29 19:48:22 My earlier point was that some of these switches s
Peng 2016/02/29 20:30:49 If some switches cannot be removed, we will only r
145 dead_on_arrival_(dead_on_arrival), 226 dead_on_arrival_(dead_on_arrival),
146 sync_point_manager_(sync_point_manager), 227 sync_point_manager_(sync_point_manager),
147 gpu_info_(gpu_info), 228 gpu_info_(gpu_info),
148 deferred_messages_(deferred_messages), 229 deferred_messages_(deferred_messages),
149 in_browser_process_(false), 230 in_browser_process_(false),
150 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { 231 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {
151 watchdog_thread_ = watchdog_thread; 232 watchdog_thread_ = watchdog_thread;
152 #if defined(OS_WIN) 233 #if defined(OS_WIN)
153 target_services_ = NULL; 234 target_services_ = NULL;
154 #endif 235 #endif
155 g_thread_safe_sender.Get() = thread_safe_sender(); 236 g_thread_safe_sender.Get() = thread_safe_sender();
156 } 237 }
157 238
158 GpuChildThread::GpuChildThread( 239 GpuChildThread::GpuChildThread(
240 const gpu::GpuPreferences* gpu_preferences,
159 const InProcessChildThreadParams& params, 241 const InProcessChildThreadParams& params,
160 GpuMemoryBufferFactory* gpu_memory_buffer_factory, 242 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
161 gpu::SyncPointManager* sync_point_manager) 243 gpu::SyncPointManager* sync_point_manager)
162 : ChildThreadImpl(ChildThreadImpl::Options::Builder() 244 : ChildThreadImpl(ChildThreadImpl::Options::Builder()
163 .InBrowserProcess(params) 245 .InBrowserProcess(params)
164 .AddStartupFilter(new GpuMemoryBufferMessageFilter( 246 .AddStartupFilter(new GpuMemoryBufferMessageFilter(
165 gpu_memory_buffer_factory)) 247 gpu_memory_buffer_factory))
166 .Build()), 248 .Build()),
249 gpu_preferences_(gpu_preferences ?
250 *gpu_preferences : GetGpuPreferencesFromCommandLine()),
boliu 2016/02/26 22:17:32 ditto
167 dead_on_arrival_(false), 251 dead_on_arrival_(false),
168 sync_point_manager_(sync_point_manager), 252 sync_point_manager_(sync_point_manager),
169 in_browser_process_(true), 253 in_browser_process_(true),
170 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { 254 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {
171 #if defined(OS_WIN) 255 #if defined(OS_WIN)
172 target_services_ = NULL; 256 target_services_ = NULL;
173 #endif 257 #endif
174 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 258 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
175 switches::kSingleProcess) || 259 switches::kSingleProcess) ||
176 base::CommandLine::ForCurrentProcess()->HasSwitch( 260 base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 434 }
351 435
352 // We don't need to pipe log messages if we are running the GPU thread in 436 // We don't need to pipe log messages if we are running the GPU thread in
353 // the browser process. 437 // the browser process.
354 if (!in_browser_process_) 438 if (!in_browser_process_)
355 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); 439 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
356 440
357 // Defer creation of the render thread. This is to prevent it from handling 441 // 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 442 // IPC messages before the sandbox has been enabled and all other necessary
359 // initialization has succeeded. 443 // initialization has succeeded.
360 gpu_channel_manager_.reset(new GpuChannelManager( 444 gpu_channel_manager_.reset(
361 this, watchdog_thread_.get(), base::ThreadTaskRunnerHandle::Get().get(), 445 new GpuChannelManager(gpu_preferences_, this, watchdog_thread_.get(),
362 ChildProcess::current()->io_task_runner(), 446 base::ThreadTaskRunnerHandle::Get().get(),
363 ChildProcess::current()->GetShutDownEvent(), sync_point_manager_, 447 ChildProcess::current()->io_task_runner(),
364 gpu_memory_buffer_factory_)); 448 ChildProcess::current()->GetShutDownEvent(),
449 sync_point_manager_, gpu_memory_buffer_factory_));
365 450
366 #if defined(USE_OZONE) 451 #if defined(USE_OZONE)
367 ui::OzonePlatform::GetInstance() 452 ui::OzonePlatform::GetInstance()
368 ->GetGpuPlatformSupport() 453 ->GetGpuPlatformSupport()
369 ->OnChannelEstablished(this); 454 ->OnChannelEstablished(this);
370 #endif 455 #endif
371 } 456 }
372 457
373 void GpuChildThread::OnFinalize() { 458 void GpuChildThread::OnFinalize() {
374 // Quit the GPU process 459 // Quit the GPU process
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 610
526 void GpuChildThread::BindProcessControlRequest( 611 void GpuChildThread::BindProcessControlRequest(
527 mojo::InterfaceRequest<ProcessControl> request) { 612 mojo::InterfaceRequest<ProcessControl> request) {
528 DVLOG(1) << "GPU: Binding ProcessControl request"; 613 DVLOG(1) << "GPU: Binding ProcessControl request";
529 DCHECK(process_control_); 614 DCHECK(process_control_);
530 process_control_bindings_.AddBinding(process_control_.get(), 615 process_control_bindings_.AddBinding(process_control_.get(),
531 std::move(request)); 616 std::move(request));
532 } 617 }
533 618
534 } // namespace content 619 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698