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

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

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months 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/AnimationNode.h ('k') | sky/engine/core/animation/AnimationNode.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #include "sky/engine/core/animation/AnimationNode.h"
32
33 #include "sky/engine/core/animation/AnimationNodeTiming.h"
34 #include "sky/engine/core/animation/AnimationPlayer.h"
35 #include "sky/engine/core/animation/TimingCalculations.h"
36
37 namespace blink {
38
39 namespace {
40
41 Timing::FillMode resolvedFillMode(Timing::FillMode fillMode, bool isAnimation)
42 {
43 if (fillMode != Timing::FillModeAuto)
44 return fillMode;
45 if (isAnimation)
46 return Timing::FillModeNone;
47 return Timing::FillModeBoth;
48 }
49
50 } // namespace
51
52 AnimationNode::AnimationNode(const Timing& timing, PassOwnPtr<EventDelegate> eve ntDelegate)
53 : m_parent(nullptr)
54 , m_startTime(0)
55 , m_player(nullptr)
56 , m_timing(timing)
57 , m_eventDelegate(eventDelegate)
58 , m_calculated()
59 , m_needsUpdate(true)
60 , m_lastUpdateTime(nullValue())
61 {
62 m_timing.assertValid();
63 }
64
65 double AnimationNode::iterationDuration() const
66 {
67 double result = std::isnan(m_timing.iterationDuration) ? intrinsicIterationD uration() : m_timing.iterationDuration;
68 ASSERT(result >= 0);
69 return result;
70 }
71
72 double AnimationNode::repeatedDuration() const
73 {
74 const double result = multiplyZeroAlwaysGivesZero(iterationDuration(), m_tim ing.iterationCount);
75 ASSERT(result >= 0);
76 return result;
77 }
78
79 double AnimationNode::activeDurationInternal() const
80 {
81 const double result = m_timing.playbackRate
82 ? repeatedDuration() / std::abs(m_timing.playbackRate)
83 : std::numeric_limits<double>::infinity();
84 ASSERT(result >= 0);
85 return result;
86 }
87
88 void AnimationNode::updateSpecifiedTiming(const Timing& timing)
89 {
90 // FIXME: Test whether the timing is actually different?
91 m_timing = timing;
92 invalidate();
93 if (m_player)
94 m_player->setOutdated();
95 specifiedTimingChanged();
96 }
97
98 void AnimationNode::updateInheritedTime(double inheritedTime, TimingUpdateReason reason) const
99 {
100 bool needsUpdate = m_needsUpdate || (m_lastUpdateTime != inheritedTime && !( isNull(m_lastUpdateTime) && isNull(inheritedTime)));
101 m_needsUpdate = false;
102 m_lastUpdateTime = inheritedTime;
103
104 const double localTime = inheritedTime - m_startTime;
105 double timeToNextIteration = std::numeric_limits<double>::infinity();
106 if (needsUpdate) {
107 const double activeDuration = this->activeDurationInternal();
108
109 const Phase currentPhase = calculatePhase(activeDuration, localTime, m_t iming);
110 // FIXME: parentPhase depends on groups being implemented.
111 const AnimationNode::Phase parentPhase = AnimationNode::PhaseActive;
112 const double activeTime = calculateActiveTime(activeDuration, resolvedFi llMode(m_timing.fillMode, isAnimation()), localTime, parentPhase, currentPhase, m_timing);
113
114 double currentIteration;
115 double timeFraction;
116 if (const double iterationDuration = this->iterationDuration()) {
117 const double startOffset = multiplyZeroAlwaysGivesZero(m_timing.iter ationStart, iterationDuration);
118 ASSERT(startOffset >= 0);
119 const double scaledActiveTime = calculateScaledActiveTime(activeDura tion, activeTime, startOffset, m_timing);
120 const double iterationTime = calculateIterationTime(iterationDuratio n, repeatedDuration(), scaledActiveTime, startOffset, m_timing);
121
122 currentIteration = calculateCurrentIteration(iterationDuration, iter ationTime, scaledActiveTime, m_timing);
123 timeFraction = calculateTransformedTime(currentIteration, iterationD uration, iterationTime, m_timing) / iterationDuration;
124
125 if (!isNull(iterationTime)) {
126 timeToNextIteration = (iterationDuration - iterationTime) / std: :abs(m_timing.playbackRate);
127 if (activeDuration - activeTime < timeToNextIteration)
128 timeToNextIteration = std::numeric_limits<double>::infinity( );
129 }
130 } else {
131 const double localIterationDuration = 1;
132 const double localRepeatedDuration = localIterationDuration * m_timi ng.iterationCount;
133 ASSERT(localRepeatedDuration >= 0);
134 const double localActiveDuration = m_timing.playbackRate ? localRepe atedDuration / std::abs(m_timing.playbackRate) : std::numeric_limits<double>::in finity();
135 ASSERT(localActiveDuration >= 0);
136 const double localLocalTime = localTime < m_timing.startDelay ? loca lTime : localActiveDuration + m_timing.startDelay;
137 const AnimationNode::Phase localCurrentPhase = calculatePhase(localA ctiveDuration, localLocalTime, m_timing);
138 const double localActiveTime = calculateActiveTime(localActiveDurati on, resolvedFillMode(m_timing.fillMode, isAnimation()), localLocalTime, parentPh ase, localCurrentPhase, m_timing);
139 const double startOffset = m_timing.iterationStart * localIterationD uration;
140 ASSERT(startOffset >= 0);
141 const double scaledActiveTime = calculateScaledActiveTime(localActiv eDuration, localActiveTime, startOffset, m_timing);
142 const double iterationTime = calculateIterationTime(localIterationDu ration, localRepeatedDuration, scaledActiveTime, startOffset, m_timing);
143
144 currentIteration = calculateCurrentIteration(localIterationDuration, iterationTime, scaledActiveTime, m_timing);
145 timeFraction = calculateTransformedTime(currentIteration, localItera tionDuration, iterationTime, m_timing);
146 }
147
148 m_calculated.currentIteration = currentIteration;
149 m_calculated.timeFraction = timeFraction;
150
151 m_calculated.phase = currentPhase;
152 m_calculated.isInEffect = !isNull(activeTime);
153 m_calculated.isInPlay = phase() == PhaseActive && (!m_parent || m_parent ->isInPlay());
154 m_calculated.isCurrent = phase() == PhaseBefore || isInPlay() || (m_pare nt && m_parent->isCurrent());
155 m_calculated.localTime = m_lastUpdateTime - m_startTime;
156 }
157
158 // Test for events even if timing didn't need an update as the player may ha ve gained a start time.
159 // FIXME: Refactor so that we can ASSERT(m_player) here, this is currently r equired to be nullable for testing.
160 if (reason == TimingUpdateForAnimationFrame && (!m_player || m_player->hasSt artTime() || m_player->paused())) {
161 if (m_eventDelegate)
162 m_eventDelegate->onEventCondition(this);
163 }
164
165 if (needsUpdate) {
166 // FIXME: This probably shouldn't be recursive.
167 updateChildrenAndEffects();
168 m_calculated.timeToForwardsEffectChange = calculateTimeToEffectChange(tr ue, localTime, timeToNextIteration);
169 m_calculated.timeToReverseEffectChange = calculateTimeToEffectChange(fal se, localTime, timeToNextIteration);
170 }
171 }
172
173 const AnimationNode::CalculatedTiming& AnimationNode::ensureCalculated() const
174 {
175 if (!m_player)
176 return m_calculated;
177 if (m_player->outdated())
178 m_player->update(TimingUpdateOnDemand);
179 ASSERT(!m_player->outdated());
180 return m_calculated;
181 }
182
183 PassRefPtr<AnimationNodeTiming> AnimationNode::timing()
184 {
185 return AnimationNodeTiming::create(this);
186 }
187
188 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/animation/AnimationNode.h ('k') | sky/engine/core/animation/AnimationNode.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698