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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 clearFrameBuffer(i); 216 clearFrameBuffer(i);
217 } 217 }
218 } 218 }
219 return frameBytesCleared; 219 return frameBytesCleared;
220 } 220 }
221 221
222 void ImageDecoder::clearFrameBuffer(size_t frameIndex) { 222 void ImageDecoder::clearFrameBuffer(size_t frameIndex) {
223 m_frameBufferCache[frameIndex].clearPixelData(); 223 m_frameBufferCache[frameIndex].clearPixelData();
224 } 224 }
225 225
226 bool ImageDecoder::initFrameBuffer(size_t frameIndex) {
227 DCHECK(frameIndex < m_frameBufferCache.size());
228
229 ImageFrame* const buffer = &m_frameBufferCache[frameIndex];
230
231 // If the frame is already initialized, return true.
232 if (buffer->getStatus() != ImageFrame::FrameEmpty)
233 return true;
234
235 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex();
236 if (requiredPreviousFrameIndex == kNotFound) {
237 // This frame doesn't rely on any previous data.
238 if (!buffer->setSizeAndColorSpace(size().width(), size().height(),
239 colorSpace())) {
240 return setFailed();
241 }
242 } else {
243 ImageFrame* const prevBuffer =
244 &m_frameBufferCache[requiredPreviousFrameIndex];
245 DCHECK(prevBuffer->getStatus() == ImageFrame::FrameComplete);
246
247 // We try to reuse |prevBuffer| as starting state to avoid copying.
248 // If canReusePreviousFrameBuffer returns false, we must copy the data since
249 // |prevBuffer| is necessary to decode this or later frames. In that case,
250 // copy the data instead.
251 if ((!canReusePreviousFrameBuffer(frameIndex) ||
252 !buffer->takeBitmapDataIfWritable(prevBuffer)) &&
253 !buffer->copyBitmapData(*prevBuffer))
254 return setFailed();
255
256 if (prevBuffer->getDisposalMethod() ==
257 ImageFrame::DisposeOverwriteBgcolor) {
258 // We want to clear the previous frame to transparent, without
259 // affecting pixels in the image outside of the frame.
260 const IntRect& prevRect = prevBuffer->originalFrameRect();
261 DCHECK(!prevRect.contains(IntRect(IntPoint(), size())));
262 buffer->zeroFillFrameRect(prevRect);
263 }
264 }
265
266 // Update our status to be partially complete.
267 buffer->setStatus(ImageFrame::FramePartial);
268
269 onInitFrameBuffer(frameIndex);
270 return true;
271 }
272
226 void ImageDecoder::updateAggressivePurging(size_t index) { 273 void ImageDecoder::updateAggressivePurging(size_t index) {
227 if (m_purgeAggressively) 274 if (m_purgeAggressively)
228 return; 275 return;
229 276
230 // We don't want to cache so much that we cause a memory issue. 277 // We don't want to cache so much that we cause a memory issue.
231 // 278 //
232 // If we used a LRU cache we would fill it and then on next animation loop 279 // If we used a LRU cache we would fill it and then on next animation loop
233 // we would need to decode all the frames again -- the LRU would give no 280 // we would need to decode all the frames again -- the LRU would give no
234 // benefit and would consume more memory. 281 // benefit and would consume more memory.
235 // So instead, simply purge unused frames if caching all of the frames of 282 // So instead, simply purge unused frames if caching all of the frames of
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 456
410 if (SkColorSpace::Equals(m_embeddedColorSpace.get(), gTargetColorSpace)) { 457 if (SkColorSpace::Equals(m_embeddedColorSpace.get(), gTargetColorSpace)) {
411 return; 458 return;
412 } 459 }
413 460
414 m_sourceToOutputDeviceColorTransform = 461 m_sourceToOutputDeviceColorTransform =
415 SkColorSpaceXform::New(m_embeddedColorSpace.get(), gTargetColorSpace); 462 SkColorSpaceXform::New(m_embeddedColorSpace.get(), gTargetColorSpace);
416 } 463 }
417 464
418 } // namespace blink 465 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698