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

Side by Side Diff: android_webview/browser/deferred_gpu_command_service.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "android_webview/browser/deferred_gpu_command_service.h" 5 #include "android_webview/browser/deferred_gpu_command_service.h"
6 6
7 #include "android_webview/browser/gl_view_renderer_manager.h" 7 #include "android_webview/browser/gl_view_renderer_manager.h"
8 #include "android_webview/browser/shared_renderer_state.h" 8 #include "android_webview/browser/shared_renderer_state.h"
9 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/strings/string_number_conversions.h"
10 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
11 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
12 #include "content/public/browser/android/synchronous_compositor.h" 14 #include "content/public/browser/android/synchronous_compositor.h"
13 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" 15 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h"
16 #include "gpu/command_buffer/service/gpu_switches.h"
14 #include "gpu/command_buffer/service/shader_translator_cache.h" 17 #include "gpu/command_buffer/service/shader_translator_cache.h"
15 #include "gpu/command_buffer/service/sync_point_manager.h" 18 #include "gpu/command_buffer/service/sync_point_manager.h"
19 #include "gpu/config/gpu_switches.h"
20 #include "ui/gl/gl_switches.h"
16 21
17 namespace android_webview { 22 namespace android_webview {
18 23
19 namespace { 24 namespace {
20 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > 25 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> >
21 g_service = LAZY_INSTANCE_INITIALIZER; 26 g_service = LAZY_INSTANCE_INITIALIZER;
27
28 bool GetSizeTFromSwitch(const base::CommandLine* command_line,
29 const base::StringPiece& switch_string,
30 size_t* value) {
31 if (!command_line->HasSwitch(switch_string))
32 return false;
33 std::string switch_value(command_line->GetSwitchValueASCII(switch_string));
34 return base::StringToSizeT(switch_value, value);
35 }
36
22 } // namespace 37 } // namespace
23 38
24 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; 39 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl;
25 40
26 // static 41 // static
27 bool ScopedAllowGL::IsAllowed() { 42 bool ScopedAllowGL::IsAllowed() {
28 return allow_gl.Get().Get(); 43 return allow_gl.Get().Get();
29 } 44 }
30 45
31 ScopedAllowGL::ScopedAllowGL() { 46 ScopedAllowGL::ScopedAllowGL() {
(...skipping 24 matching lines...) Expand all
56 } 71 }
57 } 72 }
58 73
59 // static 74 // static
60 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { 75 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() {
61 DCHECK(g_service.Get().get()); 76 DCHECK(g_service.Get().get());
62 return g_service.Get().get(); 77 return g_service.Get().get();
63 } 78 }
64 79
65 DeferredGpuCommandService::DeferredGpuCommandService() 80 DeferredGpuCommandService::DeferredGpuCommandService()
66 : sync_point_manager_(new gpu::SyncPointManager(true)) {} 81 : gpu::InProcessCommandBuffer::Service(gpu_preferences_),
piman 2016/02/25 21:56:05 Oh, this is confusing/dangerous (and probably unde
Peng 2016/02/25 22:29:08 Done.
82 sync_point_manager_(new gpu::SyncPointManager(true)) {
83 InitGpuPreferences();
84 }
67 85
68 DeferredGpuCommandService::~DeferredGpuCommandService() { 86 DeferredGpuCommandService::~DeferredGpuCommandService() {
69 base::AutoLock lock(tasks_lock_); 87 base::AutoLock lock(tasks_lock_);
70 DCHECK(tasks_.empty()); 88 DCHECK(tasks_.empty());
71 } 89 }
72 90
73 // This method can be called on any thread. 91 // This method can be called on any thread.
74 // static 92 // static
75 void DeferredGpuCommandService::RequestProcessGL(bool for_idle) { 93 void DeferredGpuCommandService::RequestProcessGL(bool for_idle) {
76 SharedRendererState* renderer_state = 94 SharedRendererState* renderer_state =
(...skipping 11 matching lines...) Expand all
88 base::AutoLock lock(tasks_lock_); 106 base::AutoLock lock(tasks_lock_);
89 tasks_.push(task); 107 tasks_.push(task);
90 } 108 }
91 if (ScopedAllowGL::IsAllowed()) { 109 if (ScopedAllowGL::IsAllowed()) {
92 RunTasks(); 110 RunTasks();
93 } else { 111 } else {
94 RequestProcessGL(false); 112 RequestProcessGL(false);
95 } 113 }
96 } 114 }
97 115
116 void DeferredGpuCommandService::InitGpuPreferences() {
117 DCHECK(base::CommandLine::InitializedForCurrentProcess());
118 const base::CommandLine* command_line =
119 base::CommandLine::ForCurrentProcess();
120 gpu_preferences_.single_process = true;
121 gpu_preferences_.in_process_gpu = true;
122 // TODO(penghuang): share below code with content/gpu/gpu_child_thread.cc
123 gpu_preferences_.compile_shader_always_succeeds =
124 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
125 gpu_preferences_.disable_gl_error_limit =
126 command_line->HasSwitch(switches::kDisableGLErrorLimit);
127 gpu_preferences_.disable_glsl_translator =
128 command_line->HasSwitch(switches::kDisableGLSLTranslator);
129 gpu_preferences_.disable_gpu_driver_bug_workarounds =
130 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
131 gpu_preferences_.disable_shader_name_hashing =
132 command_line->HasSwitch(switches::kDisableShaderNameHashing);
133 gpu_preferences_.enable_gpu_command_logging =
134 command_line->HasSwitch(switches::kEnableGPUCommandLogging);
135 gpu_preferences_.enable_gpu_debugging =
136 command_line->HasSwitch(switches::kEnableGPUDebugging);
137 gpu_preferences_.enable_gpu_service_logging_gpu =
138 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
139 gpu_preferences_.disable_gpu_program_cache =
140 command_line->HasSwitch(switches::kDisableGpuProgramCache);
141 gpu_preferences_.enforce_gl_minimums =
142 command_line->HasSwitch(switches::kEnforceGLMinimums);
143 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
144 &gpu_preferences_.force_gpu_mem_available)) {
145 gpu_preferences_.force_gpu_mem_available *= 1024 * 1024;
146 }
147 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
148 &gpu_preferences_.gpu_program_cache_size)) {
149 gpu_preferences_.gpu_program_cache_size *= 1024;
150 }
151 gpu_preferences_.enable_share_group_async_texture_upload =
152 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload);
153 gpu_preferences_.enable_subscribe_uniform_extension =
154 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension);
155 gpu_preferences_.enable_threaded_texture_mailboxes =
156 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
157 gpu_preferences_.gl_shader_interm_output =
158 command_line->HasSwitch(switches::kGLShaderIntermOutput);
159 gpu_preferences_.emulate_shader_precision =
160 command_line->HasSwitch(switches::kEmulateShaderPrecision);
161 gpu_preferences_.enable_gl_path_rendering =
162 command_line->HasSwitch(switches::kEnableGLPathRendering);
163 gpu_preferences_.enable_gpu_service_logging =
164 command_line->HasSwitch(switches::kEnableGPUServiceLogging);
165 gpu_preferences_.enable_gpu_service_tracing =
166 }
167
98 size_t DeferredGpuCommandService::IdleQueueSize() { 168 size_t DeferredGpuCommandService::IdleQueueSize() {
99 base::AutoLock lock(tasks_lock_); 169 base::AutoLock lock(tasks_lock_);
100 return idle_tasks_.size(); 170 return idle_tasks_.size();
101 } 171 }
102 172
103 void DeferredGpuCommandService::ScheduleDelayedWork( 173 void DeferredGpuCommandService::ScheduleDelayedWork(
104 const base::Closure& callback) { 174 const base::Closure& callback) {
105 { 175 {
106 base::AutoLock lock(tasks_lock_); 176 base::AutoLock lock(tasks_lock_);
107 idle_tasks_.push(std::make_pair(base::Time::Now(), callback)); 177 idle_tasks_.push(std::make_pair(base::Time::Now(), callback));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 "DeferredGpuCommandService::PerformAllIdleWork"); 212 "DeferredGpuCommandService::PerformAllIdleWork");
143 while (IdleQueueSize()) { 213 while (IdleQueueSize()) {
144 PerformIdleWork(true); 214 PerformIdleWork(true);
145 } 215 }
146 } 216 }
147 217
148 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } 218 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; }
149 219
150 scoped_refptr<gpu::gles2::ShaderTranslatorCache> 220 scoped_refptr<gpu::gles2::ShaderTranslatorCache>
151 DeferredGpuCommandService::shader_translator_cache() { 221 DeferredGpuCommandService::shader_translator_cache() {
152 if (!shader_translator_cache_.get()) 222 if (!shader_translator_cache_.get()) {
153 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; 223 shader_translator_cache_ =
224 new gpu::gles2::ShaderTranslatorCache(gpu_preferences());
225 }
154 return shader_translator_cache_; 226 return shader_translator_cache_;
155 } 227 }
156 228
157 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> 229 scoped_refptr<gpu::gles2::FramebufferCompletenessCache>
158 DeferredGpuCommandService::framebuffer_completeness_cache() { 230 DeferredGpuCommandService::framebuffer_completeness_cache() {
159 if (!framebuffer_completeness_cache_.get()) { 231 if (!framebuffer_completeness_cache_.get()) {
160 framebuffer_completeness_cache_ = 232 framebuffer_completeness_cache_ =
161 new gpu::gles2::FramebufferCompletenessCache; 233 new gpu::gles2::FramebufferCompletenessCache;
162 } 234 }
163 return framebuffer_completeness_cache_; 235 return framebuffer_completeness_cache_;
(...skipping 28 matching lines...) Expand all
192 264
193 void DeferredGpuCommandService::AddRef() const { 265 void DeferredGpuCommandService::AddRef() const {
194 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); 266 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef();
195 } 267 }
196 268
197 void DeferredGpuCommandService::Release() const { 269 void DeferredGpuCommandService::Release() const {
198 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); 270 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release();
199 } 271 }
200 272
201 } // namespace android_webview 273 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/deferred_gpu_command_service.h ('k') | components/mus/gles2/command_buffer_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698