1 // Copyright (c) 2012 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 "gpu/config/gpu_util.h" 6 7 #include <vector> 8 9 #include "base/command_line.h" 10 #include "base/logging.h" 11 #include "base/strings/string_number_conversions.h" 12 #include "gpu/command_buffer/service/gpu_switches.h" 13 #include "gpu/config/gpu_control_list_jsons.h" 14 #include "gpu/config/gpu_driver_bug_list.h" 15 #include "gpu/config/gpu_info_collector.h" 16 #include "ui/gl/gl_switches.h" 17 18 namespace gpu { 19 20 namespace { 21 22 // Combine the integers into a string, seperated by ','. 23 std::string IntSetToString(const std::set<int>& list) { 24 std::string rt; 25 for (std::set<int>::const_iterator it = list.begin(); 26 it != list.end(); ++it) { 27 if (!rt.empty()) 28 rt += ","; 29 rt += base::IntToString(*it); 30 } 31 return rt; 32 } 33 34 } // namespace anonymous 35 36 GpuSwitchingOption StringToGpuSwitchingOption( 37 const std::string& switching_string) { 38 if (switching_string == switches::kGpuSwitchingOptionNameAutomatic) 39 return GPU_SWITCHING_OPTION_AUTOMATIC; 40 if (switching_string == switches::kGpuSwitchingOptionNameForceIntegrated) 41 return GPU_SWITCHING_OPTION_FORCE_INTEGRATED; 42 if (switching_string == switches::kGpuSwitchingOptionNameForceDiscrete) 43 return GPU_SWITCHING_OPTION_FORCE_DISCRETE; 44 return GPU_SWITCHING_OPTION_UNKNOWN; 45 } 46 47 std::string GpuSwitchingOptionToString(GpuSwitchingOption option) { 48 switch (option) { 49 case GPU_SWITCHING_OPTION_AUTOMATIC: 50 return switches::kGpuSwitchingOptionNameAutomatic; 51 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED: 52 return switches::kGpuSwitchingOptionNameForceIntegrated; 53 case GPU_SWITCHING_OPTION_FORCE_DISCRETE: 54 return switches::kGpuSwitchingOptionNameForceDiscrete; 55 default: 56 return "unknown"; 57 } 58 } 59 60 void MergeFeatureSets(std::set<int>* dst, const std::set<int>& src) { 61 DCHECK(dst); 62 if (src.empty()) 63 return; 64 dst->insert(src.begin(), src.end()); 65 } 66 67 void ApplyGpuDriverBugWorkarounds(CommandLine* command_line) { 68 GPUInfo gpu_info; 69 CollectBasicGraphicsInfo(&gpu_info); 70 71 GpuDriverBugList* list = GpuDriverBugList::Create(); 72 list->LoadList("0", kGpuDriverBugListJson, 73 GpuControlList::kCurrentOsOnly); 74 std::set<int> workarounds = list->MakeDecision( 75 GpuControlList::kOsAny, std::string(), gpu_info); 76 if (!workarounds.empty()) { 77 command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, 78 IntSetToString(workarounds)); 79 } 80 } 81 82 } // namespace gpu 83