Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/public/browser/gpu_utils.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/lazy_instance.h" | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "content/public/common/content_switches.h" | |
| 11 #include "gpu/command_buffer/service/gpu_switches.h" | |
| 12 #include "gpu/config/gpu_switches.h" | |
| 13 #include "ui/gl/gl_switches.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 bool GetUintFromSwitch(const base::CommandLine* command_line, | |
| 18 const base::StringPiece& switch_string, | |
| 19 uint32_t* value) { | |
| 20 if (!command_line->HasSwitch(switch_string)) | |
| 21 return false; | |
| 22 std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); | |
| 23 return base::StringToUint(switch_value, value); | |
| 24 } | |
| 25 | |
| 26 void InitGpuPreferencesFromCommandLine(gpu::GpuPreferences* gpu_preferences) { | |
| 27 DCHECK(base::CommandLine::InitializedForCurrentProcess()); | |
| 28 const base::CommandLine* command_line = | |
| 29 base::CommandLine::ForCurrentProcess(); | |
| 30 gpu_preferences->single_process = | |
| 31 command_line->HasSwitch(switches::kSingleProcess); | |
| 32 gpu_preferences->in_process_gpu = | |
| 33 command_line->HasSwitch(switches::kInProcessGPU); | |
| 34 gpu_preferences->ui_prioritize_in_gpu_process = | |
| 35 command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess); | |
| 36 gpu_preferences->compile_shader_always_succeeds = | |
| 37 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); | |
| 38 gpu_preferences->disable_gl_error_limit = | |
| 39 command_line->HasSwitch(switches::kDisableGLErrorLimit); | |
| 40 gpu_preferences->disable_glsl_translator = | |
| 41 command_line->HasSwitch(switches::kDisableGLSLTranslator); | |
| 42 gpu_preferences->disable_gpu_driver_bug_workarounds = | |
| 43 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); | |
| 44 gpu_preferences->disable_shader_name_hashing = | |
| 45 command_line->HasSwitch(switches::kDisableShaderNameHashing); | |
| 46 gpu_preferences->enable_gpu_command_logging = | |
| 47 command_line->HasSwitch(switches::kEnableGPUCommandLogging); | |
| 48 gpu_preferences->enable_gpu_debugging = | |
| 49 command_line->HasSwitch(switches::kEnableGPUDebugging); | |
| 50 gpu_preferences->enable_gpu_service_logging_gpu = | |
| 51 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); | |
| 52 gpu_preferences->disable_gpu_program_cache = | |
| 53 command_line->HasSwitch(switches::kDisableGpuProgramCache); | |
| 54 gpu_preferences->enforce_gl_minimums = | |
| 55 command_line->HasSwitch(switches::kEnforceGLMinimums); | |
| 56 if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb, | |
| 57 &gpu_preferences->force_gpu_mem_available)) { | |
| 58 gpu_preferences->force_gpu_mem_available *= 1024 * 1024; | |
| 59 } | |
| 60 if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, | |
| 61 &gpu_preferences->gpu_program_cache_size)) { | |
| 62 gpu_preferences->gpu_program_cache_size *= 1024; | |
| 63 } | |
| 64 gpu_preferences->enable_share_group_async_texture_upload = | |
| 65 command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload); | |
| 66 gpu_preferences->enable_subscribe_uniform_extension = | |
| 67 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); | |
| 68 gpu_preferences->enable_threaded_texture_mailboxes = | |
| 69 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); | |
| 70 gpu_preferences->gl_shader_interm_output = | |
| 71 command_line->HasSwitch(switches::kGLShaderIntermOutput); | |
| 72 gpu_preferences->emulate_shader_precision = | |
| 73 command_line->HasSwitch(switches::kEmulateShaderPrecision); | |
| 74 gpu_preferences->enable_gpu_service_logging = | |
| 75 command_line->HasSwitch(switches::kEnableGPUServiceLogging); | |
| 76 gpu_preferences->enable_gpu_service_tracing = | |
| 77 command_line->HasSwitch(switches::kEnableGPUServiceTracing); | |
| 78 gpu_preferences->enable_unsafe_es3_apis = | |
| 79 command_line->HasSwitch(switches::kEnableUnsafeES3APIs); | |
| 80 } | |
| 81 | |
| 82 using base::internal::LeakyLazyInstanceTraits; | |
| 83 struct LeakyGpuPreferencesTraits | |
| 84 : LeakyLazyInstanceTraits<gpu::GpuPreferences> { | |
| 85 static gpu::GpuPreferences* New(void* instance) { | |
| 86 gpu::GpuPreferences* gpu_preferences = | |
| 87 LeakyLazyInstanceTraits<gpu::GpuPreferences>::New(instance); | |
| 88 InitGpuPreferencesFromCommandLine(gpu_preferences); | |
| 89 return gpu_preferences; | |
| 90 } | |
| 91 }; | |
| 92 | |
| 93 base::LazyInstance<gpu::GpuPreferences, LeakyGpuPreferencesTraits> | |
| 94 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.
| |
| 95 | |
| 96 } // namespace | |
| 97 | |
| 98 namespace content { | |
| 99 | |
| 100 const gpu::GpuPreferences& GetGpuPreferences() { | |
| 101 return g_gpu_preferences.Get(); | |
| 102 } | |
| 103 | |
| 104 } // namespace content | |
| OLD | NEW |