Bug 622072. Part 2: Add DidTransactionCallback to CanvasLayer. r=bas, sr=joe
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 28 Mar 2011 12:59:46 +1300
changeset 63980 8953a4aad4e5ab7bd4dd98422529620bd874b3ea
parent 63979 84ff21c7816543e707f9d678b174a1c11b138774
child 63981 d9c2c2e76a37a8f6f5c337e7a445dd4a9ec4d197
push idunknown
push userunknown
push dateunknown
reviewersbas, joe
bugs622072
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 622072. Part 2: Add DidTransactionCallback to CanvasLayer. r=bas, sr=joe
gfx/layers/Layers.h
gfx/layers/basic/BasicLayers.cpp
gfx/layers/d3d10/CanvasLayerD3D10.cpp
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/opengl/CanvasLayerOGL.cpp
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -1177,16 +1177,26 @@ public:
 
   /**
    * Notify this CanvasLayer that the canvas surface contents have
    * changed (or will change) before the next transaction.
    */
   void Updated() { mDirty = PR_TRUE; }
 
   /**
+   * Register a callback to be called at the end of each transaction.
+   */
+  typedef void (* DidTransactionCallback)(void* aClosureData);
+  void SetDidTransactionCallback(DidTransactionCallback aCallback, void* aClosureData)
+  {
+    mCallback = aCallback;
+    mCallbackData = aClosureData;
+  }
+
+  /**
    * CONSTRUCTION PHASE ONLY
    * Set the filter used to resample this image (if necessary).
    */
   void SetFilter(gfxPattern::GraphicsFilter aFilter) { mFilter = aFilter; }
   gfxPattern::GraphicsFilter GetFilter() const { return mFilter; }
 
   MOZ_LAYER_DECL_NAME("CanvasLayer", TYPE_CANVAS)
 
@@ -1199,24 +1209,35 @@ public:
     mEffectiveTransform =
         SnapTransform(GetLocalTransform(), gfxRect(0, 0, mBounds.width, mBounds.height),
                       nsnull)*
         SnapTransform(aTransformToSurface, gfxRect(0, 0, 0, 0), nsnull);
   }
 
 protected:
   CanvasLayer(LayerManager* aManager, void* aImplData)
-    : Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD), mDirty(PR_FALSE) {}
+    : Layer(aManager, aImplData),
+      mCallback(nsnull), mCallbackData(nsnull), mFilter(gfxPattern::FILTER_GOOD),
+      mDirty(PR_FALSE) {}
 
   virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
 
+  void FireDidTransactionCallback()
+  {
+    if (mCallback) {
+      mCallback(mCallbackData);
+    }
+  }
+
   /**
    * 0, 0, canvaswidth, canvasheight
    */
   nsIntRect mBounds;
+  DidTransactionCallback mCallback;
+  void* mCallbackData;
   gfxPattern::GraphicsFilter mFilter;
   /**
    * Set to true in Updated(), cleared during a transaction.
    */
   PRPackedBool mDirty;
 };
 
 }
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -990,16 +990,17 @@ BasicCanvasLayer::UpdateSurface()
     mSurface = isurf;
   }
 }
 
 void
 BasicCanvasLayer::Paint(gfxContext* aContext)
 {
   UpdateSurface();
+  FireDidTransactionCallback();
   PaintWithOpacity(aContext, GetEffectiveOpacity());
 }
 
 void
 BasicCanvasLayer::PaintWithOpacity(gfxContext* aContext,
                                    float aOpacity)
 {
   NS_ASSERTION(BasicManager()->InDrawing(),
--- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp
@@ -223,20 +223,20 @@ CanvasLayerD3D10::GetLayer()
 {
   return this;
 }
 
 void
 CanvasLayerD3D10::RenderLayer()
 {
   UpdateSurface();
+  FireDidTransactionCallback();
 
-  if (!mTexture) {
+  if (!mTexture)
     return;
-  }
 
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
 
   SetEffectTransformAndOpacity();
 
   ID3D10EffectTechnique *technique;
 
   if (mDataIsPremultiplied) {
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -204,16 +204,18 @@ CanvasLayerD3D9::GetLayer()
 {
   return this;
 }
 
 void
 CanvasLayerD3D9::RenderLayer()
 {
   UpdateSurface();
+  FireDidTransactionCallback();
+
   if (!mTexture)
     return;
 
   /*
    * We flip the Y axis here, note we can only do this because we are in 
    * CULL_NONE mode!
    */
 
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -179,16 +179,17 @@ CanvasLayerOGL::UpdateSurface()
   }
 }
 
 void
 CanvasLayerOGL::RenderLayer(int aPreviousDestination,
                             const nsIntPoint& aOffset)
 {
   UpdateSurface();
+  FireDidTransactionCallback();
 
   mOGLManager->MakeCurrent();
 
   // XXX We're going to need a different program depending on if
   // mGLBufferIsPremultiplied is TRUE or not.  The RGBLayerProgram
   // assumes that it's true.
 
   gl()->fActiveTexture(LOCAL_GL_TEXTURE0);