Skip to content

Commit

Permalink
Bug 1291071 (Part 1) - Pass ImageMetadata explicitly to FinalizeDecod…
Browse files Browse the repository at this point in the history
…er. r=edwin
  • Loading branch information
sethfowler committed Aug 6, 2016
1 parent 2fed3b7 commit adee556
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion image/Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ class Decoder

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
Expand Down
7 changes: 5 additions & 2 deletions image/IDecodingTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,21 @@ IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
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);
}));
}

Expand Down
7 changes: 4 additions & 3 deletions image/RasterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,8 @@ RasterImage::NotifyProgress(Progress aProgress,
}

void
RasterImage::FinalizeDecoder(Decoder* aDecoder)
RasterImage::FinalizeDecoder(Decoder* aDecoder,
const ImageMetadata& aMetadata)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aDecoder);
Expand All @@ -1576,7 +1577,7 @@ RasterImage::FinalizeDecoder(Decoder* 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
Expand All @@ -1588,7 +1589,7 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder)
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()) {
Expand Down
4 changes: 3 additions & 1 deletion image/RasterImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "DecodePool.h"
#include "DecoderFactory.h"
#include "FrameAnimator.h"
#include "ImageMetadata.h"
#include "Orientation.h"
#include "nsIObserver.h"
#include "mozilla/Attributes.h"
Expand Down Expand Up @@ -200,7 +201,8 @@ class RasterImage final : public ImageResource
*
* Main-thread only.
*/
void FinalizeDecoder(Decoder* aDecoder);
void FinalizeDecoder(Decoder* aDecoder,
const ImageMetadata& aMetadata);

// Helper method for FinalizeDecoder.
void ReportDecoderError(Decoder* aDecoder);
Expand Down

0 comments on commit adee556

Please sign in to comment.