PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/chromium/content/browser/gpu/compositor_util.cc

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