Bug 846028 - Coalesce invalidations in VectorImage. r=dholbert
authorSeth Fowler <seth@mozilla.com>
Thu, 28 Feb 2013 16:43:43 -0800
changeset 123428 bfb82f29c9283c9f81085b2cc8251056f8d13983
parent 123427 8e091dcbd42458b0698e63bc6c7a0070a3da4199
child 123429 5df355dff81c333a5bc4c6c7d82a257d218f475f
push id23834
push usermfowler@mozilla.com
push dateFri, 01 Mar 2013 00:43:54 +0000
treeherdermozilla-inbound@bfb82f29c928 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs846028
milestone22.0a1
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 846028 - Coalesce invalidations in VectorImage. r=dholbert
image/src/VectorImage.cpp
--- a/image/src/VectorImage.cpp
+++ b/image/src/VectorImage.cpp
@@ -50,16 +50,22 @@ public:
     else {
       NS_ABORT_IF_FALSE(!mInObserverList,
                         "Have no target, so we can't be in "
                         "target's observer list...");
     }
 #endif
   }
 
+  void ResumeListening()
+  {
+    // GetReferencedElement adds us back to our target's observer list.
+    GetReferencedElement();
+  }
+
   virtual ~SVGRootRenderingObserver()
   {
     StopListening();
   }
 
 protected:
   virtual Element* GetTarget()
   {
@@ -77,22 +83,19 @@ protected:
       if (!frame || frame->PresContext()->PresShell()->IsDestroying()) {
         // We're being destroyed. Bail out.
         return;
       }
 
       mVectorImage->InvalidateObserver();
     }
 
-    // Our caller might've removed us from rendering-observer list.
-    // Add ourselves back!
-    if (!mInObserverList) {
-      nsSVGEffects::AddRenderingObserver(elem, this);
-      mInObserverList = true;
-    }
+    // We may have been removed from the observer list by our caller. Rather
+    // than add ourselves back here, we wait until Draw gets called, ensuring
+    // that we coalesce invalidations between Draw calls.
   }
 
   // Private data
   nsRefPtr<SVGDocumentWrapper> mDocWrapper;
   VectorImage* mVectorImage;   // Raw pointer because it owns me.
 };
 
 class SVGParseCompleteListener MOZ_FINAL : public nsStubDocumentObserver {
@@ -756,16 +759,23 @@ VectorImage::Draw(gfxContext* aContext,
 
   nsRefPtr<gfxDrawable> drawable = new gfxCallbackDrawable(cb, imageSizeGfx);
 
   gfxUtils::DrawPixelSnapped(aContext, drawable,
                              aUserSpaceToImageSpace,
                              subimage, sourceRect, imageRect, aFill,
                              gfxASurface::ImageFormatARGB32, aFilter);
 
+  MOZ_ASSERT(mRenderingObserver || mHaveRestrictedRegion, 
+      "Should have a rendering observer by now unless ExtractFrame created us");
+  if (mRenderingObserver) {
+    // Allow ourselves to fire FrameChanged and OnStopFrame again.
+    mRenderingObserver->ResumeListening();
+  }
+
   mIsDrawing = false;
   return NS_OK;
 }
 
 //******************************************************************************
 /* void requestDecode() */
 NS_IMETHODIMP
 VectorImage::RequestDecode()