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

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

Issue 2618633004: Add support for Animated PNG (Closed)
Patch Set: Respond to comments Created 3 years, 9 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 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 // If the frame is already initialized, return true. 350 // If the frame is already initialized, return true.
351 if (buffer->getStatus() != ImageFrame::FrameEmpty) 351 if (buffer->getStatus() != ImageFrame::FrameEmpty)
352 return true; 352 return true;
353 353
354 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex(); 354 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex();
355 if (requiredPreviousFrameIndex == kNotFound) { 355 if (requiredPreviousFrameIndex == kNotFound) {
356 // This frame doesn't rely on any previous data. 356 // This frame doesn't rely on any previous data.
357 if (!buffer->setSizeAndColorSpace(size().width(), size().height(), 357 if (!buffer->setSizeAndColorSpace(size().width(), size().height(),
358 colorSpaceForSkImages())) { 358 colorSpaceForSkImages())) {
359 return setFailed(); 359 return false;
360 } 360 }
361 } else { 361 } else {
362 ImageFrame* const prevBuffer = 362 ImageFrame* const prevBuffer =
363 &m_frameBufferCache[requiredPreviousFrameIndex]; 363 &m_frameBufferCache[requiredPreviousFrameIndex];
364 DCHECK(prevBuffer->getStatus() == ImageFrame::FrameComplete); 364 DCHECK(prevBuffer->getStatus() == ImageFrame::FrameComplete);
365 365
366 // We try to reuse |prevBuffer| as starting state to avoid copying. 366 // We try to reuse |prevBuffer| as starting state to avoid copying.
367 // If canReusePreviousFrameBuffer returns false, we must copy the data since 367 // If canReusePreviousFrameBuffer returns false, we must copy the data since
368 // |prevBuffer| is necessary to decode this or later frames. In that case, 368 // |prevBuffer| is necessary to decode this or later frames. In that case,
369 // copy the data instead. 369 // copy the data instead.
370 if ((!canReusePreviousFrameBuffer(frameIndex) || 370 if ((!canReusePreviousFrameBuffer(frameIndex) ||
371 !buffer->takeBitmapDataIfWritable(prevBuffer)) && 371 !buffer->takeBitmapDataIfWritable(prevBuffer)) &&
372 !buffer->copyBitmapData(*prevBuffer)) 372 !buffer->copyBitmapData(*prevBuffer))
373 return setFailed(); 373 return false;
374 374
375 if (prevBuffer->getDisposalMethod() == 375 if (prevBuffer->getDisposalMethod() ==
376 ImageFrame::DisposeOverwriteBgcolor) { 376 ImageFrame::DisposeOverwriteBgcolor) {
377 // We want to clear the previous frame to transparent, without 377 // We want to clear the previous frame to transparent, without
378 // affecting pixels in the image outside of the frame. 378 // affecting pixels in the image outside of the frame.
379 const IntRect& prevRect = prevBuffer->originalFrameRect(); 379 const IntRect& prevRect = prevBuffer->originalFrameRect();
380 DCHECK(!prevRect.contains(IntRect(IntPoint(), size()))); 380 DCHECK(!prevRect.contains(IntRect(IntPoint(), size())));
381 buffer->zeroFillFrameRect(prevRect); 381 buffer->zeroFillFrameRect(prevRect);
382 } 382 }
383 } 383 }
384 384
385 onInitFrameBuffer(frameIndex);
386
385 // Update our status to be partially complete. 387 // Update our status to be partially complete.
386 buffer->setStatus(ImageFrame::FramePartial); 388 buffer->setStatus(ImageFrame::FramePartial);
387 389
388 onInitFrameBuffer(frameIndex);
389 return true; 390 return true;
390 } 391 }
391 392
392 void ImageDecoder::updateAggressivePurging(size_t index) { 393 void ImageDecoder::updateAggressivePurging(size_t index) {
393 if (m_purgeAggressively) 394 if (m_purgeAggressively)
394 return; 395 return;
395 396
396 // We don't want to cache so much that we cause a memory issue. 397 // We don't want to cache so much that we cause a memory issue.
397 // 398 //
398 // If we used a LRU cache we would fill it and then on next animation loop 399 // If we used a LRU cache we would fill it and then on next animation loop
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 sk_sp<SkColorSpace> ImageDecoder::colorSpaceForSkImages() const { 547 sk_sp<SkColorSpace> ImageDecoder::colorSpaceForSkImages() const {
547 if (!m_colorBehavior.isTag()) 548 if (!m_colorBehavior.isTag())
548 return nullptr; 549 return nullptr;
549 550
550 if (m_embeddedColorSpace) 551 if (m_embeddedColorSpace)
551 return m_embeddedColorSpace; 552 return m_embeddedColorSpace;
552 return SkColorSpace::MakeSRGB(); 553 return SkColorSpace::MakeSRGB();
553 } 554 }
554 555
555 } // namespace blink 556 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698