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

Side by Side Diff: sky/engine/core/animation/Animation.cpp

Issue 772673002: Fix Animations, Remove Compostior Animations. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: CompositorPendingAnimations -> PendingAnimations Created 6 years 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
« no previous file with comments | « sky/engine/core/animation/Animation.h ('k') | sky/engine/core/animation/AnimationPlayer.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 19 matching lines...) Expand all
30 30
31 #include "sky/engine/config.h" 31 #include "sky/engine/config.h"
32 #include "sky/engine/core/animation/Animation.h" 32 #include "sky/engine/core/animation/Animation.h"
33 33
34 #include "sky/engine/bindings/core/v8/Dictionary.h" 34 #include "sky/engine/bindings/core/v8/Dictionary.h"
35 #include "sky/engine/bindings/core/v8/ExceptionState.h" 35 #include "sky/engine/bindings/core/v8/ExceptionState.h"
36 #include "sky/engine/core/animation/ActiveAnimations.h" 36 #include "sky/engine/core/animation/ActiveAnimations.h"
37 #include "sky/engine/core/animation/AnimationHelpers.h" 37 #include "sky/engine/core/animation/AnimationHelpers.h"
38 #include "sky/engine/core/animation/AnimationPlayer.h" 38 #include "sky/engine/core/animation/AnimationPlayer.h"
39 #include "sky/engine/core/animation/AnimationTimeline.h" 39 #include "sky/engine/core/animation/AnimationTimeline.h"
40 #include "sky/engine/core/animation/CompositorAnimations.h"
41 #include "sky/engine/core/animation/Interpolation.h" 40 #include "sky/engine/core/animation/Interpolation.h"
42 #include "sky/engine/core/animation/KeyframeEffectModel.h" 41 #include "sky/engine/core/animation/KeyframeEffectModel.h"
43 #include "sky/engine/core/dom/Element.h" 42 #include "sky/engine/core/dom/Element.h"
44 #include "sky/engine/core/frame/UseCounter.h" 43 #include "sky/engine/core/frame/UseCounter.h"
45 #include "sky/engine/core/rendering/RenderLayer.h" 44 #include "sky/engine/core/rendering/RenderLayer.h"
46 45
47 namespace blink { 46 namespace blink {
48 47
49 PassRefPtr<Animation> Animation::create(Element* target, PassRefPtr<AnimationEff ect> effect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDelegate) 48 PassRefPtr<Animation> Animation::create(Element* target, PassRefPtr<AnimationEff ect> effect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDelegate)
50 { 49 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (m_sampledEffect) 120 if (m_sampledEffect)
122 clearEffects(); 121 clearEffects();
123 AnimationNode::detach(); 122 AnimationNode::detach();
124 } 123 }
125 124
126 void Animation::specifiedTimingChanged() 125 void Animation::specifiedTimingChanged()
127 { 126 {
128 if (player()) { 127 if (player()) {
129 // FIXME: Needs to consider groups when added. 128 // FIXME: Needs to consider groups when added.
130 ASSERT(player()->source() == this); 129 ASSERT(player()->source() == this);
131 player()->setCompositorPending(true); 130 player()->setPending();
132 } 131 }
133 } 132 }
134 133
135 static AnimationStack& ensureAnimationStack(Element* element) 134 static AnimationStack& ensureAnimationStack(Element* element)
136 { 135 {
137 return element->ensureActiveAnimations().defaultStack(); 136 return element->ensureActiveAnimations().defaultStack();
138 } 137 }
139 138
140 void Animation::applyEffects() 139 void Animation::applyEffects()
141 { 140 {
(...skipping 19 matching lines...) Expand all
161 m_target->setNeedsAnimationStyleRecalc(); 160 m_target->setNeedsAnimationStyleRecalc();
162 } 161 }
163 162
164 void Animation::clearEffects() 163 void Animation::clearEffects()
165 { 164 {
166 ASSERT(player()); 165 ASSERT(player());
167 ASSERT(m_sampledEffect); 166 ASSERT(m_sampledEffect);
168 167
169 m_sampledEffect->clear(); 168 m_sampledEffect->clear();
170 m_sampledEffect = nullptr; 169 m_sampledEffect = nullptr;
171 cancelAnimationOnCompositor();
172 m_target->setNeedsAnimationStyleRecalc(); 170 m_target->setNeedsAnimationStyleRecalc();
173 invalidate(); 171 invalidate();
174 } 172 }
175 173
176 void Animation::updateChildrenAndEffects() const 174 void Animation::updateChildrenAndEffects() const
177 { 175 {
178 if (!m_effect) 176 if (!m_effect)
179 return; 177 return;
180 if (isInEffect()) 178 if (isInEffect())
181 const_cast<Animation*>(this)->applyEffects(); 179 const_cast<Animation*>(this)->applyEffects();
182 else if (m_sampledEffect) 180 else if (m_sampledEffect)
183 const_cast<Animation*>(this)->clearEffects(); 181 const_cast<Animation*>(this)->clearEffects();
184 } 182 }
185 183
186 double Animation::calculateTimeToEffectChange(bool forwards, double localTime, d ouble timeToNextIteration) const 184 double Animation::calculateTimeToEffectChange(bool forwards, double localTime, d ouble timeToNextIteration) const
187 { 185 {
188 const double start = startTimeInternal() + specifiedTiming().startDelay; 186 const double start = startTimeInternal() + specifiedTiming().startDelay;
189 const double end = start + activeDurationInternal(); 187 const double end = start + activeDurationInternal();
190 188
191 switch (phase()) { 189 switch (phase()) {
192 case PhaseBefore: 190 case PhaseBefore:
193 ASSERT(start >= localTime); 191 ASSERT(start >= localTime);
194 return forwards 192 return forwards
195 ? start - localTime 193 ? start - localTime
196 : std::numeric_limits<double>::infinity(); 194 : std::numeric_limits<double>::infinity();
197 case PhaseActive: 195 case PhaseActive:
198 if (forwards && hasActiveAnimationsOnCompositor()) {
199 ASSERT(specifiedTiming().playbackRate == 1);
200 // Need service to apply fill / fire events.
201 const double timeToEnd = end - localTime;
202 if (hasEvents()) {
203 return std::min(timeToEnd, timeToNextIteration);
204 } else {
205 return timeToEnd;
206 }
207 }
208 return 0; 196 return 0;
209 case PhaseAfter: 197 case PhaseAfter:
210 ASSERT(localTime >= end); 198 ASSERT(localTime >= end);
211 // If this Animation is still in effect then it will need to update 199 // If this Animation is still in effect then it will need to update
212 // when its parent goes out of effect. We have no way of knowing when 200 // when its parent goes out of effect. We have no way of knowing when
213 // that will be, however, so the parent will need to supply it. 201 // that will be, however, so the parent will need to supply it.
214 return forwards 202 return forwards
215 ? std::numeric_limits<double>::infinity() 203 ? std::numeric_limits<double>::infinity()
216 : localTime - end; 204 : localTime - end;
217 default: 205 default:
(...skipping 14 matching lines...) Expand all
232 // destructor called when we call SampledEffect::clear(), so we need to 220 // destructor called when we call SampledEffect::clear(), so we need to
233 // clear m_sampledEffect first. 221 // clear m_sampledEffect first.
234 m_target = nullptr; 222 m_target = nullptr;
235 clearEventDelegate(); 223 clearEventDelegate();
236 SampledEffect* sampledEffect = m_sampledEffect; 224 SampledEffect* sampledEffect = m_sampledEffect;
237 m_sampledEffect = nullptr; 225 m_sampledEffect = nullptr;
238 if (sampledEffect) 226 if (sampledEffect)
239 sampledEffect->clear(); 227 sampledEffect->clear();
240 } 228 }
241 229
242 bool Animation::isCandidateForAnimationOnCompositor() const
243 {
244 if (!effect() || !m_target)
245 return false;
246 return CompositorAnimations::instance()->isCandidateForAnimationOnCompositor (specifiedTiming(), *effect());
247 }
248
249 bool Animation::maybeStartAnimationOnCompositor(double startTime, double current Time)
250 {
251 ASSERT(!hasActiveAnimationsOnCompositor());
252 if (!isCandidateForAnimationOnCompositor())
253 return false;
254 if (!CompositorAnimations::instance()->canStartAnimationOnCompositor(*m_targ et))
255 return false;
256 if (!CompositorAnimations::instance()->startAnimationOnCompositor(*m_target, startTime, currentTime, specifiedTiming(), *effect(), m_compositorAnimationIds) )
257 return false;
258 ASSERT(!m_compositorAnimationIds.isEmpty());
259 return true;
260 }
261
262 bool Animation::hasActiveAnimationsOnCompositor() const
263 {
264 return !m_compositorAnimationIds.isEmpty();
265 }
266
267 bool Animation::hasActiveAnimationsOnCompositor(CSSPropertyID property) const
268 {
269 return hasActiveAnimationsOnCompositor() && affects(property);
270 }
271
272 bool Animation::affects(CSSPropertyID property) const
273 {
274 return m_effect && m_effect->affects(property);
275 }
276
277 void Animation::cancelAnimationOnCompositor()
278 {
279 if (!hasActiveAnimationsOnCompositor())
280 return;
281 if (!m_target || !m_target->renderer())
282 return;
283 for (size_t i = 0; i < m_compositorAnimationIds.size(); ++i)
284 CompositorAnimations::instance()->cancelAnimationOnCompositor(*m_target, m_compositorAnimationIds[i]);
285 m_compositorAnimationIds.clear();
286 player()->setCompositorPending(true);
287 }
288
289 void Animation::pauseAnimationForTestingOnCompositor(double pauseTime)
290 {
291 ASSERT(hasActiveAnimationsOnCompositor());
292 if (!m_target || !m_target->renderer())
293 return;
294 for (size_t i = 0; i < m_compositorAnimationIds.size(); ++i)
295 CompositorAnimations::instance()->pauseAnimationForTestingOnCompositor(* m_target, m_compositorAnimationIds[i], pauseTime);
296 }
297
298 } // namespace blink 230 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/animation/Animation.h ('k') | sky/engine/core/animation/AnimationPlayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698