Bug 593604 - Part 11: Remove code to support D2D/D3D9 interop. r+a=roc
authorBas Schouten <bschouten@mozilla.com>
Tue, 04 Jan 2011 02:37:10 +0100
changeset 59812 0ba31efa005e6c6094315f29a0341f42df3ce1f4
parent 59811 845b9487ffb3c07b141c7f8e31dcca6bb3798c47
child 59813 f086a88e7557c2c55b41a53eb02329866d968784
push id17799
push userbschouten@mozilla.com
push dateTue, 04 Jan 2011 01:37:38 +0000
treeherdermozilla-central@f086a88e7557 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs593604
milestone2.0b9pre
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 593604 - Part 11: Remove code to support D2D/D3D9 interop. r+a=roc
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/d3d9/CanvasLayerD3D9.h
gfx/layers/d3d9/LayerManagerD3D9.cpp
gfx/layers/d3d9/LayerManagerD3D9.h
gfx/layers/d3d9/ThebesLayerD3D9.cpp
gfx/layers/d3d9/ThebesLayerD3D9.h
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -70,47 +70,28 @@ CanvasLayerD3D9::Initialize(const Data& 
     mDataIsPremultiplied = aData.mGLBufferIsPremultiplied;
     mNeedsYFlip = PR_TRUE;
   } else {
     NS_ERROR("CanvasLayer created without mSurface or mGLContext?");
   }
 
   mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
 
-  if (mSurface && mSurface->GetType() == gfxASurface::SurfaceTypeD2D) {
-    void *data = mSurface->GetData(&gKeyD3D9Texture);
-    if (data) {
-      mTexture = static_cast<IDirect3DTexture9*>(data);
-      mIsInteropTexture = true;
-      return;
-    }
-  }
-
-  mIsInteropTexture = false;
-
   CreateTexture();
 }
 
 void
 CanvasLayerD3D9::Updated(const nsIntRect& aRect)
 {
   if (!mTexture) {
     CreateTexture();
     NS_WARNING("CanvasLayerD3D9::Updated called but no texture present!");
     return;
   }
 
-#ifdef CAIRO_HAS_D2D_SURFACE
-  if (mIsInteropTexture) {
-    mSurface->Flush();
-    cairo_d2d_finish_device(gfxWindowsPlatform::GetPlatform()->GetD2DDevice());
-    return;
-  }
-#endif
-
   if (mGLContext) {
     // WebGL reads entire surface.
     D3DLOCKED_RECT r;
     HRESULT hr = mTexture->LockRect(0, &r, NULL, 0);
 
     if (FAILED(hr)) {
       NS_WARNING("Failed to lock CanvasLayer texture.");
       return;
--- a/gfx/layers/d3d9/CanvasLayerD3D9.h
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.h
@@ -79,18 +79,15 @@ protected:
   typedef mozilla::gl::GLContext GLContext;
 
   nsRefPtr<gfxASurface> mSurface;
   nsRefPtr<GLContext> mGLContext;
   nsRefPtr<IDirect3DTexture9> mTexture;
 
   PRUint32 mCanvasFramebuffer;
 
-  // Indicates whether our texture was obtained through D2D interop.
-  bool mIsInteropTexture;
-
   PRPackedBool mDataIsPremultiplied;
   PRPackedBool mNeedsYFlip;
 };
 
 } /* layers */
 } /* mozilla */
 #endif /* GFX_CANVASLAYERD3D9_H */
--- a/gfx/layers/d3d9/LayerManagerD3D9.cpp
+++ b/gfx/layers/d3d9/LayerManagerD3D9.cpp
@@ -41,20 +41,16 @@
 #include "ContainerLayerD3D9.h"
 #include "ImageLayerD3D9.h"
 #include "ColorLayerD3D9.h"
 #include "CanvasLayerD3D9.h"
 #include "gfxWindowsPlatform.h"
 #include "nsIGfxInfo.h"
 #include "nsServiceManagerUtils.h"
 
