OLD | NEW |
| (Empty) |
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 "content/browser/gpu/gpu_util.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/command_line.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 | |
17 using content::GpuFeatureType; | |
18 | |
19 namespace { | |
20 | |
21 const char kGpuFeatureNameAccelerated2dCanvas[] = "accelerated_2d_canvas"; | |
22 const char kGpuFeatureNameAcceleratedCompositing[] = "accelerated_compositing"; | |
23 const char kGpuFeatureNameWebgl[] = "webgl"; | |
24 const char kGpuFeatureNameMultisampling[] = "multisampling"; | |
25 const char kGpuFeatureNameFlash3d[] = "flash_3d"; | |
26 const char kGpuFeatureNameFlashStage3d[] = "flash_stage3d"; | |
27 const char kGpuFeatureNameTextureSharing[] = "texture_sharing"; | |
28 const char kGpuFeatureNameAcceleratedVideoDecode[] = "accelerated_video_decode"; | |
29 const char kGpuFeatureNameAll[] = "all"; | |
30 const char kGpuFeatureNameUnknown[] = "unknown"; | |
31 | |
32 enum GpuFeatureStatus { | |
33 kGpuFeatureEnabled = 0, | |
34 kGpuFeatureBlacklisted = 1, | |
35 kGpuFeatureDisabled = 2, // disabled by user but not blacklisted | |
36 kGpuFeatureNumStatus | |
37 }; | |
38 | |
39 #if defined(OS_WIN) | |
40 | |
41 enum WinSubVersion { | |
42 kWinOthers = 0, | |
43 kWinXP, | |
44 kWinVista, | |
45 kWin7, | |
46 kNumWinSubVersions | |
47 }; | |
48 | |
49 int GetGpuBlacklistHistogramValueWin(GpuFeatureStatus status) { | |
50 static WinSubVersion sub_version = kNumWinSubVersions; | |
51 if (sub_version == kNumWinSubVersions) { | |
52 sub_version = kWinOthers; | |
53 std::string version_str = base::SysInfo::OperatingSystemVersion(); | |
54 size_t pos = version_str.find_first_not_of("0123456789."); | |
55 if (pos != std::string::npos) | |
56 version_str = version_str.substr(0, pos); | |
57 Version os_version(version_str); | |
58 if (os_version.IsValid() && os_version.components().size() >= 2) { | |
59 const std::vector<uint16>& version_numbers = os_version.components(); | |
60 if (version_numbers[0] == 5) | |
61 sub_version = kWinXP; | |
62 else if (version_numbers[0] == 6 && version_numbers[1] == 0) | |
63 sub_version = kWinVista; | |
64 else if (version_numbers[0] == 6 && version_numbers[1] == 1) | |
65 sub_version = kWin7; | |
66 } | |
67 } | |
68 int entry_index = static_cast<int>(sub_version) * kGpuFeatureNumStatus; | |
69 switch (status) { | |
70 case kGpuFeatureEnabled: | |
71 break; | |
72 case kGpuFeatureBlacklisted: | |
73 entry_index++; | |
74 break; | |
75 case kGpuFeatureDisabled: | |
76 entry_index += 2; | |
77 break; | |
78 } | |
79 return entry_index; | |
80 } | |
81 #endif // OS_WIN | |
82 | |
83 } // namespace | |
84 | |
85 namespace gpu_util { | |
86 | |
87 GpuFeatureType StringToGpuFeatureType(const std::string& feature_string) { | |
88 if (feature_string == kGpuFeatureNameAccelerated2dCanvas) | |
89 return content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS; | |
90 else if (feature_string == kGpuFeatureNameAcceleratedCompositing) | |
91 return content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING; | |
92 else if (feature_string == kGpuFeatureNameWebgl) | |
93 return content::GPU_FEATURE_TYPE_WEBGL; | |
94 else if (feature_string == kGpuFeatureNameMultisampling) | |
95 return content::GPU_FEATURE_TYPE_MULTISAMPLING; | |
96 else if (feature_string == kGpuFeatureNameFlash3d) | |
97 return content::GPU_FEATURE_TYPE_FLASH3D; | |
98 else if (feature_string == kGpuFeatureNameFlashStage3d) | |
99 return content::GPU_FEATURE_TYPE_FLASH_STAGE3D; | |
100 else if (feature_string == kGpuFeatureNameTextureSharing) | |
101 return content::GPU_FEATURE_TYPE_TEXTURE_SHARING; | |
102 else if (feature_string == kGpuFeatureNameAcceleratedVideoDecode) | |
103 return content::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE; | |
104 else if (feature_string == kGpuFeatureNameAll) | |
105 return content::GPU_FEATURE_TYPE_ALL; | |
106 return content::GPU_FEATURE_TYPE_UNKNOWN; | |
107 } | |
108 | |
109 std::string GpuFeatureTypeToString(GpuFeatureType type) { | |
110 std::vector<std::string> matches; | |
111 if (type == content::GPU_FEATURE_TYPE_ALL) { | |
112 matches.push_back(kGpuFeatureNameAll); | |
113 } else { | |
114 if (type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) | |
115 matches.push_back(kGpuFeatureNameAccelerated2dCanvas); | |
116 if (type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) | |
117 matches.push_back(kGpuFeatureNameAcceleratedCompositing); | |
118 if (type & content::GPU_FEATURE_TYPE_WEBGL) | |
119 matches.push_back(kGpuFeatureNameWebgl); | |
120 if (type & content::GPU_FEATURE_TYPE_MULTISAMPLING) | |
121 matches.push_back(kGpuFeatureNameMultisampling); | |
122 if (type & content::GPU_FEATURE_TYPE_FLASH3D) | |
123 matches.push_back(kGpuFeatureNameFlash3d); | |
124 if (type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D) | |
125 matches.push_back(kGpuFeatureNameFlashStage3d); | |
126 if (type & content::GPU_FEATURE_TYPE_TEXTURE_SHARING) | |
127 matches.push_back(kGpuFeatureNameTextureSharing); | |
128 if (type & content::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) | |
129 matches.push_back(kGpuFeatureNameAcceleratedVideoDecode); | |
130 if (!matches.size()) | |
131 matches.push_back(kGpuFeatureNameUnknown); | |
132 } | |
133 return JoinString(matches, ','); | |
134 } | |
135 | |
136 void UpdateStats(const GpuBlacklist* blacklist, | |
137 uint32 blacklisted_features) { | |
138 uint32 max_entry_id = blacklist->max_entry_id(); | |
139 if (max_entry_id == 0) { | |
140 // GPU Blacklist was not loaded. No need to go further. | |
141 return; | |
142 } | |
143 | |
144 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
145 bool disabled = false; | |
146 if (blacklisted_features == 0) { | |
147 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry", | |
148 0, max_entry_id + 1); | |
149 } else { | |
150 std::vector<uint32> flag_entries; | |
151 blacklist->GetGpuFeatureTypeEntries( | |
152 content::GPU_FEATURE_TYPE_ALL, flag_entries, disabled); | |
153 DCHECK_GT(flag_entries.size(), 0u); | |
154 for (size_t i = 0; i < flag_entries.size(); ++i) { | |
155 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry", | |
156 flag_entries[i], max_entry_id + 1); | |
157 } | |
158 } | |
159 | |
160 // This counts how many users are affected by a disabled entry - this allows | |
161 // us to understand the impact of an entry before enable it. | |
162 std::vector<uint32> flag_disabled_entries; | |
163 disabled = true; | |
164 blacklist->GetGpuFeatureTypeEntries( | |
165 content::GPU_FEATURE_TYPE_ALL, flag_disabled_entries, disabled); | |
166 for (size_t i = 0; i < flag_disabled_entries.size(); ++i) { | |
167 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerDisabledEntry", | |
168 flag_disabled_entries[i], max_entry_id + 1); | |
169 } | |
170 | |
171 const content::GpuFeatureType kGpuFeatures[] = { | |
172 content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS, | |
173 content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING, | |
174 content::GPU_FEATURE_TYPE_WEBGL | |
175 }; | |
176 const std::string kGpuBlacklistFeatureHistogramNames[] = { | |
177 "GPU.BlacklistFeatureTestResults.Accelerated2dCanvas", | |
178 "GPU.BlacklistFeatureTestResults.AcceleratedCompositing", | |
179 "GPU.BlacklistFeatureTestResults.Webgl" | |
180 }; | |
181 const bool kGpuFeatureUserFlags[] = { | |
182 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas), | |
183 command_line.HasSwitch(switches::kDisableAcceleratedCompositing), | |
184 #if defined(OS_ANDROID) | |
185 !command_line.HasSwitch(switches::kEnableExperimentalWebGL) | |
186 #else | |
187 command_line.HasSwitch(switches::kDisableExperimentalWebGL) | |
188 #endif | |
189 }; | |
190 #if defined(OS_WIN) | |
191 const std::string kGpuBlacklistFeatureHistogramNamesWin[] = { | |
192 "GPU.BlacklistFeatureTestResultsWindows.Accelerated2dCanvas", | |
193 "GPU.BlacklistFeatureTestResultsWindows.AcceleratedCompositing", | |
194 "GPU.BlacklistFeatureTestResultsWindows.Webgl" | |
195 }; | |
196 #endif | |
197 const size_t kNumFeatures = | |
198 sizeof(kGpuFeatures) / sizeof(content::GpuFeatureType); | |
199 for (size_t i = 0; i < kNumFeatures; ++i) { | |
200 // We can't use UMA_HISTOGRAM_ENUMERATION here because the same name is | |
201 // expected if the macro is used within a loop. | |
202 GpuFeatureStatus value = kGpuFeatureEnabled; | |
203 if (blacklisted_features & kGpuFeatures[i]) | |
204 value = kGpuFeatureBlacklisted; | |
205 else if (kGpuFeatureUserFlags[i]) | |
206 value = kGpuFeatureDisabled; | |
207 base::Histogram* histogram_pointer = base::LinearHistogram::FactoryGet( | |
208 kGpuBlacklistFeatureHistogramNames[i], | |
209 1, kGpuFeatureNumStatus, kGpuFeatureNumStatus + 1, | |
210 base::Histogram::kUmaTargetedHistogramFlag); | |
211 histogram_pointer->Add(value); | |
212 #if defined(OS_WIN) | |
213 histogram_pointer = base::LinearHistogram::FactoryGet( | |
214 kGpuBlacklistFeatureHistogramNamesWin[i], | |
215 1, kNumWinSubVersions * kGpuFeatureNumStatus, | |
216 kNumWinSubVersions * kGpuFeatureNumStatus + 1, | |
217 base::Histogram::kUmaTargetedHistogramFlag); | |
218 histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value)); | |
219 #endif | |
220 } | |
221 } | |
222 | |
223 } // namespace gpu_util; | |
OLD | NEW |