Bug 1291071 (Part 6) - Stop passing a decoder to FinalizeDecoder() and rename it NotifyDecodeComplete(). r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Tue, 02 Aug 2016 17:22:41 -0700
changeset 397566 731d13870f6a161f47ab8bffe5ee8e2ac92d5195
parent 397565 55a26e91a828df3cd54b432a03014ed4801dc20f
child 397567 446f5f465b92e93c7389037bb3c8721ed43235ef
push id25332
push usermaglione.k@gmail.com
push dateSat, 06 Aug 2016 21:21:51 +0000
reviewersedwin
bugs1291071
milestone51.0a1
Bug 1291071 (Part 6) - Stop passing a decoder to FinalizeDecoder() and rename it NotifyDecodeComplete(). r=edwin
image/IDecodingTask.cpp
image/RasterImage.cpp
image/RasterImage.h
--- a/image/IDecodingTask.cpp
+++ b/image/IDecodingTask.cpp
@@ -70,27 +70,26 @@ IDecodingTask::NotifyDecodeComplete(NotN
   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)) {
-    aImage->FinalizeDecoder(aDecoder, finalStatus, metadata, telemetry, progress,
-                            invalidRect, frameCount, surfaceFlags);
+    aImage->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
+                                 invalidRect, frameCount, surfaceFlags);
     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(), finalStatus, metadata, telemetry,
-                           progress, invalidRect, frameCount, surfaceFlags);
+    image->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
+                                invalidRect, frameCount, surfaceFlags);
   }));
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // IDecodingTask implementation.
 ///////////////////////////////////////////////////////////////////////////////
 
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1557,31 +1557,29 @@ RasterImage::NotifyProgress(Progress aPr
     StartAnimation();
   }
 
   // Tell the observers what happened.
   image->mProgressTracker->SyncNotifyProgress(aProgress, aInvalidRect);
 }
 
 void
-RasterImage::FinalizeDecoder(Decoder* aDecoder,
-                             const DecoderFinalStatus& aStatus,
-                             const ImageMetadata& aMetadata,
-                             const DecoderTelemetry& aTelemetry,
-                             Progress aProgress,
-                             const IntRect& aInvalidRect,
-                             const Maybe<uint32_t>& aFrameCount,
-                             SurfaceFlags aSurfaceFlags)
+RasterImage::NotifyDecodeComplete(const DecoderFinalStatus& aStatus,
+                                  const ImageMetadata& aMetadata,
+                                  const DecoderTelemetry& aTelemetry,
+                                  Progress aProgress,
+                                  const IntRect& aInvalidRect,
+                                  const Maybe<uint32_t>& aFrameCount,
+                                  SurfaceFlags aSurfaceFlags)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aDecoder);
 
   // If the decoder detected an error, log it to the error console.
   if (aStatus.mShouldReportError && !aStatus.mWasAborted) {
-    ReportDecoderError(aDecoder);
+    ReportDecoderError();
   }
 
   // Record all the metadata the decoder gathered about this image.
   bool metadataOK = SetMetadata(aMetadata, aStatus.mWasMetadataDecode);
   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.
@@ -1640,17 +1638,17 @@ RasterImage::FinalizeDecoder(Decoder* aD
   // If we were a metadata decode and a full decode was requested, do it.
   if (aStatus.mFinished && aStatus.mWasMetadataDecode && mWantFullDecode) {
     mWantFullDecode = false;
     RequestDecodeForSize(mSize, DECODE_FLAGS_DEFAULT);
   }
 }
 
 void
-RasterImage::ReportDecoderError(Decoder* aDecoder)
+RasterImage::ReportDecoderError()
 {
   nsCOMPtr<nsIConsoleService> consoleService =
     do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   nsCOMPtr<nsIScriptError> errorObject =
     do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
 
   if (consoleService && errorObject) {
     nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated."));
--- a/image/RasterImage.h
+++ b/image/RasterImage.h
@@ -194,31 +194,43 @@ public:
    *                     notifications don't come from a decoder.
    */
   void NotifyProgress(Progress aProgress,
                       const gfx::IntRect& aInvalidRect = nsIntRect(),
                       const Maybe<uint32_t>& aFrameCount = Nothing(),
                       SurfaceFlags aSurfaceFlags = DefaultSurfaceFlags());
 
   /**
-   * Records telemetry and does final teardown of the provided decoder.
+   * Records decoding results, sends out any final notifications, updates the
+   * state of this image, and records telemetry.
    *
    * Main-thread only.
+   *
+   * @param aStatus      Final status information about the decoder. (Whether it
+   *                     encountered an error, etc.)
+   * @param aMetadata    Metadata about this image that the decoder gathered.
+   * @param aTelemetry   Telemetry data about the decoder.
+   * @param aProgress    Any final progress notifications to send.
+   * @param aInvalidRect Any final invalidation rect to send.
+   * @param aFrameCount  If Some(), a final updated count of the number of frames
+   *                     of animation the decoder has finished decoding so far.
+   *                     This is a lower bound for the total number of animation
+   *                     frames this image has.
+   * @param aFlags       The surface flags used by the decoder.
    */
-  void FinalizeDecoder(Decoder* aDecoder,
-                       const DecoderFinalStatus& aStatus,
-                       const ImageMetadata& aMetadata,
-                       const DecoderTelemetry& aTelemetry,
-                       Progress aProgress,
-                       const gfx::IntRect& aInvalidRect,
-                       const Maybe<uint32_t>& aFrameCount,
-                       SurfaceFlags aSurfaceFlags);
+  void NotifyDecodeComplete(const DecoderFinalStatus& aStatus,
+                            const ImageMetadata& aMetadata,
+                            const DecoderTelemetry& aTelemetry,
+                            Progress aProgress,
+                            const gfx::IntRect& aInvalidRect,
+                            const Maybe<uint32_t>& aFrameCount,
+                            SurfaceFlags aSurfaceFlags);
 
-  // Helper method for FinalizeDecoder.
-  void ReportDecoderError(Decoder* aDecoder);
+  // Helper method for NotifyDecodeComplete.
+  void ReportDecoderError();
 
 
   //////////////////////////////////////////////////////////////////////////////
   // Network callbacks.
   //////////////////////////////////////////////////////////////////////////////
 
   virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
                                         nsISupports* aContext,