| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 for (size_t i = 0; i < m_frames.size(); ++i) | 129 for (size_t i = 0; i < m_frames.size(); ++i) |
| 130 allFrameBytes += m_frames[i].m_frameBytes; | 130 allFrameBytes += m_frames[i].m_frameBytes; |
| 131 | 131 |
| 132 if (allFrameBytes > cLargeAnimationCutoff) { | 132 if (allFrameBytes > cLargeAnimationCutoff) { |
| 133 destroyDecodedData(false); | 133 destroyDecodedData(false); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void BitmapImage::notifyMemoryChanged(int delta) | 137 void BitmapImage::notifyMemoryChanged(int delta) |
| 138 { | 138 { |
| 139 if (delta && imageObserver()) | 139 if (delta && getImageObserver()) |
| 140 imageObserver()->decodedSizeChanged(this, delta); | 140 getImageObserver()->decodedSizeChanged(this, delta); |
| 141 } | 141 } |
| 142 | 142 |
| 143 int BitmapImage::totalFrameBytes() | 143 int BitmapImage::totalFrameBytes() |
| 144 { | 144 { |
| 145 const size_t numFrames = frameCount(); | 145 const size_t numFrames = frameCount(); |
| 146 size_t totalBytes = 0; | 146 size_t totalBytes = 0; |
| 147 for (size_t i = 0; i < numFrames; ++i) | 147 for (size_t i = 0; i < numFrames; ++i) |
| 148 totalBytes += m_source.frameBytesAtIndex(i); | 148 totalBytes += m_source.frameBytesAtIndex(i); |
| 149 return safeCast<int>(totalBytes); | 149 return safeCast<int>(totalBytes); |
| 150 } | 150 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 293 } |
| 294 | 294 |
| 295 SkRect skSrcRect = adjustedSrcRect; | 295 SkRect skSrcRect = adjustedSrcRect; |
| 296 canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, | 296 canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, |
| 297 WebCoreClampingModeToSkiaRectConstraint(clampMode)); | 297 WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
| 298 canvas->restoreToCount(initialSaveCount); | 298 canvas->restoreToCount(initialSaveCount); |
| 299 | 299 |
| 300 if (currentFrameIsLazyDecoded()) | 300 if (currentFrameIsLazyDecoded()) |
| 301 PlatformInstrumentation::didDrawLazyPixelRef(image->uniqueID()); | 301 PlatformInstrumentation::didDrawLazyPixelRef(image->uniqueID()); |
| 302 | 302 |
| 303 if (ImageObserver* observer = imageObserver()) | 303 if (ImageObserver* observer = getImageObserver()) |
| 304 observer->didDraw(this); | 304 observer->didDraw(this); |
| 305 | 305 |
| 306 startAnimation(); | 306 startAnimation(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 size_t BitmapImage::frameCount() | 309 size_t BitmapImage::frameCount() |
| 310 { | 310 { |
| 311 if (!m_haveFrameCount) { | 311 if (!m_haveFrameCount) { |
| 312 m_frameCount = m_source.frameCount(); | 312 m_frameCount = m_source.frameCount(); |
| 313 // If decoder is not initialized yet, m_source.frameCount() returns 0. | 313 // If decoder is not initialized yet, m_source.frameCount() returns 0. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // decoder will default to cAnimationLoopOnce, and we'll try and read | 446 // decoder will default to cAnimationLoopOnce, and we'll try and read |
| 447 // the count again once the whole image is decoded. | 447 // the count again once the whole image is decoded. |
| 448 m_repetitionCount = m_source.repetitionCount(); | 448 m_repetitionCount = m_source.repetitionCount(); |
| 449 m_repetitionCountStatus = (imageKnownToBeComplete || m_repetitionCount =
= cAnimationNone) ? Certain : Uncertain; | 449 m_repetitionCountStatus = (imageKnownToBeComplete || m_repetitionCount =
= cAnimationNone) ? Certain : Uncertain; |
| 450 } | 450 } |
| 451 return m_repetitionCount; | 451 return m_repetitionCount; |
| 452 } | 452 } |
| 453 | 453 |
| 454 bool BitmapImage::shouldAnimate() | 454 bool BitmapImage::shouldAnimate() |
| 455 { | 455 { |
| 456 bool animated = repetitionCount(false) != cAnimationNone && !m_animationFini
shed && imageObserver(); | 456 bool animated = repetitionCount(false) != cAnimationNone && !m_animationFini
shed && getImageObserver(); |
| 457 if (animated && m_animationPolicy == ImageAnimationPolicyNoAnimation) | 457 if (animated && m_animationPolicy == ImageAnimationPolicyNoAnimation) |
| 458 animated = false; | 458 animated = false; |
| 459 return animated; | 459 return animated; |
| 460 } | 460 } |
| 461 | 461 |
| 462 void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary) | 462 void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary) |
| 463 { | 463 { |
| 464 if (m_frameTimer || !shouldAnimate() || frameCount() <= 1) | 464 if (m_frameTimer || !shouldAnimate() || frameCount() <= 1) |
| 465 return; | 465 return; |
| 466 | 466 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 // startAnimation() again to keep the animation moving. | 602 // startAnimation() again to keep the animation moving. |
| 603 } | 603 } |
| 604 | 604 |
| 605 bool BitmapImage::internalAdvanceAnimation(bool skippingFrames) | 605 bool BitmapImage::internalAdvanceAnimation(bool skippingFrames) |
| 606 { | 606 { |
| 607 // Stop the animation. | 607 // Stop the animation. |
| 608 stopAnimation(); | 608 stopAnimation(); |
| 609 | 609 |
| 610 // See if anyone is still paying attention to this animation. If not, we do
n't | 610 // See if anyone is still paying attention to this animation. If not, we do
n't |
| 611 // advance and will remain suspended at the current frame until the animatio
n is resumed. | 611 // advance and will remain suspended at the current frame until the animatio
n is resumed. |
| 612 if (!skippingFrames && imageObserver()->shouldPauseAnimation(this)) | 612 if (!skippingFrames && getImageObserver()->shouldPauseAnimation(this)) |
| 613 return false; | 613 return false; |
| 614 | 614 |
| 615 ++m_currentFrame; | 615 ++m_currentFrame; |
| 616 bool advancedAnimation = true; | 616 bool advancedAnimation = true; |
| 617 if (m_currentFrame >= frameCount()) { | 617 if (m_currentFrame >= frameCount()) { |
| 618 ++m_repetitionsComplete; | 618 ++m_repetitionsComplete; |
| 619 | 619 |
| 620 // Get the repetition count again. If we weren't able to get a | 620 // Get the repetition count again. If we weren't able to get a |
| 621 // repetition count before, we should have decoded the whole image by | 621 // repetition count before, we should have decoded the whole image by |
| 622 // now, so it should now be available. | 622 // now, so it should now be available. |
| 623 // Note that we don't need to special-case cAnimationLoopOnce here | 623 // Note that we don't need to special-case cAnimationLoopOnce here |
| 624 // because it is 0 (see comments on its declaration in ImageAnimation.h)
. | 624 // because it is 0 (see comments on its declaration in ImageAnimation.h)
. |
| 625 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom
plete > m_repetitionCount) | 625 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom
plete > m_repetitionCount) |
| 626 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti
tionsComplete > 0)) { | 626 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti
tionsComplete > 0)) { |
| 627 m_animationFinished = true; | 627 m_animationFinished = true; |
| 628 m_desiredFrameStartTime = 0; | 628 m_desiredFrameStartTime = 0; |
| 629 --m_currentFrame; | 629 --m_currentFrame; |
| 630 advancedAnimation = false; | 630 advancedAnimation = false; |
| 631 } else | 631 } else |
| 632 m_currentFrame = 0; | 632 m_currentFrame = 0; |
| 633 } | 633 } |
| 634 destroyDecodedDataIfNecessary(); | 634 destroyDecodedDataIfNecessary(); |
| 635 | 635 |
| 636 // We need to draw this frame if we advanced to it while not skipping, or if | 636 // We need to draw this frame if we advanced to it while not skipping, or if |
| 637 // while trying to skip frames we hit the last frame and thus had to stop. | 637 // while trying to skip frames we hit the last frame and thus had to stop. |
| 638 if (skippingFrames != advancedAnimation) | 638 if (skippingFrames != advancedAnimation) |
| 639 imageObserver()->animationAdvanced(this); | 639 getImageObserver()->animationAdvanced(this); |
| 640 return advancedAnimation; | 640 return advancedAnimation; |
| 641 } | 641 } |
| 642 | 642 |
| 643 } // namespace blink | 643 } // namespace blink |
| OLD | NEW |