Bug 1187401 (Part 1) - Simplify the condition that determines whether we set RasterImage::mHasBeenDecoded. r=tn
authorSeth Fowler <mark.seth.fowler@gmail.com>
Fri, 14 Aug 2015 17:54:11 -0700
changeset 529472 4a649b00889e9d07604807242818bdd6395e9bb8
parent 529471 99c156585db009d32ea1d04013672415b4f6caec
child 529473 48e0a7a51e4e7459fbe743bc0a9f5efbc522a14b
push id83435
push usermfowler@mozilla.com
push dateSat, 15 Aug 2015 00:54:44 +0000
treeherdertry@1c09ccf8c62b [default view] [failures only]
reviewerstn
bugs1187401
milestone43.0a1
Bug 1187401 (Part 1) - Simplify the condition that determines whether we set RasterImage::mHasBeenDecoded. r=tn
image/Decoder.h
image/RasterImage.cpp
--- a/image/Decoder.h
+++ b/image/Decoder.h
@@ -192,29 +192,24 @@ public:
   bool HasAnimation() const { return mImageMetadata.HasAnimation(); }
 
   // Error tracking
   bool HasError() const { return HasDataError() || HasDecoderError(); }
   bool HasDataError() const { return mDataError; }
   bool HasDecoderError() const { return NS_FAILED(mFailCode); }
   bool ShouldReportError() const { return mShouldReportError; }
   nsresult GetDecoderError() const { return mFailCode; }
-  void PostResizeError() { PostDataError(); }
 
   /// Did we finish decoding enough that calling Decode() again would be useless?
   bool GetDecodeDone() const
   {
     return mDecodeDone || (mMetadataDecode && HasSize()) ||
            HasError() || mDataDone;
   }
 
-  /// Did we finish decoding enough to set |RasterImage::mHasBeenDecoded|?
-  // XXX(seth): This will be removed in bug 1187401.
-  bool GetDecodeTotallyDone() const { return mDecodeDone && !IsMetadataDecode(); }
-
   /// Are we in the middle of a frame right now? Used for assertions only.
   bool InFrame() const { return mInFrame; }
 
   /// Should we store surfaces created by this decoder in the SurfaceCache?
   bool ShouldUseSurfaceCache() const { return bool(mImage); }
 
   /**
    * Returns true if this decoder was aborted.
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1976,47 +1976,42 @@ RasterImage::NotifyProgress(Progress aPr
 void
 RasterImage::FinalizeDecoder(Decoder* aDecoder)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aDecoder);
   MOZ_ASSERT(aDecoder->HasError() || !aDecoder->InFrame(),
              "Finalizing a decoder in the middle of a frame");
 
+  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.
-  nsresult rv = SetMetadata(aDecoder->GetImageMetadata(),
-                            aDecoder->IsMetadataDecode());
-  if (NS_FAILED(rv)) {
-    aDecoder->PostResizeError();
-  }
+  SetMetadata(aDecoder->GetImageMetadata(), wasMetadata);
+  MOZ_ASSERT(mError || mHasSize || !aDecoder->HasSize(),
+             "SetMetadata should've gotten a size");
 
-  MOZ_ASSERT(mError || mHasSize || !aDecoder->HasSize(),
-             "Should have handed off size by now");
-
-  if (aDecoder->GetDecodeTotallyDone() && !mError) {
+  if (!wasMetadata && aDecoder->GetDecodeDone() && !aDecoder->WasAborted()) {
     // Flag that we've been decoded before.
     mHasBeenDecoded = true;
     if (mAnim) {
       mAnim->SetDoneDecoding(true);
     }
   }
 
   // Send out any final notifications.
   NotifyProgress(aDecoder->TakeProgress(),
                  aDecoder->TakeInvalidRect(),
                  aDecoder->GetSurfaceFlags());
 
-  bool wasMetadata = aDecoder->IsMetadataDecode();
-  bool done = aDecoder->GetDecodeDone();
-
   if (!wasMetadata && aDecoder->ChunkCount()) {
     Telemetry::Accumulate(Telemetry::IMAGE_DECODE_CHUNKS,
                           aDecoder->ChunkCount());
   }
 
   if (done) {
     // Do some telemetry if this isn't a metadata decode.
     if (!wasMetadata) {