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 19 matching lines...) Expand all Loading... |
30 #include "platform/Timer.h" | 30 #include "platform/Timer.h" |
31 #include "platform/TraceEvent.h" | 31 #include "platform/TraceEvent.h" |
32 #include "platform/geometry/FloatRect.h" | 32 #include "platform/geometry/FloatRect.h" |
33 #include "platform/graphics/BitmapImageMetrics.h" | 33 #include "platform/graphics/BitmapImageMetrics.h" |
34 #include "platform/graphics/DeferredImageDecoder.h" | 34 #include "platform/graphics/DeferredImageDecoder.h" |
35 #include "platform/graphics/ImageObserver.h" | 35 #include "platform/graphics/ImageObserver.h" |
36 #include "platform/graphics/StaticBitmapImage.h" | 36 #include "platform/graphics/StaticBitmapImage.h" |
37 #include "platform/graphics/skia/SkiaUtils.h" | 37 #include "platform/graphics/skia/SkiaUtils.h" |
38 #include "third_party/skia/include/core/SkCanvas.h" | 38 #include "third_party/skia/include/core/SkCanvas.h" |
39 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
40 #include "wtf/PtrUtil.h" | |
41 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
42 | 41 |
43 namespace blink { | 42 namespace blink { |
44 | 43 |
45 PassRefPtr<BitmapImage> BitmapImage::createWithOrientationForTesting(const SkBit
map& bitmap, ImageOrientation orientation) | 44 PassRefPtr<BitmapImage> BitmapImage::createWithOrientationForTesting(const SkBit
map& bitmap, ImageOrientation orientation) |
46 { | 45 { |
47 if (bitmap.isNull()) { | 46 if (bitmap.isNull()) { |
48 return BitmapImage::create(); | 47 return BitmapImage::create(); |
49 } | 48 } |
50 | 49 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // don't miss any repetitions, and is closer to what other browsers do; on | 472 // don't miss any repetitions, and is closer to what other browsers do; on |
474 // the other hand, it makes animations "less accurate" for pages that try to | 473 // the other hand, it makes animations "less accurate" for pages that try to |
475 // sync an image and some other resource (e.g. audio), especially if users | 474 // sync an image and some other resource (e.g. audio), especially if users |
476 // switch tabs (and thus stop drawing the animation, which will pause it) | 475 // switch tabs (and thus stop drawing the animation, which will pause it) |
477 // during that initial loop, then switch back later. | 476 // during that initial loop, then switch back later. |
478 if (nextFrame == 0 && m_repetitionsComplete == 0 && m_desiredFrameStartTime
< time) | 477 if (nextFrame == 0 && m_repetitionsComplete == 0 && m_desiredFrameStartTime
< time) |
479 m_desiredFrameStartTime = time; | 478 m_desiredFrameStartTime = time; |
480 | 479 |
481 if (catchUpIfNecessary == DoNotCatchUp || time < m_desiredFrameStartTime) { | 480 if (catchUpIfNecessary == DoNotCatchUp || time < m_desiredFrameStartTime) { |
482 // Haven't yet reached time for next frame to start; delay until then. | 481 // Haven't yet reached time for next frame to start; delay until then. |
483 m_frameTimer = wrapUnique(new Timer<BitmapImage>(this, &BitmapImage::adv
anceAnimation)); | 482 m_frameTimer = adoptPtr(new Timer<BitmapImage>(this, &BitmapImage::advan
ceAnimation)); |
484 m_frameTimer->startOneShot(std::max(m_desiredFrameStartTime - time, 0.),
BLINK_FROM_HERE); | 483 m_frameTimer->startOneShot(std::max(m_desiredFrameStartTime - time, 0.),
BLINK_FROM_HERE); |
485 } else { | 484 } else { |
486 // We've already reached or passed the time for the next frame to start. | 485 // We've already reached or passed the time for the next frame to start. |
487 // See if we've also passed the time for frames after that to start, in | 486 // See if we've also passed the time for frames after that to start, in |
488 // case we need to skip some frames entirely. Remember not to advance | 487 // case we need to skip some frames entirely. Remember not to advance |
489 // to an incomplete frame. | 488 // to an incomplete frame. |
490 for (size_t frameAfterNext = (nextFrame + 1) % frameCount(); frameIsComp
leteAtIndex(frameAfterNext); frameAfterNext = (nextFrame + 1) % frameCount()) { | 489 for (size_t frameAfterNext = (nextFrame + 1) % frameCount(); frameIsComp
leteAtIndex(frameAfterNext); frameAfterNext = (nextFrame + 1) % frameCount()) { |
491 // Should we skip the next frame? | 490 // Should we skip the next frame? |
492 double frameAfterNextStartTime = m_desiredFrameStartTime + frameDura
tionAtIndex(nextFrame); | 491 double frameAfterNextStartTime = m_desiredFrameStartTime + frameDura
tionAtIndex(nextFrame); |
493 if (time < frameAfterNextStartTime) | 492 if (time < frameAfterNextStartTime) |
494 break; | 493 break; |
495 | 494 |
496 // Yes; skip over it without notifying our observers. | 495 // Yes; skip over it without notifying our observers. |
497 if (!internalAdvanceAnimation(true)) | 496 if (!internalAdvanceAnimation(true)) |
498 return; | 497 return; |
499 m_desiredFrameStartTime = frameAfterNextStartTime; | 498 m_desiredFrameStartTime = frameAfterNextStartTime; |
500 nextFrame = frameAfterNext; | 499 nextFrame = frameAfterNext; |
501 } | 500 } |
502 | 501 |
503 // Post a task to advance the frame immediately. m_desiredFrameStartTime | 502 // Post a task to advance the frame immediately. m_desiredFrameStartTime |
504 // may be in the past, meaning the next time through this function we'll | 503 // may be in the past, meaning the next time through this function we'll |
505 // kick off the next advancement sooner than this frame's duration would | 504 // kick off the next advancement sooner than this frame's duration would |
506 // suggest. | 505 // suggest. |
507 m_frameTimer = wrapUnique(new Timer<BitmapImage>(this, &BitmapImage::adv
anceAnimationWithoutCatchUp)); | 506 m_frameTimer = adoptPtr(new Timer<BitmapImage>(this, &BitmapImage::advan
ceAnimationWithoutCatchUp)); |
508 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); | 507 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); |
509 } | 508 } |
510 } | 509 } |
511 | 510 |
512 void BitmapImage::stopAnimation() | 511 void BitmapImage::stopAnimation() |
513 { | 512 { |
514 // This timer is used to animate all occurrences of this image. Don't inval
idate | 513 // This timer is used to animate all occurrences of this image. Don't inval
idate |
515 // the timer unless all renderers have stopped drawing. | 514 // the timer unless all renderers have stopped drawing. |
516 m_frameTimer.reset(); | 515 m_frameTimer.reset(); |
517 } | 516 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 589 |
591 // We need to draw this frame if we advanced to it while not skipping, or if | 590 // We need to draw this frame if we advanced to it while not skipping, or if |
592 // while trying to skip frames we hit the last frame and thus had to stop. | 591 // while trying to skip frames we hit the last frame and thus had to stop. |
593 if (skippingFrames != advancedAnimation) | 592 if (skippingFrames != advancedAnimation) |
594 getImageObserver()->animationAdvanced(this); | 593 getImageObserver()->animationAdvanced(this); |
595 | 594 |
596 return advancedAnimation; | 595 return advancedAnimation; |
597 } | 596 } |
598 | 597 |
599 } // namespace blink | 598 } // namespace blink |
OLD | NEW |