Bug 1291071 (Part 1) - Pass ImageMetadata explicitly to FinalizeDecoder. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Tue, 02 Aug 2016 15:43:47 -0700
changeset 308439 5ce50dc53516af734f52c5eff598e8f171623040
parent 308438 d416df8849a03fb005f6bd0ed9d844ed9dd4b6db
child 308440 801b6b88b490705e4905b2b83346515e2461c5b7
push id80341
push userseth.bugzilla@blackhail.net
push dateSat, 06 Aug 2016 01:50:41 +0000
treeherdermozilla-inbound@731d13870f6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1291071
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 1291071 (Part 1) - Pass ImageMetadata explicitly to FinalizeDecoder. r=edwin
image/Decoder.h
image/IDecodingTask.cpp
image/RasterImage.cpp
image/RasterImage.h
--- a/image/Decoder.h
+++ b/image/Decoder.h
@@ -315,17 +315,18 @@ public:
    */
   gfx::IntRect FullOutputFrame() const
   {
     return gfx::IntRect(gfx::IntPoint(), OutputSize());
   }
 
   virtual Telemetry::ID SpeedHistogram();
 
-  ImageMetadata& GetImageMetadata() { return mImageMetadata; }
+  /// @return the metadata we collected about this image while decoding.
+  const 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.
    */
   NotNull<RasterImage*> GetImage() const { return WrapNotNull(mImage.get()); }
 
   /**
--- a/image/IDecodingTask.cpp
+++ b/image/IDecodingTask.cpp
@@ -58,28 +58,31 @@ IDecodingTask::NotifyProgress(NotNull<Ra
 
 /* static */ void
 IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
                                     NotNull<Decoder*> aDecoder)
 {
   MOZ_ASSERT(aDecoder->HasError() || !aDecoder->InFrame(),
              "Decode complete in the middle of a frame?");
 
+  // Capture the decoder's state.
+  ImageMetadata metadata = aDecoder->GetImageMetadata();
+
   // Synchronously notify if we can.
   if (NS_IsMainThread() &&
       !(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
-    aImage->FinalizeDecoder(aDecoder);
+    aImage->FinalizeDecoder(aDecoder, metadata);
     return;
   }
 
   // We're forced to notify asynchronously.
   NotNull<RefPtr<RasterImage>> image = aImage;
   NotNull<RefPtr<Decoder>> decoder = aDecoder;
   NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void {
-    image->FinalizeDecoder(decoder.get());
+    image->FinalizeDecoder(decoder.get(), metadata);
   }));
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // IDecodingTask implementation.
 ///////////////////////////////////////////////////////////////////////////////
 
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1557,43 +1557,44 @@ RasterImage::NotifyProgress(Progress aPr
     StartAnimation();
   }
 
   // Tell the observers what happened.
   image->mProgressTracker->SyncNotifyProgress(aProgress, aInvalidRect);
 }
 
 void
-RasterImage::FinalizeDecoder(Decoder* aDecoder)
+RasterImage::FinalizeDecoder(Decoder* aDecoder,
+                             const ImageMetadata& aMetadata)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aDecoder);
 
   bool wasMetadata = aDecoder->IsMetadataDecode();
   bool done = aDecoder->GetDecodeDone();
 
   // If the decoder detected an error, log it to the error console.
   if (aDecoder->ShouldReportError() && !aDecoder->WasAborted()) {
     ReportDecoderError(aDecoder);
   }
 
   // Record all the metadata the decoder gathered about this image.
-  bool metadataOK = SetMetadata(aDecoder->GetImageMetadata(), wasMetadata);
+  bool metadataOK = SetMetadata(aMetadata, wasMetadata);
   if (!metadataOK) {
     // This indicates a serious error that requires us to discard all existing
     // surfaces and redecode to recover. We'll drop the results from this
     // decoder on the floor, since they aren't valid.
     aDecoder->TakeProgress();
     aDecoder->TakeInvalidRect();
     RecoverFromInvalidFrames(mSize,
                              FromSurfaceFlags(aDecoder->GetSurfaceFlags()));
     return;
   }
 
-  MOZ_ASSERT(mError || mHasSize || !aDecoder->HasSize(),
+  MOZ_ASSERT(mError || mHasSize || !aMetadata.HasSize(),
              "SetMetadata should've gotten a size");
 
   if (!wasMetadata && aDecoder->GetDecodeDone() && !aDecoder->WasAborted()) {
     // Flag that we've been decoded before.
     mHasBeenDecoded = true;
   }
 
   // Send out any final notifications.
--- a/image/RasterImage.h
+++ b/image/RasterImage.h
@@ -23,16 +23,17 @@
 #include "nsIProperties.h"
 #include "nsTArray.h"
 #include "imgFrame.h"
 #include "LookupResult.h"
 #include "nsThreadUtils.h"
 #include "DecodePool.h"
 #include "DecoderFactory.h"
 #include "FrameAnimator.h"
+#include "ImageMetadata.h"
 #include "Orientation.h"
 #include "nsIObserver.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/Pair.h"
 #include "mozilla/TimeStamp.h"
@@ -195,17 +196,18 @@ public:
                       const Maybe<uint32_t>& aFrameCount = Nothing(),
                       SurfaceFlags aSurfaceFlags = DefaultSurfaceFlags());
 
   /**
    * Records telemetry and does final teardown of the provided decoder.
    *
    * Main-thread only.
    */
-  void FinalizeDecoder(Decoder* aDecoder);
+  void FinalizeDecoder(Decoder* aDecoder,
+                       const ImageMetadata& aMetadata);
 
   // Helper method for FinalizeDecoder.
   void ReportDecoderError(Decoder* aDecoder);
 
 
   //////////////////////////////////////////////////////////////////////////////
   // Network callbacks.
   //////////////////////////////////////////////////////////////////////////////