1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/gpu/gpu_util.h"
#include <vector>
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/sys_info.h"
#include "base/version.h"
#include "content/browser/gpu/gpu_blacklist.h"
#include "content/public/common/content_switches.h"
#include "ui/gl/gl_switches.h"
namespace content {
namespace {
const char kGpuFeatureNameAccelerated2dCanvas[] = "accelerated_2d_canvas";
const char kGpuFeatureNameAcceleratedCompositing[] = "accelerated_compositing";
const char kGpuFeatureNameWebgl[] = "webgl";
const char kGpuFeatureNameMultisampling[] = "multisampling";
const char kGpuFeatureNameFlash3d[] = "flash_3d";
const char kGpuFeatureNameFlashStage3d[] = "flash_stage3d";
const char kGpuFeatureNameFlashStage3dBaseline[] = "flash_stage3d_baseline";
const char kGpuFeatureNameTextureSharing[] = "texture_sharing";
const char kGpuFeatureNameAcceleratedVideoDecode[] = "accelerated_video_decode";
const char kGpuFeatureName3dCss[] = "3d_css";
const char kGpuFeatureNameAcceleratedVideo[] = "accelerated_video";
const char kGpuFeatureNamePanelFitting[] = "panel_fitting";
const char kGpuFeatureNameForceCompositingMode[] = "force_compositing_mode";
const char kGpuFeatureNameAll[] = "all";
const char kGpuFeatureNameUnknown[] = "unknown";
enum GpuFeatureStatus {
kGpuFeatureEnabled = 0,
kGpuFeatureBlacklisted = 1,
kGpuFeatureDisabled = 2, // disabled by user but not blacklisted
kGpuFeatureNumStatus
};
#if defined(OS_WIN)
enum WinSubVersion {
kWinOthers = 0,
kWinXP,
kWinVista,
kWin7,
kNumWinSubVersions
};
int GetGpuBlacklistHistogramValueWin(GpuFeatureStatus status) {
static WinSubVersion sub_version = kNumWinSubVersions;
if (sub_version == kNumWinSubVersions) {
sub_version = kWinOthers;
std::string version_str = base::SysInfo::OperatingSystemVersion();
size_t pos = version_str.find_first_not_of("0123456789.");
if (pos != std::string::npos)
version_str = version_str.substr(0, pos);
Version os_version(version_str);
if (os_version.IsValid() && os_version.components().size() >= 2) {
const std::vector<uint16>& version_numbers = os_version.components();
if (version_numbers[0] == 5)
sub_version = kWinXP;
else if (version_numbers[0] == 6 && version_numbers[1] == 0)
sub_version = kWinVista;
else if (version_numbers[0] == 6 && version_numbers[1] == 1)
sub_version = kWin7;
}
}
int entry_index = static_cast<int>(sub_version) * kGpuFeatureNumStatus;
switch (status) {
case kGpuFeatureEnabled:
break;
case kGpuFeatureBlacklisted:
entry_index++;
break;
case kGpuFeatureDisabled:
entry_index += 2;
break;
}
return entry_index;
}
#endif // OS_WIN
} // namespace
GpuFeatureType StringToGpuFeatureType(const std::string& feature_string) {
if (feature_string == kGpuFeatureNameAccelerated2dCanvas)
return GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS;
if (feature_string == kGpuFeatureNameAcceleratedCompositing)
return GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING;
if (feature_string == kGpuFeatureNameWebgl)
return GPU_FEATURE_TYPE_WEBGL;
if (feature_string == kGpuFeatureNameMultisampling)
return GPU_FEATURE_TYPE_MULTISAMPLING;
if (feature_string == kGpuFeatureNameFlash3d)
return GPU_FEATURE_TYPE_FLASH3D;
if (feature_string == kGpuFeatureNameFlashStage3d)
return GPU_FEATURE_TYPE_FLASH_STAGE3D;
if (feature_string == kGpuFeatureNameFlashStage3dBaseline)
return GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE;
if (feature_string == kGpuFeatureNameTextureSharing)
return GPU_FEATURE_TYPE_TEXTURE_SHARING;
if (feature_string == kGpuFeatureNameAcceleratedVideoDecode)
return GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE;
if (feature_string == kGpuFeatureName3dCss)
return GPU_FEATURE_TYPE_3D_CSS;
if (feature_string == kGpuFeatureNameAcceleratedVideo)
return GPU_FEATURE_TYPE_ACCELERATED_VIDEO;
if (feature_string == kGpuFeatureNamePanelFitting)
return GPU_FEATURE_TYPE_PANEL_FITTING;
if (feature_string == kGpuFeatureNameForceCompositingMode)
return GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE;
if (feature_string == kGpuFeatureNameAll)
return GPU_FEATURE_TYPE_ALL;
return GPU_FEATURE_TYPE_UNKNOWN;
}
std::string GpuFeatureTypeToString(GpuFeatureType type) {
std::vector<std::string> matches;
if (type == GPU_FEATURE_TYPE_ALL) {
matches.push_back(kGpuFeatureNameAll);
} else {
if (type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
matches.push_back(kGpuFeatureNameAccelerated2dCanvas);
if (type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
matches.push_back(kGpuFeatureNameAcceleratedCompositing);
if (type & GPU_FEATURE_TYPE_WEBGL)
matches.push_back(kGpuFeatureNameWebgl);
if (type & GPU_FEATURE_TYPE_MULTISAMPLING)
matches.push_back(kGpuFeatureNameMultisampling);
if (type & GPU_FEATURE_TYPE_FLASH3D)
matches.push_back(kGpuFeatureNameFlash3d);
if (type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
matches.push_back(kGpuFeatureNameFlashStage3d);
if (type & GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE)
matches.push_back(kGpuFeatureNameFlashStage3dBaseline);
if (type & GPU_FEATURE_TYPE_TEXTURE_SHARING)
matches.push_back(kGpuFeatureNameTextureSharing);
if (type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE)
matches.push_back(kGpuFeatureNameAcceleratedVideoDecode);
if (type & GPU_FEATURE_TYPE_3D_CSS)
matches.push_back(kGpuFeatureName3dCss);
if (type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
matches.push_back(kGpuFeatureNameAcceleratedVideo);
if (type & GPU_FEATURE_TYPE_PANEL_FITTING)
matches.push_back(kGpuFeatureNamePanelFitting);
if (type & GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE)
matches.push_back(kGpuFeatureNameForceCompositingMode);
if (!matches.size())
matches.push_back(kGpuFeatureNameUnknown);
}
return JoinString(matches, ',');
}
GpuSwitchingOption StringToGpuSwitchingOption(
const std::string& switching_string) {
if (switching_string == switches::kGpuSwitchingOptionNameAutomatic)
return GPU_SWITCHING_OPTION_AUTOMATIC;
if (switching_string == switches::kGpuSwitchingOptionNameForceIntegrated)
return GPU_SWITCHING_OPTION_FORCE_INTEGRATED;
if (switching_string == switches::kGpuSwitchingOptionNameForceDiscrete)
return GPU_SWITCHING_OPTION_FORCE_DISCRETE;
return GPU_SWITCHING_OPTION_UNKNOWN;
}
std::string GpuSwitchingOptionToString(GpuSwitchingOption option) {
switch (option) {
case GPU_SWITCHING_OPTION_AUTOMATIC:
return switches::kGpuSwitchingOptionNameAutomatic;
case GPU_SWITCHING_OPTION_FORCE_INTEGRATED:
return switches::kGpuSwitchingOptionNameForceIntegrated;
case GPU_SWITCHING_OPTION_FORCE_DISCRETE:
return switches::kGpuSwitchingOptionNameForceDiscrete;
default:
return "unknown";
}
}
void UpdateStats(const GpuBlacklist* blacklist,
uint32 blacklisted_features) {
uint32 max_entry_id = blacklist->max_entry_id();
if (max_entry_id == 0) {
// GPU Blacklist was not loaded. No need to go further.
return;
}
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
bool disabled = false;
if (blacklisted_features == 0) {
UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry",
0, max_entry_id + 1);
} else {
std::vector<uint32> flag_entries;
blacklist->GetDecisionEntries(&flag_entries, disabled);
DCHECK_GT(flag_entries.size(), 0u);
for (size_t i = 0; i < flag_entries.size(); ++i) {
UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry",
flag_entries[i], max_entry_id + 1);
}
}
// This counts how many users are affected by a disabled entry - this allows
// us to understand the impact of an entry before enable it.
std::vector<uint32> flag_disabled_entries;
disabled = true;
blacklist->GetDecisionEntries(&flag_disabled_entries, disabled);
for (size_t i = 0; i < flag_disabled_entries.size(); ++i) {
UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerDisabledEntry",
flag_disabled_entries[i], max_entry_id + 1);
}
const GpuFeatureType kGpuFeatures[] = {
GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS,
GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING,
GPU_FEATURE_TYPE_WEBGL
};
const std::string kGpuBlacklistFeatureHistogramNames[] = {
"GPU.BlacklistFeatureTestResults.Accelerated2dCanvas",
"GPU.BlacklistFeatureTestResults.AcceleratedCompositing",
"GPU.BlacklistFeatureTestResults.Webgl"
};
const bool kGpuFeatureUserFlags[] = {
command_line.HasSwitch(switches::kDisableAccelerated2dCanvas),
command_line.HasSwitch(switches::kDisableAcceleratedCompositing),
#if defined(OS_ANDROID)
!command_line.HasSwitch(switches::kEnableExperimentalWebGL)
#else
command_line.HasSwitch(switches::kDisableExperimentalWebGL)
#endif
};
#if defined(OS_WIN)
const std::string kGpuBlacklistFeatureHistogramNamesWin[] = {
"GPU.BlacklistFeatureTestResultsWindows.Accelerated2dCanvas",
"GPU.BlacklistFeatureTestResultsWindows.AcceleratedCompositing",
"GPU.BlacklistFeatureTestResultsWindows.Webgl"
};
#endif
const size_t kNumFeatures =
sizeof(kGpuFeatures) / sizeof(GpuFeatureType);
for (size_t i = 0; i < kNumFeatures; ++i) {
// We can't use UMA_HISTOGRAM_ENUMERATION here because the same name is
// expected if the macro is used within a loop.
GpuFeatureStatus value = kGpuFeatureEnabled;
if (blacklisted_features & kGpuFeatures[i])
value = kGpuFeatureBlacklisted;
else if (kGpuFeatureUserFlags[i])
value = kGpuFeatureDisabled;
base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
kGpuBlacklistFeatureHistogramNames[i],
1, kGpuFeatureNumStatus, kGpuFeatureNumStatus + 1,
base::HistogramBase::kUmaTargetedHistogramFlag);
histogram_pointer->Add(value);
#if defined(OS_WIN)
histogram_pointer = base::LinearHistogram::FactoryGet(
kGpuBlacklistFeatureHistogramNamesWin[i],
1, kNumWinSubVersions * kGpuFeatureNumStatus,
kNumWinSubVersions * kGpuFeatureNumStatus + 1,
base::HistogramBase::kUmaTargetedHistogramFlag);
histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value));
#endif
}
}
} // namespace content
|