Bug 615316 - Part 7: Support surfaces with Alpha for CairoImageD3D9. r=jrmuizel a=blocking-betaN
authorBas Schouten <bschouten@mozilla.com>
Mon, 20 Dec 2010 22:37:08 +0000
changeset 59533 b6e4e41dbee04fdaa0a9100f50f2ef92233ee834
parent 59532 5c0fb0080a5ac96dd12022def1a67bde4bfa2f8a
child 59534 7d05c8f6c4da72ed60a83f08346892d7a3a56ab2
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjrmuizel, blocking-betaN
bugs615316
milestone2.0b9pre
Bug 615316 - Part 7: Support surfaces with Alpha for CairoImageD3D9. r=jrmuizel a=blocking-betaN
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/d3d9/ImageLayerD3D9.h
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -310,17 +310,21 @@ ImageLayerD3D9::RenderLayer()
                                        ShaderConstantRect(0,
                                                           0,
                                                           cairoImage->GetSize().width,
                                                           cairoImage->GetSize().height),
                                        1);
 
     SetShaderTransformAndOpacity();
 
-    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
+    if (cairoImage->HasAlpha()) {
+      mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
+    } else {
+      mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+    }
 
     device()->SetTexture(0, cairoImage->GetOrCreateTexture());
     device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   }
 }
 
 PlanarYCbCrImageD3D9::PlanarYCbCrImageD3D9(mozilla::layers::LayerManagerD3D9* aManager)
   : PlanarYCbCrImage(static_cast<ImageD3D9*>(this))
--- a/gfx/layers/d3d9/ImageLayerD3D9.h
+++ b/gfx/layers/d3d9/ImageLayerD3D9.h
@@ -153,16 +153,21 @@ public:
 
   /**
    * Uploading a texture may fail if the screen is locked. If this happens,
    * we need to save the backing surface and retry when we are asked to paint.
    */
   virtual IDirect3DTexture9* GetOrCreateTexture();
   const gfxIntSize& GetSize() { return mSize; }
 
+  bool HasAlpha() {
+    return mCachedSurface->GetContentType() ==
+      gfxASurface::CONTENT_COLOR_ALPHA;
+  }
+
 private:
   gfxIntSize mSize;
   nsRefPtr<gfxASurface> mCachedSurface;
   nsRefPtr<IDirect3DDevice9> mDevice;
   nsRefPtr<IDirect3DTexture9> mTexture;
   LayerManagerD3D9 *mManager;
 };