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