| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 BitmapImage::BitmapImage(ImageObserver* observer) | 51 BitmapImage::BitmapImage(ImageObserver* observer) |
| 52 : Image(observer) | 52 : Image(observer) |
| 53 , m_currentFrame(0) | 53 , m_currentFrame(0) |
| 54 , m_frames() | 54 , m_frames() |
| 55 , m_frameTimer(0) | 55 , m_frameTimer(0) |
| 56 , m_repetitionCount(cAnimationNone) | 56 , m_repetitionCount(cAnimationNone) |
| 57 , m_repetitionCountStatus(Unknown) | 57 , m_repetitionCountStatus(Unknown) |
| 58 , m_repetitionsComplete(0) | 58 , m_repetitionsComplete(0) |
| 59 , m_desiredFrameStartTime(0) | 59 , m_desiredFrameStartTime(0) |
| 60 , m_frameCount(0) | 60 , m_frameCount(0) |
| 61 , m_animationPolicy(ImageAnimationPolicyAllowed) |
| 61 , m_isSolidColor(false) | 62 , m_isSolidColor(false) |
| 62 , m_checkedForSolidColor(false) | 63 , m_checkedForSolidColor(false) |
| 63 , m_animationFinished(false) | 64 , m_animationFinished(false) |
| 64 , m_allDataReceived(false) | 65 , m_allDataReceived(false) |
| 65 , m_haveSize(false) | 66 , m_haveSize(false) |
| 66 , m_sizeAvailable(false) | 67 , m_sizeAvailable(false) |
| 67 , m_hasUniformFrameSize(true) | 68 , m_hasUniformFrameSize(true) |
| 68 , m_haveFrameCount(false) | 69 , m_haveFrameCount(false) |
| 69 { | 70 { |
| 70 } | 71 } |
| 71 | 72 |
| 72 BitmapImage::BitmapImage(PassRefPtr<NativeImageSkia> nativeImage, ImageObserver*
observer) | 73 BitmapImage::BitmapImage(PassRefPtr<NativeImageSkia> nativeImage, ImageObserver*
observer) |
| 73 : Image(observer) | 74 : Image(observer) |
| 74 , m_size(nativeImage->bitmap().width(), nativeImage->bitmap().height()) | 75 , m_size(nativeImage->bitmap().width(), nativeImage->bitmap().height()) |
| 75 , m_currentFrame(0) | 76 , m_currentFrame(0) |
| 76 , m_frames(0) | 77 , m_frames(0) |
| 77 , m_frameTimer(0) | 78 , m_frameTimer(0) |
| 78 , m_repetitionCount(cAnimationNone) | 79 , m_repetitionCount(cAnimationNone) |
| 79 , m_repetitionCountStatus(Unknown) | 80 , m_repetitionCountStatus(Unknown) |
| 80 , m_repetitionsComplete(0) | 81 , m_repetitionsComplete(0) |
| 81 , m_frameCount(1) | 82 , m_frameCount(1) |
| 83 , m_animationPolicy(ImageAnimationPolicyAllowed) |
| 82 , m_isSolidColor(false) | 84 , m_isSolidColor(false) |
| 83 , m_checkedForSolidColor(false) | 85 , m_checkedForSolidColor(false) |
| 84 , m_animationFinished(true) | 86 , m_animationFinished(true) |
| 85 , m_allDataReceived(true) | 87 , m_allDataReceived(true) |
| 86 , m_haveSize(true) | 88 , m_haveSize(true) |
| 87 , m_sizeAvailable(true) | 89 , m_sizeAvailable(true) |
| 88 , m_haveFrameCount(true) | 90 , m_haveFrameCount(true) |
| 89 { | 91 { |
| 90 // Since we don't have a decoder, we can't figure out the image orientation. | 92 // Since we don't have a decoder, we can't figure out the image orientation. |
| 91 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. | 93 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // decoder will default to cAnimationLoopOnce, and we'll try and read | 434 // decoder will default to cAnimationLoopOnce, and we'll try and read |
| 433 // the count again once the whole image is decoded. | 435 // the count again once the whole image is decoded. |
| 434 m_repetitionCount = m_source.repetitionCount(); | 436 m_repetitionCount = m_source.repetitionCount(); |
| 435 m_repetitionCountStatus = (imageKnownToBeComplete || m_repetitionCount =
= cAnimationNone) ? Certain : Uncertain; | 437 m_repetitionCountStatus = (imageKnownToBeComplete || m_repetitionCount =
= cAnimationNone) ? Certain : Uncertain; |
| 436 } | 438 } |
| 437 return m_repetitionCount; | 439 return m_repetitionCount; |
| 438 } | 440 } |
| 439 | 441 |
| 440 bool BitmapImage::shouldAnimate() | 442 bool BitmapImage::shouldAnimate() |
| 441 { | 443 { |
| 442 return (repetitionCount(false) != cAnimationNone && !m_animationFinished &&
imageObserver()); | 444 bool animated = repetitionCount(false) != cAnimationNone && !m_animationFini
shed && imageObserver(); |
| 445 if (imageObserver()) { |
| 446 imageObserver()->imageAnimationPolicy(this, m_animationPolicy); |
| 447 if (animated && m_animationPolicy == ImageAnimationPolicyNoAnimation) |
| 448 animated = false; |
| 449 } |
| 450 return animated; |
| 443 } | 451 } |
| 444 | 452 |
| 445 void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary) | 453 void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary) |
| 446 { | 454 { |
| 447 if (m_frameTimer || !shouldAnimate() || frameCount() <= 1) | 455 if (m_frameTimer || !shouldAnimate() || frameCount() <= 1) |
| 448 return; | 456 return; |
| 449 | 457 |
| 450 // If we aren't already animating, set now as the animation start time. | 458 // If we aren't already animating, set now as the animation start time. |
| 451 const double time = monotonicallyIncreasingTime(); | 459 const double time = monotonicallyIncreasingTime(); |
| 452 if (!m_desiredFrameStartTime) | 460 if (!m_desiredFrameStartTime) |
| 453 m_desiredFrameStartTime = time; | 461 m_desiredFrameStartTime = time; |
| 454 | 462 |
| 455 // Don't advance the animation to an incomplete frame. | 463 // Don't advance the animation to an incomplete frame. |
| 456 size_t nextFrame = (m_currentFrame + 1) % frameCount(); | 464 size_t nextFrame = (m_currentFrame + 1) % frameCount(); |
| 457 if (!m_allDataReceived && !frameIsCompleteAtIndex(nextFrame)) | 465 if (!m_allDataReceived && !frameIsCompleteAtIndex(nextFrame)) |
| 458 return; | 466 return; |
| 459 | 467 |
| 460 // Don't advance past the last frame if we haven't decoded the whole image | 468 // Don't advance past the last frame if we haven't decoded the whole image |
| 461 // yet and our repetition count is potentially unset. The repetition count | 469 // yet and our repetition count is potentially unset. The repetition count |
| 462 // in a GIF can potentially come after all the rest of the image data, so | 470 // in a GIF can potentially come after all the rest of the image data, so |
| 463 // wait on it. | 471 // wait on it. |
| 464 if (!m_allDataReceived && repetitionCount(false) == cAnimationLoopOnce && m_
currentFrame >= (frameCount() - 1)) | 472 if (!m_allDataReceived |
| 473 && (repetitionCount(false) == cAnimationLoopOnce || m_animationPolicy ==
ImageAnimationPolicyAnimateOnce) |
| 474 && m_currentFrame >= (frameCount() - 1)) |
| 465 return; | 475 return; |
| 466 | 476 |
| 467 // Determine time for next frame to start. By ignoring paint and timer lag | 477 // Determine time for next frame to start. By ignoring paint and timer lag |
| 468 // in this calculation, we make the animation appear to run at its desired | 478 // in this calculation, we make the animation appear to run at its desired |
| 469 // rate regardless of how fast it's being repainted. | 479 // rate regardless of how fast it's being repainted. |
| 470 const double currentDuration = frameDurationAtIndex(m_currentFrame); | 480 const double currentDuration = frameDurationAtIndex(m_currentFrame); |
| 471 m_desiredFrameStartTime += currentDuration; | 481 m_desiredFrameStartTime += currentDuration; |
| 472 | 482 |
| 473 // When an animated image is more than five minutes out of date, the | 483 // When an animated image is more than five minutes out of date, the |
| 474 // user probably doesn't care about resyncing and we could burn a lot of | 484 // user probably doesn't care about resyncing and we could burn a lot of |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 ++m_currentFrame; | 599 ++m_currentFrame; |
| 590 bool advancedAnimation = true; | 600 bool advancedAnimation = true; |
| 591 if (m_currentFrame >= frameCount()) { | 601 if (m_currentFrame >= frameCount()) { |
| 592 ++m_repetitionsComplete; | 602 ++m_repetitionsComplete; |
| 593 | 603 |
| 594 // Get the repetition count again. If we weren't able to get a | 604 // Get the repetition count again. If we weren't able to get a |
| 595 // repetition count before, we should have decoded the whole image by | 605 // repetition count before, we should have decoded the whole image by |
| 596 // now, so it should now be available. | 606 // now, so it should now be available. |
| 597 // Note that we don't need to special-case cAnimationLoopOnce here | 607 // Note that we don't need to special-case cAnimationLoopOnce here |
| 598 // because it is 0 (see comments on its declaration in ImageSource.h). | 608 // because it is 0 (see comments on its declaration in ImageSource.h). |
| 599 if (repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsComp
lete > m_repetitionCount) { | 609 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom
plete > m_repetitionCount) |
| 610 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti
tionsComplete > 0)) { |
| 600 m_animationFinished = true; | 611 m_animationFinished = true; |
| 601 m_desiredFrameStartTime = 0; | 612 m_desiredFrameStartTime = 0; |
| 602 --m_currentFrame; | 613 --m_currentFrame; |
| 603 advancedAnimation = false; | 614 advancedAnimation = false; |
| 604 } else | 615 } else |
| 605 m_currentFrame = 0; | 616 m_currentFrame = 0; |
| 606 } | 617 } |
| 607 destroyDecodedDataIfNecessary(); | 618 destroyDecodedDataIfNecessary(); |
| 608 | 619 |
| 609 // We need to draw this frame if we advanced to it while not skipping, or if | 620 // We need to draw this frame if we advanced to it while not skipping, or if |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 653 |
| 643 return m_isSolidColor && !m_currentFrame; | 654 return m_isSolidColor && !m_currentFrame; |
| 644 } | 655 } |
| 645 | 656 |
| 646 Color BitmapImage::solidColor() const | 657 Color BitmapImage::solidColor() const |
| 647 { | 658 { |
| 648 return m_solidColor; | 659 return m_solidColor; |
| 649 } | 660 } |
| 650 | 661 |
| 651 } // namespace blink | 662 } // namespace blink |
| OLD | NEW |