Bug 623446. Turn the layer acceleration prefs into a tri-state. r=joe,a=b
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 11 Jan 2011 17:01:37 -0500
changeset 60324 58d9f36e3a49
parent 60323 e2e5b5e57ca4
child 60325 82ac194b7537
push id17934
push userjmuizelaar@mozilla.com
push dateTue, 11 Jan 2011 22:03:30 +0000
treeherdermozilla-central@58d9f36e3a49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe, b
bugs623446
milestone2.0b10pre
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 623446. Turn the layer acceleration prefs into a tri-state. r=joe,a=b This removes: layers.accelerate-all layers.accelerate-none and adds: layers.acceleration.disabled layers.acceleration.force-enabled This is closer to what D2D does.
browser/components/preferences/advanced.js
browser/components/preferences/advanced.xul
gfx/layers/d3d9/LayerManagerD3D9.cpp
gfx/layers/opengl/LayerManagerOGL.cpp
modules/libpref/src/init/all.js
widget/src/windows/nsWindow.cpp
widget/src/xpwidgets/nsBaseWidget.cpp
--- a/browser/components/preferences/advanced.js
+++ b/browser/components/preferences/advanced.js
@@ -168,23 +168,23 @@ var gAdvancedPane = {
     try {
       var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
                getService(Components.interfaces.nsICrashReporter);
       cr.submitReports = checkbox.checked;
     } catch (e) { }
   },
 
   /**
-   * When the user toggles the layers.accelerate-none pref,
+   * When the user toggles the layers.acceleration.disabled pref,
    * sync its new value to the gfx.direct2d.disabled pref too.
    */
   updateHardwareAcceleration: function()
   {
 #ifdef XP_WIN
-    var pref = document.getElementById("layers.accelerate-none");
+    var pref = document.getElementById("layers.acceleration.disabled");
     Services.prefs.setBoolPref("gfx.direct2d.disabled", !pref.value);
 #endif
   },
 
   // NETWORK TAB
 
   /*
    * Preferences:
--- a/browser/components/preferences/advanced.xul
+++ b/browser/components/preferences/advanced.xul
@@ -63,17 +63,17 @@
 
       <!-- General tab -->
       <preference id="accessibility.browsewithcaret"   name="accessibility.browsewithcaret"   type="bool"/>
       <preference id="accessibility.typeaheadfind"     name="accessibility.typeaheadfind"     type="bool"/>
       <preference id="accessibility.blockautorefresh"  name="accessibility.blockautorefresh"  type="bool"/>
 
       <preference id="general.autoScroll"              name="general.autoScroll"              type="bool"/>
       <preference id="general.smoothScroll"            name="general.smoothScroll"            type="bool"/>
-      <preference id="layers.accelerate-none"          name="layers.accelerate-none"          type="bool"   inverted="true"
+      <preference id="layers.acceleration.disabled"    name="layers.acceleration.disabled"    type="bool"   inverted="true"
                   onchange="gAdvancedPane.updateHardwareAcceleration()"/>
       <preference id="layout.spellcheckDefault"        name="layout.spellcheckDefault"        type="int"/>
 
 #ifdef HAVE_SHELL_SERVICE
       <preference id="browser.shell.checkDefaultBrowser"
                   name="browser.shell.checkDefaultBrowser"
                   type="bool"/>
 
@@ -179,17 +179,17 @@
                       preference="general.autoScroll"/>
             <checkbox id="useSmoothScrolling"
                       label="&useSmoothScrolling.label;"
                       accesskey="&useSmoothScrolling.accesskey;"
                       preference="general.smoothScroll"/>
             <checkbox id="allowHWAccel"
                       label="&allowHWAccel.label;"
                       accesskey="&allowHWAccel.accesskey;"
-                      preference="layers.accelerate-none"/>
+                      preference="layers.acceleration.disabled"/>
             <checkbox id="checkSpelling"
                       label="&checkSpelling.label;"
                       accesskey="&checkSpelling.accesskey;"
                       onsyncfrompreference="return gAdvancedPane.readCheckSpelling();"
                       onsynctopreference="return gAdvancedPane.writeCheckSpelling();"
                       preference="layout.spellcheckDefault"/>
           </groupbox>
 
--- a/gfx/layers/d3d9/LayerManagerD3D9.cpp
+++ b/gfx/layers/d3d9/LayerManagerD3D9.cpp
@@ -40,16 +40,18 @@
 #include "ThebesLayerD3D9.h"
 #include "ContainerLayerD3D9.h"
 #include "ImageLayerD3D9.h"
 #include "ColorLayerD3D9.h"
 #include "CanvasLayerD3D9.h"
 #include "gfxWindowsPlatform.h"
 #include "nsIGfxInfo.h"
 #include "nsServiceManagerUtils.h"
+#include "nsIPrefService.h"
+#include "nsIPrefBranch2.h"
 
 namespace mozilla {
 namespace layers {
 
 DeviceManagerD3D9 *LayerManagerD3D9::mDefaultDeviceManager = nsnull;
 
 LayerManagerD3D9::LayerManagerD3D9(nsIWidget *aWidget)
 {
@@ -61,21 +63,30 @@ LayerManagerD3D9::LayerManagerD3D9(nsIWi
 LayerManagerD3D9::~LayerManagerD3D9()
 {
   Destroy();
 }
 
 PRBool
 LayerManagerD3D9::Initialize()
 {
+  nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
+
+  PRBool forceAccelerate = PR_FALSE;
+  if (prefs) {
+    // we should use AddBoolPrefVarCache
+    prefs->GetBoolPref("layers.acceleration.force-enabled",
+                       &forceAccelerate);
+  }
+
   nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
   if (gfxInfo) {
     PRInt32 status;
     if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS, &status))) {
-      if (status != nsIGfxInfo::FEATURE_NO_INFO)
+      if (status != nsIGfxInfo::FEATURE_NO_INFO && !forceAccelerate)
       {
         NS_WARNING("Direct3D 9-accelerated layers are not supported on this system.");
         return PR_FALSE;
       }
     }
   }
 
   if (!mDefaultDeviceManager) {
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -53,16 +53,18 @@
 #include "gfxContext.h"
 #include "nsIWidget.h"
 
 #include "GLContext.h"
 #include "GLContextProvider.h"
 
 #include "nsIServiceManager.h"
 #include "nsIConsoleService.h"
+#include "nsIPrefService.h"
+#include "nsIPrefBranch2.h"
 
 #include "nsIGfxInfo.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gl;
 
@@ -152,21 +154,30 @@ PRBool
 LayerManagerOGL::Initialize(GLContext *aExistingContext)
 {
   if (aExistingContext) {
     mGLContext = aExistingContext;
   } else {
     if (mGLContext)
       CleanupResources();
 
+    nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
+
+    PRBool forceAccelerate = PR_FALSE;
+    if (prefs) {
+      // we should use AddBoolPrefVarCache
+      prefs->GetBoolPref("layers.acceleration.force-enabled",
+                         &forceAccelerate);
+    }
+
     nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
     if (gfxInfo) {
       PRInt32 status;
       if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &status))) {
-        if (status != nsIGfxInfo::FEATURE_NO_INFO) {
+        if (status != nsIGfxInfo::FEATURE_NO_INFO && !forceAccelerate) {
           NS_WARNING("OpenGL-accelerated layers are not supported on this system.");
           return PR_FALSE;
         }
       }
     }
 
     mGLContext = nsnull;
 
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -3212,29 +3212,21 @@ pref("network.tcp.sendbuffer", 131072);
 #endif
 #endif
 
 #ifdef WINCE
 pref("mozilla.widget.disable-native-theme", true);
 pref("gfx.color_management.mode", 0);
 #endif
 
-// Default value of acceleration for all widgets.
-#ifdef XP_WIN
-pref("layers.accelerate-all", true);
-#else
-#ifdef XP_MACOSX
-pref("layers.accelerate-all", true);
-#else
-pref("layers.accelerate-all", false);
-#endif
-#endif
-
-// Whether to allow acceleration on layers at all.
-pref("layers.accelerate-none", false);
+// Whether to disable acceleration for all widgets.
+pref("layers.acceleration.disabled", false);
+
+// Whether to force acceleration on, ignoring blacklists.
+pref("layers.acceleration.force-enabled", false);
 
 #ifdef XP_WIN
 #ifndef WINCE
 // Whether to disable the automatic detection and use of direct2d.
 pref("gfx.direct2d.disabled", false);
 // Whether to attempt to enable Direct2D regardless of automatic detection or
 // blacklisting
 pref("gfx.direct2d.force-enabled", false);
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -3304,19 +3304,17 @@ nsWindow::GetLayerManager(LayerManagerPe
     // -and- we're currently using basic layers, run through this check.
     nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
 
     PRBool accelerateByDefault = PR_TRUE;
     PRBool disableAcceleration = PR_FALSE;
     PRBool preferOpenGL = PR_FALSE;
     PRBool preferD3D9 = PR_FALSE;
     if (prefs) {
-      prefs->GetBoolPref("layers.accelerate-all",
-                         &accelerateByDefault);
-      prefs->GetBoolPref("layers.accelerate-none",
+      prefs->GetBoolPref("layers.acceleration.disabled",
                          &disableAcceleration);
       prefs->GetBoolPref("layers.prefer-opengl",
                          &preferOpenGL);
       prefs->GetBoolPref("layers.prefer-d3d9",
                          &preferD3D9);
     }
 
     const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
--- a/widget/src/xpwidgets/nsBaseWidget.cpp
+++ b/widget/src/xpwidgets/nsBaseWidget.cpp
@@ -778,22 +778,25 @@ nsBaseWidget::AutoUseBasicLayerManager::
 }
 
 PRBool
 nsBaseWidget::GetShouldAccelerate()
 {
   nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
 
   PRBool disableAcceleration = PR_FALSE;
+#if defined(XP_WIN) || defined(XP_MACOSX)
   PRBool accelerateByDefault = PR_TRUE;
+#else
+  PRBool accelerateByDefault = PR_FALSE;
+#endif
 
   if (prefs) {
-    prefs->GetBoolPref("layers.accelerate-all",
-                       &accelerateByDefault);
-    prefs->GetBoolPref("layers.accelerate-none",
+    // we should use AddBoolPrefVarCache
+    prefs->GetBoolPref("layers.acceleration.disabled",
                        &disableAcceleration);
   }
 
   const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
   accelerateByDefault = accelerateByDefault || 
                         (acceleratedEnv && (*acceleratedEnv != '0'));
 
   nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
@@ -802,16 +805,17 @@ nsBaseWidget::GetShouldAccelerate()
     xr->GetInSafeMode(&safeMode);
 
   if (disableAcceleration || safeMode)
     return PR_FALSE;
 
   if (accelerateByDefault)
     return PR_TRUE;
 
+  /* use the window acceleration flag */
   return mUseAcceleratedRendering;
 }
 
 LayerManager* nsBaseWidget::GetLayerManager(bool* aAllowRetaining)
 {
   return GetLayerManager(LAYER_MANAGER_CURRENT, aAllowRetaining);
 }