Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / gpu / compositor_util.cc
blob15eb6fee2531e18885597e68d83c6c0bc54d610e
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 "content/browser/gpu/compositor_util.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/metrics/field_trial.h"
10 #include "build/build_config.h"
11 #include "cc/base/switches.h"
12 #include "content/browser/gpu/gpu_data_manager_impl.h"
13 #include "content/public/common/content_switches.h"
14 #include "gpu/config/gpu_feature_type.h"
16 namespace content {
18 namespace {
20 static bool IsGpuRasterizationBlacklisted() {
21 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
22 return manager->IsFeatureBlacklisted(
23 gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION);
26 const char* kGpuCompositingFeatureName = "gpu_compositing";
27 const char* kWebGLFeatureName = "webgl";
28 const char* kRasterizationFeatureName = "rasterization";
29 const char* kThreadedRasterizationFeatureName = "threaded_rasterization";
31 struct GpuFeatureInfo {
32 std::string name;
33 bool blocked;
34 bool disabled;
35 std::string disabled_description;
36 bool fallback_to_software;
39 const GpuFeatureInfo GetGpuFeatureInfo(size_t index, bool* eof) {
40 const base::CommandLine& command_line =
41 *base::CommandLine::ForCurrentProcess();
42 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
44 const GpuFeatureInfo kGpuFeatureInfo[] = {
46 "2d_canvas",
47 manager->IsFeatureBlacklisted(
48 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS),
49 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas) ||
50 !GpuDataManagerImpl::GetInstance()->
51 GetGPUInfo().SupportsAccelerated2dCanvas(),
52 "Accelerated 2D canvas is unavailable: either disabled at the command"
53 " line or not supported by the current system.",
54 true
57 kGpuCompositingFeatureName,
58 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING),
59 false,
60 "Gpu compositing has been disabled, either via about:flags or"
61 " command line. The browser will fall back to software compositing"
62 " and hardware acceleration will be unavailable.",
63 true
66 kWebGLFeatureName,
67 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL),
68 command_line.HasSwitch(switches::kDisableExperimentalWebGL),
69 "WebGL has been disabled, either via about:flags or command line.",
70 false
73 "flash_3d",
74 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D),
75 command_line.HasSwitch(switches::kDisableFlash3d),
76 "Using 3d in flash has been disabled, either via about:flags or"
77 " command line.",
78 true
81 "flash_stage3d",
82 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D),
83 command_line.HasSwitch(switches::kDisableFlashStage3d),
84 "Using Stage3d in Flash has been disabled, either via about:flags or"
85 " command line.",
86 true
89 "flash_stage3d_baseline",
90 manager->IsFeatureBlacklisted(
91 gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE) ||
92 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D),
93 command_line.HasSwitch(switches::kDisableFlashStage3d),
94 "Using Stage3d Baseline profile in Flash has been disabled, either"
95 " via about:flags or command line.",
96 true
99 "video_decode",
100 manager->IsFeatureBlacklisted(
101 gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE),
102 command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode),
103 "Accelerated video decode has been disabled, either via about:flags"
104 " or command line.",
105 true
107 #if defined(ENABLE_WEBRTC)
109 "video_encode",
110 manager->IsFeatureBlacklisted(
111 gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE),
112 command_line.HasSwitch(switches::kDisableWebRtcHWEncoding),
113 "Accelerated video encode has been disabled, either via about:flags"
114 " or command line.",
115 true
117 #endif
118 #if defined(OS_CHROMEOS)
120 "panel_fitting",
121 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_PANEL_FITTING),
122 command_line.HasSwitch(switches::kDisablePanelFitting),
123 "Panel fitting has been disabled, either via about:flags or command"
124 " line.",
125 false
127 #endif
129 kRasterizationFeatureName,
130 IsGpuRasterizationBlacklisted() &&
131 !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled(),
132 !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled() &&
133 !IsGpuRasterizationBlacklisted(),
134 "Accelerated rasterization has been disabled, either via about:flags"
135 " or command line.",
136 true
139 kThreadedRasterizationFeatureName,
140 false,
141 !IsImplSidePaintingEnabled(),
142 "Threaded rasterization has not been enabled or"
143 " is not supported by the current system.",
144 false
148 DCHECK(index < arraysize(kGpuFeatureInfo));
149 *eof = (index == arraysize(kGpuFeatureInfo) - 1);
150 return kGpuFeatureInfo[index];
153 } // namespace
155 bool IsPinchVirtualViewportEnabled() {
156 const base::CommandLine& command_line =
157 *base::CommandLine::ForCurrentProcess();
159 // Command line switches take precedence over platform default.
160 if (command_line.HasSwitch(cc::switches::kDisablePinchVirtualViewport))
161 return false;
162 if (command_line.HasSwitch(cc::switches::kEnablePinchVirtualViewport))
163 return true;
165 #if defined(OS_CHROMEOS)
166 return true;
167 #else
168 return false;
169 #endif
172 bool IsDelegatedRendererEnabled() {
173 const base::CommandLine& command_line =
174 *base::CommandLine::ForCurrentProcess();
175 bool enabled = false;
177 #if defined(USE_AURA) || defined(OS_MACOSX)
178 // Enable on Aura and Mac.
179 enabled = true;
180 #endif
182 // Flags override.
183 enabled |= command_line.HasSwitch(switches::kEnableDelegatedRenderer);
184 enabled &= !command_line.HasSwitch(switches::kDisableDelegatedRenderer);
185 return enabled;
188 bool IsImplSidePaintingEnabled() {
189 const base::CommandLine& command_line =
190 *base::CommandLine::ForCurrentProcess();
192 if (command_line.HasSwitch(switches::kDisableImplSidePainting))
193 return false;
194 else if (command_line.HasSwitch(switches::kEnableImplSidePainting))
195 return true;
196 else if (command_line.HasSwitch(
197 switches::kEnableBleedingEdgeRenderingFastPaths))
198 return true;
200 return true;
203 bool IsGpuRasterizationEnabled() {
204 const base::CommandLine& command_line =
205 *base::CommandLine::ForCurrentProcess();
207 if (!IsImplSidePaintingEnabled())
208 return false;
210 if (command_line.HasSwitch(switches::kDisableGpuRasterization))
211 return false;
212 else if (command_line.HasSwitch(switches::kEnableGpuRasterization))
213 return true;
215 if (IsGpuRasterizationBlacklisted()) {
216 return false;
219 return true;
222 bool IsForceGpuRasterizationEnabled() {
223 const base::CommandLine& command_line =
224 *base::CommandLine::ForCurrentProcess();
226 if (!IsImplSidePaintingEnabled())
227 return false;
229 return command_line.HasSwitch(switches::kForceGpuRasterization);
232 base::Value* GetFeatureStatus() {
233 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
234 std::string gpu_access_blocked_reason;
235 bool gpu_access_blocked =
236 !manager->GpuAccessAllowed(&gpu_access_blocked_reason);
238 base::DictionaryValue* feature_status_dict = new base::DictionaryValue();
240 bool eof = false;
241 for (size_t i = 0; !eof; ++i) {
242 const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i, &eof);
243 std::string status;
244 if (gpu_feature_info.disabled) {
245 status = "disabled";
246 if (gpu_feature_info.fallback_to_software)
247 status += "_software";
248 else
249 status += "_off";
250 if (gpu_feature_info.name == kThreadedRasterizationFeatureName)
251 status += "_ok";
252 } else if (gpu_feature_info.blocked ||
253 gpu_access_blocked) {
254 status = "unavailable";
255 if (gpu_feature_info.fallback_to_software) {
256 status += "_software";
257 } else
258 status += "_off";
259 } else {
260 status = "enabled";
261 if (gpu_feature_info.name == kWebGLFeatureName &&
262 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING))
263 status += "_readback";
264 if (gpu_feature_info.name == kRasterizationFeatureName) {
265 if (IsForceGpuRasterizationEnabled())
266 status += "_force";
268 if (gpu_feature_info.name == kThreadedRasterizationFeatureName)
269 status += "_on";
271 if (gpu_feature_info.name == kWebGLFeatureName &&
272 (gpu_feature_info.blocked || gpu_access_blocked) &&
273 manager->ShouldUseSwiftShader()) {
274 status = "unavailable_software";
277 feature_status_dict->SetString(
278 gpu_feature_info.name.c_str(), status.c_str());
280 return feature_status_dict;
283 base::Value* GetProblems() {
284 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
285 std::string gpu_access_blocked_reason;
286 bool gpu_access_blocked =
287 !manager->GpuAccessAllowed(&gpu_access_blocked_reason);
289 base::ListValue* problem_list = new base::ListValue();
290 manager->GetBlacklistReasons(problem_list);
292 if (gpu_access_blocked) {
293 base::DictionaryValue* problem = new base::DictionaryValue();
294 problem->SetString("description",
295 "GPU process was unable to boot: " + gpu_access_blocked_reason);
296 problem->Set("crBugs", new base::ListValue());
297 problem->Set("webkitBugs", new base::ListValue());
298 base::ListValue* disabled_features = new base::ListValue();
299 disabled_features->AppendString("all");
300 problem->Set("affectedGpuSettings", disabled_features);
301 problem->SetString("tag", "disabledFeatures");
302 problem_list->Insert(0, problem);
305 bool eof = false;
306 for (size_t i = 0; !eof; ++i) {
307 const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i, &eof);
308 if (gpu_feature_info.disabled) {
309 base::DictionaryValue* problem = new base::DictionaryValue();
310 problem->SetString(
311 "description", gpu_feature_info.disabled_description);
312 problem->Set("crBugs", new base::ListValue());
313 problem->Set("webkitBugs", new base::ListValue());
314 base::ListValue* disabled_features = new base::ListValue();
315 disabled_features->AppendString(gpu_feature_info.name);
316 problem->Set("affectedGpuSettings", disabled_features);
317 problem->SetString("tag", "disabledFeatures");
318 problem_list->Append(problem);
321 return problem_list;
324 base::Value* GetDriverBugWorkarounds() {
325 base::ListValue* workaround_list = new base::ListValue();
326 GpuDataManagerImpl::GetInstance()->GetDriverBugWorkarounds(workaround_list);
327 return workaround_list;
330 } // namespace content