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

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

Issue 2495183002: Pull up initFrameBuffer to ImageDecoder. (Closed)
Patch Set: Process feedback patch set 1 Created 4 years, 1 month 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 327db4bc499b48345e2c0633a66afe98dcc50e4a..4454453d584545882376bb974b620c40fbd7d846 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -223,6 +223,53 @@ void ImageDecoder::clearFrameBuffer(size_t frameIndex) {
m_frameBufferCache[frameIndex].clearPixelData();
}
+bool ImageDecoder::initFrameBuffer(size_t frameIndex) {
+ DCHECK(frameIndex < m_frameBufferCache.size());
+
+ ImageFrame* const buffer = &m_frameBufferCache[frameIndex];
+
+ // If the frame is already initialized, return true.
+ if (buffer->getStatus() != ImageFrame::FrameEmpty)
+ return true;
+
+ size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex();
+ if (requiredPreviousFrameIndex == kNotFound) {
+ // This frame doesn't rely on any previous data.
+ if (!buffer->setSizeAndColorSpace(size().width(), size().height(),
+ colorSpace())) {
+ return setFailed();
+ }
+ } else {
+ ImageFrame* const prevBuffer =
+ &m_frameBufferCache[requiredPreviousFrameIndex];
+ DCHECK(prevBuffer->getStatus() == ImageFrame::FrameComplete);
+
+ // We try to reuse |prevBuffer| as starting state to avoid copying.
+ // If canReusePreviousFrameBuffer returns false, we must copy the data since
+ // |prevBuffer| is necessary to decode this or later frames. In that case,
+ // copy the data instead.
+ if ((!canReusePreviousFrameBuffer(frameIndex) ||
+ !buffer->takeBitmapDataIfWritable(prevBuffer)) &&
+ !buffer->copyBitmapData(*prevBuffer))
+ return setFailed();
+
+ if (prevBuffer->getDisposalMethod() ==
+ ImageFrame::DisposeOverwriteBgcolor) {
+ // We want to clear the previous frame to transparent, without
+ // affecting pixels in the image outside of the frame.
+ const IntRect& prevRect = prevBuffer->originalFrameRect();
+ DCHECK(!prevRect.contains(IntRect(IntPoint(), size())));
+ buffer->zeroFillFrameRect(prevRect);
+ }
+ }
+
+ // Update our status to be partially complete.
+ buffer->setStatus(ImageFrame::FramePartial);
+
+ onInitFrameBuffer(frameIndex);
+ return true;
+}
+
void ImageDecoder::updateAggressivePurging(size_t index) {
if (m_purgeAggressively)
return;

Powered by Google App Engine
This is Rietveld 408576698