Bug 621156: Return a properly working surface from GetAsSurface. r=jrmuizel a=blocking-final
authorBas Schouten <bschouten@mozilla.com>
Mon, 03 Jan 2011 18:05:47 +0100
changeset 59791 9330470d6a3859a0a939b44ddd7db01791efc6f8
parent 59790 72d9ec027cba9cc14c5260cbe0be376a44bb02a9
child 59792 5526992ff569674f60bd31617f839725b4d38180
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjrmuizel, blocking-final
bugs621156
milestone2.0b9pre
Bug 621156: Return a properly working surface from GetAsSurface. r=jrmuizel a=blocking-final
gfx/layers/d3d10/ImageLayerD3D10.cpp
--- a/gfx/layers/d3d10/ImageLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ImageLayerD3D10.cpp
@@ -452,16 +452,30 @@ CairoImageD3D10::SetData(const CairoImag
   }
 
   mDevice->CreateShaderResourceView(mTexture, NULL, getter_AddRefs(mSRView));
 }
 
 already_AddRefed<gfxASurface>
 CairoImageD3D10::GetAsSurface()
 {
+  nsRefPtr<ID3D10Texture2D> surfTexture;
+
+  // Make a copy of the texture since our current texture is not suitable for
+  // drawing with Direct2D.
+  D3D10_TEXTURE2D_DESC texDesc;
+  mTexture->GetDesc(&texDesc);
+  texDesc.Usage = D3D10_USAGE_DEFAULT;
+  texDesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
+  texDesc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
+
+  mDevice->CreateTexture2D(&texDesc, NULL, getter_AddRefs(surfTexture));
+
+  mDevice->CopyResource(surfTexture, mTexture);
+
   nsRefPtr<gfxASurface> surf =
-    new gfxD2DSurface(mTexture, mHasAlpha ? gfxASurface::CONTENT_COLOR_ALPHA :
-                                            gfxASurface::CONTENT_COLOR);
+    new gfxD2DSurface(surfTexture, mHasAlpha ? gfxASurface::CONTENT_COLOR_ALPHA :
+                                               gfxASurface::CONTENT_COLOR);
   return surf.forget();
 }
 
 } /* layers */
 } /* mozilla */