Bug 1561073 - powerPreference 'default' => 'low-power' if Canvas element has no parent. r=jrmuizel
☠☠ backed out by 11921e0666e8 ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 24 Jun 2019 22:09:31 +0000
changeset 542820 bd8a279979b3969d4d8a6dd3d155df5df4bf7a3e
parent 542819 abacb77a97bbcfb54915aedd34ef7aefafdb0e78
child 542821 e225c2251a14b88d8f50103e3d60e79634aa72aa
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1561073
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1561073 - powerPreference 'default' => 'low-power' if Canvas element has no parent. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D35704
dom/canvas/WebGLContext.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -478,42 +478,56 @@ bool WebGLContext::CreateAndInitGL(
   }
 
   if (IsWebGL2()) {
     flags |= gl::CreateContextFlags::PREFER_ES3;
   } else if (!StaticPrefs::WebGL1AllowCoreProfile()) {
     flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
   }
 
-  switch (mOptions.powerPreference) {
-    case dom::WebGLPowerPreference::Low_power:
-      break;
-
-    case dom::WebGLPowerPreference::High_performance:
+  {
+    bool highPower = false;
+    switch (mOptions.powerPreference) {
+      case dom::WebGLPowerPreference::Low_power:
+        highPower = false;
+        break;
+
+      case dom::WebGLPowerPreference::High_performance:
+        highPower = true;
+        break;
+
+        // Eventually add a heuristic, but for now default to high-performance.
+        // We can even make it dynamic by holding on to a
+        // ForceDiscreteGPUHelperCGL iff we decide it's a high-performance
+        // application:
+        // - Non-trivial canvas size
+        // - Many draw calls
+        // - Same origin with root page (try to stem bleeding from WebGL
+        // ads/trackers)
+      default:
+        highPower = true;
+        if (StaticPrefs::WebGLDefaultLowPower()) {
+          highPower = false;
+        } else if (!mCanvasElement->GetParentNode()) {
+          GenerateWarning(
+              "WebGLContextAttributes.powerPreference: 'default' when <canvas>"
+              " has no parent Element defaults to 'low-power'.");
+          highPower = false;
+        }
+        break;
+    }
+
+    // If "Use hardware acceleration when available" option is disabled:
+    if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
+      highPower = false;
+    }
+
+    if (highPower) {
       flags |= gl::CreateContextFlags::HIGH_POWER;
-      break;
-
-      // Eventually add a heuristic, but for now default to high-performance.
-      // We can even make it dynamic by holding on to a
-      // ForceDiscreteGPUHelperCGL iff we decide it's a high-performance
-      // application:
-      // - Non-trivial canvas size
-      // - Many draw calls
-      // - Same origin with root page (try to stem bleeding from WebGL
-      // ads/trackers)
-    default:
-      if (!StaticPrefs::WebGLDefaultLowPower()) {
-        flags |= gl::CreateContextFlags::HIGH_POWER;
-      }
-      break;
-  }
-
-  // If "Use hardware acceleration when available" option is disabled:
-  if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
-    flags &= ~gl::CreateContextFlags::HIGH_POWER;
+    }
   }
 
 #ifdef XP_MACOSX
   const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
   nsString vendorID, deviceID;
 
   // Avoid crash for Intel HD Graphics 3000 on OSX. (Bug 1413269)
   gfxInfo->GetAdapterVendorID(vendorID);