-#ifdef CAIRO_HAS_D2D_SURFACE
-#include "gfxD2DSurface.h"
-#endif
-
 namespace mozilla {
 namespace layers {
 
 DeviceManagerD3D9 *LayerManagerD3D9::mDefaultDeviceManager = nsnull;
 
 LayerManagerD3D9::LayerManagerD3D9(nsIWidget *aWidget)
 {
   mWidget = aWidget;
@@ -205,61 +201,21 @@ LayerManagerD3D9::CreateCanvasLayer()
 
 already_AddRefed<ImageContainer>
 LayerManagerD3D9::CreateImageContainer()
 {
   nsRefPtr<ImageContainer> container = new ImageContainerD3D9(device());
   return container.forget();
 }
 
-cairo_user_data_key_t gKeyD3D9Texture;
-
 void ReleaseTexture(void *texture)
 {
   static_cast<IDirect3DTexture9*>(texture)->Release();
 }
 
-already_AddRefed<gfxASurface>
-LayerManagerD3D9::CreateOptimalSurface(const gfxIntSize &aSize,
-                                   gfxASurface::gfxImageFormat aFormat)
-{
-#ifdef CAIRO_HAS_D2D_SURFACE
-  if ((aFormat != gfxASurface::ImageFormatRGB24 &&
-       aFormat != gfxASurface::ImageFormatARGB32) ||
-      gfxWindowsPlatform::GetPlatform()->GetRenderMode() !=
-        gfxWindowsPlatform::RENDER_DIRECT2D ||
-      !deviceManager()->IsD3D9Ex()) {
-    return LayerManager::CreateOptimalSurface(aSize, aFormat);
-  }
-
-  nsRefPtr<IDirect3DTexture9> texture;
-  
-  HANDLE sharedHandle = 0;
-  device()->CreateTexture(aSize.width, aSize.height, 1,
-                          D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
-                          D3DPOOL_DEFAULT, getter_AddRefs(texture), &sharedHandle);
-
-  nsRefPtr<gfxD2DSurface> surface =
-    new gfxD2DSurface(sharedHandle, aFormat == gfxASurface::ImageFormatRGB24 ?
-      gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA);
-
-  if (!surface || surface->CairoStatus()) {
-    return LayerManager::CreateOptimalSurface(aSize, aFormat);
-  }
-
-  surface->SetData(&gKeyD3D9Texture,
-                   texture.forget().get(),
-                   ReleaseTexture);
-
-  return surface.forget();
-#else
-  return LayerManager::CreateOptimalSurface(aSize, aFormat);
-#endif
-}
-
 void
 LayerManagerD3D9::ReportFailure(const nsACString &aMsg, HRESULT aCode)
 {
   // We could choose to abort here when hr == E_OUTOFMEMORY.
   nsCString msg;
   msg.Append(aMsg);
   msg.AppendLiteral(" Error code: ");
   msg.AppendInt(PRUint32(aCode));
--- a/gfx/layers/d3d9/LayerManagerD3D9.h
+++ b/gfx/layers/d3d9/LayerManagerD3D9.h
@@ -46,18 +46,16 @@
 #include "gfxContext.h"
 #include "nsIWidget.h"
 
 #include "DeviceManagerD3D9.h"
 
 namespace mozilla {
 namespace layers {
 
-extern cairo_user_data_key_t gKeyD3D9Texture;
-
 class LayerD3D9;
 class ThebesLayerD3D9;
 
 /**
  * This structure is used to pass rectangles to our shader constant. We can use
  * this for passing rectangular areas to SetVertexShaderConstant. In the format
  * of a 4 component float(x,y,width,height). Our vertex shader can then use
  * this to construct rectangular positions from the 0,0-1,1 quad that we source
@@ -146,20 +144,16 @@ public:
   virtual already_AddRefed<ImageLayer> CreateImageLayer();
 
   virtual already_AddRefed<ColorLayer> CreateColorLayer();
 
   virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
 
   virtual already_AddRefed<ImageContainer> CreateImageContainer();
 
-  virtual already_AddRefed<gfxASurface>
-    CreateOptimalSurface(const gfxIntSize &aSize,
-                         gfxASurface::gfxImageFormat imageFormat);
-
   virtual LayersBackend GetBackendType() { return LAYERS_D3D9; }
   virtual void GetBackendName(nsAString& name) { name.AssignLiteral("Direct3D 9"); }
   bool DeviceWasRemoved() { return deviceManager()->DeviceWasRemoved(); }
 
   /*
    * Helper methods.
    */
   void SetClippingEnabled(PRBool aEnabled);
--- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp
@@ -34,29 +34,25 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "ThebesLayerD3D9.h"
 #include "gfxPlatform.h"
 
 #include "gfxWindowsPlatform.h"
-#ifdef CAIRO_HAS_D2D_SURFACE
-#include "gfxD2DSurface.h"
-#endif
 #include "gfxTeeSurface.h"
 #include "gfxUtils.h"
 
 namespace mozilla {
 namespace layers {
 
 ThebesLayerD3D9::ThebesLayerD3D9(LayerManagerD3D9 *aManager)
   : ThebesLayer(aManager, NULL)
   , LayerD3D9(aManager)
-  , mD2DSurfaceInitialized(false)
 {
   mImplData = static_cast<LayerD3D9*>(this);
   aManager->deviceManager()->mLayersWithResources.AppendElement(this);
 }
 
 ThebesLayerD3D9::~ThebesLayerD3D9()
 {
   if (mD3DManager) {
@@ -241,21 +237,16 @@ ThebesLayerD3D9::RenderLayer()
     device()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
     RenderVisibleRegion();
 
     // Restore defaults
     device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
     device()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
     device()->SetTexture(1, NULL);
   } else {
-#ifdef CAIRO_HAS_D2D_SURFACE
-    if (mD2DSurface && CanUseOpaqueSurface()) {
-      mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
-    } else
-#endif
     mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
     device()->SetTexture(0, mTexture);
     RenderVisibleRegion();
   }
 
   // Set back to default.
   device()->SetVertexShaderConstantF(CBvTextureCoords,
                                      ShaderConstantRect(0, 0, 1.0f, 1.0f),
@@ -286,34 +277,16 @@ PRBool
 ThebesLayerD3D9::IsEmpty()
 {
   return !mTexture;
 }
 
 void
 ThebesLayerD3D9::VerifyContentType(SurfaceMode aMode)
 {
-#ifdef CAIRO_HAS_D2D_SURFACE
-  if (mD2DSurface) {
-    NS_ASSERTION(!mTextureOnWhite, "No component-alpha textures should be around with D2D");
-
-    gfxASurface::gfxContentType type = CanUseOpaqueSurface() ?
-      gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA;
-
-    if (type != mD2DSurface->GetContentType()) {
-      // We could choose to recreate only the D2D surface, but since we can't
-      // use retention the synchronisation overhead probably isn't worth it.
-      mD2DSurface = nsnull;
-      mTexture = nsnull;
-      mValidRegion.SetEmpty();
-    }
-    return;
-  }
-#endif
-
   if (!mTexture)
     return;
 
   D3DSURFACE_DESC desc;
   mTexture->GetLevelDesc(0, &desc);
 
   switch (aMode) {
   case SURFACE_OPAQUE:
@@ -407,49 +380,16 @@ FillSurface(gfxASurface* aSurface, const
 
 void
 ThebesLayerD3D9::DrawRegion(const nsIntRegion &aRegion, SurfaceMode aMode)
 {
   HRESULT hr;
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
   nsRefPtr<gfxContext> context;
 
-#ifdef CAIRO_HAS_D2D_SURFACE
-  if (mD2DSurface) {
-    context = new gfxContext(mD2DSurface);
-    nsIntRegionRectIterator iter(aRegion);
-
-    context->Translate(gfxPoint(-visibleRect.x, -visibleRect.y));
-    context->NewPath();
-    const nsIntRect *iterRect;
-    while ((iterRect = iter.Next())) {
-      context->Rectangle(gfxRect(iterRect->x, iterRect->y, iterRect->width, iterRect->height));      
-    }
-    context->Clip();
-    if (!mD2DSurfaceInitialized || 
-        mD2DSurface->GetContentType() != gfxASurface::CONTENT_COLOR) {
-      context->SetOperator(gfxContext::OPERATOR_CLEAR);
-      context->Paint();
-      context->SetOperator(gfxContext::OPERATOR_OVER);
-      mD2DSurfaceInitialized = true;
-    }
-
-    LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
-    cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData);
-    mD2DSurface->Flush();
-
-    // XXX - This call is quite expensive, we may want to consider doing our
-    // drawing in a seperate 'validation' iteration. And then flushing once for
-    // all the D2D surfaces we might have drawn, before doing our D3D9 rendering
-    // loop.
-    cairo_d2d_finish_device(gfxWindowsPlatform::GetPlatform()->GetD2DDevice());
-    return;
-  }
-#endif
-
   nsRefPtr<gfxASurface> destinationSurface;
   nsIntRect bounds = aRegion.GetBounds();
   nsRefPtr<IDirect3DTexture9> tmpTexture;
   OpaqueRenderer opaqueRenderer(aRegion);
   OpaqueRenderer opaqueRendererOnWhite(aRegion);
 
   switch (aMode)
   {
@@ -576,46 +516,22 @@ ThebesLayerD3D9::CreateNewTextures(const
 {
   if (aSize.width == 0 || aSize.height == 0) {
     // Nothing to do.
     return;
   }
 
   mTexture = nsnull;
   mTextureOnWhite = nsnull;
-#ifdef CAIRO_HAS_D2D_SURFACE
-  if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() ==
-      gfxWindowsPlatform::RENDER_DIRECT2D) {
-        if (mD3DManager->deviceManager()->IsD3D9Ex()) {
-          // We should have D3D9Ex where we have D2D.
-          HANDLE sharedHandle = 0;
-          device()->CreateTexture(aSize.width, aSize.height, 1,
-                                  D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
-                                  D3DPOOL_DEFAULT, getter_AddRefs(mTexture), &sharedHandle);
-
-          mD2DSurfaceInitialized = false;
-          mD2DSurface = new gfxD2DSurface(sharedHandle, aMode == SURFACE_OPAQUE ?
-            gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA);
-
-          // If there's an error, go on and do what we always do.
-          if (mD2DSurface->CairoStatus()) {
-            mD2DSurface = nsnull;
-            mTexture = nsnull;
-          }
-        }
-  }
-#endif
-  if (!mTexture) {
+  device()->CreateTexture(aSize.width, aSize.height, 1,
+                          D3DUSAGE_RENDERTARGET,
+                          aMode != SURFACE_SINGLE_CHANNEL_ALPHA ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8,
+                          D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
+  if (aMode == SURFACE_COMPONENT_ALPHA) {
     device()->CreateTexture(aSize.width, aSize.height, 1,
                             D3DUSAGE_RENDERTARGET,
-                            aMode != SURFACE_SINGLE_CHANNEL_ALPHA ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8,
-                            D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
-    if (aMode == SURFACE_COMPONENT_ALPHA) {
-      device()->CreateTexture(aSize.width, aSize.height, 1,
-                              D3DUSAGE_RENDERTARGET,
-                              D3DFMT_X8R8G8B8,
-                              D3DPOOL_DEFAULT, getter_AddRefs(mTextureOnWhite), NULL);
-    }
+                            D3DFMT_X8R8G8B8,
+                            D3DPOOL_DEFAULT, getter_AddRefs(mTextureOnWhite), NULL);
   }
 }
 
 } /* namespace layers */
 } /* namespace mozilla */
--- a/gfx/layers/d3d9/ThebesLayerD3D9.h
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.h
@@ -71,21 +71,16 @@ private:
    * D3D9 texture for render-on-white when doing component alpha
    */
   nsRefPtr<IDirect3DTexture9> mTextureOnWhite;
   /**
    * Visible region bounds used when we drew the contents of the textures
    */
   nsIntRect mTextureRect;
 
-  /* This contains the D2D surface if we have one */
-  nsRefPtr<gfxASurface> mD2DSurface;
-
-  bool mD2DSurfaceInitialized;
-
   bool HaveTextures(SurfaceMode aMode)
   {
     return mTexture && (aMode != SURFACE_COMPONENT_ALPHA || mTextureOnWhite);
   }
 
   /* Checks if our surface has the right content type */
   void VerifyContentType(SurfaceMode aMode);