Bug 973875 - Make CanvasClient2D not keep a TextureClient's DrawTarget after unlocking its memory. r=bjacob
authorNicolas Silva <nical@mozilla.com>
Wed, 19 Feb 2014 16:53:26 +0100
changeset 169869 f516f1a8f3069a9962a4742e63e2b6b1793e1b7b
parent 169868 3edf59b5ca9f6bd06889a92cf2a4f9511f0e7af3
child 169870 a82a575e586ad3728924c6abfc56ee10dad3d5e1
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbjacob
bugs973875
milestone30.0a1
Bug 973875 - Make CanvasClient2D not keep a TextureClient's DrawTarget after unlocking its memory. r=bjacob
gfx/layers/client/CanvasClient.cpp
--- a/gfx/layers/client/CanvasClient.cpp
+++ b/gfx/layers/client/CanvasClient.cpp
@@ -71,30 +71,34 @@ CanvasClient2D::Update(gfx::IntSize aSiz
 
     bufferCreated = true;
   }
 
   if (!mBuffer->Lock(OPEN_WRITE_ONLY)) {
     return;
   }
 
-  RefPtr<DrawTarget> drawTarget =
-    mBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget();
-  if (drawTarget) {
-    aLayer->UpdateTarget(drawTarget);
+  bool updated = false;
+  {
+    // Restrict drawTarget to a scope so that terminates before Unlock.
+    RefPtr<DrawTarget> drawTarget =
+      mBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget();
+    if (drawTarget) {
+      aLayer->UpdateTarget(drawTarget);
+      updated = true;
+    }
   }
-
   mBuffer->Unlock();
 
   if (bufferCreated && !AddTextureClient(mBuffer)) {
     mBuffer = nullptr;
     return;
   }
 
-  if (drawTarget) {
+  if (updated) {
     GetForwarder()->UpdatedTexture(this, mBuffer, nullptr);
     GetForwarder()->UseTexture(this, mBuffer);
   }
 }
 
 TemporaryRef<BufferTextureClient>
 CanvasClient2D::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
 {