Bug 776802; Give better info about Azure. r=Bas
authorNicholas Cameron <ncameron@mozilla.com>
Tue, 31 Jul 2012 13:45:59 +1200
changeset 102779 037783860cab6c3ae6e7be961fe3ba8fca625a2c
parent 102778 2587526de94cdea87e6c1f22c44555bcb16b6487
child 102780 ab354866845bebab1a99d8bed067e11e73a15364
push id18
push usershu@rfrn.org
push dateMon, 06 Aug 2012 22:42:45 +0000
reviewersBas
bugs776802
milestone17.0a1
Bug 776802; Give better info about Azure. r=Bas
content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
content/canvas/test/test_canvas.html
gfx/layers/d3d10/LayerManagerD3D10.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxWindowsPlatform.h
layout/tools/reftest/reftest.js
--- a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
@@ -547,18 +547,17 @@ PRUint8 (*nsCanvasRenderingContext2DAzur
 PRUint8 (*nsCanvasRenderingContext2DAzure::sPremultiplyTable)[256] = nullptr;
 
 namespace mozilla {
 namespace dom {
 
 bool
 AzureCanvasEnabled()
 {
-  BackendType dontCare;
-  return gfxPlatform::GetPlatform()->SupportsAzureCanvas(dontCare);
+  return gfxPlatform::GetPlatform()->SupportsAzureCanvas();
 }
 
 }
 }
 
 nsresult
 NS_NewCanvasRenderingContext2DAzure(nsIDOMCanvasRenderingContext2D** aResult)
 {
--- a/content/canvas/test/test_canvas.html
+++ b/content/canvas/test/test_canvas.html
@@ -39,41 +39,41 @@ function IsMacOSX10_5orOlder() {
 }
 
 
 function IsAzureEnabled() {
   var enabled = false;
 
   try {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureBackend;
+    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureCanvasBackend;
     enabled = (backend != "none");
   } catch (e) { }
 
   return enabled;
 }
 
 function IsAzureSkia() {
   var enabled = false;
   
   try {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureBackend;
+    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureCanvasBackend;
     enabled = (backend == "skia");
   } catch (e) { }
 
   return enabled;
 }
 
 function IsAzureCairo() {
   var enabled = false;
   
   try {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureBackend;
+    var backend = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).getInfo().AzureCanvasBackend;
     enabled = (backend == "cairo");
   } catch (e) { }
 
   return enabled;
 }
 
 </script>
 <!-- Includes all the tests in the content/canvas/tests except for test_bug397524.html -->
--- a/gfx/layers/d3d10/LayerManagerD3D10.cpp
+++ b/gfx/layers/d3d10/LayerManagerD3D10.cpp
@@ -479,21 +479,20 @@ LayerManagerD3D10::CreateOptimalMaskSurf
   return CreateOptimalSurface(aSize, gfxASurface::ImageFormatARGB32);
 }
 
 
 TemporaryRef<DrawTarget>
 LayerManagerD3D10::CreateDrawTarget(const IntSize &aSize,
                                     SurfaceFormat aFormat)
 {
-  BackendType backend;
   if ((aFormat != FORMAT_B8G8R8A8 &&
        aFormat != FORMAT_B8G8R8X8) ||
-       !gfxPlatform::GetPlatform()->SupportsAzureCanvas(backend) ||
-       backend != BACKEND_DIRECT2D) {
+       !gfxPlatform::GetPlatform()->SupportsAzureCanvas() ||
+       gfxPlatform::GetPlatform()->GetPreferredCanvasBackend() != 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()
-  : mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureCanvasBackendInfo)
+  : mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureBackendInfo)
 {
     mUseHarfBuzzScripts = UNINITIALIZED_VALUE;
     mAllowDownloadableFonts = UNINITIALIZED_VALUE;
     mDownloadableFontsSanitize = UNINITIALIZED_VALUE;
     mFallbackUsesCmaps = UNINITIALIZED_VALUE;
 
 #ifdef MOZ_GRAPHITE
     mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
@@ -670,18 +670,17 @@ gfxPlatform::GetThebesSurfaceForDrawTarg
   surf->SetData(&kDrawTargetForSurface, aTarget, DataDrawTargetDestroy);
 
   return surf.forget();
 }
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateDrawTargetForBackend(BackendType aBackend, const IntSize& aSize, SurfaceFormat aFormat)
 {
-  BackendType backend;
-  if (!SupportsAzureCanvas(backend)) {
+  if (!SupportsAzureCanvas()) {
     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
@@ -699,47 +698,44 @@ gfxPlatform::CreateDrawTargetForBackend(
   } else {
     return Factory::CreateDrawTarget(aBackend, aSize, aFormat);
   }
 }
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateOffscreenDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
 {
-  BackendType backend;
-  if (!SupportsAzureCanvas(backend)) {
+  if (!SupportsAzureCanvas()) {
     return NULL;
   }
 
-  RefPtr<DrawTarget> target = CreateDrawTargetForBackend(backend, aSize, aFormat);
+  RefPtr<DrawTarget> target = CreateDrawTargetForBackend(mPreferredCanvasBackend, aSize, aFormat);
   if (target ||
       mFallbackCanvasBackend == BACKEND_NONE) {
     return target;
   }
 
   return CreateDrawTargetForBackend(mFallbackCanvasBackend, aSize, aFormat);
 }
 
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
 {
-  BackendType backend;
-  if (!SupportsAzureCanvas(backend)) {
+  if (!SupportsAzureCanvas()) {
     return NULL;
   }
-  return Factory::CreateDrawTargetForData(backend, aData, aSize, aStride, aFormat); 
+  return Factory::CreateDrawTargetForData(mPreferredCanvasBackend, aData, aSize, aStride, aFormat);
 }
 
 bool
-gfxPlatform::SupportsAzureCanvas(BackendType& aBackend)
+gfxPlatform::SupportsAzureCanvas()
 {
   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;
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -190,22 +190,26 @@ 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 SupportsAzureCanvas(mozilla::gfx::BackendType& aBackend);
+    bool SupportsAzureCanvas();
 
-    // aObj will contain the preferred backend for Azure canvas
-    void GetAzureCanvasBackendInfo(mozilla::widget::InfoObject &aObj) {
-      aObj.DefineProperty("AzureBackend", GetBackendName(mPreferredCanvasBackend));
+    void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) {
+      aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend));
+      aObj.DefineProperty("AzureFallbackCanvasBackend", GetBackendName(mFallbackCanvasBackend));
+      aObj.DefineProperty("AzureContentBackend", GetBackendName(GetContentBackend()));
+    }
+
+    mozilla::gfx::BackendType GetPreferredCanvasBackend() {
+      return mPreferredCanvasBackend;
     }
 
     /*
      * Font bits
      */
 
     virtual void SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aString);
 
@@ -471,17 +475,22 @@ protected:
      * by the gfx.canvas.azure.backends pref.
      */
     void InitCanvasBackend(PRUint32 aBackendBitmask);
     /**
      * returns the first backend named in the pref gfx.canvas.azure.backends
      * which is a component of aBackendBitmask, a bitmask of backend types
      */
     static mozilla::gfx::BackendType GetCanvasBackendPref(PRUint32 aBackendBitmask);
-    static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName);
+    static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName);
+
+    virtual mozilla::gfx::BackendType GetContentBackend()
+    {
+      return mozilla::gfx::BACKEND_NONE;
+    }
 
     PRInt8  mAllowDownloadableFonts;
     PRInt8  mDownloadableFontsSanitize;
 #ifdef MOZ_GRAPHITE
     PRInt8  mGraphiteShapingEnabled;
 #endif
 
     PRInt8  mBidiNumeralOption;
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -237,16 +237,23 @@ public:
     cairo_device_t *GetD2DDevice() { return mD2DDevice; }
     ID3D10Device1 *GetD3D10Device() { return mD2DDevice ? cairo_d2d_device_get_device(mD2DDevice) : nullptr; }
 #endif
 
     static bool IsOptimus();
     static bool IsRunningInWindows8Metro();
 
 protected:
