Bug 615316 - Part 6: Support device changing for CairoImageD3D9. r=jrmuizel a=blocking-betaN
authorBas Schouten <bschouten@mozilla.com>
Mon, 20 Dec 2010 22:37:04 +0000
changeset 59532 5c0fb0080a5ac96dd12022def1a67bde4bfa2f8a
parent 59531 56caf266b854ffec7b770df874befcd94a7592d3
child 59533 b6e4e41dbee04fdaa0a9100f50f2ef92233ee834
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjrmuizel, blocking-betaN
bugs615316
milestone2.0b9pre
Bug 615316 - Part 6: Support device changing 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
@@ -297,16 +297,19 @@ ImageLayerD3D9::RenderLayer()
     device()->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
 
     device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
 
   } else if (image->GetFormat() == Image::CAIRO_SURFACE) {
     CairoImageD3D9 *cairoImage =
       static_cast<CairoImageD3D9*>(image.get());
 
+    if (cairoImage->device() != device()) {
+      cairoImage->SetDevice(device());
+    }
 
     device()->SetVertexShaderConstantF(CBvLayerQuad,
                                        ShaderConstantRect(0,
                                                           0,
                                                           cairoImage->GetSize().width,
                                                           cairoImage->GetSize().height),
                                        1);
 
@@ -544,16 +547,23 @@ PlanarYCbCrImageD3D9::GetAsSurface()
   return imageSurface.forget().get();
 }
 
 CairoImageD3D9::~CairoImageD3D9()
 {
 }
 
 void
+CairoImageD3D9::SetDevice(IDirect3DDevice9 *aDevice)
+{
+  mTexture = NULL;
+  mDevice = aDevice;
+}
+
+void
 CairoImageD3D9::SetData(const CairoImage::Data &aData)
 {
   mSize = aData.mSize;
   mCachedSurface = aData.mSurface;
   mTexture = NULL;
 
   // Try to upload the surface immediately, so that we don't block the
   // rendering pipeline at paint time.
@@ -563,18 +573,17 @@ CairoImageD3D9::SetData(const CairoImage
 IDirect3DTexture9*
 CairoImageD3D9::GetOrCreateTexture()
 {
   if (mTexture)
     return mTexture;
 
   mTexture = SurfaceToTexture(mDevice, mCachedSurface, mSize);
 
-  // Release our no-longer-needed mCachedSurface
-  mCachedSurface = NULL;
+  // We need to keep our cached surface around in case the device changes.
   return mTexture;
 }
 
 already_AddRefed<gfxASurface>
 CairoImageD3D9::GetAsSurface()
 {
   return nsnull;
 }
--- a/gfx/layers/d3d9/ImageLayerD3D9.h
+++ b/gfx/layers/d3d9/ImageLayerD3D9.h
@@ -143,16 +143,19 @@ public:
     , mDevice(aDevice)
   { }
   ~CairoImageD3D9();
 
   virtual void SetData(const Data &aData);
 
   virtual already_AddRefed<gfxASurface> GetAsSurface();
 
+  IDirect3DDevice9 *device() { return mDevice; }
+  void SetDevice(IDirect3DDevice9 *aDevice);
+
   /**
    * 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; }
 
 private: