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"
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
{
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
[] = {
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.",
57 kGpuCompositingFeatureName
,
58 manager
->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING
),
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.",
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.",
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"
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"
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.",
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"
107 #if defined(ENABLE_WEBRTC)
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"
118 #if defined(OS_CHROMEOS)
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"
129 kRasterizationFeatureName
,
130 IsGpuRasterizationBlacklisted() &&
131 !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled(),
132 !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled() &&
133 !IsGpuRasterizationBlacklisted(),
134 "Accelerated rasterization has been disabled, either via about:flags"
139 kThreadedRasterizationFeatureName
,
141 !IsImplSidePaintingEnabled(),
142 "Threaded rasterization has not been enabled or"
143 " is not supported by the current system.",
148 DCHECK(index
< arraysize(kGpuFeatureInfo
));
149 *eof
= (index
== arraysize(kGpuFeatureInfo
) - 1);
150 return kGpuFeatureInfo
[index
];
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
))
162 if (command_line
.HasSwitch(cc::switches::kEnablePinchVirtualViewport
))
165 #if defined(OS_CHROMEOS)
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.
183 enabled
|= command_line
.HasSwitch(switches::kEnableDelegatedRenderer
);
184 enabled
&= !command_line
.HasSwitch(switches::kDisableDelegatedRenderer
);
188 bool IsImplSidePaintingEnabled() {
189 const base::CommandLine
& command_line
=
190 *base::CommandLine::ForCurrentProcess();
192 if (command_line
.HasSwitch(switches::kDisableImplSidePainting
))
194 else if (command_line
.HasSwitch(switches::kEnableImplSidePainting
))
196 else if (command_line
.HasSwitch(
197 switches::kEnableBleedingEdgeRenderingFastPaths
))
203 bool IsGpuRasterizationEnabled() {
204 const base::CommandLine
& command_line
=
205 *base::CommandLine::ForCurrentProcess();
207 if (!IsImplSidePaintingEnabled())
210 if (command_line
.HasSwitch(switches::kDisableGpuRasterization
))
212 else if (command_line
.HasSwitch(switches::kEnableGpuRasterization
))
215 if (IsGpuRasterizationBlacklisted()) {
222 bool IsForceGpuRasterizationEnabled() {
223 const base::CommandLine
& command_line
=
224 *base::CommandLine::ForCurrentProcess();
226 if (!IsImplSidePaintingEnabled())
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();
241 for (size_t i
= 0; !eof
; ++i
) {
242 const GpuFeatureInfo gpu_feature_info
= GetGpuFeatureInfo(i
, &eof
);
244 if (gpu_feature_info
.disabled
) {
246 if (gpu_feature_info
.fallback_to_software
)
247 status
+= "_software";
250 if (gpu_feature_info
.name
== kThreadedRasterizationFeatureName
)
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";
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())
268 if (gpu_feature_info
.name
== kThreadedRasterizationFeatureName
)
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
);
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();
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
);
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