Skip to content

Commit

Permalink
Bug 1291071 (Part 2) - Pass decoder progress explicitly to FinalizeDe…
Browse files Browse the repository at this point in the history
…coder. r=edwin
  • Loading branch information
sethfowler committed Aug 6, 2016
1 parent adee556 commit 667642c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 8 additions & 2 deletions image/IDecodingTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,25 @@ IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,

// Capture the decoder's state.
ImageMetadata metadata = aDecoder->GetImageMetadata();
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, metadata);
aImage->FinalizeDecoder(aDecoder, metadata, 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(), metadata);
image->FinalizeDecoder(decoder.get(), metadata, progress, invalidRect,
frameCount, surfaceFlags);
}));
}

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

void
RasterImage::FinalizeDecoder(Decoder* aDecoder,
const ImageMetadata& aMetadata)
const ImageMetadata& aMetadata,
Progress aProgress,
const IntRect& aInvalidRect,
const Maybe<uint32_t>& aFrameCount,
SurfaceFlags aSurfaceFlags)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aDecoder);
Expand All @@ -1582,10 +1586,8 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder,
// 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()));
FromSurfaceFlags(aSurfaceFlags));
return;
}

Expand All @@ -1598,10 +1600,7 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder,
}

// Send out any final notifications.
NotifyProgress(aDecoder->TakeProgress(),
aDecoder->TakeInvalidRect(),
aDecoder->TakeCompleteFrameCount(),
aDecoder->GetSurfaceFlags());
NotifyProgress(aProgress, aInvalidRect, aFrameCount, aSurfaceFlags);

if (mHasBeenDecoded && mAnimationState) {
// We're done decoding and our AnimationState has been notified about all
Expand Down
6 changes: 5 additions & 1 deletion image/RasterImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ class RasterImage final : public ImageResource
* Main-thread only.
*/
void FinalizeDecoder(Decoder* aDecoder,
const ImageMetadata& aMetadata);
const ImageMetadata& aMetadata,
Progress aProgress,
const gfx::IntRect& aInvalidRect,
const Maybe<uint32_t>& aFrameCount,
SurfaceFlags aSurfaceFlags);

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

0 comments on commit 667642c

Please sign in to comment.