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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 2376033005: Move GIF decoder's aggressive purge into ImageDecoder (Closed)
Patch Set: Rebasing. Created 4 years, 2 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/image-decoders/ImageDecoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
index 2bd604708fd4be6c8ad2e573b4cd84e44ab80045..9f3aeab110589bd7936797be2924085778974665 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -234,6 +234,40 @@ void ImageDecoder::clearFrameBuffer(size_t frameIndex) {
m_frameBufferCache[frameIndex].clearPixelData();
}
+void ImageDecoder::updateAggressivePurging(size_t index) {
+ if (m_purgeAggressively)
+ return;
+
+ // We don't want to cache so much that we cause a memory issue.
+ //
+ // If we used a LRU cache we would fill it and then on next animation loop
+ // we would need to decode all the frames again -- the LRU would give no
+ // benefit and would consume more memory.
+ // So instead, simply purge unused frames if caching all of the frames of
+ // the image would use more memory than the image decoder is allowed
+ // (m_maxDecodedBytes) or would overflow 32 bits..
+ //
+ // As we decode we will learn the total number of frames, and thus total
+ // possible image memory used.
+
+ const uint64_t frameArea = decodedSize().area();
+ const uint64_t frameMemoryUsage = frameArea * 4; // 4 bytes per pixel
+ if (frameMemoryUsage / 4 != frameArea) { // overflow occurred
+ m_purgeAggressively = true;
+ return;
+ }
+
+ const uint64_t totalMemoryUsage = frameMemoryUsage * index;
+ if (totalMemoryUsage / frameMemoryUsage != index) { // overflow occurred
+ m_purgeAggressively = true;
+ return;
+ }
+
+ if (totalMemoryUsage > m_maxDecodedBytes) {
+ m_purgeAggressively = true;
+ }
+}
+
size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex,
bool frameRectIsOpaque) {
ASSERT(frameIndex <= m_frameBufferCache.size());

Powered by Google App Engine
This is Rietveld 408576698