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

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: 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
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 cancelCompositorAnimations();
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 (isRunningCompositorAnimation()) {
125 // Need service to apply fill / fire events.
126 const double activeEndTime = activeStartTime + activeDuration();
127 return isNull(timeToNextIteration) ? activeEndTime - localTime : tim eToNextIteration;
128 }
123 return 0; 129 return 0;
124 case PhaseAfter: 130 case PhaseAfter:
125 // If this Animation is still in effect then it will need to update 131 // 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 132 // 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. 133 // that will be, however, so the parent will need to supply it.
128 return std::numeric_limits<double>::infinity(); 134 return std::numeric_limits<double>::infinity();
129 case PhaseNone: 135 case PhaseNone:
130 default: 136 default:
131 ASSERT_NOT_REACHED(); 137 ASSERT_NOT_REACHED();
132 return 0; 138 return 0;
133 } 139 }
134 } 140 }
135 141
142 bool Animation::isCandidateForCompositorAnimation() const
143 {
144 if (!effect() || !m_target)
145 return false;
146 return CompositorAnimations::instance()->isCandidateForCompositorAnimation(s pecified(), *effect());
147 }
148
149 bool Animation::startCompositorAnimations()
150 {
151 ASSERT(!isRunningCompositorAnimation());
152 if (!isCandidateForCompositorAnimation())
shans 2013/11/18 01:02:06 If this is part of the this method, then it should
dstockwell 2013/11/18 05:30:34 Done.
153 return false;
154 if (!CompositorAnimations::instance()->canStartCompositorAnimation(*m_target .get()))
155 return false;
156 if (CompositorAnimations::instance()->startCompositorAnimation(*m_target.get (), specified(), *effect(), m_acceleratedAnimationIds)) {
157 ASSERT(!m_acceleratedAnimationIds.isEmpty());
158 return true;
159 }
160 return false;
161 }
162
163 bool Animation::isRunningCompositorAnimation(const Element* element, CSSProperty ID property) const
164 {
165 if (element && element != m_target)
166 return false;
167
168 if (m_acceleratedAnimationIds.isEmpty())
169 return false;
170
171 return affects(property);
172 }
173
174 bool Animation::affects(CSSPropertyID property) const
175 {
176 if (property == CSSPropertyInvalid) {
177 // Can't affect anything if there's no effect.
178 return m_effect;
179 }
180
181 return toKeyframeAnimationEffect(m_effect.get())->affects(property);
182 }
183
184 void Animation::cancelCompositorAnimations()
185 {
186 if (!isRunningCompositorAnimation())
187 return;
188 if (!m_target || !m_target->renderer())
189 return;
190 for (size_t i = 0; i < m_acceleratedAnimationIds.size(); ++i) {
191 CompositorAnimations::instance()->cancelCompositorAnimation(*m_target.ge t(), m_acceleratedAnimationIds[i]);
192 }
193 m_acceleratedAnimationIds.clear();
194 }
195
136 } // namespace WebCore 196 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698