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

Side by Side Diff: sky/engine/core/animation/AnimationTimeline.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
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/AnimationTimeline.h"
32
33 #include "sky/engine/core/animation/ActiveAnimations.h"
34 #include "sky/engine/core/animation/AnimationClock.h"
35 #include "sky/engine/core/dom/Document.h"
36 #include "sky/engine/core/frame/FrameView.h"
37 #include "sky/engine/core/page/Page.h"
38 #include "sky/engine/platform/TraceEvent.h"
39
40 namespace blink {
41
42 namespace {
43
44 bool compareAnimationPlayers(const RefPtr<blink::AnimationPlayer>& left, const R efPtr<blink::AnimationPlayer>& right)
45 {
46 return AnimationPlayer::hasLowerPriority(left.get(), right.get());
47 }
48
49 }
50
51 // This value represents 1 frame at 30Hz plus a little bit of wiggle room.
52 // TODO: Plumb a nominal framerate through and derive this value from that.
53 const double AnimationTimeline::s_minimumDelay = 0.04;
54
55
56 PassRefPtr<AnimationTimeline> AnimationTimeline::create(Document* document, Pass OwnPtr<PlatformTiming> timing)
57 {
58 return adoptRef(new AnimationTimeline(document, timing));
59 }
60
61 AnimationTimeline::AnimationTimeline(Document* document, PassOwnPtr<PlatformTimi ng> timing)
62 : m_document(document)
63 {
64 if (!timing)
65 m_timing = adoptPtr(new AnimationTimelineTiming(this));
66 else
67 m_timing = timing;
68
69 ASSERT(document);
70 }
71
72 AnimationTimeline::~AnimationTimeline()
73 {
74 #if !ENABLE(OILPAN)
75 for (HashSet<RawPtr<AnimationPlayer> >::iterator it = m_players.begin(); it != m_players.end(); ++it)
76 (*it)->timelineDestroyed();
77 #endif
78 }
79
80 AnimationPlayer* AnimationTimeline::createAnimationPlayer(AnimationNode* child)
81 {
82 RefPtr<AnimationPlayer> player = AnimationPlayer::create(m_document->context Document().get(), *this, child);
83 AnimationPlayer* result = player.get();
84 m_players.add(result);
85 setOutdatedAnimationPlayer(result);
86 return result;
87 }
88
89 AnimationPlayer* AnimationTimeline::play(AnimationNode* child)
90 {
91 if (!m_document)
92 return 0;
93 AnimationPlayer* player = createAnimationPlayer(child);
94 return player;
95 }
96
97 Vector<RefPtr<AnimationPlayer> > AnimationTimeline::getAnimationPlayers()
98 {
99 Vector<RefPtr<AnimationPlayer> > animationPlayers;
100 for (HashSet<RawPtr<AnimationPlayer> >::iterator it = m_players.begin(); it != m_players.end(); ++it) {
101 if ((*it)->source() && (*it)->source()->isCurrent()) {
102 animationPlayers.append(*it);
103 }
104 }
105 std::sort(animationPlayers.begin(), animationPlayers.end(), compareAnimation Players);
106 return animationPlayers;
107 }
108
109 void AnimationTimeline::wake()
110 {
111 m_timing->serviceOnNextFrame();
112 }
113
114 void AnimationTimeline::serviceAnimations(TimingUpdateReason reason)
115 {
116 TRACE_EVENT0("blink", "AnimationTimeline::serviceAnimations");
117
118 m_timing->cancelWake();
119
120 double timeToNextEffect = std::numeric_limits<double>::infinity();
121
122 Vector<RawPtr<AnimationPlayer> > players;
123 players.reserveInitialCapacity(m_playersNeedingUpdate.size());
124 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate .begin(); it != m_playersNeedingUpdate.end(); ++it)
125 players.append(it->get());
126
127 std::sort(players.begin(), players.end(), AnimationPlayer::hasLowerPriority) ;
128
129 for (size_t i = 0; i < players.size(); ++i) {
130 AnimationPlayer* player = players[i];
131 if (player->update(reason))
132 timeToNextEffect = std::min(timeToNextEffect, player->timeToEffectCh ange());
133 else
134 m_playersNeedingUpdate.remove(player);
135 }
136
137 if (timeToNextEffect < s_minimumDelay)
138 m_timing->serviceOnNextFrame();
139 else if (timeToNextEffect != std::numeric_limits<double>::infinity())
140 m_timing->wakeAfter(timeToNextEffect - s_minimumDelay);
141
142 ASSERT(!hasOutdatedAnimationPlayer());
143 }
144
145 void AnimationTimeline::AnimationTimelineTiming::wakeAfter(double duration)
146 {
147 m_timer.startOneShot(duration, FROM_HERE);
148 }
149
150 void AnimationTimeline::AnimationTimelineTiming::cancelWake()
151 {
152 m_timer.stop();
153 }
154
155 void AnimationTimeline::AnimationTimelineTiming::serviceOnNextFrame()
156 {
157 if (m_timeline->m_document)
158 m_timeline->m_document->page()->scheduleVisualUpdate();
159 }
160
161 double AnimationTimeline::currentTime(bool& isNull)
162 {
163 return currentTimeInternal(isNull) * 1000;
164 }
165
166 double AnimationTimeline::currentTimeInternal(bool& isNull)
167 {
168 if (!m_document) {
169 isNull = true;
170 return std::numeric_limits<double>::quiet_NaN();
171 }
172 double result = m_document->animationClock().currentTime() - zeroTime();
173 isNull = std::isnan(result);
174 return result;
175 }
176
177 double AnimationTimeline::currentTime()
178 {
179 return currentTimeInternal() * 1000;
180 }
181
182 double AnimationTimeline::currentTimeInternal()
183 {
184 bool isNull;
185 return currentTimeInternal(isNull);
186 }
187
188 double AnimationTimeline::effectiveTime()
189 {
190 double time = currentTimeInternal();
191 return std::isnan(time) ? 0 : time;
192 }
193
194 bool AnimationTimeline::hasOutdatedAnimationPlayer() const
195 {
196 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate .begin(); it != m_playersNeedingUpdate.end(); ++it) {
197 if ((*it)->outdated())
198 return true;
199 }
200 return false;
201 }
202
203 void AnimationTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player)
204 {
205 ASSERT(player->outdated());
206 m_playersNeedingUpdate.add(player);
207 if (m_document && m_document->page() && !m_document->page()->animator().isSe rvicingAnimations())
208 m_timing->serviceOnNextFrame();
209 }
210
211 #if !ENABLE(OILPAN)
212 void AnimationTimeline::detachFromDocument()
213 {
214 // FIXME: AnimationTimeline should keep Document alive.
215 m_document = nullptr;
216 }
217 #endif
218
219 } // namespace
OLDNEW
« no previous file with comments | « sky/engine/core/animation/AnimationTimeline.h ('k') | sky/engine/core/animation/AnimationTimeline.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698