Bug 764125; remove AzureEnabled from gfxInfo and replace with backend check. r=roc
authorNicholas Cameron <ncameron@mozilla.com>
Thu, 26 Jul 2012 13:56:42 +1200
changeset 100625 3c73222e6e1c2a7c9b16b0fe55a8c1fe71e2ddfc
parent 100624 148d57e5d0620b5a8bdda9eec325eafdfac49b57
child 100626 c5125dde4bbf7a8d49835df8a48c4584ada0da02
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs764125
milestone17.0a1
Bug 764125; remove AzureEnabled from gfxInfo and replace with backend check. r=roc
content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
content/canvas/test/test_canvas.html
gfx/layers/d3d10/LayerManagerD3D10.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
widget/android/GfxInfo.h
widget/cocoa/GfxInfo.h
widget/nsIGfxInfo.idl
widget/windows/GfxInfo.h
widget/xpwidgets/GfxInfoBase.cpp
widget/xpwidgets/GfxInfoBase.h
widget/xpwidgets/GfxInfoX11.h
--- a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
@@ -547,25 +547,18 @@ PRUint8 (*nsCanvasRenderingContext2DAzur
 PRUint8 (*nsCanvasRenderingContext2DAzure::sPremultiplyTable)[256] = nsnull;
 
 namespace mozilla {
 namespace dom {
 
 bool
 AzureCanvasEnabled()
 {
-  static bool checkedPref = false;
-  static bool azureEnabled;
-  if (!checkedPref) {
-    azureEnabled = Preferences::GetBool("gfx.canvas.azure.enabled", false);
-    checkedPref = true;
-  }
-
   BackendType dontCare;
-  return azureEnabled && gfxPlatform::GetPlatform()->SupportsAzure(dontCare);
+  return gfxPlatform::GetPlatform()->SupportsAzureCanvas(dontCare);
 }
 
 }
 }
 
 nsresult
 NS_NewCanvasRenderingContext2DAzure(nsIDOMCanvasRenderingContext2D** aResult)
 {
--- a/content/canvas/test/test_canvas.html
+++ b/content/canvas/test/test_canvas.html
@@ -39,17 +39,18 @@ function IsMacOSX10_5orOlder() {
 }
 
 
 function IsAzureEnabled() {
   var enabled = false;
 
   try {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    enabled = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).AzureEnabled;
+    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureBackend;
+    enabled = (backend != "none");
   } catch (e) { }
 
   return enabled;
 }
 
 function IsAzureSkia() {
   var enabled = false;
   
--- a/gfx/layers/d3d10/LayerManagerD3D10.cpp
+++ b/gfx/layers/d3d10/LayerManagerD3D10.cpp
@@ -482,17 +482,17 @@ LayerManagerD3D10::CreateOptimalMaskSurf
 
 TemporaryRef<DrawTarget>
 LayerManagerD3D10::CreateDrawTarget(const IntSize &aSize,
                                     SurfaceFormat aFormat)
 {
   BackendType backend;
   if ((aFormat != FORMAT_B8G8R8A8 &&
        aFormat != FORMAT_B8G8R8X8) ||
-       !gfxPlatform::GetPlatform()->SupportsAzure(backend) ||
+       !gfxPlatform::GetPlatform()->SupportsAzureCanvas(backend) ||
        backend != BACKEND_DIRECT2D) {
     return LayerManager::CreateDrawTarget(aSize, aFormat);
   }
 
   nsRefPtr<ID3D10Texture2D> texture;
   
   CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1);
   desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -208,17 +208,17 @@ static const char *gPrefLangNames[] = {
     "x-knda",
     "x-sinh",
     "x-tibt",
     "x-unicode",
     "x-user-def"
 };
 
 gfxPlatform::gfxPlatform()
-  : mAzureBackendCollector(this, &gfxPlatform::GetAzureBackendInfo)
+  : mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureCanvasBackendInfo)
 {
     mUseHarfBuzzScripts = UNINITIALIZED_VALUE;
     mAllowDownloadableFonts = UNINITIALIZED_VALUE;
     mDownloadableFontsSanitize = UNINITIALIZED_VALUE;
     mFallbackUsesCmaps = UNINITIALIZED_VALUE;
 
 #ifdef MOZ_GRAPHITE
     mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
@@ -669,17 +669,17 @@ gfxPlatform::GetThebesSurfaceForDrawTarg
 
   return surf.forget();
 }
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateDrawTargetForBackend(BackendType aBackend, const IntSize& aSize, SurfaceFormat aFormat)
 {
   BackendType backend;
-  if (!SupportsAzure(backend)) {
+  if (!SupportsAzureCanvas(backend)) {
     return NULL;
   }
 
   // There is a bunch of knowledge in the gfxPlatform heirarchy about how to
   // create the best offscreen surface for the current system and situation. We
   // can easily take advantage of this for the Cairo backend, so that's what we
   // do.
   // mozilla::gfx::Factory can get away without having all this knowledge for
@@ -698,17 +698,17 @@ gfxPlatform::CreateDrawTargetForBackend(
     return Factory::CreateDrawTarget(aBackend, aSize, aFormat);
   }
 }
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateOffscreenDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
 {
   BackendType backend;
-  if (!SupportsAzure(backend)) {
+  if (!SupportsAzureCanvas(backend)) {
     return NULL;
   }
 
   RefPtr<DrawTarget> target = CreateDrawTargetForBackend(backend, aSize, aFormat);
   if (target ||
       mFallbackCanvasBackend == BACKEND_NONE) {
     return target;
   }
@@ -716,31 +716,29 @@ gfxPlatform::CreateOffscreenDrawTarget(c
   return CreateDrawTargetForBackend(mFallbackCanvasBackend, aSize, aFormat);
 }
 
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
 {
   BackendType backend;
-  if (!SupportsAzure(backend)) {
+  if (!SupportsAzureCanvas(backend)) {
     return NULL;
   }
   return Factory::CreateDrawTargetForData(backend, aData, aSize, aStride, aFormat); 
 }
 
 bool
-gfxPlatform::SupportsAzure(BackendType& aBackend)
+gfxPlatform::SupportsAzureCanvas(BackendType& aBackend)
 {
-  if (mPreferredCanvasBackend != BACKEND_NONE) {
-    aBackend = mPreferredCanvasBackend;
-    return true;
-  }
-
-  return false;
+  NS_ASSERTION(mFallbackCanvasBackend == BACKEND_NONE || mPreferredCanvasBackend != BACKEND_NONE,
+               "fallback backend with no preferred backend");
+  aBackend = mPreferredCanvasBackend;
+  return mPreferredCanvasBackend != BACKEND_NONE;
 }
 
 /* static */ BackendType
 gfxPlatform::BackendTypeForName(const nsCString& aName)
 {
   if (aName.EqualsLiteral("cairo"))
     return BACKEND_CAIRO;
   if (aName.EqualsLiteral("skia"))
@@ -1170,16 +1168,22 @@ gfxPlatform::AppendPrefLang(eFontPrefLan
         aPrefLangs[aLen] = aAddLang;
         aLen++;
     }
 }
 
 void
 gfxPlatform::InitCanvasBackend(PRUint32 aBackendBitmask)
 {
+    if (!Preferences::GetBool("gfx.canvas.azure.enabled", false)) {
+        mPreferredCanvasBackend = BACKEND_NONE;
+        mFallbackCanvasBackend = BACKEND_NONE;
+        return;
+    }
+
     mPreferredCanvasBackend = GetCanvasBackendPref(aBackendBitmask);
     mFallbackCanvasBackend = GetCanvasBackendPref(aBackendBitmask & ~(1 << mPreferredCanvasBackend));
 }
 
 /* static */ BackendType
 gfxPlatform::GetCanvasBackendPref(PRUint32 aBackendBitmask)
 {
     if (!gBackendList) {
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -125,17 +125,17 @@ GetBackendName(mozilla::gfx::BackendType
         return "quartz";
       case mozilla::gfx::BACKEND_CAIRO:
         return "cairo";
       case mozilla::gfx::BACKEND_SKIA:
         return "skia";
       case mozilla::gfx::BACKEND_NONE:
         return "none";
   }
-  MOZ_NOT_REACHED("Incomplet switch");
+  MOZ_NOT_REACHED("Incomplete switch");
 }
 
 class THEBES_API gfxPlatform {
 public:
     /**
      * Return a pointer to the current active platform.
      * This is a singleton; it contains mostly convenience
      * functions to obtain platform-specific objects.
@@ -191,24 +191,21 @@ public:
     virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
       CreateOffscreenDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
 
     virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
       CreateDrawTargetForData(unsigned char* aData, const mozilla::gfx::IntSize& aSize, 
                               int32_t aStride, mozilla::gfx::SurfaceFormat aFormat);
 
     // aBackend will be set to the preferred backend for Azure canvas
-    bool SupportsAzure(mozilla::gfx::BackendType& aBackend);
+    bool SupportsAzureCanvas(mozilla::gfx::BackendType& aBackend);
 
     // aObj will contain the preferred backend for Azure canvas
-    void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) {
-      mozilla::gfx::BackendType backend;
-      if (SupportsAzure(backend)) {
-        aObj.DefineProperty("AzureBackend", GetBackendName(backend)); 
-      }
+    void GetAzureCanvasBackendInfo(mozilla::widget::InfoObject &aObj) {
+      aObj.DefineProperty("AzureBackend", GetBackendName(mPreferredCanvasBackend));
     }
 
     /*
      * Font bits
      */
 
     virtual void SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aString);
 
@@ -491,30 +488,31 @@ protected:
 
     // whether to always search font cmaps globally 
     // when doing system font fallback
     PRInt8  mFallbackUsesCmaps;
 
     // which scripts should be shaped with harfbuzz
     PRInt32 mUseHarfBuzzScripts;
 
-    // The preferred draw target backend to use for canvas
-    mozilla::gfx::BackendType mPreferredCanvasBackend;
-    // The fallback draw target backend to use for canvas, if the preferred backend fails
-    mozilla::gfx::BackendType mFallbackCanvasBackend;
-
 private:
     /**
      * Start up Thebes.
      */
     static void Init();
 
     virtual qcms_profile* GetPlatformCMSOutputProfile();
 
     nsRefPtr<gfxASurface> mScreenReferenceSurface;
     nsTArray<PRUint32> mCJKPrefLangs;
     nsCOMPtr<nsIObserver> mSRGBOverrideObserver;
     nsCOMPtr<nsIObserver> mFontPrefsObserver;
-    mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureBackendCollector;
+
+    // The preferred draw target backend to use for canvas
+    mozilla::gfx::BackendType mPreferredCanvasBackend;
+    // The fallback draw target backend to use for canvas, if the preferred backend fails
+    mozilla::gfx::BackendType mFallbackCanvasBackend;
+
+    mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureCanvasBackendCollector;
     bool mWorkAroundDriverBugs;
 };
 
 #endif /* GFX_PLATFORM_H */
--- a/widget/android/GfxInfo.h
+++ b/widget/android/GfxInfo.h
@@ -40,17 +40,16 @@ public:
   NS_IMETHOD GetAdapterDeviceID2(nsAString & aAdapterDeviceID);
   NS_IMETHOD GetAdapterRAM2(nsAString & aAdapterRAM);
   NS_IMETHOD GetAdapterDriverVersion2(nsAString & aAdapterDriverVersion);
   NS_IMETHOD GetAdapterDriverDate2(nsAString & aAdapterDriverDate);
   NS_IMETHOD GetIsGPU2Active(bool *aIsGPU2Active);
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
-  using GfxInfoBase::GetAzureEnabled;
 
   void EnsureInitializedFromGfxInfoData();
 
 #ifdef DEBUG
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG
 #endif
 
--- a/widget/cocoa/GfxInfo.h
+++ b/widget/cocoa/GfxInfo.h
@@ -40,17 +40,16 @@ public:
   NS_IMETHOD GetAdapterRAM2(nsAString & aAdapterRAM);
   NS_IMETHOD GetAdapterDriverVersion2(nsAString & aAdapterDriverVersion);
   NS_IMETHOD GetAdapterDriverDate2(nsAString & aAdapterDriverDate);
   NS_IMETHOD GetIsGPU2Active(bool *aIsGPU2Active);
 
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
-  using GfxInfoBase::GetAzureEnabled;
 
   virtual nsresult Init();
 
 #ifdef DEBUG
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG
 #endif
 
--- a/widget/nsIGfxInfo.idl
+++ b/widget/nsIGfxInfo.idl
@@ -11,17 +11,16 @@
 [scriptable, uuid(a67c77af-2952-4028-93ab-e7bc3b43cf81)]
 interface nsIGfxInfo : nsISupports
 {
   /*
    * These are win32-specific
    */
   readonly attribute boolean D2DEnabled;
   readonly attribute boolean DWriteEnabled;
-  readonly attribute boolean AzureEnabled;
   readonly attribute DOMString DWriteVersion;
   readonly attribute DOMString cleartypeParameters;
 
   // XXX: Switch to a list of devices, rather than explicitly numbering them. 
 
   /**
    * The name of the display adapter.
    */
--- a/widget/windows/GfxInfo.h
+++ b/widget/windows/GfxInfo.h
@@ -37,17 +37,16 @@ public:
   NS_IMETHOD GetAdapterDeviceID2(nsAString & aAdapterDeviceID);
   NS_IMETHOD GetAdapterRAM2(nsAString & aAdapterRAM);
   NS_IMETHOD GetAdapterDriverVersion2(nsAString & aAdapterDriverVersion);
   NS_IMETHOD GetAdapterDriverDate2(nsAString & aAdapterDriverDate);
   NS_IMETHOD GetIsGPU2Active(bool *aIsGPU2Active);
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
-  using GfxInfoBase::GetAzureEnabled;
 
   virtual nsresult Init();
 
 #ifdef DEBUG
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG
 #endif
 
--- a/widget/xpwidgets/GfxInfoBase.cpp
+++ b/widget/xpwidgets/GfxInfoBase.cpp
@@ -719,32 +719,16 @@ GfxInfoBase::GetFeatureSuggestedDriverVe
 
 NS_IMETHODIMP
 GfxInfoBase::GetWebGLParameter(const nsAString& aParam,
                                nsAString& aResult)
 {
   return GfxInfoWebGL::GetWebGLParameter(aParam, aResult);
 }
 
-nsresult
-GfxInfoBase::GetAzureEnabled(bool *aEnabled)
-{
-  static bool azure = false;
-  static bool azureInited = false;
-
-  if (!azureInited) {
-    azure = mozilla::Preferences::GetBool("gfx.canvas.azure.enabled", false);
-    azureInited = true;
-  }
-
-  *aEnabled = azure;
-
-  return NS_OK;
-}
-
 void
 GfxInfoBase::EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo)
 {
   PRInt32 features[] = {
     nsIGfxInfo::FEATURE_DIRECT2D,
     nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
     nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
     nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
--- a/widget/xpwidgets/GfxInfoBase.h
+++ b/widget/xpwidgets/GfxInfoBase.h
@@ -36,22 +36,20 @@ public:
   NS_DECL_NSIOBSERVER
 
   // We only declare a subset of the nsIGfxInfo interface. It's up to derived
   // classes to implement the rest of the interface.  
   // Derived classes need to use
   // using GfxInfoBase::GetFeatureStatus;
   // using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   // using GfxInfoBase::GetWebGLParameter;
-  // using GfxInfoBase::GetAzureEnabled;
   // to import the relevant methods into their namespace.
   NS_IMETHOD GetFeatureStatus(PRInt32 aFeature, PRInt32 *_retval);
   NS_IMETHOD GetFeatureSuggestedDriverVersion(PRInt32 aFeature, nsAString & _retval);
   NS_IMETHOD GetWebGLParameter(const nsAString & aParam, nsAString & _retval);
-  NS_IMETHOD GetAzureEnabled(bool *aAzureEnabled);
 
   NS_IMETHOD GetFailures(PRUint32 *failureCount, char ***failures);
   NS_IMETHOD_(void) LogFailure(const nsACString &failure);
   NS_IMETHOD GetInfo(JSContext*, jsval*);
 
   // Initialization function. If you override this, you must call this class's
   // version of Init first.
   // We need Init to be called separately from the constructor so we can
--- a/widget/xpwidgets/GfxInfoX11.h
+++ b/widget/xpwidgets/GfxInfoX11.h
@@ -36,17 +36,16 @@ public:
   NS_IMETHOD GetAdapterDeviceID2(nsAString & aAdapterDeviceID);
   NS_IMETHOD GetAdapterRAM2(nsAString & aAdapterRAM);
   NS_IMETHOD GetAdapterDriverVersion2(nsAString & aAdapterDriverVersion);
   NS_IMETHOD GetAdapterDriverDate2(nsAString & aAdapterDriverDate);
   NS_IMETHOD GetIsGPU2Active(bool *aIsGPU2Active);
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
-  using GfxInfoBase::GetAzureEnabled;
 
   virtual nsresult Init();
   
   NS_IMETHOD_(void) GetData();
 
 #ifdef DEBUG
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG