Bug 624170. Part 1: Don't try to release the DC for null surfaces. r=bas; a=blocking-beta9+ landed on a CLOSED TREE
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 10 Jan 2011 17:24:10 -0500
changeset 60263 12c4de7f40575730d82b5950b6cd5e478a43d489
parent 60262 1c7797564bd299ffeb5255b352f7fe2f5f4b1c90
child 60265 badef0f336d2ae302e7bb17cc025d550a67e2ac4
push idunknown
push userunknown
push dateunknown
reviewersbas, blocking-beta9
bugs624170
milestone2.0b9pre
Bug 624170. Part 1: Don't try to release the DC for null surfaces. r=bas; a=blocking-beta9+ landed on a CLOSED TREE
gfx/layers/d3d9/ThebesLayerD3D9.cpp
--- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp
@@ -314,16 +314,17 @@ ThebesLayerD3D9::VerifyContentType(Surfa
   mTextureOnWhite = nsnull;
   mValidRegion.SetEmpty();
 }
 
 class OpaqueRenderer {
 public:
   OpaqueRenderer(const nsIntRegion& aUpdateRegion) :
     mUpdateRegion(aUpdateRegion), mDC(NULL) {}
+  ~OpaqueRenderer() { End(); }
   already_AddRefed<gfxWindowsSurface> Begin(LayerD3D9* aLayer);
   void End();
   IDirect3DTexture9* GetTexture() { return mTmpTexture; }
 
 private:
   const nsIntRegion& mUpdateRegion;
   nsRefPtr<IDirect3DTexture9> mTmpTexture;
   nsRefPtr<IDirect3DSurface9> mSurface;
@@ -360,17 +361,21 @@ OpaqueRenderer::Begin(LayerD3D9* aLayer)
 
   nsRefPtr<gfxWindowsSurface> result = new gfxWindowsSurface(mDC);
   return result.forget();
 }
 
 void
 OpaqueRenderer::End()
 {
-  mSurface->ReleaseDC(mDC);
+  if (mSurface && mDC) {
+    mSurface->ReleaseDC(mDC);
+    mSurface = NULL;
+    mDC = NULL;
+  }
 }
 
 static void
 FillSurface(gfxASurface* aSurface, const nsIntRegion& aRegion,
             const nsIntPoint& aOffset, const gfxRGBA& aColor)
 {
   nsRefPtr<gfxContext> ctx = new gfxContext(aSurface);
   ctx->Translate(-gfxPoint(aOffset.x, aOffset.y));
@@ -432,22 +437,23 @@ ThebesLayerD3D9::DrawRegion(const nsIntR
         // only the onBlack surface will really be used, so alpha information will
         // be incorrect.
         destinationSurface->SetAllowUseAsSource(PR_FALSE);
       }
       break;
     }
   }
 
-  if (destinationSurface) {
-    nsRefPtr<gfxContext> context = new gfxContext(destinationSurface);
-    context->Translate(gfxPoint(-bounds.x, -bounds.y));
-    LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
-    cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData);
-  }
+  if (!destinationSurface)
+    return;
+
+  nsRefPtr<gfxContext> context = new gfxContext(destinationSurface);
+  context->Translate(gfxPoint(-bounds.x, -bounds.y));
+  LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
+  cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData);
 
   nsAutoTArray<IDirect3DTexture9*,2> srcTextures;
   nsAutoTArray<IDirect3DTexture9*,2> destTextures;
   switch (aMode)
   {
     case SURFACE_OPAQUE:
       opaqueRenderer.End();
       srcTextures.AppendElement(opaqueRenderer.GetTexture());