James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 "base/strings/string_split.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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" |
James Robinson | aa0657c | 2015-05-11 15:28:26 -0700 | [diff] [blame] | 16 | #include "gpu/config/gpu_switches.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 17 | #include "ui/gl/gl_switches.h" |
| 18 | |
| 19 | namespace gpu { |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | // Combine the integers into a string, seperated by ','. |
| 24 | std::string IntSetToString(const std::set<int>& list) { |
| 25 | std::string rt; |
| 26 | for (std::set<int>::const_iterator it = list.begin(); |
| 27 | it != list.end(); ++it) { |
| 28 | if (!rt.empty()) |
| 29 | rt += ","; |
| 30 | rt += base::IntToString(*it); |
| 31 | } |
| 32 | return rt; |
| 33 | } |
| 34 | |
| 35 | void StringToIntSet(const std::string& str, std::set<int>* list) { |
| 36 | DCHECK(list); |
Viet-Trung Luu | b3a28be | 2016-05-31 11:20:28 -0700 | [diff] [blame^] | 37 | std::vector<std::string> pieces = |
| 38 | base::SplitString(str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 | |
| 47 | } // namespace anonymous |
| 48 | |
| 49 | void MergeFeatureSets(std::set<int>* dst, const std::set<int>& src) { |
| 50 | DCHECK(dst); |
| 51 | if (src.empty()) |
| 52 | return; |
| 53 | dst->insert(src.begin(), src.end()); |
| 54 | } |
| 55 | |
James Robinson | 9127e72 | 2014-12-29 14:41:55 -0800 | [diff] [blame] | 56 | void ApplyGpuDriverBugWorkarounds(base::CommandLine* command_line) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 57 | GPUInfo gpu_info; |
| 58 | CollectBasicGraphicsInfo(&gpu_info); |
| 59 | |
| 60 | ApplyGpuDriverBugWorkarounds(gpu_info, command_line); |
| 61 | } |
| 62 | |
James Robinson | 9127e72 | 2014-12-29 14:41:55 -0800 | [diff] [blame] | 63 | void ApplyGpuDriverBugWorkarounds(const GPUInfo& gpu_info, |
| 64 | base::CommandLine* command_line) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 65 | scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create()); |
| 66 | list->LoadList(kGpuDriverBugListJson, |
| 67 | GpuControlList::kCurrentOsOnly); |
| 68 | std::set<int> workarounds = list->MakeDecision( |
| 69 | GpuControlList::kOsAny, std::string(), gpu_info); |
| 70 | GpuDriverBugList::AppendWorkaroundsFromCommandLine( |
| 71 | &workarounds, *command_line); |
| 72 | if (!workarounds.empty()) { |
| 73 | command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, |
| 74 | IntSetToString(workarounds)); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void StringToFeatureSet( |
| 79 | const std::string& str, std::set<int>* feature_set) { |
| 80 | StringToIntSet(str, feature_set); |
| 81 | } |
| 82 | |
| 83 | } // namespace gpu |