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

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

Issue 2376033005: Move GIF decoder's aggressive purge into ImageDecoder (Closed)
Patch Set: Checking more overflow. 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/gif/GIFImageDecoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.cpp
index ba4cca2bb13c8da2bcc7cbc66cdad6fd869999b3..32cc3e56a6e5ea948bcaba2bef99da49d7cd70a0 100644
--- a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.cpp
@@ -34,7 +34,6 @@ namespace blink {
GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOptions, size_t maxDecodedBytes)
: ImageDecoder(alphaOption, colorOptions, maxDecodedBytes)
- , m_purgeAggressively(false)
, m_repetitionCount(cAnimationLoopOnce)
{
}
@@ -382,48 +381,4 @@ bool GIFImageDecoder::initFrameBuffer(size_t frameIndex)
m_currentBufferSawAlpha = false;
return true;
}
-
-void GIFImageDecoder::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();
- // We are about to multiply by 4, which may require an extra bit of storage
- bool wouldOverflow = frameArea > (UINT64_C(1) << 62);
- if (wouldOverflow) {
- m_purgeAggressively = true;
- return;
- }
-
- const uint64_t frameMemoryUsage = frameArea * 4; // 4 bytes per pixel
- // We are about to multiply by a size_t, which does not have a fixed
- // size.
- // To simplify things, let's make sure our per-frame memory usage and
- // index can be stored in 32 bits and store the multiplicand in a 64-bit
- // number.
- wouldOverflow = (frameMemoryUsage > (UINT32_C(1) << 31))
- || (index > (UINT32_C(1) << 31));
- if (wouldOverflow) {
- m_purgeAggressively = true;
- return;
- }
-
- const uint64_t totalMemoryUsage = frameMemoryUsage * index;
- if (totalMemoryUsage > m_maxDecodedBytes) {
- m_purgeAggressively = true;
- }
-}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698