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

Controlled by image.animated.decode-on-demand.threshold-kb, default 256MB

Includes squashed bugfixes/regressions:
 - m-c 1444537: Shutting down the decode pool should make animated decoders bail early
 - m-c 1628606: Make sure to mark the surface cache entry available before sending the frame complete notification
 - m-c 1502275: Skip recreating the decoder after redecode errors if an animated image is reset
 - m-c 1443232: Don't insert frames into our AnimationFrameBuffer that we consider in error and unusable
This commit is contained in:
Martok 2022-12-31 22:55:46 +01:00 • committed by roytam1
commit e96122ede2
25 changed files with 925 additions and 63 deletions

View file

@ -13,6 +13,7 @@
#include "FrameAnimator.h"
#include "IDecodingTask.h"
#include "ISurfaceProvider.h"
#include "AnimationFrameBuffer.h"
namespace mozilla {
namespace image {
@ -31,7 +32,8 @@ public:
AnimationSurfaceProvider(NotNull<RasterImage*> aImage,
const SurfaceKey& aSurfaceKey,
NotNull<Decoder*> aDecoder);
NotNull<Decoder*> aDecoder,
size_t aCurrentFrame);
//////////////////////////////////////////////////////////////////////////////
@ -44,10 +46,13 @@ public:
DrawableSurface Surface() override { return DrawableSurface(WrapNotNull(this)); }
bool IsFinished() const override;
bool IsFullyDecoded() const override;
size_t LogicalSizeInBytes() const override;
void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
size_t& aHeapSizeOut,
size_t& aNonHeapSizeOut) override;
void Reset() override;
void Advance(size_t aFrame) override;
protected:
DrawableFrameRef DrawableRef(size_t aFrame) override;
@ -77,11 +82,15 @@ private:
virtual ~AnimationSurfaceProvider();
void DropImageReference();
void CheckForNewFrameAtYield();
void CheckForNewFrameAtTerminalState();
void AnnounceSurfaceAvailable();
void FinishDecoding();
// @returns Whether or not we should continue decoding.
bool CheckForNewFrameAtYield();
// @returns Whether or not we should restart decoding.
bool CheckForNewFrameAtTerminalState();
/// The image associated with our decoder.
RefPtr<RasterImage> mImage;
@ -95,7 +104,7 @@ private:
mutable Mutex mFramesMutex;
/// The frames of this animation, in order.
nsTArray<RawAccessFrameRef> mFrames;
AnimationFrameBuffer mFrames;
};
} // namespace image