Add an exponential backoff to rechecking the app list doodle.
[chromium-blink-merge.git] / content / browser / gpu / compositor_util.cc
blob98cbf615da9a4bcb4b89c62b4f95a5ae5e37296e
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 "base/strings/string_number_conversions.h"
11 #include "base/sys_info.h"
12 #include "build/build_config.h"
13 #include "cc/base/switches.h"
14 #include "content/browser/gpu/gpu_data_manager_impl.h"
15 #include "content/public/common/content_switches.h"
16 #include "gpu/config/gpu_feature_type.h"
18 namespace content {
20 namespace {
22 static bool IsGpuRasterizationBlacklisted() {
23 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
24 return manager->IsFeatureBlacklisted(
25 gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION);
28 const char* kGpuCompositingFeatureName = "gpu_compositing";
29 const char* kWebGLFeatureName = "webgl";
30 const char* kRasterizationFeatureName = "rasterization";
31 const char* kThreadedRasterizationFeatureName = "threaded_rasterization";
32 const char* kMultipleRasterThreadsFeatureName = "multiple_raster_threads";
34 const int kMinRasterThreads = 1;
35 const int kMaxRasterThreads = 64;
37 const int kMinMSAASampleCount = 0;
39 struct GpuFeatureInfo {
40 std::string name;
41 bool blocked;
42 bool disabled;
43 std::string disabled_description;
44 bool fallback_to_software;
47 const GpuFeatureInfo GetGpuFeatureInfo(size_t index, bool* eof) {
48 const base::CommandLine& command_line =
49 *base::CommandLine::ForCurrentProcess();
50 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
52 const GpuFeatureInfo kGpuFeatureInfo[] = {
54 "2d_canvas",
55 manager->IsFeatureBlacklisted(
56 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS),
57 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas) ||
58 !GpuDataManagerImpl::GetInstance()->
59 GetGPUInfo().SupportsAccelerated2dCanvas(),
60 "Accelerated 2D canvas is unavailable: either disabled at the command"
61 " line or not supported by the current system.",
62 true
65 kGpuCompositingFeatureName,
66 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING),
67 command_line.HasSwitch(switches::kDisableGpuCompositing),
68 "Gpu compositing has been disabled, either via about:flags or"
69 " command line. The browser will fall back to software compositing"
70 " and hardware acceleration will be unavailable.",
71 true
74 kWebGLFeatureName,
75 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL),
76 command_line.HasSwitch(switches::kDisableExperimentalWebGL),
77 "WebGL has been disabled, either via about:flags or command line.",
78 false
81 "flash_3d",
82 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D),
83 command_line.HasSwitch(switches::kDisableFlash3d),
84 "Using 3d in flash has been disabled, either via about:flags or"
85 " command line.",
86 true
89 "flash_stage3d",
90 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D),
91 command_line.HasSwitch(switches::kDisableFlashStage3d),
92 "Using Stage3d in Flash has been disabled, either via about:flags or"
93 " command line.",
94 true
97 "flash_stage3d_baseline",
98 manager->IsFeatureBlacklisted(
99 gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE) ||
100 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D),
101 command_line.HasSwitch(switches::kDisableFlashStage3d),
102 "Using Stage3d Baseline profile in Flash has been disabled, either"
103 " via about:flags or command line.",
104 true
107 "video_decode",
108 manager->IsFeatureBlacklisted(
109 gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE),
110 command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode),
111 "Accelerated video decode has been disabled, either via about:flags"
112 " or command line.",
113 true
115 #if defined(ENABLE_WEBRTC)
117 "video_encode",
118 manager->IsFeatureBlacklisted(
119 gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE),
120 command_line.HasSwitch(switches::kDisableWebRtcHWEncoding),
121 "Accelerated video encode has been disabled, either via about:flags"
122 " or command line.",
123 true
125 #endif
126 #if defined(OS_CHROMEOS)
128 "panel_fitting",
129 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_PANEL_FITTING),
130 command_line.HasSwitch(switches::kDisablePanelFitting),
131 "Panel fitting has been disabled, either via about:flags or command"
132 " line.",
133 false
135 #endif
137 kRasterizationFeatureName,
138 IsGpuRasterizationBlacklisted() &&
139 !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled(),
140 !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled() &&
141 !IsGpuRasterizationBlacklisted(),
142 "Accelerated rasterization has been disabled, either via about:flags"
143 " or command line.",
144 true
147 kThreadedRasterizationFeatureName,
148 false,
149 !IsImplSidePaintingEnabled(),
150 "Threaded rasterization has not been enabled or"
151 " is not supported by the current system.",
152 false
155 kMultipleRasterThreadsFeatureName,
156 false,
157 NumberOfRendererRasterThreads() == 1,
158 "Raster is using a single thread.",
159 false
162 DCHECK(index < arraysize(kGpuFeatureInfo));
163 *eof = (index == arraysize(kGpuFeatureInfo) - 1);
164 return kGpuFeatureInfo[index];
167 } // namespace
169 bool IsPinchVirtualViewportEnabled() {
170 const base::CommandLine& command_line =
171 *base::CommandLine::ForCurrentProcess();
173 // Command line switches take precedence over platform default.
174 if (command_line.HasSwitch(cc::switches::kDisablePinchVirtualViewport))
175 return false;
176 if (command_line.HasSwitch(cc::switches::kEnablePinchVirtualViewport))
177 return true;
179 return true;
182 bool IsPropertyTreeVerificationEnabled() {
183 const base::CommandLine& command_line =
184 *base::CommandLine::ForCurrentProcess();
185 return command_line.HasSwitch(cc::switches::kEnablePropertyTreeVerification);
188 bool IsDelegatedRendererEnabled() {
189 const base::CommandLine& command_line =
190 *base::CommandLine::ForCurrentProcess();
191 bool enabled = false;
193 #if defined(USE_AURA) || defined(OS_MACOSX)
194 // Enable on Aura and Mac.
195 enabled = true;
196 #endif
198 // Flags override.
199 enabled |= command_line.HasSwitch(switches::kEnableDelegatedRenderer);
200 enabled &= !command_line.HasSwitch(switches::kDisableDelegatedRenderer);
201 return enabled;
204 bool IsImplSidePaintingEnabled() {
205 const base::CommandLine& command_line =
206 *base::CommandLine::ForCurrentProcess();
207 if (command_line.HasSwitch(switches::kDisableImplSidePainting))
208 return false;
209 return true;
212 int NumberOfRendererRasterThreads() {
213 int num_raster_threads = 1;
215 // Async uploads uses its own thread, so allow an extra thread when async
216 // uploads is not in use.
217 bool allow_extra_thread =
218 IsZeroCopyUploadEnabled() || IsOneCopyUploadEnabled();
219 if (base::SysInfo::NumberOfProcessors() >= 4 && allow_extra_thread)
220 num_raster_threads = 2;
222 int force_num_raster_threads = ForceNumberOfRendererRasterThreads();
223 if (force_num_raster_threads)
224 num_raster_threads = force_num_raster_threads;
226 return num_raster_threads;
229 bool IsOneCopyUploadEnabled() {
230 if (IsZeroCopyUploadEnabled())
231 return false;
233 const base::CommandLine& command_line =
234 *base::CommandLine::ForCurrentProcess();
235 if (command_line.HasSwitch(switches::kEnableOneCopy))
236 return true;
237 if (command_line.HasSwitch(switches::kDisableOneCopy))
238 return false;
240 #if defined(OS_ANDROID)
241 return false;
242 #endif
243 return true;
246 bool IsZeroCopyUploadEnabled() {
247 const base::CommandLine& command_line =
248 *base::CommandLine::ForCurrentProcess();
249 return command_line.HasSwitch(switches::kEnableZeroCopy);
252 int ForceNumberOfRendererRasterThreads() {
253 const base::CommandLine& command_line =
254 *base::CommandLine::ForCurrentProcess();
256 if (!command_line.HasSwitch(switches::kNumRasterThreads))
257 return 0;
258 std::string string_value =
259 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
260 int force_num_raster_threads = 0;
261 if (base::StringToInt(string_value, &force_num_raster_threads) &&
262 force_num_raster_threads >= kMinRasterThreads &&
263 force_num_raster_threads <= kMaxRasterThreads) {
264 return force_num_raster_threads;
265 } else {
266 DLOG(WARNING) << "Failed to parse switch " <<
267 switches::kNumRasterThreads << ": " << string_value;
268 return 0;
272 bool IsGpuRasterizationEnabled() {
273 const base::CommandLine& command_line =
274 *base::CommandLine::ForCurrentProcess();
276 if (!IsImplSidePaintingEnabled())
277 return false;
279 if (command_line.HasSwitch(switches::kDisableGpuRasterization))
280 return false;
281 else if (command_line.HasSwitch(switches::kEnableGpuRasterization))
282 return true;
284 if (IsGpuRasterizationBlacklisted()) {
285 return false;
288 return true;
291 bool IsForceGpuRasterizationEnabled() {
292 const base::CommandLine& command_line =
293 *base::CommandLine::ForCurrentProcess();
295 if (!IsImplSidePaintingEnabled())
296 return false;
298 return command_line.HasSwitch(switches::kForceGpuRasterization);
301 bool UseSurfacesEnabled() {
302 #if defined(OS_ANDROID)
303 return false;
304 #endif
305 bool enabled = false;
306 #if defined(USE_AURA) || defined(OS_MACOSX)
307 enabled = true;
308 #endif
310 const base::CommandLine& command_line =
311 *base::CommandLine::ForCurrentProcess();
313 // Flags override.
314 enabled |= command_line.HasSwitch(switches::kUseSurfaces);
315 enabled &= !command_line.HasSwitch(switches::kDisableSurfaces);
316 return enabled;
319 int GpuRasterizationMSAASampleCount() {
320 const base::CommandLine& command_line =
321 *base::CommandLine::ForCurrentProcess();
323 if (!command_line.HasSwitch(switches::kGpuRasterizationMSAASampleCount))
324 return 0;
325 std::string string_value = command_line.GetSwitchValueASCII(
326 switches::kGpuRasterizationMSAASampleCount);
327 int msaa_sample_count = 0;
328 if (base::StringToInt(string_value, &msaa_sample_count) &&
329 msaa_sample_count >= kMinMSAASampleCount) {
330 return msaa_sample_count;
331 } else {
332 DLOG(WARNING) << "Failed to parse switch "
333 << switches::kGpuRasterizationMSAASampleCount << ": "
334 << string_value;
335 return 0;
339 base::DictionaryValue* GetFeatureStatus() {
340 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
341 std::string gpu_access_blocked_reason;
342 bool gpu_access_blocked =
343 !manager->GpuAccessAllowed(&gpu_access_blocked_reason);
345 base::DictionaryValue* feature_status_dict = new base::DictionaryValue();
347 bool eof = false;
348 for (size_t i = 0; !eof; ++i) {
349 const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i, &eof);
350 std::string status;
351 if (gpu_feature_info.disabled) {
352 status = "disabled";
353 if (gpu_feature_info.fallback_to_software)
354 status += "_software";
355 else
356 status += "_off";
357 if (gpu_feature_info.name == kThreadedRasterizationFeatureName)
358 status += "_ok";
359 } else if (gpu_feature_info.blocked ||
360 gpu_access_blocked) {
361 status = "unavailable";
362 if (gpu_feature_info.fallback_to_software)
363 status += "_software";
364 else
365 status += "_off";
366 } else {
367 status = "enabled";
368 if (gpu_feature_info.name == kWebGLFeatureName &&
369 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING))
370 status += "_readback";
371 if (gpu_feature_info.name == kRasterizationFeatureName) {
372 if (IsForceGpuRasterizationEnabled())
373 status += "_force";
375 if (gpu_feature_info.name == kMultipleRasterThreadsFeatureName) {
376 if (ForceNumberOfRendererRasterThreads() > 0)
377 status += "_force";
379 if (gpu_feature_info.name == kThreadedRasterizationFeatureName ||
380 gpu_feature_info.name == kMultipleRasterThreadsFeatureName)
381 status += "_on";
383 if (gpu_feature_info.name == kWebGLFeatureName &&
384 (gpu_feature_info.blocked || gpu_access_blocked) &&
385 manager->ShouldUseSwiftShader()) {
386 status = "unavailable_software";
389 feature_status_dict->SetString(
390 gpu_feature_info.name.c_str(), status.c_str());
392 return feature_status_dict;
395 base::Value* GetProblems() {
396 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
397 std::string gpu_access_blocked_reason;
398 bool gpu_access_blocked =
399 !manager->GpuAccessAllowed(&gpu_access_blocked_reason);
401 base::ListValue* problem_list = new base::ListValue();
402 manager->GetBlacklistReasons(problem_list);
404 if (gpu_access_blocked) {
405 base::DictionaryValue* problem = new base::DictionaryValue();
406 problem->SetString("description",
407 "GPU process was unable to boot: " + gpu_access_blocked_reason);
408 problem->Set("crBugs", new base::ListValue());
409 problem->Set("webkitBugs", new base::ListValue());
410 base::ListValue* disabled_features = new base::ListValue();
411 disabled_features->AppendString("all");
412 problem->Set("affectedGpuSettings", disabled_features);
413 problem->SetString("tag", "disabledFeatures");
414 problem_list->Insert(0, problem);
417 bool eof = false;
418 for (size_t i = 0; !eof; ++i) {
419 const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i, &eof);
420 if (gpu_feature_info.disabled) {
421 base::DictionaryValue* problem = new base::DictionaryValue();
422 problem->SetString(
423 "description", gpu_feature_info.disabled_description);
424 problem->Set("crBugs", new base::ListValue());
425 problem->Set("webkitBugs", new base::ListValue());
426 base::ListValue* disabled_features = new base::ListValue();
427 disabled_features->AppendString(gpu_feature_info.name);
428 problem->Set("affectedGpuSettings", disabled_features);
429 problem->SetString("tag", "disabledFeatures");
430 problem_list->Append(problem);
433 return problem_list;
436 std::vector<std::string> GetDriverBugWorkarounds() {
437 return GpuDataManagerImpl::GetInstance()->GetDriverBugWorkarounds();
440 } // namespace content