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.
5 #include "gpu/config/gpu_util.h"
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"
22 // Combine the integers into a string, seperated by ','.
23 std::string
IntSetToString(const std::set
<int>& list
) {
25 for (std::set
<int>::const_iterator it
= list
.begin();
26 it
!= list
.end(); ++it
) {
29 rt
+= base::IntToString(*it
);
34 } // namespace anonymous
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
;
47 std::string
GpuSwitchingOptionToString(GpuSwitchingOption 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
;
60 void MergeFeatureSets(std::set
<int>* dst
, const std::set
<int>& src
) {
64 dst
->insert(src
.begin(), src
.end());
67 void ApplyGpuDriverBugWorkarounds(CommandLine
* command_line
) {
69 CollectBasicGraphicsInfo(&gpu_info
);
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
));