ported from UXP: Issue #2073 - m-c 523950: Discard decoded frames of very large GIF animations (squashed) (e96122ed)

This commit is contained in:
2023-01-10 15:51:34 +08:00
parent 4c5ee58563
commit f468f934d7
25 changed files with 925 additions and 63 deletions
+27 -2
View File
@@ -179,7 +179,8 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType,
NotNull<SourceBuffer*> aSourceBuffer,
const IntSize& aIntrinsicSize,
DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags)
SurfaceFlags aSurfaceFlags,
size_t aCurrentFrame)
{
if (aType == DecoderType::UNKNOWN) {
return nullptr;
@@ -211,7 +212,8 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType,
NotNull<RefPtr<AnimationSurfaceProvider>> provider =
WrapNotNull(new AnimationSurfaceProvider(aImage,
surfaceKey,
WrapNotNull(decoder)));
WrapNotNull(decoder),
aCurrentFrame));
// Attempt to insert the surface provider into the surface cache right away so
// we won't trigger any more decoders with the same parameters.
@@ -224,6 +226,29 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType,
return task.forget();
}
/* static */ already_AddRefed<Decoder>
DecoderFactory::CloneAnimationDecoder(Decoder* aDecoder)
{
MOZ_ASSERT(aDecoder);
MOZ_ASSERT(aDecoder->HasAnimation());
RefPtr<Decoder> decoder = GetDecoder(aDecoder->GetType(), nullptr,
/* aIsRedecode = */ true);
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetMetadataDecode(false);
decoder->SetIterator(aDecoder->GetSourceBuffer()->Iterator());
decoder->SetDecoderFlags(aDecoder->GetDecoderFlags());
decoder->SetSurfaceFlags(aDecoder->GetSurfaceFlags());
if (NS_FAILED(decoder->Init())) {
return nullptr;
}
return decoder.forget();
}
/* static */ already_AddRefed<IDecodingTask>
DecoderFactory::CreateMetadataDecoder(DecoderType aType,
NotNull<RasterImage*> aImage,