Chromium Code Reviews| Index: content/public/browser/gpu_utils.cc |
| diff --git a/content/public/browser/gpu_utils.cc b/content/public/browser/gpu_utils.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..faa69434ae4879e9aeae35935650e26286e06542 |
| --- /dev/null |
| +++ b/content/public/browser/gpu_utils.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/public/browser/gpu_utils.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "gpu/command_buffer/service/gpu_switches.h" |
| +#include "gpu/config/gpu_switches.h" |
| +#include "ui/gl/gl_switches.h" |
| + |
| +namespace { |
| + |
| +bool GetUintFromSwitch(const base::CommandLine* command_line, |
| + const base::StringPiece& switch_string, |
| + uint32_t* value) { |
| + if (!command_line->HasSwitch(switch_string)) |
| + return false; |
| + std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| + return base::StringToUint(switch_value, value); |
| +} |
| + |
| +void InitGpuPreferencesFromCommandLine(gpu::GpuPreferences* gpu_preferences) { |
| + DCHECK(base::CommandLine::InitializedForCurrentProcess()); |
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + gpu_preferences->single_process = |
| + command_line->HasSwitch(switches::kSingleProcess); |
| + gpu_preferences->in_process_gpu = |
| + command_line->HasSwitch(switches::kInProcessGPU); |
| + gpu_preferences->ui_prioritize_in_gpu_process = |
| + command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess); |
| + gpu_preferences->compile_shader_always_succeeds = |
| + command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| + gpu_preferences->disable_gl_error_limit = |
| + command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| + gpu_preferences->disable_glsl_translator = |
| + command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| + gpu_preferences->disable_gpu_driver_bug_workarounds = |
| + command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); |
| + gpu_preferences->disable_shader_name_hashing = |
| + command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| + gpu_preferences->enable_gpu_command_logging = |
| + command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| + gpu_preferences->enable_gpu_debugging = |
| + command_line->HasSwitch(switches::kEnableGPUDebugging); |
| + gpu_preferences->enable_gpu_service_logging_gpu = |
| + command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| + gpu_preferences->disable_gpu_program_cache = |
| + command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| + gpu_preferences->enforce_gl_minimums = |
| + command_line->HasSwitch(switches::kEnforceGLMinimums); |
| + if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
| + &gpu_preferences->force_gpu_mem_available)) { |
| + gpu_preferences->force_gpu_mem_available *= 1024 * 1024; |
| + } |
| + if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, |
| + &gpu_preferences->gpu_program_cache_size)) { |
| + gpu_preferences->gpu_program_cache_size *= 1024; |
| + } |
| + gpu_preferences->enable_share_group_async_texture_upload = |
| + command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload); |
| + gpu_preferences->enable_subscribe_uniform_extension = |
| + command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); |
| + gpu_preferences->enable_threaded_texture_mailboxes = |
| + command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); |
| + gpu_preferences->gl_shader_interm_output = |
| + command_line->HasSwitch(switches::kGLShaderIntermOutput); |
| + gpu_preferences->emulate_shader_precision = |
| + command_line->HasSwitch(switches::kEmulateShaderPrecision); |
| + gpu_preferences->enable_gpu_service_logging = |
| + command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| + gpu_preferences->enable_gpu_service_tracing = |
| + command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| + gpu_preferences->enable_unsafe_es3_apis = |
| + command_line->HasSwitch(switches::kEnableUnsafeES3APIs); |
| +} |
| + |
| +using base::internal::LeakyLazyInstanceTraits; |
| +struct LeakyGpuPreferencesTraits |
| + : LeakyLazyInstanceTraits<gpu::GpuPreferences> { |
| + static gpu::GpuPreferences* New(void* instance) { |
| + gpu::GpuPreferences* gpu_preferences = |
| + LeakyLazyInstanceTraits<gpu::GpuPreferences>::New(instance); |
| + InitGpuPreferencesFromCommandLine(gpu_preferences); |
| + return gpu_preferences; |
| + } |
| +}; |
| + |
| +base::LazyInstance<gpu::GpuPreferences, LeakyGpuPreferencesTraits> |
| + g_gpu_preferences = LAZY_INSTANCE_INITIALIZER; |
|
piman
2016/03/03 20:18:12
Do we need this global, in particular, do we need
Peng
2016/03/03 22:20:55
Done.
|
| + |
| +} // namespace |
| + |
| +namespace content { |
| + |
| +const gpu::GpuPreferences& GetGpuPreferences() { |
| + return g_gpu_preferences.Get(); |
| +} |
| + |
| +} // namespace content |