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

Unified Diff: Source/platform/graphics/ImageFrameGenerator.cpp

Issue 688423004: Remove multi-frame image decoder when the image is completely decoded (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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: Source/platform/graphics/ImageFrameGenerator.cpp
diff --git a/Source/platform/graphics/ImageFrameGenerator.cpp b/Source/platform/graphics/ImageFrameGenerator.cpp
index 46e281b4f5ad6ca3dbc0987c93883a982d2a18fb..c9cb7b5b093b15d1574a4b4b97d6d802692e529d 100644
--- a/Source/platform/graphics/ImageFrameGenerator.cpp
+++ b/Source/platform/graphics/ImageFrameGenerator.cpp
@@ -90,6 +90,7 @@ ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha
, m_isMultiFrame(isMultiFrame)
, m_decodeFailedAndEmpty(false)
, m_decodeCount(0)
+ , m_framesCount(0)
Alpha Left Google 2014/10/31 17:17:49 No need to have this variable.
{
setData(data.get(), allDataReceived);
}
@@ -204,6 +205,9 @@ SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
if (!decoder)
return SkBitmap();
+ if (index >= m_frameComplete.size())
+ m_frameComplete.resize(index + 1);
+ m_frameComplete[index] = complete;
// If we are not resuming decoding that means the decoder is freshly
// created and we have ownership. If we are resuming decoding then
@@ -225,7 +229,14 @@ SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
// If the image generated is complete then there is no need to keep
// the decoder. The exception is multi-frame decoder which can generate
// multiple complete frames.
- const bool removeDecoder = complete && !m_isMultiFrame;
+ size_t completeFrameCount = 0;
+
+ for (Vector<bool>::iterator it = m_frameComplete.begin(); it != m_frameComplete.end(); ++it) {
+ if (*it)
+ completeFrameCount++;
+ }
+
+ const bool removeDecoder = m_framesCount && (completeFrameCount >= m_framesCount);
Alpha Left Google 2014/10/31 17:17:49 It's better to have all the states to compute |rem
if (resumeDecoding) {
if (removeDecoder)
@@ -282,6 +293,11 @@ bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap*
(*decoder)->setData(data, allDataReceived);
ImageFrame* frame = (*decoder)->frameBufferAtIndex(index);
+ if (allDataReceived) {
Alpha Left Google 2014/10/31 17:17:48 I prefer you move this block to "tryToResumeDecode
Zhenyu Shan 2014/11/03 08:19:17 There is an issue here: decoder->frameCount() and
Alpha Left Google 2014/11/05 00:31:00 Okay that makes sense. Please see latest comments.
+ m_framesCount = (*decoder)->frameCount();
+ m_frameComplete.resize(m_framesCount);
+ }
+
(*decoder)->setData(0, false); // Unref SharedBuffer from ImageDecoder.
(*decoder)->clearCacheExceptFrame(index);
(*decoder)->setMemoryAllocator(0);

Powered by Google App Engine
This is Rietveld 408576698