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

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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "content/public/browser/android/synchronous_compositor.h" 12 #include "content/public/browser/android/synchronous_compositor.h"
13 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" 13 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h"
14 #include "gpu/command_buffer/service/gpu_switches.h"
14 #include "gpu/command_buffer/service/shader_translator_cache.h" 15 #include "gpu/command_buffer/service/shader_translator_cache.h"
15 #include "gpu/command_buffer/service/sync_point_manager.h" 16 #include "gpu/command_buffer/service/sync_point_manager.h"
17 #include "gpu/config/gpu_switches.h"
18 #include "ui/gl/gl_switches.h"
16 19
17 namespace android_webview { 20 namespace android_webview {
18 21
19 namespace { 22 namespace {
20 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > 23 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> >
21 g_service = LAZY_INSTANCE_INITIALIZER; 24 g_service = LAZY_INSTANCE_INITIALIZER;
22 } // namespace 25 } // namespace
23 26
24 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; 27 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl;
25 28
(...skipping 30 matching lines...) Expand all
56 } 59 }
57 } 60 }
58 61
59 // static 62 // static
60 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { 63 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() {
61 DCHECK(g_service.Get().get()); 64 DCHECK(g_service.Get().get());
62 return g_service.Get().get(); 65 return g_service.Get().get();
63 } 66 }
64 67
65 DeferredGpuCommandService::DeferredGpuCommandService() 68 DeferredGpuCommandService::DeferredGpuCommandService()
66 : sync_point_manager_(new gpu::SyncPointManager(true)) {} 69 : gpu::Service(gpu_preferences_),
70 sync_point_manager_(new gpu::SyncPointManager(true)) {
71 InitGpuPreferences();
72 }
67 73
68 DeferredGpuCommandService::~DeferredGpuCommandService() { 74 DeferredGpuCommandService::~DeferredGpuCommandService() {
69 base::AutoLock lock(tasks_lock_); 75 base::AutoLock lock(tasks_lock_);
70 DCHECK(tasks_.empty()); 76 DCHECK(tasks_.empty());
71 } 77 }
72 78
73 // This method can be called on any thread. 79 // This method can be called on any thread.
74 // static 80 // static
75 void DeferredGpuCommandService::RequestProcessGL(bool for_idle) { 81 void DeferredGpuCommandService::RequestProcessGL(bool for_idle) {
76 SharedRendererState* renderer_state = 82 SharedRendererState* renderer_state =
(...skipping 11 matching lines...) Expand all
88 base::AutoLock lock(tasks_lock_); 94 base::AutoLock lock(tasks_lock_);
89 tasks_.push(task); 95 tasks_.push(task);
90 } 96 }
91 if (ScopedAllowGL::IsAllowed()) { 97 if (ScopedAllowGL::IsAllowed()) {
92 RunTasks(); 98 RunTasks();
93 } else { 99 } else {
94 RequestProcessGL(false); 100 RequestProcessGL(false);
95 } 101 }
96 } 102 }
97 103
104 void DeferredGpuCommandService::InitGpuPreferences() {
105 DCHECK(base::CommandLine::InitializedForCurrentProcess());
106 const base::CommandLine* command_line =
107 base::CommandLine::ForCurrentProcess();
108 gpu_preferences_.single_process = true;
109 gpu_preferences_.in_process_gpu = true;
110 // TODO(penghuang): share below code with content/gpu/gpu_child_thread.cc
111 gpu_preferences_.compile_shader_always_succeeds =
112 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
113 gpu_preferences_.disable_gl_error_limit =
114 command_line->HasSwitch(switches::kDisableGLErrorLimit);
115 gpu_preferences_.disable_glsl_translator =
116 command_line->HasSwitch(switches::kDisableGLSLTranslator);
117 gpu_preferences_.disable_gpu_driver_bug_workarounds =
118 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
119 gpu_preferences_.disable_shader_name_hashing =
120 command_line->HasSwitch(switches::kDisableShaderNameHashing);
121 gpu_preferences_.enable_gpu_command_logging =
122 command_line->HasSwitch(switches::kEnableGPUCommandLogging);
123 gpu_preferences_.enable_gpu_debugging =
124 command_line->HasSwitch(switches::kEnableGPUDebugging);
125 gpu_preferences_.enable_gpu_service_logging_gpu =
126 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
127 gpu_preferences_.disable_gpu_program_cache =
128 command_line->HasSwitch(switches::kDisableGpuProgramCache);
129 gpu_preferences_.enforce_gl_minimums =
130 command_line->HasSwitch(switches::kEnforceGLMinimums);
131 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
132 &gpu_preferences_.force_gpu_mem_available)) {
133 gpu_preferences_.force_gpu_mem_available *= 1024 * 1024;
134 }
135 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
136 &gpu_preferences_.gpu_program_cache_size)) {
137 gpu_preferences_.gpu_program_cache_size *= 1024;
138 }
139 gpu_preferences_.enable_share_group_async_texture_upload =
140 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload);
141 gpu_preferences_.enable_subscribe_uniform_extension =
142 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension);
143 gpu_preferences_.enable_threaded_texture_mailboxes =
144 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
145 gpu_preferences_.gl_shader_interm_output =
146 command_line->HasSwitch(switches::kGLShaderIntermOutput);
147 gpu_preferences_.emulate_shader_precision =
148 command_line->HasSwitch(switches::kEmulateShaderPrecision);
149 gpu_preferences_.enable_gl_path_rendering =
150 command_line->HasSwitch(switches::kEnableGLPathRendering);
151 gpu_preferences_.enable_gpu_service_logging =
152 command_line->HasSwitch(switches::kEnableGPUServiceLogging);
153 gpu_preferences_.enable_gpu_service_tracing =
154 }
155
98 size_t DeferredGpuCommandService::IdleQueueSize() { 156 size_t DeferredGpuCommandService::IdleQueueSize() {
99 base::AutoLock lock(tasks_lock_); 157 base::AutoLock lock(tasks_lock_);
100 return idle_tasks_.size(); 158 return idle_tasks_.size();
101 } 159 }
102 160
103 void DeferredGpuCommandService::ScheduleDelayedWork( 161 void DeferredGpuCommandService::ScheduleDelayedWork(
104 const base::Closure& callback) { 162 const base::Closure& callback) {
105 { 163 {
106 base::AutoLock lock(tasks_lock_); 164 base::AutoLock lock(tasks_lock_);
107 idle_tasks_.push(std::make_pair(base::Time::Now(), callback)); 165 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"); 200 "DeferredGpuCommandService::PerformAllIdleWork");
143 while (IdleQueueSize()) { 201 while (IdleQueueSize()) {
144 PerformIdleWork(true); 202 PerformIdleWork(true);
145 } 203 }
146 } 204 }
147 205
148 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } 206 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; }
149 207
150 scoped_refptr<gpu::gles2::ShaderTranslatorCache> 208 scoped_refptr<gpu::gles2::ShaderTranslatorCache>
151 DeferredGpuCommandService::shader_translator_cache() { 209 DeferredGpuCommandService::shader_translator_cache() {
152 if (!shader_translator_cache_.get()) 210 if (!shader_translator_cache_.get()) {
153 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; 211 shader_translator_cache_ =
212 new gpu::gles2::ShaderTranslatorCache(gpu_preferences());
213 }
154 return shader_translator_cache_; 214 return shader_translator_cache_;
155 } 215 }
156 216
157 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> 217 scoped_refptr<gpu::gles2::FramebufferCompletenessCache>
158 DeferredGpuCommandService::framebuffer_completeness_cache() { 218 DeferredGpuCommandService::framebuffer_completeness_cache() {
159 if (!framebuffer_completeness_cache_.get()) { 219 if (!framebuffer_completeness_cache_.get()) {
160 framebuffer_completeness_cache_ = 220 framebuffer_completeness_cache_ =
161 new gpu::gles2::FramebufferCompletenessCache; 221 new gpu::gles2::FramebufferCompletenessCache;
162 } 222 }
163 return framebuffer_completeness_cache_; 223 return framebuffer_completeness_cache_;
(...skipping 28 matching lines...) Expand all
192 252
193 void DeferredGpuCommandService::AddRef() const { 253 void DeferredGpuCommandService::AddRef() const {
194 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); 254 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef();
195 } 255 }
196 256
197 void DeferredGpuCommandService::Release() const { 257 void DeferredGpuCommandService::Release() const {
198 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); 258 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release();
199 } 259 }
200 260
201 } // namespace android_webview 261 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698