Chromium Code Reviews| 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(this, &SVGImageChromeClient::animationTimerFired) |
| 42 , m_timelineState(Running) | |
| 44 { | 43 { |
| 45 } | 44 } |
| 46 | 45 |
| 47 SVGImageChromeClient* SVGImageChromeClient::create(SVGImage* image) | 46 SVGImageChromeClient* SVGImageChromeClient::create(SVGImage* image) |
| 48 { | 47 { |
| 49 return new SVGImageChromeClient(image); | 48 return new SVGImageChromeClient(image); |
| 50 } | 49 } |
| 51 | 50 |
| 52 bool SVGImageChromeClient::isSVGImageChromeClient() const | 51 bool SVGImageChromeClient::isSVGImageChromeClient() const |
| 53 { | 52 { |
| 54 return true; | 53 return true; |
| 55 } | 54 } |
| 56 | 55 |
| 57 void SVGImageChromeClient::chromeDestroyed() | 56 void SVGImageChromeClient::chromeDestroyed() |
| 58 { | 57 { |
| 59 m_image = nullptr; | 58 m_image = nullptr; |
| 60 } | 59 } |
| 61 | 60 |
| 62 void SVGImageChromeClient::invalidateRect(const IntRect& r) | 61 void SVGImageChromeClient::invalidateRect(const IntRect& r) |
| 63 { | 62 { |
| 64 // If m_image->m_page is null, we're being destructed, don't fire changedInR ect() in that case. | 63 // 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) | 64 if (m_image && m_image->getImageObserver() && m_image->m_page) |
| 66 m_image->getImageObserver()->changedInRect(m_image, r); | 65 m_image->getImageObserver()->changedInRect(m_image, r); |
| 67 } | 66 } |
| 68 | 67 |
| 68 void SVGImageChromeClient::suspendAnimation() | |
| 69 { | |
| 70 // Preserve SuspendedWithFramePending if set. | |
| 71 m_timelineState = std::max(m_timelineState, Suspended); | |
| 72 } | |
| 73 | |
| 74 void SVGImageChromeClient::resumeAnimation() | |
| 75 { | |
| 76 bool havePendingFrame = m_timelineState == SuspendedWithFramePending; | |
| 77 m_timelineState = Running; | |
| 78 | |
| 79 // If an animation frame was requested while animations were blocked, kick | |
| 80 // off an animation timer right away. | |
| 81 if (!havePendingFrame) | |
| 82 return; | |
| 83 // In the unlikely event that we suspend and resume within a single frame, | |
| 84 // the timer could still be running, so just leave it at the current | |
| 85 // timeout. | |
| 86 if (m_animationTimer.isActive()) | |
|
chrishtr
2016/05/20 18:26:15
Why not just call scheduleAnimation() directly? Th
fs
2016/05/20 19:23:58
That would schedule a timer with a delay of |anima
chrishtr
2016/05/20 19:55:18
Does that matter?
fs
2016/05/20 20:03:06
I guess we can try it and see.
chrishtr
2016/05/23 20:02:51
I suppose it doesn't matter that much. Only a few
fs
2016/05/23 20:58:34
I've shuffled this around a bit now, and this is n
| |
| 87 return; | |
| 88 m_animationTimer.startOneShot(0, BLINK_FROM_HERE); | |
| 89 } | |
| 90 | |
| 69 void SVGImageChromeClient::scheduleAnimation(Widget*) | 91 void SVGImageChromeClient::scheduleAnimation(Widget*) |
| 70 { | 92 { |
| 71 // Because a single SVGImage can be shared by multiple pages, we can't key | 93 // 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 | 94 // 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, | 95 // run this fake animation timer to trigger layout in SVGImages. The name, |
| 74 // "animationTimer", is to match the new requestAnimationFrame-based layout | 96 // "animationTimer", is to match the new requestAnimationFrame-based layout |
| 75 // approach. | 97 // approach. |
| 76 if (m_animationTimer.isActive()) | 98 if (m_animationTimer.isActive()) |
| 77 return; | 99 return; |
| 78 // Schedule the 'animation' ASAP if the image does not contain any | 100 // Schedule the 'animation' ASAP if the image does not contain any |
| 79 // animations, but prefer a fixed, jittery, frame-delay if there're any | 101 // animations, but prefer a fixed, jittery, frame-delay if there're any |
| 80 // animations. Checking for pending/active animations could be more | 102 // animations. Checking for pending/active animations could be more |
| 81 // stringent. | 103 // stringent. |
| 82 double fireTime = m_image->hasAnimations() ? animationFrameDelay : 0; | 104 double fireTime = 0; |
| 105 if (m_image->hasAnimations()) { | |
| 106 if (m_timelineState >= Suspended) { | |
| 107 m_timelineState = SuspendedWithFramePending; | |
| 108 return; | |
| 109 } | |
| 110 fireTime = animationFrameDelay; | |
| 111 } | |
| 83 m_animationTimer.startOneShot(fireTime, BLINK_FROM_HERE); | 112 m_animationTimer.startOneShot(fireTime, BLINK_FROM_HERE); |
| 84 } | 113 } |
| 85 | 114 |
| 86 void SVGImageChromeClient::animationTimerFired(Timer<SVGImageChromeClient>*) | 115 void SVGImageChromeClient::animationTimerFired(Timer<SVGImageChromeClient>*) |
| 87 { | 116 { |
| 88 if (!m_image) | 117 if (!m_image) |
| 89 return; | 118 return; |
| 90 | 119 |
| 91 // The SVGImageChromeClient object's lifetime is dependent on | 120 // The SVGImageChromeClient object's lifetime is dependent on |
| 92 // the ImageObserver (an ImageResource) of its image. Should it | 121 // the ImageObserver (an ImageResource) of its image. Should it |
| 93 // be dead and about to be lazily swept out, do not proceed. | 122 // be dead and about to be lazily swept out, do not proceed. |
| 94 // | 123 // |
| 95 // TODO(Oilpan): move (SVG)Image to the Oilpan heap, and avoid | 124 // TODO(Oilpan): move (SVG)Image to the Oilpan heap, and avoid |
| 96 // this explicit lifetime check. | 125 // this explicit lifetime check. |
| 97 if (ThreadHeap::willObjectBeLazilySwept(m_image->getImageObserver())) | 126 if (ThreadHeap::willObjectBeLazilySwept(m_image->getImageObserver())) |
| 98 return; | 127 return; |
| 99 | 128 |
| 100 // serviceScriptedAnimations runs requestAnimationFrame callbacks, but SVG | 129 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 } | 130 } |
| 111 | 131 |
| 112 } // namespace blink | 132 } // namespace blink |
| OLD | NEW |