Bug 1317552. Send unlocked draw notifications for images async when asked to. r=aosmond
authorTimothy Nikkel <tnikkel@gmail.com>
Thu, 17 Nov 2016 00:25:53 -0600
changeset 322990 0e069443912292d0f98b82a425eeb0a60582c2f1
parent 322989 b1ad7c0aadfbcff130dc8570784148f1e4e85d85
child 322991 41fe2fa4ddabb611c4da3cdb0585d6e1cd9722c4
child 323067 cf0f72f0b0be8817389893a625c12c4bbc04922b
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersaosmond
bugs1317552
milestone53.0a1
Bug 1317552. Send unlocked draw notifications for images async when asked to. r=aosmond
image/Image.cpp
image/Image.h
image/RasterImage.cpp
image/VectorImage.cpp
--- a/image/Image.cpp
+++ b/image/Image.cpp
@@ -141,10 +141,30 @@ ImageResource::EvaluateAnimation()
   if (!mAnimating && ShouldAnimate()) {
     nsresult rv = StartAnimation();
     mAnimating = NS_SUCCEEDED(rv);
   } else if (mAnimating && !ShouldAnimate()) {
     StopAnimation();
   }
 }
 
+void
+ImageResource::SendOnUnlockedDraw(uint32_t aFlags)
+{
+  if (!mProgressTracker) {
+    return;
+  }
+
+  if (!(aFlags & FLAG_ASYNC_NOTIFY)) {
+    mProgressTracker->OnUnlockedDraw();
+  } else {
+    NotNull<RefPtr<ImageResource>> image = WrapNotNull(this);
+    NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void {
+      RefPtr<ProgressTracker> tracker = image->GetProgressTracker();
+      if (tracker) {
+        tracker->OnUnlockedDraw();
+      }
+    }));
+  }
+}
+
 } // namespace image
 } // namespace mozilla
--- a/image/Image.h
+++ b/image/Image.h
@@ -300,16 +300,18 @@ protected:
    */
   virtual bool ShouldAnimate() {
     return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
   }
 
   virtual nsresult StartAnimation() = 0;
   virtual nsresult StopAnimation() = 0;
 
+  void SendOnUnlockedDraw(uint32_t aFlags);
+
   // Member data shared by all implementations of this abstract class
   RefPtr<ProgressTracker>     mProgressTracker;
   RefPtr<ImageURL>            mURI;
   TimeStamp                     mLastRefreshTime;
   uint64_t                      mInnerWindowId;
   uint32_t                      mAnimationConsumers;
   uint16_t                      mAnimationMode; // Enum values in imgIContainer
   bool                          mInitialized:1; // Have we been initalized?
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -582,18 +582,18 @@ RasterImage::GetImageContainer(LayerMana
 
   int32_t maxTextureSize = aManager->GetMaxTextureSize();
   if (!mHasSize ||
       mSize.width > maxTextureSize ||
       mSize.height > maxTextureSize) {
     return nullptr;
   }
 
-  if (IsUnlocked() && mProgressTracker) {
-    mProgressTracker->OnUnlockedDraw();
+  if (IsUnlocked()) {
+    SendOnUnlockedDraw(aFlags);
   }
 
   RefPtr<layers::ImageContainer> container = mImageContainer.get();
 
   bool mustRedecode =
     (aFlags & (FLAG_SYNC_DECODE | FLAG_SYNC_DECODE_IF_FAST)) &&
     mLastImageContainerDrawResult != DrawResult::SUCCESS &&
     mLastImageContainerDrawResult != DrawResult::BAD_IMAGE;
@@ -1338,20 +1338,21 @@ RasterImage::Draw(gfxContext* aContext,
   if (ToSurfaceFlags(aFlags) != DefaultSurfaceFlags()) {
     return DrawResult::BAD_ARGS;
   }
 
   if (!aContext) {
     return DrawResult::BAD_ARGS;
   }
 
-  if (IsUnlocked() && mProgressTracker) {
-    mProgressTracker->OnUnlockedDraw();
+  if (IsUnlocked()) {
+    SendOnUnlockedDraw(aFlags);
   }
 
+
   // If we're not using SamplingFilter::GOOD, we shouldn't high-quality scale or
   // downscale during decode.
   uint32_t flags = aSamplingFilter == SamplingFilter::GOOD
                  ? aFlags
                  : aFlags & ~FLAG_HIGH_QUALITY_SCALING;
 
   DrawableSurface surface =
     LookupFrame(aSize, flags, ToPlaybackType(aWhichFrame));
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -830,18 +830,18 @@ VectorImage::Draw(gfxContext* aContext,
     return DrawResult::NOT_READY;
   }
 
   if (mIsDrawing) {
     NS_WARNING("Refusing to make re-entrant call to VectorImage::Draw");
     return DrawResult::TEMPORARY_ERROR;
   }
 
-  if (mAnimationConsumers == 0 && mProgressTracker) {
-    mProgressTracker->OnUnlockedDraw();
+  if (mAnimationConsumers == 0) {
+    SendOnUnlockedDraw(aFlags);
   }
 
   AutoRestore<bool> autoRestoreIsDrawing(mIsDrawing);
   mIsDrawing = true;
 
   Maybe<SVGImageContext> svgContext;
   // If FLAG_FORCE_PRESERVEASPECTRATIO_NONE bit is set, that mean we should
   // overwrite SVG preserveAspectRatio attibute of this image with none, and