Bug 628173 - Part 1: Update CanvasLayerD3D9 to respect surface content type. r=jrmuizel a=blocking-final
authorBas Schouten <bschouten@mozilla.com>
Thu, 10 Feb 2011 21:03:24 +0100
changeset 62301 d1c5def46796203e45f690aa1047283c09bb4aa9
parent 62300 53d06f07a4d2bacb18a217d243973d97eafdd7ca
child 62302 8379db2b16d29f75ca825e2184275eab134f990e
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel, blocking-final
bugs628173
milestone2.0b12pre
Bug 628173 - Part 1: Update CanvasLayerD3D9 to respect surface content type. r=jrmuizel a=blocking-final
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/d3d9/CanvasLayerD3D9.h
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -186,16 +186,22 @@ CanvasLayerD3D9::Updated(const nsIntRect
       ctx->Translate(gfxPoint(-aRect.x, -aRect.y));
       ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
       ctx->SetSource(mSurface);
       ctx->Paint();
       startBits = sourceSurface->Data();
       sourceStride = sourceSurface->Stride();
     }
 
+    if (sourceSurface->Format() != gfxASurface::ImageFormatARGB32) {
+      mHasAlpha = false;
+    } else {
+      mHasAlpha = true;
+    }
+
     for (int y = 0; y < aRect.height; y++) {
       memcpy((PRUint8*)lockedRect.pBits + lockedRect.Pitch * y,
              startBits + sourceStride * y,
              aRect.width * 4);
     }
 
     mTexture->UnlockRect(0);
   }
@@ -224,17 +230,21 @@ CanvasLayerD3D9::RenderLayer()
     quad.mHeight = (float)-mBounds.height;
     quad.mY = (float)mBounds.height;
   }
 
   device()->SetVertexShaderConstantF(CBvLayerQuad, quad, 1);
 
   SetShaderTransformAndOpacity();
 
-  mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
+  if (mHasAlpha) {
+    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
+  } else {
+    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+  }
 
   if (mFilter == gfxPattern::FILTER_NEAREST) {
     device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
     device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
   }
   if (!mDataIsPremultiplied) {
     device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
     device()->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
--- a/gfx/layers/d3d9/CanvasLayerD3D9.h
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.h
@@ -47,20 +47,21 @@ namespace mozilla {
 namespace layers {
 
 class THEBES_API CanvasLayerD3D9 :
   public CanvasLayer,
   public LayerD3D9
 {
 public:
   CanvasLayerD3D9(LayerManagerD3D9 *aManager)
-    : CanvasLayer(aManager, NULL),
-      LayerD3D9(aManager),
-      mDataIsPremultiplied(PR_FALSE),
-      mNeedsYFlip(PR_FALSE)
+    : CanvasLayer(aManager, NULL)
+    , LayerD3D9(aManager)
+    , mDataIsPremultiplied(PR_FALSE)
+    , mNeedsYFlip(PR_FALSE)
+    , mHasAlpha(PR_TRUE)
   {
       mImplData = static_cast<LayerD3D9*>(this);
       aManager->deviceManager()->mLayersWithResources.AppendElement(this);
   }
 
   ~CanvasLayerD3D9();
 
   // CanvasLayer implementation
@@ -81,13 +82,14 @@ protected:
   nsRefPtr<gfxASurface> mSurface;
   nsRefPtr<GLContext> mGLContext;
   nsRefPtr<IDirect3DTexture9> mTexture;
 
   PRUint32 mCanvasFramebuffer;
 
   PRPackedBool mDataIsPremultiplied;
   PRPackedBool mNeedsYFlip;
+  PRPackedBool mHasAlpha;
 };
 
 } /* layers */
 } /* mozilla */
 #endif /* GFX_CANVASLAYERD3D9_H */