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/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "content/public/browser/android/synchronous_compositor.h" | 14 #include "content/public/browser/android/synchronous_compositor.h" |
| 15 #include "content/public/browser/gpu_utils.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" | 17 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" |
17 #include "gpu/command_buffer/service/gpu_preferences.h" | 18 #include "gpu/command_buffer/service/gpu_preferences.h" |
18 #include "gpu/command_buffer/service/gpu_switches.h" | 19 #include "gpu/command_buffer/service/gpu_switches.h" |
19 #include "gpu/command_buffer/service/shader_translator_cache.h" | 20 #include "gpu/command_buffer/service/shader_translator_cache.h" |
20 #include "gpu/command_buffer/service/sync_point_manager.h" | 21 #include "gpu/command_buffer/service/sync_point_manager.h" |
21 #include "gpu/config/gpu_switches.h" | 22 #include "gpu/config/gpu_switches.h" |
22 #include "ui/gl/gl_switches.h" | 23 #include "ui/gl/gl_switches.h" |
23 | 24 |
24 namespace android_webview { | 25 namespace android_webview { |
25 | 26 |
26 namespace { | 27 namespace { |
27 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > | 28 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > |
28 g_service = LAZY_INSTANCE_INITIALIZER; | 29 g_service = LAZY_INSTANCE_INITIALIZER; |
29 | 30 |
30 bool GetSizeTFromSwitch(const base::CommandLine* command_line, | |
31 const base::StringPiece& switch_string, | |
32 size_t* value) { | |
33 if (!command_line->HasSwitch(switch_string)) | |
34 return false; | |
35 std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); | |
36 return base::StringToSizeT(switch_value, value); | |
37 } | |
38 | |
39 gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { | |
40 // TODO(penghuang): share below code with content/gpu/gpu_child_thread.cc | |
41 // http://crbug.com/590825 | |
42 DCHECK(base::CommandLine::InitializedForCurrentProcess()); | |
43 const base::CommandLine* command_line = | |
44 base::CommandLine::ForCurrentProcess(); | |
45 gpu::GpuPreferences gpu_preferences; | |
46 gpu_preferences.single_process = | |
47 command_line->HasSwitch(switches::kSingleProcess); | |
48 gpu_preferences.in_process_gpu = | |
49 command_line->HasSwitch(switches::kInProcessGPU); | |
50 gpu_preferences.ui_prioritize_in_gpu_process = | |
51 command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess); | |
52 gpu_preferences.compile_shader_always_succeeds = | |
53 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); | |
54 gpu_preferences.disable_gl_error_limit = | |
55 command_line->HasSwitch(switches::kDisableGLErrorLimit); | |
56 gpu_preferences.disable_glsl_translator = | |
57 command_line->HasSwitch(switches::kDisableGLSLTranslator); | |
58 gpu_preferences.disable_gpu_driver_bug_workarounds = | |
59 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); | |
60 gpu_preferences.disable_shader_name_hashing = | |
61 command_line->HasSwitch(switches::kDisableShaderNameHashing); | |
62 gpu_preferences.enable_gpu_command_logging = | |
63 command_line->HasSwitch(switches::kEnableGPUCommandLogging); | |
64 gpu_preferences.enable_gpu_debugging = | |
65 command_line->HasSwitch(switches::kEnableGPUDebugging); | |
66 gpu_preferences.enable_gpu_service_logging_gpu = | |
67 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); | |
68 gpu_preferences.disable_gpu_program_cache = | |
69 command_line->HasSwitch(switches::kDisableGpuProgramCache); | |
70 gpu_preferences.enforce_gl_minimums = | |
71 command_line->HasSwitch(switches::kEnforceGLMinimums); | |
72 if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb, | |
73 &gpu_preferences.force_gpu_mem_available)) { | |
74 gpu_preferences.force_gpu_mem_available *= 1024 * 1024; | |
75 } | |
76 if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, | |
77 &gpu_preferences.gpu_program_cache_size)) { | |
78 gpu_preferences.gpu_program_cache_size *= 1024; | |
79 } | |
80 gpu_preferences.enable_share_group_async_texture_upload = | |
81 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload); | |
82 gpu_preferences.enable_subscribe_uniform_extension = | |
83 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); | |
84 gpu_preferences.enable_threaded_texture_mailboxes = | |
85 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); | |
86 gpu_preferences.gl_shader_interm_output = | |
87 command_line->HasSwitch(switches::kGLShaderIntermOutput); | |
88 gpu_preferences.emulate_shader_precision = | |
89 command_line->HasSwitch(switches::kEmulateShaderPrecision); | |
90 gpu_preferences.enable_gpu_service_logging = | |
91 command_line->HasSwitch(switches::kEnableGPUServiceLogging); | |
92 gpu_preferences.enable_gpu_service_tracing = | |
93 command_line->HasSwitch(switches::kEnableGPUServiceTracing); | |
94 gpu_preferences.enable_unsafe_es3_apis = | |
95 command_line->HasSwitch(switches::kEnableUnsafeES3APIs); | |
96 return gpu_preferences; | |
97 } | |
98 | |
99 } // namespace | 31 } // namespace |
100 | 32 |
101 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; | 33 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; |
102 | 34 |
103 // static | 35 // static |
104 bool ScopedAllowGL::IsAllowed() { | 36 bool ScopedAllowGL::IsAllowed() { |
105 return allow_gl.Get().Get(); | 37 return allow_gl.Get().Get(); |
106 } | 38 } |
107 | 39 |
108 ScopedAllowGL::ScopedAllowGL() { | 40 ScopedAllowGL::ScopedAllowGL() { |
(...skipping 24 matching lines...) Expand all Loading... |
133 } | 65 } |
134 } | 66 } |
135 | 67 |
136 // static | 68 // static |
137 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { | 69 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { |
138 DCHECK(g_service.Get().get()); | 70 DCHECK(g_service.Get().get()); |
139 return g_service.Get().get(); | 71 return g_service.Get().get(); |
140 } | 72 } |
141 | 73 |
142 DeferredGpuCommandService::DeferredGpuCommandService() | 74 DeferredGpuCommandService::DeferredGpuCommandService() |
143 : gpu::InProcessCommandBuffer::Service(GetGpuPreferencesFromCommandLine()), | 75 : gpu::InProcessCommandBuffer::Service( |
| 76 content::GetGpuPreferencesFromCommandLine()), |
144 sync_point_manager_(new gpu::SyncPointManager(true)) { | 77 sync_point_manager_(new gpu::SyncPointManager(true)) { |
145 } | 78 } |
146 | 79 |
147 DeferredGpuCommandService::~DeferredGpuCommandService() { | 80 DeferredGpuCommandService::~DeferredGpuCommandService() { |
148 base::AutoLock lock(tasks_lock_); | 81 base::AutoLock lock(tasks_lock_); |
149 DCHECK(tasks_.empty()); | 82 DCHECK(tasks_.empty()); |
150 } | 83 } |
151 | 84 |
152 // This method can be called on any thread. | 85 // This method can be called on any thread. |
153 // static | 86 // static |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 206 |
274 void DeferredGpuCommandService::AddRef() const { | 207 void DeferredGpuCommandService::AddRef() const { |
275 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); | 208 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); |
276 } | 209 } |
277 | 210 |
278 void DeferredGpuCommandService::Release() const { | 211 void DeferredGpuCommandService::Release() const { |
279 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); | 212 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); |
280 } | 213 } |
281 | 214 |
282 } // namespace android_webview | 215 } // namespace android_webview |
OLD | NEW |