+    virtual mozilla::gfx::BackendType GetContentBackend()
+    {
+      return UseAzureContentDrawing() && mRenderMode == RENDER_DIRECT2D ?
+               mozilla::gfx::BACKEND_DIRECT2D :
+               mozilla::gfx::BACKEND_NONE;
+    }
+
     RenderMode mRenderMode;
 
     PRInt8 mUseClearTypeForDownloadableFonts;
     PRInt8 mUseClearTypeAlways;
     HDC mScreenDC;
 
 private:
     void Init();
--- a/layout/tools/reftest/reftest.js
+++ b/layout/tools/reftest/reftest.js
@@ -481,18 +481,18 @@ function BuildConditionSandbox(aURL) {
  
     
     var gfxInfo = (NS_GFXINFO_CONTRACTID in CC) && CC[NS_GFXINFO_CONTRACTID].getService(CI.nsIGfxInfo);
     try {
       sandbox.d2d = gfxInfo.D2DEnabled;
     } catch (e) {
       sandbox.d2d = false;
     }
-    sandbox.azureQuartz = gfxInfo.getInfo().AzureBackend == "quartz";
-    sandbox.azureSkia = gfxInfo.getInfo().AzureBackend == "skia";
+    sandbox.azureQuartz = gfxInfo.getInfo().AzureCanvasBackend == "quartz";
+    sandbox.azureSkia = gfxInfo.getInfo().AzureCanvasBackend == "skia";
 
     sandbox.layersGPUAccelerated =
       gWindowUtils.layerManagerType != "Basic";
     sandbox.layersOpenGL =
       gWindowUtils.layerManagerType == "OpenGL";
 
     // Shortcuts for widget toolkits.
     sandbox.Android = xr.OS == "Android";