Make consistent with Accelerated 2D Canvas flag on both implementation and chrome...
[chromium-blink-merge.git] / content / browser / gpu / compositor_util.cc
blob81436e2752e4ece81c4339a6501249d44b713751
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 "build/build_config.h"
10 #include "cc/base/switches.h"
11 #include "content/browser/gpu/gpu_data_manager_impl.h"
12 #include "content/public/common/content_switches.h"
13 #include "gpu/config/gpu_feature_type.h"
15 namespace content {
17 namespace {
19 struct GpuFeatureInfo {
20 std::string name;
21 uint32 blocked;
22 bool disabled;
23 std::string disabled_description;
24 bool fallback_to_software;
27 #if defined(OS_CHROMEOS)
28 const size_t kNumFeatures = 14;
29 #else
30 const size_t kNumFeatures = 13;
31 #endif
32 const GpuFeatureInfo GetGpuFeatureInfo(size_t index) {
33 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
34 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
36 const GpuFeatureInfo kGpuFeatureInfo[] = {
38 "2d_canvas",
39 manager->IsFeatureBlacklisted(
40 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS),
41 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas) ||
42 !GpuDataManagerImpl::GetInstance()->
43 GetGPUInfo().SupportsAccelerated2dCanvas(),
44 "Accelerated 2D canvas is unavailable: either disabled at the command"
45 " line or not supported by the current system.",
46 true
49 "compositing",
50 manager->IsFeatureBlacklisted(
51 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING),
52 command_line.HasSwitch(switches::kDisableAcceleratedCompositing),
53 "Accelerated compositing has been disabled, either via about:flags or"
54 " command line. This adversely affects performance of all hardware"
55 " accelerated features.",
56 true
59 "3d_css",
60 manager->IsFeatureBlacklisted(
61 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
62 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_3D_CSS),
63 command_line.HasSwitch(switches::kDisableAcceleratedLayers),
64 "Accelerated layers have been disabled at the command line.",
65 false
68 "css_animation",
69 manager->IsFeatureBlacklisted(
70 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
71 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_3D_CSS),
72 command_line.HasSwitch(cc::switches::kDisableThreadedAnimation) ||
73 command_line.HasSwitch(switches::kDisableAcceleratedCompositing) ||
74 command_line.HasSwitch(switches::kDisableAcceleratedLayers),
75 "Accelerated CSS animation has been disabled at the command line.",
76 true
79 "webgl",
80 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL),
81 command_line.HasSwitch(switches::kDisableExperimentalWebGL),
82 "WebGL has been disabled, either via about:flags or command line.",
83 false
86 "multisampling",
87 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_MULTISAMPLING),
88 command_line.HasSwitch(switches::kDisableGLMultisampling),
89 "Multisampling has been disabled, either via about:flags or command"
90 " line.",
91 false
94 "flash_3d",
95 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D),
96 command_line.HasSwitch(switches::kDisableFlash3d),
97 "Using 3d in flash has been disabled, either via about:flags or"
98 " command line.",
99 false
102 "flash_stage3d",
103 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D),
104 command_line.HasSwitch(switches::kDisableFlashStage3d),
105 "Using Stage3d in Flash has been disabled, either via about:flags or"
106 " command line.",
107 false
110 "flash_stage3d_baseline",
111 manager->IsFeatureBlacklisted(
112 gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE) ||
113 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D),
114 command_line.HasSwitch(switches::kDisableFlashStage3d),
115 "Using Stage3d Baseline profile in Flash has been disabled, either"
116 " via about:flags or command line.",
117 false
120 "texture_sharing",
121 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_TEXTURE_SHARING),
122 command_line.HasSwitch(switches::kDisableImageTransportSurface),
123 "Sharing textures between processes has been disabled, either via"
124 " about:flags or command line.",
125 false
128 "video_decode",
129 manager->IsFeatureBlacklisted(
130 gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE),
131 command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode),
132 "Accelerated video decode has been disabled, either via about:flags"
133 " or command line.",
134 true
137 "video",
138 manager->IsFeatureBlacklisted(
139 gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO),
140 command_line.HasSwitch(switches::kDisableAcceleratedVideo) ||
141 command_line.HasSwitch(switches::kDisableAcceleratedCompositing),
142 "Accelerated video presentation has been disabled, either via"
143 " about:flags or command line.",
144 true
146 #if defined(OS_CHROMEOS)
148 "panel_fitting",
149 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_PANEL_FITTING),
150 command_line.HasSwitch(switches::kDisablePanelFitting),
151 "Panel fitting has been disabled, either via about:flags or command"
152 " line.",
153 false
155 #endif
157 "force_compositing_mode",
158 manager->IsFeatureBlacklisted(
159 gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE) &&
160 !IsForceCompositingModeEnabled(),
161 !IsForceCompositingModeEnabled() &&
162 !manager->IsFeatureBlacklisted(
163 gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE),
164 "Force compositing mode is off, either disabled at the command"
165 " line or not supported by the current system.",
166 false
169 return kGpuFeatureInfo[index];
172 bool CanDoAcceleratedCompositing() {
173 const GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
175 // Don't use force compositing mode if gpu access has been blocked or
176 // accelerated compositing is blacklisted.
177 if (!manager->GpuAccessAllowed(NULL) ||
178 manager->IsFeatureBlacklisted(
179 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING))
180 return false;
182 // Check for SwiftShader.
183 if (manager->ShouldUseSwiftShader())
184 return false;
186 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
187 if (command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
188 return false;
190 return true;
193 bool IsForceCompositingModeBlacklisted() {
194 return GpuDataManagerImpl::GetInstance()->IsFeatureBlacklisted(
195 gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE);
198 } // namespace
200 bool IsThreadedCompositingEnabled() {
201 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
203 // Command line switches take precedence over blacklist.
204 if (command_line.HasSwitch(switches::kDisableForceCompositingMode) ||
205 command_line.HasSwitch(switches::kDisableThreadedCompositing)) {
206 return false;
207 } else if (command_line.HasSwitch(switches::kEnableThreadedCompositing)) {
208 return true;
211 #if defined(USE_AURA)
212 // We always want threaded compositing on Aura.
213 return true;
214 #endif
216 if (!CanDoAcceleratedCompositing() || IsForceCompositingModeBlacklisted())
217 return false;
219 #if defined(OS_MACOSX) || defined(OS_WIN)
220 // Windows Vista+ has been shipping with TCM enabled at 100% since M24 and
221 // Mac OSX 10.8+ since M28. The blacklist check above takes care of returning
222 // false before this hits on unsupported Win/Mac versions.
223 return true;
224 #endif
226 return false;
229 bool IsForceCompositingModeEnabled() {
230 // Force compositing mode is a subset of threaded compositing mode.
231 if (IsThreadedCompositingEnabled())
232 return true;
234 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
236 // Command line switches take precedence over blacklisting.
237 if (command_line.HasSwitch(switches::kDisableForceCompositingMode))
238 return false;
239 else if (command_line.HasSwitch(switches::kForceCompositingMode))
240 return true;
242 if (!CanDoAcceleratedCompositing() || IsForceCompositingModeBlacklisted())
243 return false;
245 #if defined(OS_MACOSX) || defined(OS_WIN)
246 // Windows Vista+ has been shipping with TCM enabled at 100% since M24 and
247 // Mac OSX 10.8+ since M28. The blacklist check above takes care of returning
248 // false before this hits on unsupported Win/Mac versions.
249 return true;
250 #endif
252 return false;
255 bool IsDelegatedRendererEnabled() {
256 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
257 bool enabled = false;
259 #if defined(USE_AURA)
260 // Enable on Aura.
261 enabled = true;
262 #endif
264 // Flags override.
265 enabled |= command_line.HasSwitch(switches::kEnableDelegatedRenderer);
266 enabled &= !command_line.HasSwitch(switches::kDisableDelegatedRenderer);
268 // Needs compositing, and thread.
269 if (enabled &&
270 (!IsForceCompositingModeEnabled() || !IsThreadedCompositingEnabled())) {
271 enabled = false;
272 LOG(ERROR) << "Disabling delegated-rendering because it needs "
273 << "force-compositing-mode and threaded-compositing.";
276 return enabled;
279 bool IsDeadlineSchedulingEnabled() {
280 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
282 // Default to enabled.
283 bool enabled = true;
285 // Flags override.
286 enabled |= command_line.HasSwitch(switches::kEnableDeadlineScheduling);
287 enabled &= !command_line.HasSwitch(switches::kDisableDeadlineScheduling);
289 return enabled;
292 base::Value* GetFeatureStatus() {
293 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
294 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
295 std::string gpu_access_blocked_reason;
296 bool gpu_access_blocked =
297 !manager->GpuAccessAllowed(&gpu_access_blocked_reason);
299 base::DictionaryValue* feature_status_dict = new base::DictionaryValue();
301 for (size_t i = 0; i < kNumFeatures; ++i) {
302 const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i);
303 // force_compositing_mode status is part of the compositing status.
304 if (gpu_feature_info.name == "force_compositing_mode")
305 continue;
307 std::string status;
308 if (gpu_feature_info.disabled) {
309 status = "disabled";
310 if (gpu_feature_info.name == "css_animation") {
311 status += "_software_animated";
312 } else if (gpu_feature_info.name == "raster") {
313 if (cc::switches::IsImplSidePaintingEnabled())
314 status += "_software_multithreaded";
315 else
316 status += "_software";
317 } else {
318 if (gpu_feature_info.fallback_to_software)
319 status += "_software";
320 else
321 status += "_off";
323 } else if (manager->ShouldUseSwiftShader()) {
324 status = "unavailable_software";
325 } else if (gpu_feature_info.blocked ||
326 gpu_access_blocked) {
327 status = "unavailable";
328 if (gpu_feature_info.fallback_to_software)
329 status += "_software";
330 else
331 status += "_off";
332 } else {
333 status = "enabled";
334 if (gpu_feature_info.name == "webgl" &&
335 (command_line.HasSwitch(switches::kDisableAcceleratedCompositing) ||
336 manager->IsFeatureBlacklisted(
337 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)))
338 status += "_readback";
339 bool has_thread = IsThreadedCompositingEnabled();
340 if (gpu_feature_info.name == "compositing") {
341 bool force_compositing = IsForceCompositingModeEnabled();
342 if (force_compositing)
343 status += "_force";
344 if (has_thread)
345 status += "_threaded";
347 if (gpu_feature_info.name == "css_animation") {
348 if (has_thread)
349 status = "accelerated_threaded";
350 else
351 status = "accelerated";
354 // TODO(reveman): Remove this when crbug.com/223286 has been fixed.
355 if (gpu_feature_info.name == "raster" &&
356 cc::switches::IsImplSidePaintingEnabled()) {
357 status = "disabled_software_multithreaded";
359 feature_status_dict->SetString(
360 gpu_feature_info.name.c_str(), status.c_str());
362 return feature_status_dict;
365 base::Value* GetProblems() {
366 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
367 std::string gpu_access_blocked_reason;
368 bool gpu_access_blocked =
369 !manager->GpuAccessAllowed(&gpu_access_blocked_reason);
371 base::ListValue* problem_list = new base::ListValue();
372 manager->GetBlacklistReasons(problem_list);
374 if (gpu_access_blocked) {
375 base::DictionaryValue* problem = new base::DictionaryValue();
376 problem->SetString("description",
377 "GPU process was unable to boot: " + gpu_access_blocked_reason);
378 problem->Set("crBugs", new base::ListValue());
379 problem->Set("webkitBugs", new base::ListValue());
380 problem_list->Insert(0, problem);
383 for (size_t i = 0; i < kNumFeatures; ++i) {
384 const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i);
385 if (gpu_feature_info.disabled) {
386 base::DictionaryValue* problem = new base::DictionaryValue();
387 problem->SetString(
388 "description", gpu_feature_info.disabled_description);
389 problem->Set("crBugs", new base::ListValue());
390 problem->Set("webkitBugs", new base::ListValue());
391 problem_list->Append(problem);
394 return problem_list;
397 base::Value* GetDriverBugWorkarounds() {
398 base::ListValue* workaround_list = new base::ListValue();
399 GpuDataManagerImpl::GetInstance()->GetDriverBugWorkarounds(workaround_list);
400 return workaround_list;
403 } // namespace content