Bug 1426191 - Update test_acceleration to check for webrender windows. r?dvander draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 21 Dec 2017 09:25:07 -0500
changeset 714024 51391a52510e7bcca6bd3b90b14b347e9ca37eab
parent 713529 2ff08db67b917fba1558986f3f2f796260f970f8
child 714025 f4e1bff052db08e79a9a4e96bcc1de02993c203a
push id93815
push userkgupta@mozilla.com
push dateThu, 21 Dec 2017 14:26:33 +0000
reviewersdvander
bugs1426191
milestone59.0a1
Bug 1426191 - Update test_acceleration to check for webrender windows. r?dvander MozReview-Commit-ID: gbBJs4OR9f
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
gfx/tests/mochitest/test_acceleration.html
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -2333,16 +2333,24 @@ nsDOMWindowUtils::GetUsingAdvancedLayers
   *retval = false;
   if (KnowsCompositor* fwd = mgr->AsKnowsCompositor()) {
     *retval = fwd->GetTextureFactoryIdentifier().mUsingAdvancedLayers;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDOMWindowUtils::GetIsWebRenderRequested(bool* retval)
+{
+  *retval = gfxPlatform::WebRenderPrefEnabled() ||
+            gfxPlatform::WebRenderEnvvarEnabled();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentAudioBackend(nsAString& aBackend)
 {
   CubebUtils::GetCurrentBackend(aBackend);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentMaxAudioChannels(uint32_t* aChannels)
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -1327,16 +1327,23 @@ interface nsIDOMWindowUtils : nsISupport
   readonly attribute boolean layerManagerRemote;
 
   /**
    * True if advanced layers is enabled on this window, false otherwise.
    */
   readonly attribute boolean usingAdvancedLayers;
 
   /**
+   * True if webrender was requested by the user (via pref or env-var), false
+   * otherwise. Note that this doesn't represent whether or not webrender is
+   * *actually* enabled, just whether or not it was requested.
+   */
+  readonly attribute boolean isWebRenderRequested;
+
+  /**
    * Returns the current audio backend as a free-form string.
    */
   readonly attribute AString currentAudioBackend;
 
   /**
    * Returns the max channel counts of the current audio device.
    */
   readonly attribute unsigned long currentMaxAudioChannels;
--- a/gfx/tests/mochitest/test_acceleration.html
+++ b/gfx/tests/mochitest/test_acceleration.html
@@ -30,24 +30,28 @@ function runTest() {
 
   var sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
   var xr = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
 
   var windows = SpecialPowers.Services.ww.getWindowEnumerator();
   var windowutils;
   var acceleratedWindows = 0;
   var advancedLayersWindows = 0;
+  var webrenderWindows = 0;
   var layerManagerLog = [];
   while (windows.hasMoreElements()) {
     windowutils = windows.getNext().QueryInterface(Ci.nsIInterfaceRequestor)
                                    .getInterface(Ci.nsIDOMWindowUtils);
     try {
       if (windowutils.layerManagerType != "Basic") {
         acceleratedWindows++;
       }
+      if (windowutils.layerManagerType == "WebRender") {
+        webrenderWindows++;
+      }
       if (windowutils.usingAdvancedLayers) {
         advancedLayersWindows++;
       }
       layerManagerLog.push(windowutils.layerManagerType + ":" +
                            windowutils.usingAdvancedLayers);
     } catch (e) {
       // The window may not have a layer manager, in which case we get an error.
       // Don't count it as an accelerated window.
@@ -103,32 +107,47 @@ function runTest() {
         } else {
           ok(gfxInfo.DWriteEnabled, "DirectWrite enabled on Windows 7 or newer");
         }
       } else {
         ok(gfxInfo.D2DEnabled, "Direct2D enabled on Windows 8 or newer");
         ok(gfxInfo.DWriteEnabled, "DirectWrite enabled on Windows 7 or newer");
       }
 
+      var shouldGetWR = false;
+      try {
+        shouldGetWR = SpecialPowers.DOMWindowUtils.isWebRenderRequested;
+      } catch (e) {}
+
       var advancedLayersEnabled = false;
       var advancedLayersEnabledOnWin7 = false;
       try {
         advancedLayersEnabled = SpecialPowers.getBoolPref("layers.mlgpu.enabled");
         advancedLayersEnabledOnWin7 = SpecialPowers.getBoolPref("layers.mlgpu.enable-on-windows7");
       } catch (e) {}
       var shouldGetAL = advancedLayersEnabled;
       if (version < 6.2) {
         shouldGetAL &= advancedLayersEnabledOnWin7;
       }
+      if (shouldGetWR) {
+        shouldGetAL = false;
+      }
+
       if (shouldGetAL) {
         isnot(advancedLayersWindows, 0, "Advanced Layers enabled on Windows; "
                                         + layerManagerLog.join(","));
       } else {
         is(advancedLayersWindows, 0, "Advanced Layers disabled on Windows");
       }
+
+      if (shouldGetWR) {
+        isnot(webrenderWindows, 0, "WebRender enabled on Windows");
+      } else {
+        is(webrenderWindows, 0, "WebRender disabled on Windows");
+      }
       break;
 
     case "Linux":
       todo(false, "Acceleration supported on Linux, but only on taskcluster instances (bug 1296086)");
       break;
 
     default:
       if (xr.OS == "Android") {
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -2455,20 +2455,33 @@ gfxPlatform::InitCompositorAccelerationP
                          NS_LITERAL_CSTRING("FEATURE_FAILURE_COMP_SAFEMODE"));
   }
   if (IsHeadless()) {
     feature.ForceDisable(FeatureStatus::Blocked, "Acceleration blocked by headless mode",
                          NS_LITERAL_CSTRING("FEATURE_FAILURE_COMP_HEADLESSMODE"));
   }
 }
 
+/*static*/ bool
+gfxPlatform::WebRenderPrefEnabled()
+{
+  return Preferences::GetBool("gfx.webrender.enabled", false);
+}
+
+/*static*/ bool
+gfxPlatform::WebRenderEnvvarEnabled()
+{
+  const char* env = PR_GetEnv("MOZ_WEBRENDER");
+  return (env && *env == '1');
+}
+
 void
 gfxPlatform::InitWebRenderConfig()
 {
-  bool prefEnabled = Preferences::GetBool("gfx.webrender.enabled", false);
+  bool prefEnabled = WebRenderPrefEnabled();
 
   ScopedGfxFeatureReporter reporter("WR", prefEnabled);
   if (!XRE_IsParentProcess()) {
     // The parent process runs through all the real decision-making code
     // later in this function. For other processes we still want to report
     // the state of the feature for crash reports.
     if (gfxVars::UseWebRender()) {
       reporter.SetSuccessful();
@@ -2480,21 +2493,18 @@ gfxPlatform::InitWebRenderConfig()
 
   featureWebRender.DisableByDefault(
       FeatureStatus::OptIn,
       "WebRender is an opt-in feature",
       NS_LITERAL_CSTRING("FEATURE_FAILURE_DEFAULT_OFF"));
 
   if (prefEnabled) {
     featureWebRender.UserEnable("Enabled by pref");
-  } else {
-    const char* env = PR_GetEnv("MOZ_WEBRENDER");
-    if (env && *env == '1') {
-      featureWebRender.UserEnable("Enabled by envvar");
-    }
+  } else if (WebRenderEnvvarEnabled()) {
+    featureWebRender.UserEnable("Enabled by envvar");
   }
 
   // HW_COMPOSITING being disabled implies interfacing with the GPU might break
   if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
     featureWebRender.ForceDisable(
       FeatureStatus::Unavailable,
       "Hardware compositing is disabled",
       NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBRENDER_NEED_HWCOMP"));
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -705,16 +705,21 @@ public:
      * GPUProcessManager, in the UI process.
      */
     virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData);
 
     virtual FT_Library GetFTLibrary() {
       return nullptr;
     }
 
+    // you probably want to use gfxVars::UseWebRender() instead of this
+    static bool WebRenderPrefEnabled();
+    // you probably want to use gfxVars::UseWebRender() instead of this
+    static bool WebRenderEnvvarEnabled();
+
 protected:
     gfxPlatform();
     virtual ~gfxPlatform();
 
     virtual void InitAcceleration();
 
     /**
      * Called immediately before deleting the gfxPlatform object.