Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / gpu / compositor_util.cc
index 85240fa..7854aef 100644 (file)
@@ -16,6 +16,10 @@ namespace content {
 
 namespace {
 
+const char* kGpuCompositingFeatureName = "gpu_compositing";
+const char* kWebGLFeatureName = "webgl";
+const char* kRasterizationFeatureName = "rasterization";
+
 struct GpuFeatureInfo {
   std::string name;
   uint32 blocked;
@@ -24,20 +28,7 @@ struct GpuFeatureInfo {
   bool fallback_to_software;
 };
 
-// Determine if accelerated-2d-canvas is supported, which depends on whether
-// lose_context could happen.
-bool SupportsAccelerated2dCanvas() {
-  if (GpuDataManagerImpl::GetInstance()->GetGPUInfo().can_lose_context)
-    return false;
-  return true;
-}
-
-#if defined(OS_CHROMEOS)
-const size_t kNumFeatures = 14;
-#else
-const size_t kNumFeatures = 13;
-#endif
-const GpuFeatureInfo GetGpuFeatureInfo(size_t index) {
+const GpuFeatureInfo GetGpuFeatureInfo(size_t index, bool* eof) {
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
   GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
 
@@ -47,57 +38,29 @@ const GpuFeatureInfo GetGpuFeatureInfo(size_t index) {
           manager->IsFeatureBlacklisted(
               gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS),
           command_line.HasSwitch(switches::kDisableAccelerated2dCanvas) ||
-          !SupportsAccelerated2dCanvas(),
+          !GpuDataManagerImpl::GetInstance()->
+              GetGPUInfo().SupportsAccelerated2dCanvas(),
           "Accelerated 2D canvas is unavailable: either disabled at the command"
           " line or not supported by the current system.",
           true
       },
       {
-          "compositing",
-          manager->IsFeatureBlacklisted(
-              gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING),
-          command_line.HasSwitch(switches::kDisableAcceleratedCompositing),
-          "Accelerated compositing has been disabled, either via about:flags or"
-          " command line. This adversely affects performance of all hardware"
-          " accelerated features.",
-          true
-      },
-      {
-          "3d_css",
-          manager->IsFeatureBlacklisted(
-              gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
-          manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_3D_CSS),
-          command_line.HasSwitch(switches::kDisableAcceleratedLayers),
-          "Accelerated layers have been disabled at the command line.",
-          false
-      },
-      {
-          "css_animation",
-          manager->IsFeatureBlacklisted(
-              gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
-          manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_3D_CSS),
-          command_line.HasSwitch(cc::switches::kDisableThreadedAnimation) ||
-          command_line.HasSwitch(switches::kDisableAcceleratedCompositing) ||
-          command_line.HasSwitch(switches::kDisableAcceleratedLayers),
-          "Accelerated CSS animation has been disabled at the command line.",
+          kGpuCompositingFeatureName,
+          manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING),
+          false,
+          "Gpu compositing has been disabled, either via about:flags or"
+          " command line. The browser will fall back to software compositing"
+          " and hardware acceleration will be unavailable.",
           true
       },
       {
-          "webgl",
+          kWebGLFeatureName,
           manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL),
           command_line.HasSwitch(switches::kDisableExperimentalWebGL),
           "WebGL has been disabled, either via about:flags or command line.",
           false
       },
       {
-          "multisampling",
-          manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_MULTISAMPLING),
-          command_line.HasSwitch(switches::kDisableGLMultisampling),
-          "Multisampling has been disabled, either via about:flags or command"
-          " line.",
-          false
-      },
-      {
           "flash_3d",
           manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D),
           command_line.HasSwitch(switches::kDisableFlash3d),
@@ -124,14 +87,6 @@ const GpuFeatureInfo GetGpuFeatureInfo(size_t index) {
           false
       },
       {
-          "texture_sharing",
-          manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_TEXTURE_SHARING),
-          command_line.HasSwitch(switches::kDisableImageTransportSurface),
-          "Sharing textures between processes has been disabled, either via"
-          " about:flags or command line.",
-          false
-      },
-      {
           "video_decode",
           manager->IsFeatureBlacklisted(
               gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE),
@@ -140,16 +95,17 @@ const GpuFeatureInfo GetGpuFeatureInfo(size_t index) {
           " or command line.",
           true
       },
+#if defined(ENABLE_WEBRTC)
       {
-          "video",
+          "video_encode",
           manager->IsFeatureBlacklisted(
-              gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO),
-          command_line.HasSwitch(switches::kDisableAcceleratedVideo) ||
-          command_line.HasSwitch(switches::kDisableAcceleratedCompositing),
-          "Accelerated video presentation has been disabled, either via"
-          " about:flags or command line.",
+              gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE),
+          command_line.HasSwitch(switches::kDisableWebRtcHWEncoding),
+          "Accelerated video encode has been disabled, either via about:flags"
+          " or command line.",
           true
       },
+#endif
 #if defined(OS_CHROMEOS)
       {
           "panel_fitting",
@@ -161,102 +117,57 @@ const GpuFeatureInfo GetGpuFeatureInfo(size_t index) {
       },
 #endif
       {
-          "force_compositing_mode",
+          kRasterizationFeatureName,
           manager->IsFeatureBlacklisted(
-              gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE) &&
-          !IsForceCompositingModeEnabled(),
-          !IsForceCompositingModeEnabled() &&
+              gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION) &&
+          !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled(),
+          !IsGpuRasterizationEnabled() && !IsForceGpuRasterizationEnabled() &&
           !manager->IsFeatureBlacklisted(
-              gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE),
-          "Force compositing mode is off, either disabled at the command"
-          " line or not supported by the current system.",
-          false
-      },
+              gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION),
+          "Accelerated rasterization has not been enabled or"
+          " is not supported by the current system.",
+          true
+      }
   };
