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