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 2cae67e0a9f1d413a973a22988c768fe3a689094..be4ce7f052a65d817c5acb3ee23393a7c2dbdc31 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.cpp |
+++ b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.cpp |
@@ -34,6 +34,7 @@ namespace blink { |
GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOptions, size_t maxDecodedBytes) |
: ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) |
+ , m_purgeAggressively(false) |
, m_repetitionCount(cAnimationLoopOnce) |
{ |
} |
@@ -301,6 +302,27 @@ void GIFImageDecoder::decode(size_t index) |
if (failed()) |
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 our image would be too large. |
+ |
+ // As we decode we will learn the total number of frames, and thus total |
+ // image memory usage. |
scroggo_chromium
2016/06/20 17:59:40
It might be interesting to note that the "MemoryUs
cblume
2016/06/21 01:00:52
Oh, oops. I originally wrote this with a * 4 since
|
+ IntSize decodedImageSize = this->decodedSize(); |
+ unsigned frameMemoryUsage = decodedImageSize.width() * decodedImageSize.height(); |
scroggo_chromium
2016/06/20 17:59:40
Why is this unsigned? Should we call decodedImageS
cblume
2016/06/21 01:00:52
Hrmmm, the unsigned was a mistake. the .width() an
|
+ unsigned long long imageMemoryUsage = static_cast<unsigned long long>(frameMemoryUsage) |
scroggo_chromium
2016/06/20 17:59:40
The meaning of the word "image" here is not entire
cblume
2016/06/21 01:00:52
I did not parse what you said very well.
If I unde
scroggo_chromium
2016/06/21 15:46:08
Sorry, I'll try to explain it better:
You compute
cblume
2016/06/22 01:23:06
Ah, okay. I think I understand better now.
You ar
scroggo_chromium
2016/06/22 15:10:04
Yes, that is what I mean.
|
+ * static_cast<unsigned long long>(index); |
+ |
+ bool overflowed = imageMemoryUsage > ((1 << 29) - 1); |
scroggo_chromium
2016/06/20 17:59:40
How'd you pick this number?
|
+ if (overflowed) { |
scroggo_chromium
2016/06/20 17:59:40
It looks like this should be
if (overflowed |
|
+ m_purgeAggressively = true; |
+ } else { |
+ if (imageMemoryUsage > m_maxDecodedBytes) |
scroggo_chromium
2016/06/20 17:59:40
As mentioned above, imageMemoryUsage is in units o
|
+ m_purgeAggressively = true; |
+ } |
+ |
Vector<size_t> framesToDecode; |
size_t frameToDecode = index; |
do { |
@@ -314,6 +336,9 @@ void GIFImageDecoder::decode(size_t index) |
return; |
} |
+ if (m_purgeAggressively) |
scroggo_chromium
2016/06/20 17:59:40
As written, m_purgeAggressively could be a local v
cblume
2016/06/21 01:00:52
I do not want it to be a local variable.
If it wa
scroggo_chromium
2016/06/21 15:46:08
But isn't that already true in this patch set, at
|
+ this->clearCacheExceptFrame(*i); |
+ |
// We need more data to continue decoding. |
if (m_frameBufferCache[*i].getStatus() != ImageFrame::FrameComplete) |
break; |