OLD | NEW |
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" |
| 15 #include "content/public/common/content_switches.h" |
13 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" | 16 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" |
| 17 #include "gpu/command_buffer/service/gpu_switches.h" |
14 #include "gpu/command_buffer/service/shader_translator_cache.h" | 18 #include "gpu/command_buffer/service/shader_translator_cache.h" |
15 #include "gpu/command_buffer/service/sync_point_manager.h" | 19 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 20 #include "gpu/config/gpu_switches.h" |
| 21 #include "ui/gl/gl_switches.h" |
16 | 22 |
17 namespace android_webview { | 23 namespace android_webview { |
18 | 24 |
19 namespace { | 25 namespace { |
20 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > | 26 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > |
21 g_service = LAZY_INSTANCE_INITIALIZER; | 27 g_service = LAZY_INSTANCE_INITIALIZER; |
| 28 |
| 29 bool GetSizeTFromSwitch(const base::CommandLine* command_line, |
| 30 const base::StringPiece& switch_string, |
| 31 size_t* value) { |
| 32 if (!command_line->HasSwitch(switch_string)) |
| 33 return false; |
| 34 std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 35 return base::StringToSizeT(switch_value, value); |
| 36 } |
| 37 |
| 38 gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { |
| 39 // TODO(penghuang): share below code with content/gpu/gpu_child_thread.cc |
| 40 // http://crbug.com/590825 |
| 41 DCHECK(base::CommandLine::InitializedForCurrentProcess()); |
| 42 const base::CommandLine* command_line = |
| 43 base::CommandLine::ForCurrentProcess(); |
| 44 gpu::GpuPreferences gpu_preferences; |
| 45 gpu_preferences.single_process = |
| 46 command_line->HasSwitch(switches::kSingleProcess); |
| 47 gpu_preferences.in_process_gpu = |
| 48 command_line->HasSwitch(switches::kInProcessGPU); |
| 49 gpu_preferences.ui_prioritize_in_gpu_process = |
| 50 command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess); |
| 51 gpu_preferences.compile_shader_always_succeeds = |
| 52 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| 53 gpu_preferences.disable_gl_error_limit = |
| 54 command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| 55 gpu_preferences.disable_glsl_translator = |
| 56 command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| 57 gpu_preferences.disable_gpu_driver_bug_workarounds = |
| 58 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); |
| 59 gpu_preferences.disable_shader_name_hashing = |
| 60 command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| 61 gpu_preferences.enable_gpu_command_logging = |
| 62 command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| 63 gpu_preferences.enable_gpu_debugging = |
| 64 command_line->HasSwitch(switches::kEnableGPUDebugging); |
| 65 gpu_preferences.enable_gpu_service_logging_gpu = |
| 66 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| 67 gpu_preferences.disable_gpu_program_cache = |
| 68 command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| 69 gpu_preferences.enforce_gl_minimums = |
| 70 command_line->HasSwitch(switches::kEnforceGLMinimums); |
| 71 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
| 72 &gpu_preferences.force_gpu_mem_available)) { |
| 73 gpu_preferences.force_gpu_mem_available *= 1024 * 1024; |
| 74 } |
| 75 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, |
| 76 &gpu_preferences.gpu_program_cache_size)) { |
| 77 gpu_preferences.gpu_program_cache_size *= 1024; |
| 78 } |
| 79 gpu_preferences.enable_share_group_async_texture_upload = |
| 80 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload); |
| 81 gpu_preferences.enable_subscribe_uniform_extension = |
| 82 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); |
| 83 gpu_preferences.enable_threaded_texture_mailboxes = |
| 84 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); |
| 85 gpu_preferences.gl_shader_interm_output = |
| 86 command_line->HasSwitch(switches::kGLShaderIntermOutput); |
| 87 gpu_preferences.emulate_shader_precision = |
| 88 command_line->HasSwitch(switches::kEmulateShaderPrecision); |
| 89 gpu_preferences.enable_gpu_service_logging = |
| 90 command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| 91 gpu_preferences.enable_gpu_service_tracing = |
| 92 command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| 93 gpu_preferences.enable_unsafe_es3_apis = |
| 94 command_line->HasSwitch(switches::kEnableUnsafeES3APIs); |
| 95 return gpu_preferences; |
| 96 } |
| 97 |
22 } // namespace | 98 } // namespace |
23 | 99 |
24 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; | 100 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; |
25 | 101 |
26 // static | 102 // static |
27 bool ScopedAllowGL::IsAllowed() { | 103 bool ScopedAllowGL::IsAllowed() { |
28 return allow_gl.Get().Get(); | 104 return allow_gl.Get().Get(); |
29 } | 105 } |
30 | 106 |
31 ScopedAllowGL::ScopedAllowGL() { | 107 ScopedAllowGL::ScopedAllowGL() { |
(...skipping 24 matching lines...) Expand all Loading... |
56 } | 132 } |
57 } | 133 } |
58 | 134 |
59 // static | 135 // static |
60 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { | 136 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { |
61 DCHECK(g_service.Get().get()); | 137 DCHECK(g_service.Get().get()); |
62 return g_service.Get().get(); | 138 return g_service.Get().get(); |
63 } | 139 } |
64 | 140 |
65 DeferredGpuCommandService::DeferredGpuCommandService() | 141 DeferredGpuCommandService::DeferredGpuCommandService() |
66 : sync_point_manager_(new gpu::SyncPointManager(true)) {} | 142 : gpu::InProcessCommandBuffer::Service(GetGpuPreferencesFromCommandLine()), |
| 143 sync_point_manager_(new gpu::SyncPointManager(true)) { |
| 144 } |
67 | 145 |
68 DeferredGpuCommandService::~DeferredGpuCommandService() { | 146 DeferredGpuCommandService::~DeferredGpuCommandService() { |
69 base::AutoLock lock(tasks_lock_); | 147 base::AutoLock lock(tasks_lock_); |
70 DCHECK(tasks_.empty()); | 148 DCHECK(tasks_.empty()); |
71 } | 149 } |
72 | 150 |
73 // This method can be called on any thread. | 151 // This method can be called on any thread. |
74 // static | 152 // static |
75 void DeferredGpuCommandService::RequestProcessGL(bool for_idle) { | 153 void DeferredGpuCommandService::RequestProcessGL(bool for_idle) { |
76 SharedRendererState* renderer_state = | 154 SharedRendererState* renderer_state = |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 "DeferredGpuCommandService::PerformAllIdleWork"); | 220 "DeferredGpuCommandService::PerformAllIdleWork"); |
143 while (IdleQueueSize()) { | 221 while (IdleQueueSize()) { |
144 PerformIdleWork(true); | 222 PerformIdleWork(true); |
145 } | 223 } |
146 } | 224 } |
147 | 225 |
148 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } | 226 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } |
149 | 227 |
150 scoped_refptr<gpu::gles2::ShaderTranslatorCache> | 228 scoped_refptr<gpu::gles2::ShaderTranslatorCache> |
151 DeferredGpuCommandService::shader_translator_cache() { | 229 DeferredGpuCommandService::shader_translator_cache() { |
152 if (!shader_translator_cache_.get()) | 230 if (!shader_translator_cache_.get()) { |
153 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; | 231 shader_translator_cache_ = |
| 232 new gpu::gles2::ShaderTranslatorCache(gpu_preferences()); |
| 233 } |
154 return shader_translator_cache_; | 234 return shader_translator_cache_; |
155 } | 235 } |
156 | 236 |
157 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> | 237 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> |
158 DeferredGpuCommandService::framebuffer_completeness_cache() { | 238 DeferredGpuCommandService::framebuffer_completeness_cache() { |
159 if (!framebuffer_completeness_cache_.get()) { | 239 if (!framebuffer_completeness_cache_.get()) { |
160 framebuffer_completeness_cache_ = | 240 framebuffer_completeness_cache_ = |
161 new gpu::gles2::FramebufferCompletenessCache; | 241 new gpu::gles2::FramebufferCompletenessCache; |
162 } | 242 } |
163 return framebuffer_completeness_cache_; | 243 return framebuffer_completeness_cache_; |
(...skipping 28 matching lines...) Expand all Loading... |
192 | 272 |
193 void DeferredGpuCommandService::AddRef() const { | 273 void DeferredGpuCommandService::AddRef() const { |
194 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); | 274 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); |
195 } | 275 } |
196 | 276 |
197 void DeferredGpuCommandService::Release() const { | 277 void DeferredGpuCommandService::Release() const { |
198 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); | 278 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); |
199 } | 279 } |
200 | 280 |
201 } // namespace android_webview | 281 } // namespace android_webview |
OLD | NEW |