Chromium Code Reviews| 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 // See if we've also passed the time for frames after that to start, in | 514 // See if we've also passed the time for frames after that to start, in |
| 515 // case we need to skip some frames entirely. Remember not to advance | 515 // case we need to skip some frames entirely. Remember not to advance |
| 516 // to an incomplete frame. | 516 // to an incomplete frame. |
| 517 for (size_t frameAfterNext = (nextFrame + 1) % frameCount(); frameIsComp leteAtIndex(frameAfterNext); frameAfterNext = (nextFrame + 1) % frameCount()) { | 517 for (size_t frameAfterNext = (nextFrame + 1) % frameCount(); frameIsComp leteAtIndex(frameAfterNext); frameAfterNext = (nextFrame + 1) % frameCount()) { |
| 518 // Should we skip the next frame? | 518 // Should we skip the next frame? |
| 519 double frameAfterNextStartTime = m_desiredFrameStartTime + frameDura tionAtIndex(nextFrame); | 519 double frameAfterNextStartTime = m_desiredFrameStartTime + frameDura tionAtIndex(nextFrame); |
| 520 if (time < frameAfterNextStartTime) | 520 if (time < frameAfterNextStartTime) |
| 521 break; | 521 break; |
| 522 | 522 |
| 523 // Yes; skip over it without notifying our observers. | 523 // Yes; skip over it without notifying our observers. |
| 524 if (!internalAdvanceAnimation(true)) | 524 if (!internalAdvanceAnimation(SkipFramesToCatchUp)) { |
| 525 // If we can no longer advance the animation (i.e., it has hit | |
| 526 // the last frame), post a task to notify observers immediately | |
| 527 // so they redraw the last frame. | |
| 528 m_frameTimer = wrapUnique(new Timer<BitmapImage>(this, &BitmapIm age::notifyObserversOfAnimationAdvance)); | |
| 529 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); | |
| 525 return; | 530 return; |
| 531 } | |
| 526 m_desiredFrameStartTime = frameAfterNextStartTime; | 532 m_desiredFrameStartTime = frameAfterNextStartTime; |
| 527 nextFrame = frameAfterNext; | 533 nextFrame = frameAfterNext; |
| 528 } | 534 } |
| 529 | 535 |
| 530 // Post a task to advance the frame immediately. m_desiredFrameStartTime | 536 // Post a task to advance the frame immediately. m_desiredFrameStartTime |
| 531 // may be in the past, meaning the next time through this function we'll | 537 // may be in the past, meaning the next time through this function we'll |
| 532 // kick off the next advancement sooner than this frame's duration would | 538 // kick off the next advancement sooner than this frame's duration would |
| 533 // suggest. | 539 // suggest. |
| 534 m_frameTimer = wrapUnique(new Timer<BitmapImage>(this, &BitmapImage::adv anceAnimationWithoutCatchUp)); | 540 m_frameTimer = wrapUnique(new Timer<BitmapImage>(this, &BitmapImage::adv anceAnimationWithoutCatchUp)); |
| 535 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); | 541 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 566 void BitmapImage::advanceTime(double deltaTimeInSeconds) | 572 void BitmapImage::advanceTime(double deltaTimeInSeconds) |
| 567 { | 573 { |
| 568 if (m_desiredFrameStartTime) | 574 if (m_desiredFrameStartTime) |
| 569 m_desiredFrameStartTime -= deltaTimeInSeconds; | 575 m_desiredFrameStartTime -= deltaTimeInSeconds; |
| 570 else | 576 else |
| 571 m_desiredFrameStartTime = monotonicallyIncreasingTime() - deltaTimeInSec onds; | 577 m_desiredFrameStartTime = monotonicallyIncreasingTime() - deltaTimeInSec onds; |
| 572 } | 578 } |
| 573 | 579 |
| 574 void BitmapImage::advanceAnimation(TimerBase*) | 580 void BitmapImage::advanceAnimation(TimerBase*) |
| 575 { | 581 { |
| 576 internalAdvanceAnimation(false); | 582 internalAdvanceAnimation(); |
| 577 // At this point the image region has been marked dirty, and if it's | 583 // At this point the image region has been marked dirty, and if it's |
| 578 // onscreen, we'll soon make a call to draw(), which will call | 584 // onscreen, we'll soon make a call to draw(), which will call |
| 579 // startAnimation() again to keep the animation moving. | 585 // startAnimation() again to keep the animation moving. |
| 580 } | 586 } |
| 581 | 587 |
| 582 void BitmapImage::advanceAnimationWithoutCatchUp(TimerBase*) | 588 void BitmapImage::advanceAnimationWithoutCatchUp(TimerBase*) |
| 583 { | 589 { |
| 584 if (internalAdvanceAnimation(false)) | 590 if (internalAdvanceAnimation()) |
| 585 startAnimation(DoNotCatchUp); | 591 startAnimation(DoNotCatchUp); |
| 586 } | 592 } |
| 587 | 593 |
| 588 bool BitmapImage::internalAdvanceAnimation(bool skippingFrames) | 594 bool BitmapImage::internalAdvanceAnimation(AnimationAdvancement advancement) |
| 589 { | 595 { |
| 590 // Stop the animation. | 596 // Stop the animation. |
| 591 stopAnimation(); | 597 stopAnimation(); |
| 592 | 598 |
| 593 // See if anyone is still paying attention to this animation. If not, we do n't | 599 // See if anyone is still paying attention to this animation. If not, we do n't |
| 594 // advance and will remain suspended at the current frame until the animatio n is resumed. | 600 // advance and will remain suspended at the current frame until the animatio n is resumed. |
| 595 if (!skippingFrames && getImageObserver()->shouldPauseAnimation(this)) | 601 if (advancement != SkipFramesToCatchUp && getImageObserver()->shouldPauseAni mation(this)) |
| 596 return false; | 602 return false; |
| 597 | 603 |
| 598 ++m_currentFrame; | 604 ++m_currentFrame; |
| 599 bool advancedAnimation = true; | 605 bool advancedAnimation = true; |
| 600 if (m_currentFrame >= frameCount()) { | 606 if (m_currentFrame >= frameCount()) { |
| 601 ++m_repetitionsComplete; | 607 ++m_repetitionsComplete; |
| 602 | 608 |
| 603 // Get the repetition count again. If we weren't able to get a | 609 // Get the repetition count again. If we weren't able to get a |
| 604 // repetition count before, we should have decoded the whole image by | 610 // repetition count before, we should have decoded the whole image by |
| 605 // now, so it should now be available. | 611 // now, so it should now be available. |
| 606 // Note that we don't need to special-case cAnimationLoopOnce here | 612 // Note that we don't need to special-case cAnimationLoopOnce here |
| 607 // because it is 0 (see comments on its declaration in ImageAnimation.h) . | 613 // because it is 0 (see comments on its declaration in ImageAnimation.h) . |
| 608 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom plete > m_repetitionCount) | 614 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom plete > m_repetitionCount) |
| 609 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti tionsComplete > 0)) { | 615 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti tionsComplete > 0)) { |
| 610 m_animationFinished = true; | 616 m_animationFinished = true; |
| 611 m_desiredFrameStartTime = 0; | 617 m_desiredFrameStartTime = 0; |
| 612 --m_currentFrame; | 618 --m_currentFrame; |
| 613 advancedAnimation = false; | 619 advancedAnimation = false; |
| 614 } else | 620 } else |
| 615 m_currentFrame = 0; | 621 m_currentFrame = 0; |
| 616 } | 622 } |
| 617 | 623 |
| 618 // We need to draw this frame if we advanced to it while not skipping, or if | 624 // We need to draw this frame if we advanced to it while not skipping. |
| 619 // while trying to skip frames we hit the last frame and thus had to stop. | 625 if (advancement != SkipFramesToCatchUp && advancedAnimation) |
|
pdr.
2016/08/22 18:27:08
For ease of review:
This line is the primary chang
| |
| 620 if (skippingFrames != advancedAnimation) | |
| 621 getImageObserver()->animationAdvanced(this); | 626 getImageObserver()->animationAdvanced(this); |
| 622 | 627 |
|
chrishtr
2016/08/22 22:55:51
Put lines 528-529 down here?
| |
| 623 return advancedAnimation; | 628 return advancedAnimation; |
| 624 } | 629 } |
| 625 | 630 |
| 631 void BitmapImage::notifyObserversOfAnimationAdvance(TimerBase*) | |
| 632 { | |
| 633 getImageObserver()->animationAdvanced(this); | |
| 634 } | |
| 635 | |
| 626 } // namespace blink | 636 } // namespace blink |
| OLD | NEW |