Bug 1475355. Only use WebRender if there's no battery. r=kats
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 17 Jul 2018 18:05:44 -0400
changeset 819811 162af260bace9f34f633ae743a748e415490b03f
parent 819644 7692346c4515d94e12966f22f2278a9c2b7946b9
child 819812 9ba8a6f1857d16d3389c81f3323df1149ae94841
push id116678
push userbmo:nchevobbe@mozilla.com
push dateWed, 18 Jul 2018 18:05:12 +0000
reviewerskats
bugs1475355
milestone63.0a1
Bug 1475355. Only use WebRender if there's no battery. r=kats MozReview-Commit-ID: 86cfi2SGkA2
gfx/thebes/gfxPlatform.cpp
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -52,16 +52,17 @@
 #include "nsCocoaFeatures.h"
 #elif defined(MOZ_WIDGET_GTK)
 #include "gfxPlatformGtk.h"
 #elif defined(ANDROID)
 #include "gfxAndroidPlatform.h"
 #endif
 
 #ifdef XP_WIN
+#include <windows.h>
 #include "mozilla/WindowsVersion.h"
 #include "mozilla/gfx/DeviceManagerDx.h"
 #endif
 
 #include "nsGkAtoms.h"
 #include "gfxPlatformFontList.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
@@ -2517,16 +2518,32 @@ gfxPlatform::WebRenderPrefEnabled()
 
 /*static*/ bool
 gfxPlatform::WebRenderEnvvarEnabled()
 {
   const char* env = PR_GetEnv("MOZ_WEBRENDER");
   return (env && *env == '1');
 }
 
+/* This is a pretty conservative check for having a battery.
+ * For now we'd rather err on the side of thinking we do. */
+static bool HasBattery()
+{
+#ifdef XP_WIN
+  SYSTEM_POWER_STATUS status;
+  const BYTE NO_SYSTEM_BATTERY = 128;
+  if (GetSystemPowerStatus(&status)) {
+    if (status.BatteryFlag == NO_SYSTEM_BATTERY) {
+      return false;
+    }
+  }
+#endif
+  return true;
+}
+
 void
 gfxPlatform::InitWebRenderConfig()
 {
   bool prefEnabled = WebRenderPrefEnabled();
   bool envvarEnabled = WebRenderEnvvarEnabled();
 
   // On Nightly:
   //   WR? WR+   => means WR was enabled via gfx.webrender.all.qualified
@@ -2567,17 +2584,17 @@ gfxPlatform::InitWebRenderConfig()
 
   // gfx.webrender.all.qualified works on all channels
   } else if (gfxPrefs::WebRenderAllQualified()) {
     nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
     nsCString discardFailureId;
     int32_t status;
     if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBRENDER,
                                                discardFailureId, &status))) {
-      if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
+      if (status == nsIGfxInfo::FEATURE_STATUS_OK && !HasBattery()) {
         featureWebRender.UserEnable("Qualified enabled by pref ");
       } else {
         featureWebRender.ForceDisable(FeatureStatus::Blocked,
                                       "Qualified enable blocked",
                                       discardFailureId);
       }
     }
   }