Bug 1291045 (Part 2) - Pass the image into NotifyProgress() and NotifyDecodeComplete() explicitly. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Thu, 04 Aug 2016 19:04:14 -0700
changeset 349747 50ac73a27eb3206a849e8eb397c95ab75cddd4f9
parent 349746 41ecafc5752459e2e10de8df764b403559feb28a
child 349748 4999ae42eaec6fce2ca8cc439ba660a2fdb9ec58
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1291045
milestone51.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 1291045 (Part 2) - Pass the image into NotifyProgress() and NotifyDecodeComplete() explicitly. r=edwin
image/Decoder.h
image/IDecodingTask.cpp
--- a/image/Decoder.h
+++ b/image/Decoder.h
@@ -310,17 +310,17 @@ public:
   virtual Telemetry::ID SpeedHistogram();
 
   ImageMetadata& GetImageMetadata() { return mImageMetadata; }
 
   /**
    * @return a weak pointer to the image associated with this decoder. Illegal
    * to call if this decoder is not associated with an image.
    */
-  RasterImage* GetImage() const { MOZ_ASSERT(mImage); return mImage.get(); }
+  NotNull<RasterImage*> GetImage() const { return WrapNotNull(mImage.get()); }
 
   /**
    * @return a possibly-null weak pointer to the image associated with this
    * decoder. May be called even if this decoder is not associated with an
    * image.
    */
   RasterImage* GetImageMaybeNull() const { return mImage.get(); }
 
--- a/image/IDecodingTask.cpp
+++ b/image/IDecodingTask.cpp
@@ -18,17 +18,17 @@ using gfx::IntRect;
 
 namespace image {
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for sending notifications to the image associated with a decoder.
 ///////////////////////////////////////////////////////////////////////////////
 
 static void
-NotifyProgress(NotNull<Decoder*> aDecoder)
+NotifyProgress(NotNull<RasterImage*> aImage, NotNull<Decoder*> aDecoder)
 {
   MOZ_ASSERT(aDecoder->HasProgress() && !aDecoder->IsMetadataDecode());
 
   // Capture the decoder's state. If we need to notify asynchronously, it's
   // important that we don't wait until the lambda actually runs to capture the
   // state that we're going to notify. That would both introduce data races on
   // the decoder's state and cause inconsistencies between the NotifyProgress()
   // calls we make off-main-thread and the notifications that RasterImage
@@ -36,43 +36,44 @@ NotifyProgress(NotNull<Decoder*> aDecode
   Progress progress = aDecoder->TakeProgress();
   IntRect invalidRect = aDecoder->TakeInvalidRect();
   Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
   SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
 
   // Synchronously notify if we can.
   if (NS_IsMainThread() &&
       !(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
-    aDecoder->GetImage()->NotifyProgress(progress, invalidRect,
-                                         frameCount, surfaceFlags);
+    aImage->NotifyProgress(progress, invalidRect,
+                           frameCount, surfaceFlags);
     return;
   }
 
   // We're forced to notify asynchronously.
-  NotNull<RefPtr<Decoder>> decoder = aDecoder;
+  NotNull<RefPtr<RasterImage>> image = aImage;
   NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void {
-    decoder->GetImage()->NotifyProgress(progress, invalidRect,
-                                        frameCount, surfaceFlags);
+    image->NotifyProgress(progress, invalidRect,
+                          frameCount, surfaceFlags);
   }));
 }
 
 static void
-NotifyDecodeComplete(NotNull<Decoder*> aDecoder)
+NotifyDecodeComplete(NotNull<RasterImage*> aImage, NotNull<Decoder*> aDecoder)
 {
   // Synchronously notify if we can.
   if (NS_IsMainThread() &&
       !(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
-    aDecoder->GetImage()->FinalizeDecoder(aDecoder);
+    aImage->FinalizeDecoder(aDecoder);
     return;
   }
 
   // We're forced to notify asynchronously.
+  NotNull<RefPtr<RasterImage>> image = aImage;
   NotNull<RefPtr<Decoder>> decoder = aDecoder;
   NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void {
-    decoder->GetImage()->FinalizeDecoder(decoder.get());
+    image->FinalizeDecoder(decoder.get());
   }));
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // IDecodingTask implementation.
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -98,25 +99,25 @@ DecodingTask::DecodingTask(NotNull<Decod
 
 void
 DecodingTask::Run()
 {
   while (true) {
     LexerResult result = mDecoder->Decode(WrapNotNull(this));
 
     if (result.is<TerminalState>()) {
-      NotifyDecodeComplete(mDecoder);
+      NotifyDecodeComplete(mDecoder->GetImage(), mDecoder);
       return;  // We're done.
     }
 
     MOZ_ASSERT(result.is<Yield>());
 
     // Notify for the progress we've made so far.
     if (mDecoder->HasProgress()) {
-      NotifyProgress(mDecoder);
+      NotifyProgress(mDecoder->GetImage(), mDecoder);
     }
 
     if (result == LexerResult(Yield::NEED_MORE_DATA)) {
       // We can't make any more progress right now. The decoder itself will
       // ensure that we get reenqueued when more data is available; just return
       // for now.
       return;
     }
@@ -148,25 +149,25 @@ AnimationDecodingTask::AnimationDecoding
 
 void
 AnimationDecodingTask::Run()
 {
   while (true) {
     LexerResult result = mDecoder->Decode(WrapNotNull(this));
 
     if (result.is<TerminalState>()) {
-      NotifyDecodeComplete(mDecoder);
+      NotifyDecodeComplete(mDecoder->GetImage(), mDecoder);
       return;  // We're done.
     }
 
     MOZ_ASSERT(result.is<Yield>());
 
     // Notify for the progress we've made so far.
     if (mDecoder->HasProgress()) {
-      NotifyProgress(mDecoder);
+      NotifyProgress(mDecoder->GetImage(), mDecoder);
     }
 
     if (result == LexerResult(Yield::NEED_MORE_DATA)) {
       // We can't make any more progress right now. The decoder itself will
       // ensure that we get reenqueued when more data is available; just return
       // for now.
       return;
     }
@@ -195,17 +196,17 @@ MetadataDecodingTask::MetadataDecodingTa
 }
 
 void
 MetadataDecodingTask::Run()
 {
   LexerResult result = mDecoder->Decode(WrapNotNull(this));
 
   if (result.is<TerminalState>()) {
-    NotifyDecodeComplete(mDecoder);
+    NotifyDecodeComplete(mDecoder->GetImage(), mDecoder);
     return;  // We're done.
   }
 
   if (result == LexerResult(Yield::NEED_MORE_DATA)) {
     // We can't make any more progress right now. We also don't want to report
     // any progress, because it's important that metadata decode results are
     // delivered atomically. The decoder itself will ensure that we get
     // reenqueued when more data is available; just return for now.