| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 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 10 matching lines...) Expand all Loading... |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "core/svg/graphics/SVGImageChromeClient.h" | 29 #include "core/svg/graphics/SVGImageChromeClient.h" |
| 30 | 30 |
| 31 #include "core/frame/FrameView.h" | |
| 32 #include "core/svg/graphics/SVGImage.h" | 31 #include "core/svg/graphics/SVGImage.h" |
| 33 #include "platform/ScriptForbiddenScope.h" | |
| 34 #include "platform/graphics/ImageObserver.h" | 32 #include "platform/graphics/ImageObserver.h" |
| 35 #include "wtf/CurrentTime.h" | 33 #include "wtf/CurrentTime.h" |
| 36 | 34 |
| 37 namespace blink { | 35 namespace blink { |
| 38 | 36 |
| 39 static const double animationFrameDelay = 0.025; | 37 static const double animationFrameDelay = 0.025; |
| 40 | 38 |
| 41 SVGImageChromeClient::SVGImageChromeClient(SVGImage* image) | 39 SVGImageChromeClient::SVGImageChromeClient(SVGImage* image) |
| 42 : m_image(image) | 40 : m_image(image) |
| 43 , m_animationTimer(this, &SVGImageChromeClient::animationTimerFired) | 41 , m_animationTimer( |
| 42 adoptPtr(new Timer<SVGImageChromeClient>( |
| 43 this, &SVGImageChromeClient::animationTimerFired))) |
| 44 , m_timelineState(Running) |
| 44 { | 45 { |
| 45 } | 46 } |
| 46 | 47 |
| 47 SVGImageChromeClient* SVGImageChromeClient::create(SVGImage* image) | 48 SVGImageChromeClient* SVGImageChromeClient::create(SVGImage* image) |
| 48 { | 49 { |
| 49 return new SVGImageChromeClient(image); | 50 return new SVGImageChromeClient(image); |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool SVGImageChromeClient::isSVGImageChromeClient() const | 53 bool SVGImageChromeClient::isSVGImageChromeClient() const |
| 53 { | 54 { |
| 54 return true; | 55 return true; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void SVGImageChromeClient::chromeDestroyed() | 58 void SVGImageChromeClient::chromeDestroyed() |
| 58 { | 59 { |
| 59 m_image = nullptr; | 60 m_image = nullptr; |
| 60 } | 61 } |
| 61 | 62 |
| 62 void SVGImageChromeClient::invalidateRect(const IntRect& r) | 63 void SVGImageChromeClient::invalidateRect(const IntRect& r) |
| 63 { | 64 { |
| 64 // If m_image->m_page is null, we're being destructed, don't fire changedInR
ect() in that case. | 65 // If m_image->m_page is null, we're being destructed, don't fire changedInR
ect() in that case. |
| 65 if (m_image && m_image->getImageObserver() && m_image->m_page) | 66 if (m_image && m_image->getImageObserver() && m_image->m_page) |
| 66 m_image->getImageObserver()->changedInRect(m_image, r); | 67 m_image->getImageObserver()->changedInRect(m_image, r); |
| 67 } | 68 } |
| 68 | 69 |
| 70 void SVGImageChromeClient::suspendAnimation() |
| 71 { |
| 72 if (m_image->hasAnimations()) { |
| 73 m_timelineState = SuspendedWithAnimationPending; |
| 74 } else { |
| 75 // Preserve SuspendedWithAnimationPending if set. |
| 76 m_timelineState = std::max(m_timelineState, Suspended); |
| 77 } |
| 78 } |
| 79 |
| 80 void SVGImageChromeClient::resumeAnimation() |
| 81 { |
| 82 bool havePendingAnimation = m_timelineState == SuspendedWithAnimationPending
; |
| 83 m_timelineState = Running; |
| 84 |
| 85 // If an animation frame was pending/requested while animations were |
| 86 // suspended, schedule a new animation frame. |
| 87 if (!havePendingAnimation) |
| 88 return; |
| 89 scheduleAnimation(nullptr); |
| 90 } |
| 91 |
| 69 void SVGImageChromeClient::scheduleAnimation(Widget*) | 92 void SVGImageChromeClient::scheduleAnimation(Widget*) |
| 70 { | 93 { |
| 71 // Because a single SVGImage can be shared by multiple pages, we can't key | 94 // Because a single SVGImage can be shared by multiple pages, we can't key |
| 72 // our svg image layout on the page's real animation frame. Therefore, we | 95 // our svg image layout on the page's real animation frame. Therefore, we |
| 73 // run this fake animation timer to trigger layout in SVGImages. The name, | 96 // run this fake animation timer to trigger layout in SVGImages. The name, |
| 74 // "animationTimer", is to match the new requestAnimationFrame-based layout | 97 // "animationTimer", is to match the new requestAnimationFrame-based layout |
| 75 // approach. | 98 // approach. |
| 76 if (m_animationTimer.isActive()) | 99 if (m_animationTimer->isActive()) |
| 77 return; | 100 return; |
| 78 // Schedule the 'animation' ASAP if the image does not contain any | 101 // Schedule the 'animation' ASAP if the image does not contain any |
| 79 // animations, but prefer a fixed, jittery, frame-delay if there're any | 102 // animations, but prefer a fixed, jittery, frame-delay if there're any |
| 80 // animations. Checking for pending/active animations could be more | 103 // animations. Checking for pending/active animations could be more |
| 81 // stringent. | 104 // stringent. |
| 82 double fireTime = m_image->hasAnimations() ? animationFrameDelay : 0; | 105 double fireTime = 0; |
| 83 m_animationTimer.startOneShot(fireTime, BLINK_FROM_HERE); | 106 if (m_image->hasAnimations()) { |
| 107 if (m_timelineState >= Suspended) |
| 108 return; |
| 109 fireTime = animationFrameDelay; |
| 110 } |
| 111 m_animationTimer->startOneShot(fireTime, BLINK_FROM_HERE); |
| 112 } |
| 113 |
| 114 void SVGImageChromeClient::setTimer(Timer<SVGImageChromeClient>* timer) |
| 115 { |
| 116 m_animationTimer = adoptPtr(timer); |
| 84 } | 117 } |
| 85 | 118 |
| 86 void SVGImageChromeClient::animationTimerFired(Timer<SVGImageChromeClient>*) | 119 void SVGImageChromeClient::animationTimerFired(Timer<SVGImageChromeClient>*) |
| 87 { | 120 { |
| 88 if (!m_image) | 121 if (!m_image) |
| 89 return; | 122 return; |
| 90 | 123 |
| 91 // The SVGImageChromeClient object's lifetime is dependent on | 124 // The SVGImageChromeClient object's lifetime is dependent on |
| 92 // the ImageObserver (an ImageResource) of its image. Should it | 125 // the ImageObserver (an ImageResource) of its image. Should it |
| 93 // be dead and about to be lazily swept out, do not proceed. | 126 // be dead and about to be lazily swept out, do not proceed. |
| 94 // | 127 // |
| 95 // TODO(Oilpan): move (SVG)Image to the Oilpan heap, and avoid | 128 // TODO(Oilpan): move (SVG)Image to the Oilpan heap, and avoid |
| 96 // this explicit lifetime check. | 129 // this explicit lifetime check. |
| 97 if (ThreadHeap::willObjectBeLazilySwept(m_image->getImageObserver())) | 130 if (ThreadHeap::willObjectBeLazilySwept(m_image->getImageObserver())) |
| 98 return; | 131 return; |
| 99 | 132 |
| 100 // serviceScriptedAnimations runs requestAnimationFrame callbacks, but SVG | 133 m_image->serviceAnimations(monotonicallyIncreasingTime()); |
| 101 // images can't have any so we assert there's no script. | |
| 102 ScriptForbiddenScope forbidScript; | |
| 103 | |
| 104 // The calls below may trigger GCs, so set up the required persistent | |
| 105 // reference on the ImageResource which owns this SVGImage. By transitivity, | |
| 106 // that will keep this SVGImageChromeClient object alive. | |
| 107 Persistent<ImageObserver> protect(m_image->getImageObserver()); | |
| 108 m_image->frameView()->page()->animator().serviceScriptedAnimations(monotonic
allyIncreasingTime()); | |
| 109 m_image->frameView()->updateAllLifecyclePhases(); | |
| 110 } | 134 } |
| 111 | 135 |
| 112 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |