diff --git a/image/DecoderFactory.cpp b/image/DecoderFactory.cpp index d8159a063a53..4786b6931e7b 100644 --- a/image/DecoderFactory.cpp +++ b/image/DecoderFactory.cpp @@ -108,6 +108,7 @@ DecoderFactory::GetDecoder(DecoderType aType, DecoderFactory::CreateDecoder(DecoderType aType, NotNull aImage, NotNull aSourceBuffer, + const IntSize& aIntrinsicSize, const Maybe& aTargetSize, DecoderFlags aDecoderFlags, SurfaceFlags aSurfaceFlags, @@ -139,6 +140,17 @@ DecoderFactory::CreateDecoder(DecoderType aType, return nullptr; } + // Add a placeholder to the SurfaceCache so we won't trigger any more decoders + // with the same parameters. + IntSize surfaceSize = aTargetSize.valueOr(aIntrinsicSize); + SurfaceKey surfaceKey = + RasterSurfaceKey(surfaceSize, aSurfaceFlags, /* aFrameNum = */ 0); + InsertOutcome outcome = + SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey); + if (outcome != InsertOutcome::SUCCESS) { + return nullptr; + } + RefPtr task = new DecodingTask(WrapNotNull(decoder)); return task.forget(); } @@ -147,6 +159,7 @@ DecoderFactory::CreateDecoder(DecoderType aType, DecoderFactory::CreateAnimationDecoder(DecoderType aType, NotNull aImage, NotNull aSourceBuffer, + const IntSize& aIntrinsicSize, DecoderFlags aDecoderFlags, SurfaceFlags aSurfaceFlags) { @@ -172,6 +185,16 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType, return nullptr; } + // Add a placeholder for the first frame to the SurfaceCache so we won't + // trigger any more decoders with the same parameters. + SurfaceKey surfaceKey = + RasterSurfaceKey(aIntrinsicSize, aSurfaceFlags, /* aFrameNum = */ 0); + InsertOutcome outcome = + SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey); + if (outcome != InsertOutcome::SUCCESS) { + return nullptr; + } + RefPtr task = new DecodingTask(WrapNotNull(decoder)); return task.forget(); } diff --git a/image/DecoderFactory.h b/image/DecoderFactory.h index e91b73bcdcdd..59d6aff663c1 100644 --- a/image/DecoderFactory.h +++ b/image/DecoderFactory.h @@ -54,6 +54,8 @@ public: * notifications as decoding progresses. * @param aSourceBuffer The SourceBuffer which the decoder will read its data * from. + * @param aIntrinsicSize The intrinsic size of the image, normally obtained + * during the metadata decode. * @param aTargetSize If not Nothing(), the target size which the image should * be scaled to during decoding. It's an error to specify * a target size for a decoder type which doesn't support @@ -68,6 +70,7 @@ public: CreateDecoder(DecoderType aType, NotNull aImage, NotNull aSourceBuffer, + const gfx::IntSize& aIntrinsicSize, const Maybe& aTargetSize, DecoderFlags aDecoderFlags, SurfaceFlags aSurfaceFlags, @@ -82,6 +85,8 @@ public: * notifications as decoding progresses. * @param aSourceBuffer The SourceBuffer which the decoder will read its data * from. + * @param aIntrinsicSize The intrinsic size of the image, normally obtained + * during the metadata decode. * @param aDecoderFlags Flags specifying the behavior of this decoder. * @param aSurfaceFlags Flags specifying the type of output this decoder * should produce. @@ -90,6 +95,7 @@ public: CreateAnimationDecoder(DecoderType aType, NotNull aImage, NotNull aSourceBuffer, + const gfx::IntSize& aIntrinsicSize, DecoderFlags aDecoderFlags, SurfaceFlags aSurfaceFlags); diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index f670f277398f..fe4b7a6def7f 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -1309,12 +1309,13 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags) RefPtr task; if (mAnim) { task = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this), - mSourceBuffer, decoderFlags, - surfaceFlags); + mSourceBuffer, mSize, + decoderFlags, surfaceFlags); } else { task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this), - mSourceBuffer, targetSize, decoderFlags, - surfaceFlags, mRequestedSampleSize); + mSourceBuffer, mSize, targetSize, + decoderFlags, surfaceFlags, + mRequestedSampleSize); } // Make sure DecoderFactory was able to create a decoder successfully. @@ -1322,18 +1323,6 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags) return NS_ERROR_FAILURE; } - // Add a placeholder for the first frame to the SurfaceCache so we won't - // trigger any more decoders with the same parameters. - SurfaceKey surfaceKey = - RasterSurfaceKey(aSize, - task->GetDecoder()->GetSurfaceFlags(), - /* aFrameNum = */ 0); - InsertOutcome outcome = - SurfaceCache::InsertPlaceholder(ImageKey(this), surfaceKey); - if (outcome != InsertOutcome::SUCCESS) { - return NS_ERROR_FAILURE; - } - mDecodeCount++; // We're ready to decode; start the decoder.