+  DCHECK(index < arraysize(kGpuFeatureInfo));
+  *eof = (index == arraysize(kGpuFeatureInfo) - 1);
   return kGpuFeatureInfo[index];
 }
 
-bool CanDoAcceleratedCompositing() {
-  const GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
-
-  // Don't use force compositing mode if gpu access has been blocked or
-  // accelerated compositing is blacklisted.
-  if (!manager->GpuAccessAllowed(NULL) ||
-      manager->IsFeatureBlacklisted(
-          gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING))
-    return false;
-
-  // Check for SwiftShader.
-  if (manager->ShouldUseSwiftShader())
-    return false;
-
-  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
-  if (command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
-    return false;
-
-  return true;
-}
-
-bool IsForceCompositingModeBlacklisted() {
-  return GpuDataManagerImpl::GetInstance()->IsFeatureBlacklisted(
-      gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE);
-}
-
 }  // namespace
 
-bool IsThreadedCompositingEnabled() {
+bool IsPinchVirtualViewportEnabled() {
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
 
-  // Command line switches take precedence over blacklist.
-  if (command_line.HasSwitch(switches::kDisableForceCompositingMode) ||
-      command_line.HasSwitch(switches::kDisableThreadedCompositing)) {
+  // Command line switches take precedence over platform default.
+  if (command_line.HasSwitch(cc::switches::kDisablePinchVirtualViewport))
     return false;
-  } else if (command_line.HasSwitch(switches::kEnableThreadedCompositing)) {
+  if (command_line.HasSwitch(cc::switches::kEnablePinchVirtualViewport))
     return true;
-  }
-
-#if defined(USE_AURA)
-  // We always want threaded compositing on Aura.
-  return true;
-#endif
 
-  if (!CanDoAcceleratedCompositing() || IsForceCompositingModeBlacklisted())
-    return false;
-
-#if defined(OS_MACOSX) || defined(OS_WIN)
-  // Windows Vista+ has been shipping with TCM enabled at 100% since M24 and
-  // Mac OSX 10.8+ since M28. The blacklist check above takes care of returning
-  // false before this hits on unsupported Win/Mac versions.
+#if defined(OS_CHROMEOS)
   return true;
-#endif
-
+#else
   return false;
+#endif
 }
 
-bool IsForceCompositingModeEnabled() {
-  // Force compositing mode is a subset of threaded compositing mode.
-  if (IsThreadedCompositingEnabled())
-    return true;
-
+bool IsThreadedCompositingEnabled() {
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
 
-  // Command line switches take precedence over blacklisting.
-  if (command_line.HasSwitch(switches::kDisableForceCompositingMode))
+  // Command line switches take precedence over blacklist.
+  if (command_line.HasSwitch(switches::kDisableThreadedCompositing))
     return false;
-  else if (command_line.HasSwitch(switches::kForceCompositingMode))
+  if (command_line.HasSwitch(switches::kEnableThreadedCompositing))
     return true;
 
-  if (!CanDoAcceleratedCompositing() || IsForceCompositingModeBlacklisted())
-    return false;
-
-#if defined(OS_MACOSX) || defined(OS_WIN)
-  // Windows Vista+ has been shipping with TCM enabled at 100% since M24 and
-  // Mac OSX 10.8+ since M28. The blacklist check above takes care of returning
-  // false before this hits on unsupported Win/Mac versions.
+#if defined(USE_AURA) || defined(OS_MACOSX)
+  // We always want threaded compositing on Aura and Mac (the fallback is a
+  // threaded software compositor).
   return true;
-#endif
-
+#else
   return false;
+#endif
 }
 
 bool IsDelegatedRendererEnabled() {
@@ -273,8 +184,7 @@ bool IsDelegatedRendererEnabled() {
   enabled &= !command_line.HasSwitch(switches::kDisableDelegatedRenderer);
 
   // Needs compositing, and thread.
-  if (enabled &&
-      (!IsForceCompositingModeEnabled() || !IsThreadedCompositingEnabled())) {
+  if (enabled && !IsThreadedCompositingEnabled()) {
     enabled = false;
     LOG(ERROR) << "Disabling delegated-rendering because it needs "
                << "force-compositing-mode and threaded-compositing.";
@@ -283,21 +193,53 @@ bool IsDelegatedRendererEnabled() {
   return enabled;
 }
 
-bool IsDeadlineSchedulingEnabled() {
+bool IsImplSidePaintingEnabled() {
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
 
-  // Default to enabled.
-  bool enabled = true;
+  if (command_line.HasSwitch(switches::kDisableImplSidePainting))
+    return false;
+  else if (command_line.HasSwitch(switches::kEnableImplSidePainting))
+    return true;
+  else if (command_line.HasSwitch(
+      switches::kEnableBleedingEdgeRenderingFastPaths))
+    return true;
 
-  // Flags override.
-  enabled |= command_line.HasSwitch(switches::kEnableDeadlineScheduling);
-  enabled &= !command_line.HasSwitch(switches::kDisableDeadlineScheduling);
+#if defined(OS_ANDROID)
+  return true;
+#else
+  return false;
+#endif
+}
 
-  return enabled;
+bool IsGpuRasterizationEnabled() {
+  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+
+  if (!IsImplSidePaintingEnabled())
+    return false;
+
+  if (command_line.HasSwitch(switches::kDisableGpuRasterization))
+    return false;
+  else if (command_line.HasSwitch(switches::kEnableGpuRasterization))
+    return true;
+
+  if (GpuDataManagerImpl::GetInstance()->IsFeatureBlacklisted(
+          gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION)) {
+    return false;
+  }
+
+  return true;
 }
 
-base::Value* GetFeatureStatus() {
+bool IsForceGpuRasterizationEnabled() {
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+
+  if (!IsImplSidePaintingEnabled())
+    return false;
+
+  return command_line.HasSwitch(switches::kForceGpuRasterization);
+}
+
+base::Value* GetFeatureStatus() {
   GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance();
   std::string gpu_access_blocked_reason;
   bool gpu_access_blocked =
@@ -305,19 +247,14 @@ base::Value* GetFeatureStatus() {
 
   base::DictionaryValue* feature_status_dict = new base::DictionaryValue();
 
-  for (size_t i = 0; i < kNumFeatures; ++i) {
-    const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i);
-    // force_compositing_mode status is part of the compositing status.
-    if (gpu_feature_info.name == "force_compositing_mode")
-      continue;
-
+  bool eof = false;
+  for (size_t i = 0; !eof; ++i) {
+    const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i, &eof);
     std::string status;
     if (gpu_feature_info.disabled) {
       status = "disabled";
-      if (gpu_feature_info.name == "css_animation") {
-        status += "_software_animated";
-      } else if (gpu_feature_info.name == "raster") {
-        if (cc::switches::IsImplSidePaintingEnabled())
+      if (gpu_feature_info.name == kRasterizationFeatureName) {
+        if (IsImplSidePaintingEnabled())
           status += "_software_multithreaded";
         else
           status += "_software";
@@ -338,53 +275,21 @@ base::Value* GetFeatureStatus() {
         status += "_off";
     } else {
       status = "enabled";
-      if (gpu_feature_info.name == "webgl" &&
-          (command_line.HasSwitch(switches::kDisableAcceleratedCompositing) ||
-           manager->IsFeatureBlacklisted(
-               gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)))
+      if (gpu_feature_info.name == kWebGLFeatureName &&
+          manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING))
         status += "_readback";
-      bool has_thread = IsThreadedCompositingEnabled();
-      if (gpu_feature_info.name == "compositing") {
-        bool force_compositing = IsForceCompositingModeEnabled();
-        if (force_compositing)
+      if (gpu_feature_info.name == kRasterizationFeatureName) {
+        if (IsForceGpuRasterizationEnabled())
           status += "_force";
-        if (has_thread)
-          status += "_threaded";
-      }
-      if (gpu_feature_info.name == "css_animation") {
-        if (has_thread)
-          status = "accelerated_threaded";
-        else
-          status = "accelerated";
       }
     }
-    // TODO(reveman): Remove this when crbug.com/223286 has been fixed.
-    if (gpu_feature_info.name == "raster" &&
-        cc::switches::IsImplSidePaintingEnabled()) {
-      status = "disabled_software_multithreaded";
+    if (gpu_feature_info.name == kGpuCompositingFeatureName) {
+      if (IsThreadedCompositingEnabled())
+        status += "_threaded";
     }
     feature_status_dict->SetString(
         gpu_feature_info.name.c_str(), status.c_str());
   }
-  gpu::GpuSwitchingOption gpu_switching_option =
-      manager->GetGpuSwitchingOption();
-  if (gpu_switching_option != gpu::GPU_SWITCHING_OPTION_UNKNOWN) {
-    std::string gpu_switching;
-    switch (gpu_switching_option) {
-    case gpu::GPU_SWITCHING_OPTION_AUTOMATIC:
-        gpu_switching = "gpu_switching_automatic";
-        break;
-    case gpu::GPU_SWITCHING_OPTION_FORCE_DISCRETE:
-        gpu_switching = "gpu_switching_force_discrete";
-        break;
-    case gpu::GPU_SWITCHING_OPTION_FORCE_INTEGRATED:
-        gpu_switching = "gpu_switching_force_integrated";
-        break;
-      default:
-        break;
-    }
-    feature_status_dict->SetString("gpu_switching", gpu_switching.c_str());
-  }
   return feature_status_dict;
 }
 
@@ -403,17 +308,26 @@ base::Value* GetProblems() {
         "GPU process was unable to boot: " + gpu_access_blocked_reason);
     problem->Set("crBugs", new base::ListValue());
     problem->Set("webkitBugs", new base::ListValue());
+    base::ListValue* disabled_features = new base::ListValue();
+    disabled_features->AppendString("all");
+    problem->Set("affectedGpuSettings", disabled_features);
+    problem->SetString("tag", "disabledFeatures");
     problem_list->Insert(0, problem);
   }
 
-  for (size_t i = 0; i < kNumFeatures; ++i) {
-    const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i);
+  bool eof = false;
+  for (size_t i = 0; !eof; ++i) {
+    const GpuFeatureInfo gpu_feature_info = GetGpuFeatureInfo(i, &eof);
     if (gpu_feature_info.disabled) {
       base::DictionaryValue* problem = new base::DictionaryValue();
       problem->SetString(
           "description", gpu_feature_info.disabled_description);
       problem->Set("crBugs", new base::ListValue());
       problem->Set("webkitBugs", new base::ListValue());
+      base::ListValue* disabled_features = new base::ListValue();
+      disabled_features->AppendString(gpu_feature_info.name);
+      problem->Set("affectedGpuSettings", disabled_features);
+      problem->SetString("tag", "disabledFeatures");
       problem_list->Append(problem);
     }
   }