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 "base/strings/string_split.h"
13 #include "gpu/command_buffer/service/gpu_switches.h"
14 #include "gpu/config/gpu_control_list_jsons.h"
15 #include "gpu/config/gpu_driver_bug_list.h"
16 #include "gpu/config/gpu_info_collector.h"
17 #include "ui/gl/gl_switches.h"
23 // Combine the integers into a string, seperated by ','.
24 std::string IntSetToString(const std::set<int>& list) {
26 for (std::set<int>::const_iterator it = list.begin();
27 it != list.end(); ++it) {
30 rt += base::IntToString(*it);
35 void StringToIntSet(const std::string& str, std::set<int>* list) {
37 std::vector<std::string> pieces;
38 base::SplitString(str, ',', &pieces);
39 for (size_t i = 0; i < pieces.size(); ++i) {
41 bool succeed = base::StringToInt(pieces[i], &number);
47 } // namespace anonymous
49 void MergeFeatureSets(std::set<int>* dst, const std::set<int>& src) {
53 dst->insert(src.begin(), src.end());
56 void ApplyGpuDriverBugWorkarounds(CommandLine* command_line) {
58 CollectBasicGraphicsInfo(&gpu_info);
60 ApplyGpuDriverBugWorkarounds(gpu_info, command_line);
63 void ApplyGpuDriverBugWorkarounds(
64 const GPUInfo& gpu_info, CommandLine* command_line) {
65 scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
66 list->LoadList(kGpuDriverBugListJson,
67 GpuControlList::kCurrentOsOnly);
68 std::set<int> workarounds = WorkaroundsFromCommandLine(command_line);
69 if (workarounds.empty()) {
70 workarounds = list->MakeDecision(
71 GpuControlList::kOsAny, std::string(), gpu_info);
73 if (!workarounds.empty()) {
74 command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
75 IntSetToString(workarounds));
79 void StringToFeatureSet(
80 const std::string& str, std::set<int>* feature_set) {
81 StringToIntSet(str, feature_set);
84 std::set<int> WorkaroundsFromCommandLine(CommandLine* command_line) {
85 std::set<int> workarounds;
86 const struct DriverBugInfo* kFeatureList = GetDriverBugWorkarounds();
88 for (int i = 0; i < NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES; i++) {
89 if (command_line->HasSwitch(kFeatureList[i].feature_name))
90 workarounds.insert(kFeatureList[i].feature_type);