| 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 "content/browser/gpu/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/logging.h" |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/string_util.h" | |
| 12 #include "base/sys_info.h" | |
| 13 #include "base/version.h" | |
| 14 #include "content/browser/gpu/gpu_blacklist.h" | |
| 15 #include "content/public/common/content_switches.h" | |
| 16 #include "content/public/common/gpu_feature_type.h" | |
| 17 #include "ui/gl/gl_switches.h" | 10 #include "ui/gl/gl_switches.h" |
| 18 | 11 |
| 19 namespace content { | 12 namespace gpu { |
| 20 namespace { | |
| 21 | |
| 22 enum GpuFeatureStatus { | |
| 23 kGpuFeatureEnabled = 0, | |
| 24 kGpuFeatureBlacklisted = 1, | |
| 25 kGpuFeatureDisabled = 2, // disabled by user but not blacklisted | |
| 26 kGpuFeatureNumStatus | |
| 27 }; | |
| 28 | |
| 29 #if defined(OS_WIN) | |
| 30 | |
| 31 enum WinSubVersion { | |
| 32 kWinOthers = 0, | |
| 33 kWinXP, | |
| 34 kWinVista, | |
| 35 kWin7, | |
| 36 kNumWinSubVersions | |
| 37 }; | |
| 38 | |
| 39 int GetGpuBlacklistHistogramValueWin(GpuFeatureStatus status) { | |
| 40 static WinSubVersion sub_version = kNumWinSubVersions; | |
| 41 if (sub_version == kNumWinSubVersions) { | |
| 42 sub_version = kWinOthers; | |
| 43 std::string version_str = base::SysInfo::OperatingSystemVersion(); | |
| 44 size_t pos = version_str.find_first_not_of("0123456789."); | |
| 45 if (pos != std::string::npos) | |
| 46 version_str = version_str.substr(0, pos); | |
| 47 Version os_version(version_str); | |
| 48 if (os_version.IsValid() && os_version.components().size() >= 2) { | |
| 49 const std::vector<uint16>& version_numbers = os_version.components(); | |
| 50 if (version_numbers[0] == 5) | |
| 51 sub_version = kWinXP; | |
| 52 else if (version_numbers[0] == 6 && version_numbers[1] == 0) | |
| 53 sub_version = kWinVista; | |
| 54 else if (version_numbers[0] == 6 && version_numbers[1] == 1) | |
| 55 sub_version = kWin7; | |
| 56 } | |
| 57 } | |
| 58 int entry_index = static_cast<int>(sub_version) * kGpuFeatureNumStatus; | |
| 59 switch (status) { | |
| 60 case kGpuFeatureEnabled: | |
| 61 break; | |
| 62 case kGpuFeatureBlacklisted: | |
| 63 entry_index++; | |
| 64 break; | |
| 65 case kGpuFeatureDisabled: | |
| 66 entry_index += 2; | |
| 67 break; | |
| 68 } | |
| 69 return entry_index; | |
| 70 } | |
| 71 #endif // OS_WIN | |
| 72 | |
| 73 } // namespace anonymous | |
| 74 | 13 |
| 75 GpuSwitchingOption StringToGpuSwitchingOption( | 14 GpuSwitchingOption StringToGpuSwitchingOption( |
| 76 const std::string& switching_string) { | 15 const std::string& switching_string) { |
| 77 if (switching_string == switches::kGpuSwitchingOptionNameAutomatic) | 16 if (switching_string == switches::kGpuSwitchingOptionNameAutomatic) |
| 78 return GPU_SWITCHING_OPTION_AUTOMATIC; | 17 return GPU_SWITCHING_OPTION_AUTOMATIC; |
| 79 if (switching_string == switches::kGpuSwitchingOptionNameForceIntegrated) | 18 if (switching_string == switches::kGpuSwitchingOptionNameForceIntegrated) |
| 80 return GPU_SWITCHING_OPTION_FORCE_INTEGRATED; | 19 return GPU_SWITCHING_OPTION_FORCE_INTEGRATED; |
| 81 if (switching_string == switches::kGpuSwitchingOptionNameForceDiscrete) | 20 if (switching_string == switches::kGpuSwitchingOptionNameForceDiscrete) |
| 82 return GPU_SWITCHING_OPTION_FORCE_DISCRETE; | 21 return GPU_SWITCHING_OPTION_FORCE_DISCRETE; |
| 83 return GPU_SWITCHING_OPTION_UNKNOWN; | 22 return GPU_SWITCHING_OPTION_UNKNOWN; |
| 84 } | 23 } |
| 85 | 24 |
| 86 std::string GpuSwitchingOptionToString(GpuSwitchingOption option) { | 25 std::string GpuSwitchingOptionToString(GpuSwitchingOption option) { |
| 87 switch (option) { | 26 switch (option) { |
| 88 case GPU_SWITCHING_OPTION_AUTOMATIC: | 27 case GPU_SWITCHING_OPTION_AUTOMATIC: |
| 89 return switches::kGpuSwitchingOptionNameAutomatic; | 28 return switches::kGpuSwitchingOptionNameAutomatic; |
| 90 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED: | 29 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED: |
| 91 return switches::kGpuSwitchingOptionNameForceIntegrated; | 30 return switches::kGpuSwitchingOptionNameForceIntegrated; |
| 92 case GPU_SWITCHING_OPTION_FORCE_DISCRETE: | 31 case GPU_SWITCHING_OPTION_FORCE_DISCRETE: |
| 93 return switches::kGpuSwitchingOptionNameForceDiscrete; | 32 return switches::kGpuSwitchingOptionNameForceDiscrete; |
| 94 default: | 33 default: |
| 95 return "unknown"; | 34 return "unknown"; |
| 96 } | 35 } |
| 97 } | 36 } |
| 98 | 37 |
| 99 void UpdateStats(const GpuBlacklist* blacklist, | |
| 100 const std::set<int>& blacklisted_features) { | |
| 101 uint32 max_entry_id = blacklist->max_entry_id(); | |
| 102 if (max_entry_id == 0) { | |
| 103 // GPU Blacklist was not loaded. No need to go further. | |
| 104 return; | |
| 105 } | |
| 106 | |
| 107 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 108 bool disabled = false; | |
| 109 if (blacklisted_features.size() == 0) { | |
| 110 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry", | |
| 111 0, max_entry_id + 1); | |
| 112 } else { | |
| 113 std::vector<uint32> flag_entries; | |
| 114 blacklist->GetDecisionEntries(&flag_entries, disabled); | |
| 115 DCHECK_GT(flag_entries.size(), 0u); | |
| 116 for (size_t i = 0; i < flag_entries.size(); ++i) { | |
| 117 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry", | |
| 118 flag_entries[i], max_entry_id + 1); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 // This counts how many users are affected by a disabled entry - this allows | |
| 123 // us to understand the impact of an entry before enable it. | |
| 124 std::vector<uint32> flag_disabled_entries; | |
| 125 disabled = true; | |
| 126 blacklist->GetDecisionEntries(&flag_disabled_entries, disabled); | |
| 127 for (size_t i = 0; i < flag_disabled_entries.size(); ++i) { | |
| 128 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerDisabledEntry", | |
| 129 flag_disabled_entries[i], max_entry_id + 1); | |
| 130 } | |
| 131 | |
| 132 const GpuFeatureType kGpuFeatures[] = { | |
| 133 GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS, | |
| 134 GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING, | |
| 135 GPU_FEATURE_TYPE_WEBGL | |
| 136 }; | |
| 137 const std::string kGpuBlacklistFeatureHistogramNames[] = { | |
| 138 "GPU.BlacklistFeatureTestResults.Accelerated2dCanvas", | |
| 139 "GPU.BlacklistFeatureTestResults.AcceleratedCompositing", | |
| 140 "GPU.BlacklistFeatureTestResults.Webgl" | |
| 141 }; | |
| 142 const bool kGpuFeatureUserFlags[] = { | |
| 143 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas), | |
| 144 command_line.HasSwitch(switches::kDisableAcceleratedCompositing), | |
| 145 #if defined(OS_ANDROID) | |
| 146 !command_line.HasSwitch(switches::kEnableExperimentalWebGL) | |
| 147 #else | |
| 148 command_line.HasSwitch(switches::kDisableExperimentalWebGL) | |
| 149 #endif | |
| 150 }; | |
| 151 #if defined(OS_WIN) | |
| 152 const std::string kGpuBlacklistFeatureHistogramNamesWin[] = { | |
| 153 "GPU.BlacklistFeatureTestResultsWindows.Accelerated2dCanvas", | |
| 154 "GPU.BlacklistFeatureTestResultsWindows.AcceleratedCompositing", | |
| 155 "GPU.BlacklistFeatureTestResultsWindows.Webgl" | |
| 156 }; | |
| 157 #endif | |
| 158 const size_t kNumFeatures = | |
| 159 sizeof(kGpuFeatures) / sizeof(GpuFeatureType); | |
| 160 for (size_t i = 0; i < kNumFeatures; ++i) { | |
| 161 // We can't use UMA_HISTOGRAM_ENUMERATION here because the same name is | |
| 162 // expected if the macro is used within a loop. | |
| 163 GpuFeatureStatus value = kGpuFeatureEnabled; | |
| 164 if (blacklisted_features.count(kGpuFeatures[i])) | |
| 165 value = kGpuFeatureBlacklisted; | |
| 166 else if (kGpuFeatureUserFlags[i]) | |
| 167 value = kGpuFeatureDisabled; | |
| 168 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( | |
| 169 kGpuBlacklistFeatureHistogramNames[i], | |
| 170 1, kGpuFeatureNumStatus, kGpuFeatureNumStatus + 1, | |
| 171 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 172 histogram_pointer->Add(value); | |
| 173 #if defined(OS_WIN) | |
| 174 histogram_pointer = base::LinearHistogram::FactoryGet( | |
| 175 kGpuBlacklistFeatureHistogramNamesWin[i], | |
| 176 1, kNumWinSubVersions * kGpuFeatureNumStatus, | |
| 177 kNumWinSubVersions * kGpuFeatureNumStatus + 1, | |
| 178 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 179 histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value)); | |
| 180 #endif | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 void MergeFeatureSets(std::set<int>* dst, const std::set<int>& src) { | 38 void MergeFeatureSets(std::set<int>* dst, const std::set<int>& src) { |
| 185 DCHECK(dst); | 39 DCHECK(dst); |
| 186 if (src.empty()) | 40 if (src.empty()) |
| 187 return; | 41 return; |
| 188 dst->insert(src.begin(), src.end()); | 42 dst->insert(src.begin(), src.end()); |
| 189 } | 43 } |
| 190 | 44 |
| 191 } // namespace content | 45 } // namespace gpu |
| OLD | NEW |