Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Unified Diff: third_party/WebKit/Source/platform/graphics/BitmapImage.h

Issue 1925533003: High CPU and increased memory usage fix for high-res (GIF, WEBP...) animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing. DCHECK. Thanks fmalita@. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/BitmapImage.h
diff --git a/third_party/WebKit/Source/platform/graphics/BitmapImage.h b/third_party/WebKit/Source/platform/graphics/BitmapImage.h
index 3c4611356daf956c8252a3a35144423d09339d36..c237257adedce8137d641d3cfb2792a54ee9e015 100644
--- a/third_party/WebKit/Source/platform/graphics/BitmapImage.h
+++ b/third_party/WebKit/Source/platform/graphics/BitmapImage.h
@@ -44,8 +44,9 @@ namespace blink {
template <typename T> class Timer;
class PLATFORM_EXPORT BitmapImage final : public Image {
- friend class GeneratedImage;
+ friend class BitmapImageTest;
friend class CrossfadeGeneratedImage;
+ friend class GeneratedImage;
friend class GradientGeneratedImage;
friend class GraphicsContext;
public:
@@ -69,11 +70,6 @@ public:
bool isAllDataReceived() const { return m_allDataReceived; }
bool hasColorProfile() const;
- // It may look unusual that there's no start animation call as public API.
- // This because we start and stop animating lazily. Animation starts when
- // the image is rendered, and automatically pauses once all observers no
- // longer want to render the image.
- void stopAnimation() override;
void resetAnimation() override;
bool maybeAnimated() override;
@@ -96,11 +92,6 @@ public:
void advanceAnimationForTesting() override { internalAdvanceAnimation(false); }
private:
- friend class BitmapImageTest;
-
- void updateSize() const;
-
-private:
enum RepetitionCountStatus {
Unknown, // We haven't checked the source's repetition count.
Uncertain, // We have a repetition count, but it might be wrong (some GIFs have a count after the image data, and will report "loop once" until all data has been decoded).
@@ -122,27 +113,17 @@ private:
bool frameHasAlphaAtIndex(size_t);
ImageOrientation frameOrientationAtIndex(size_t);
- // Decodes and caches a frame. Never accessed except internally.
- void cacheFrame(size_t index);
-
- // Called before accessing m_frames[index]. Returns false on index out of bounds.
- bool ensureFrameIsCached(size_t index);
+ PassRefPtr<SkImage> decodeAndCacheFrame(size_t index);
+ void updateSize() const;
// Returns the total number of bytes allocated for all framebuffers, i.e.
// the sum of m_source.frameBytesAtIndex(...) for all frames.
size_t totalFrameBytes();
- // Called to invalidate cached data. When |destroyAll| is true, we wipe out
- // the entire frame buffer cache and tell the image source to destroy
- // everything; this is used when e.g. we want to free some room in the image
- // cache. If |destroyAll| is false, we delete frames except the current
- // frame; this is used while animating large images to keep memory footprint
- // low; the decoder should preserve the current frame and may preserve some
- // other frames to avoid redecoding the whole image on every frame.
- void destroyDecodedData(bool destroyAll) override;
-
- // If the image is large enough, calls destroyDecodedData().
- void destroyDecodedDataIfNecessary();
+ // Called to wipe out the entire frame buffer cache and tell the image
+ // source to destroy everything; this is used when e.g. we want to free
+ // some room in the image cache.
+ void destroyDecodedData() override;
// Notifies observers that the memory footprint has changed.
void notifyMemoryChanged();
@@ -151,9 +132,13 @@ private:
bool isSizeAvailable();
// Animation.
+ // We start and stop animating lazily. Animation starts when the image is
+ // rendered, and automatically stops once no observer wants to render the
+ // image.
int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplete| should be set if the caller knows the entire image has been decoded.
bool shouldAnimate();
void startAnimation(CatchUpAnimation = CatchUp) override;
+ void stopAnimation();
void advanceAnimation(Timer<BitmapImage>*);
// Function that does the real work of advancing the animation. When
@@ -170,6 +155,9 @@ private:
size_t m_currentFrame; // The index of the current frame of animation.
Vector<FrameData, 1> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
+ RefPtr<SkImage> m_cachedFrame; // A cached copy of the most recently-accessed frame.
+ size_t m_cachedFrameIndex; // Index of the frame that is cached.
+
OwnPtr<Timer<BitmapImage>> m_frameTimer;
int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation.
RepetitionCountStatus m_repetitionCountStatus;
« no previous file with comments | « third_party/WebKit/Source/platform/DragImageTest.cpp ('k') | third_party/WebKit/Source/platform/graphics/BitmapImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698