Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: Source/core/animation/Animation.cpp

Issue 23874019: Web Animations CSS: Start running animations on the compositor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase and rename hasActiveAnimationOnCompositor to hasActiveAnimationsOnCompositor Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/Animation.h ('k') | Source/core/animation/AnimationEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/animation/Animation.h" 32 #include "core/animation/Animation.h"
33 33
34 #include "core/animation/ActiveAnimations.h" 34 #include "core/animation/ActiveAnimations.h"
35 #include "core/animation/CompositorAnimations.h"
36 #include "core/animation/KeyframeAnimationEffect.h"
35 #include "core/animation/Player.h" 37 #include "core/animation/Player.h"
36 #include "core/dom/Element.h" 38 #include "core/dom/Element.h"
37 39
38 namespace WebCore { 40 namespace WebCore {
39 41
40 PassRefPtr<Animation> Animation::create(PassRefPtr<Element> target, PassRefPtr<A nimationEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<Even tDelegate> eventDelegate) 42 PassRefPtr<Animation> Animation::create(PassRefPtr<Element> target, PassRefPtr<A nimationEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<Even tDelegate> eventDelegate)
41 { 43 {
42 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e)); 44 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e));
43 } 45 }
44 46
45 Animation::Animation(PassRefPtr<Element> target, PassRefPtr<AnimationEffect> eff ect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDel egate) 47 Animation::Animation(PassRefPtr<Element> target, PassRefPtr<AnimationEffect> eff ect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDel egate)
46 : TimedItem(timing, eventDelegate) 48 : TimedItem(timing, eventDelegate)
47 , m_target(target) 49 , m_target(target)
48 , m_effect(effect) 50 , m_effect(effect)
49 , m_activeInAnimationStack(false) 51 , m_activeInAnimationStack(false)
50 , m_priority(priority) 52 , m_priority(priority)
51 { 53 {
52 } 54 }
53 55
54 void Animation::didAttach() 56 void Animation::didAttach()
55 { 57 {
56 if (m_target) 58 if (m_target)
57 m_target->ensureActiveAnimations()->players().add(player()); 59 m_target->ensureActiveAnimations()->players().add(player());
58 } 60 }
59 61
60 void Animation::willDetach() 62 void Animation::willDetach()
61 { 63 {
62 if (m_target) 64 if (m_target)
63 m_target->activeAnimations()->players().remove(player()); 65 m_target->activeAnimations()->players().remove(player());
64
65 if (m_activeInAnimationStack) 66 if (m_activeInAnimationStack)
66 clearEffects(); 67 clearEffects();
67 } 68 }
68 69
69 static AnimationStack& ensureAnimationStack(Element* element) 70 static AnimationStack& ensureAnimationStack(Element* element)
70 { 71 {
71 return element->ensureActiveAnimations()->defaultStack(); 72 return element->ensureActiveAnimations()->defaultStack();
72 } 73 }
73 74
74 bool Animation::applyEffects(bool previouslyInEffect) 75 bool Animation::applyEffects(bool previouslyInEffect)
(...skipping 10 matching lines...) Expand all
85 m_compositableValues = m_effect->sample(currentIteration(), timeFraction()); 86 m_compositableValues = m_effect->sample(currentIteration(), timeFraction());
86 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); 87 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer);
87 return true; 88 return true;
88 } 89 }
89 90
90 void Animation::clearEffects() 91 void Animation::clearEffects()
91 { 92 {
92 ASSERT(player()); 93 ASSERT(player());
93 ASSERT(m_activeInAnimationStack); 94 ASSERT(m_activeInAnimationStack);
94 ensureAnimationStack(m_target.get()).remove(this); 95 ensureAnimationStack(m_target.get()).remove(this);
96 cancelAnimationOnCompositor();
95 m_activeInAnimationStack = false; 97 m_activeInAnimationStack = false;
96 m_compositableValues.clear(); 98 m_compositableValues.clear();
97 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); 99 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer);
98 } 100 }
99 101
100 bool Animation::updateChildrenAndEffects() const 102 bool Animation::updateChildrenAndEffects() const
101 { 103 {
102 if (!m_effect) 104 if (!m_effect)
103 return false; 105 return false;
104 106
105 if (isInEffect()) 107 if (isInEffect())
106 return const_cast<Animation*>(this)->applyEffects(m_activeInAnimationSta ck); 108 return const_cast<Animation*>(this)->applyEffects(m_activeInAnimationSta ck);
107 109
108 if (m_activeInAnimationStack) { 110 if (m_activeInAnimationStack) {
109 const_cast<Animation*>(this)->clearEffects(); 111 const_cast<Animation*>(this)->clearEffects();
110 return true; 112 return true;
111 } 113 }
112 return false; 114 return false;
113 } 115 }
114 116
115 double Animation::calculateTimeToEffectChange(double localTime, double) const 117 double Animation::calculateTimeToEffectChange(double localTime, double timeToNex tIteration) const
116 { 118 {
117 const double activeStartTime = startTime() + specified().startDelay; 119 const double activeStartTime = startTime() + specified().startDelay;
118
119 switch (phase()) { 120 switch (phase()) {
120 case PhaseBefore: 121 case PhaseBefore:
121 return activeStartTime - localTime; 122 return activeStartTime - localTime;
122 case PhaseActive: 123 case PhaseActive:
124 if (hasActiveAnimationsOnCompositor()) {
125 // Need service to apply fill / fire events.
126 const double activeEndTime = activeStartTime + activeDuration();
127 ASSERT(isNull(timeToNextIteration) || timeToNextIteration <= (active EndTime - localTime));
128 return isNull(timeToNextIteration) ? activeEndTime - localTime : tim eToNextIteration;
129 }
123 return 0; 130 return 0;
124 case PhaseAfter: 131 case PhaseAfter:
125 // If this Animation is still in effect then it will need to update 132 // If this Animation is still in effect then it will need to update
126 // when its parent goes out of effect. We have no way of knowing when 133 // when its parent goes out of effect. We have no way of knowing when
127 // that will be, however, so the parent will need to supply it. 134 // that will be, however, so the parent will need to supply it.
128 return std::numeric_limits<double>::infinity(); 135 return std::numeric_limits<double>::infinity();
129 case PhaseNone: 136 case PhaseNone:
130 default: 137 default:
131 ASSERT_NOT_REACHED(); 138 ASSERT_NOT_REACHED();
132 return 0; 139 return 0;
133 } 140 }
134 } 141 }
135 142
143 bool Animation::isCandidateForAnimationOnCompositor() const
144 {
145 if (!effect() || !m_target)
146 return false;
147 return CompositorAnimations::instance()->isCandidateForAnimationOnCompositor (specified(), *effect());
148 }
149
150 bool Animation::maybeStartAnimationOnCompositor()
151 {
152 ASSERT(!hasActiveAnimationsOnCompositor());
153 if (!isCandidateForAnimationOnCompositor())
154 return false;
155 if (!CompositorAnimations::instance()->canStartAnimationOnCompositor(*m_targ et.get()))
156 return false;
157 if (!CompositorAnimations::instance()->startAnimationOnCompositor(*m_target. get(), specified(), *effect(), m_compositorAnimationIds))
158 return false;
159 ASSERT(!m_compositorAnimationIds.isEmpty());
160 return true;
161 }
162
163 bool Animation::hasActiveAnimationsOnCompositor() const
164 {
165 return !m_compositorAnimationIds.isEmpty();
166 }
167
168 bool Animation::hasActiveAnimationsOnCompositor(CSSPropertyID property) const
169 {
170 return hasActiveAnimationsOnCompositor() && affects(property);
171 }
172
173 bool Animation::affects(CSSPropertyID property) const
174 {
175 return m_effect && m_effect->affects(property);
176 }
177
178 void Animation::cancelAnimationOnCompositor()
179 {
180 if (!hasActiveAnimationsOnCompositor())
181 return;
182 if (!m_target || !m_target->renderer())
183 return;
184 for (size_t i = 0; i < m_compositorAnimationIds.size(); ++i) {
185 CompositorAnimations::instance()->cancelAnimationOnCompositor(*m_target. get(), m_compositorAnimationIds[i]);
186 }
187 m_compositorAnimationIds.clear();
188 }
189
136 } // namespace WebCore 190 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/Animation.h ('k') | Source/core/animation/AnimationEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698