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

Side by Side Diff: Source/core/svg/animation/SMILTimeContainer.cpp

Issue 143403005: Make the timer in SMILTimeContainer more of an implementation detail (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Not Soon anymore. Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/animation/SMILTimeContainer.h ('k') | no next file » | 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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 , m_timer(this, &SMILTimeContainer::timerFired) 47 , m_timer(this, &SMILTimeContainer::timerFired)
48 , m_ownerSVGElement(owner) 48 , m_ownerSVGElement(owner)
49 #ifndef NDEBUG 49 #ifndef NDEBUG
50 , m_preventScheduledAnimationsChanges(false) 50 , m_preventScheduledAnimationsChanges(false)
51 #endif 51 #endif
52 { 52 {
53 } 53 }
54 54
55 SMILTimeContainer::~SMILTimeContainer() 55 SMILTimeContainer::~SMILTimeContainer()
56 { 56 {
57 m_timer.stop(); 57 cancelAnimationFrame();
58 ASSERT(!m_timer.isActive()); 58 ASSERT(!m_timer.isActive());
59 #ifndef NDEBUG 59 #ifndef NDEBUG
60 ASSERT(!m_preventScheduledAnimationsChanges); 60 ASSERT(!m_preventScheduledAnimationsChanges);
61 #endif 61 #endif
62 } 62 }
63 63
64 void SMILTimeContainer::schedule(SVGSMILElement* animation, SVGElement* target, const QualifiedName& attributeName) 64 void SMILTimeContainer::schedule(SVGSMILElement* animation, SVGElement* target, const QualifiedName& attributeName)
65 { 65 {
66 ASSERT(animation->timeContainer() == this); 66 ASSERT(animation->timeContainer() == this);
67 ASSERT(target); 67 ASSERT(target);
(...skipping 28 matching lines...) Expand all
96 ASSERT(scheduled); 96 ASSERT(scheduled);
97 size_t idx = scheduled->find(animation); 97 size_t idx = scheduled->find(animation);
98 ASSERT(idx != kNotFound); 98 ASSERT(idx != kNotFound);
99 scheduled->remove(idx); 99 scheduled->remove(idx);
100 } 100 }
101 101
102 void SMILTimeContainer::notifyIntervalsChanged() 102 void SMILTimeContainer::notifyIntervalsChanged()
103 { 103 {
104 // Schedule updateAnimations() to be called asynchronously so multiple inter vals 104 // Schedule updateAnimations() to be called asynchronously so multiple inter vals
105 // can change with updateAnimations() only called once at the end. 105 // can change with updateAnimations() only called once at the end.
106 startTimer(0); 106 scheduleAnimationFrame();
107 } 107 }
108 108
109 SMILTime SMILTimeContainer::elapsed() const 109 SMILTime SMILTimeContainer::elapsed() const
110 { 110 {
111 if (!m_beginTime) 111 if (!m_beginTime)
112 return 0; 112 return 0;
113 113
114 if (isPaused()) 114 if (isPaused())
115 return m_accumulatedActiveTime; 115 return m_accumulatedActiveTime;
116 116
(...skipping 16 matching lines...) Expand all
133 double now = currentTime(); 133 double now = currentTime();
134 134
135 // If 'm_presetStartTime' is set, the timeline was modified via setElapsed() before the document began. 135 // If 'm_presetStartTime' is set, the timeline was modified via setElapsed() before the document began.
136 // In this case pass on 'seekToTime=true' to updateAnimations(). 136 // In this case pass on 'seekToTime=true' to updateAnimations().
137 m_beginTime = now - m_presetStartTime; 137 m_beginTime = now - m_presetStartTime;
138 updateAnimations(SMILTime(m_presetStartTime), m_presetStartTime ? true : fal se); 138 updateAnimations(SMILTime(m_presetStartTime), m_presetStartTime ? true : fal se);
139 m_presetStartTime = 0; 139 m_presetStartTime = 0;
140 140
141 if (m_pauseTime) { 141 if (m_pauseTime) {
142 m_pauseTime = now; 142 m_pauseTime = now;
143 m_timer.stop(); 143 cancelAnimationFrame();
144 } 144 }
145 } 145 }
146 146
147 void SMILTimeContainer::pause() 147 void SMILTimeContainer::pause()
148 { 148 {
149 ASSERT(!isPaused()); 149 ASSERT(!isPaused());
150 m_pauseTime = currentTime(); 150 m_pauseTime = currentTime();
151 151
152 if (m_beginTime) { 152 if (m_beginTime) {
153 m_accumulatedActiveTime += m_pauseTime - lastResumeTime(); 153 m_accumulatedActiveTime += m_pauseTime - lastResumeTime();
154 m_timer.stop(); 154 cancelAnimationFrame();
155 } 155 }
156 m_resumeTime = 0; 156 m_resumeTime = 0;
157 } 157 }
158 158
159 void SMILTimeContainer::resume() 159 void SMILTimeContainer::resume()
160 { 160 {
161 ASSERT(isPaused()); 161 ASSERT(isPaused());
162 m_resumeTime = currentTime(); 162 m_resumeTime = currentTime();
163 163
164 m_pauseTime = 0; 164 m_pauseTime = 0;
165 startTimer(0); 165 scheduleAnimationFrame();
166 } 166 }
167 167
168 void SMILTimeContainer::setElapsed(SMILTime time) 168 void SMILTimeContainer::setElapsed(SMILTime time)
169 { 169 {
170 // If the documment didn't begin yet, record a new start time, we'll seek to once its possible. 170 // If the documment didn't begin yet, record a new start time, we'll seek to once its possible.
171 if (!m_beginTime) { 171 if (!m_beginTime) {
172 m_presetStartTime = time.value(); 172 m_presetStartTime = time.value();
173 return; 173 return;
174 } 174 }
175 175
176 if (m_beginTime) 176 if (m_beginTime)
177 m_timer.stop(); 177 cancelAnimationFrame();
178 178
179 double now = currentTime(); 179 double now = currentTime();
180 m_beginTime = now - time.value(); 180 m_beginTime = now - time.value();
181 m_resumeTime = 0; 181 m_resumeTime = 0;
182 if (m_pauseTime) { 182 if (m_pauseTime) {
183 m_pauseTime = now; 183 m_pauseTime = now;
184 m_accumulatedActiveTime = time.value(); 184 m_accumulatedActiveTime = time.value();
185 } else { 185 } else {
186 m_accumulatedActiveTime = 0; 186 m_accumulatedActiveTime = 0;
187 } 187 }
188 188
189 #ifndef NDEBUG 189 #ifndef NDEBUG
190 m_preventScheduledAnimationsChanges = true; 190 m_preventScheduledAnimationsChanges = true;
191 #endif 191 #endif
192 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end(); 192 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end();
193 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) { 193 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) {
194 AnimationsVector* scheduled = it->value.get(); 194 AnimationsVector* scheduled = it->value.get();
195 unsigned size = scheduled->size(); 195 unsigned size = scheduled->size();
196 for (unsigned n = 0; n < size; n++) 196 for (unsigned n = 0; n < size; n++)
197 scheduled->at(n)->reset(); 197 scheduled->at(n)->reset();
198 } 198 }
199 #ifndef NDEBUG 199 #ifndef NDEBUG
200 m_preventScheduledAnimationsChanges = false; 200 m_preventScheduledAnimationsChanges = false;
201 #endif 201 #endif
202 202
203 updateAnimations(time, true); 203 updateAnimations(time, true);
204 } 204 }
205 205
206 void SMILTimeContainer::startTimer(SMILTime fireTime, SMILTime minimumDelay) 206 bool SMILTimeContainer::isTimelineRunning() const
207 { 207 {
208 if (!m_beginTime || isPaused()) 208 return m_beginTime && !isPaused();
209 }
210
211 void SMILTimeContainer::scheduleAnimationFrame(SMILTime fireTime)
212 {
213 if (!isTimelineRunning())
209 return; 214 return;
210 215
211 if (!fireTime.isFinite()) 216 if (!fireTime.isFinite())
212 return; 217 return;
213 218
214 SMILTime delay = max(fireTime - elapsed(), minimumDelay); 219 SMILTime delay = max(fireTime - elapsed(), SMILTime(animationFrameDelay));
215 m_timer.startOneShot(delay.value()); 220 m_timer.startOneShot(delay.value());
216 } 221 }
217 222
223 void SMILTimeContainer::scheduleAnimationFrame()
224 {
225 if (!isTimelineRunning())
226 return;
227
228 m_timer.startOneShot(0);
229 }
230
231 void SMILTimeContainer::cancelAnimationFrame()
232 {
233 m_timer.stop();
234 }
235
218 void SMILTimeContainer::timerFired(Timer<SMILTimeContainer>*) 236 void SMILTimeContainer::timerFired(Timer<SMILTimeContainer>*)
219 { 237 {
220 ASSERT(m_beginTime); 238 ASSERT(isTimelineRunning());
221 ASSERT(!m_pauseTime);
222 updateAnimations(elapsed()); 239 updateAnimations(elapsed());
223 } 240 }
224 241
225 void SMILTimeContainer::updateDocumentOrderIndexes() 242 void SMILTimeContainer::updateDocumentOrderIndexes()
226 { 243 {
227 unsigned timingElementCount = 0; 244 unsigned timingElementCount = 0;
228 for (Element* element = m_ownerSVGElement; element; element = ElementTravers al::next(*element, m_ownerSVGElement)) { 245 for (Element* element = m_ownerSVGElement; element; element = ElementTravers al::next(*element, m_ownerSVGElement)) {
229 if (isSVGSMILElement(*element)) 246 if (isSVGSMILElement(*element))
230 toSVGSMILElement(element)->setDocumentOrderIndex(timingElementCount+ +); 247 toSVGSMILElement(element)->setDocumentOrderIndex(timingElementCount+ +);
231 } 248 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 animationsToApply.append(resultElement); 319 animationsToApply.append(resultElement);
303 } 320 }
304 321
305 std::sort(animationsToApply.begin(), animationsToApply.end(), PriorityCompar e(elapsed)); 322 std::sort(animationsToApply.begin(), animationsToApply.end(), PriorityCompar e(elapsed));
306 323
307 unsigned animationsToApplySize = animationsToApply.size(); 324 unsigned animationsToApplySize = animationsToApply.size();
308 if (!animationsToApplySize) { 325 if (!animationsToApplySize) {
309 #ifndef NDEBUG 326 #ifndef NDEBUG
310 m_preventScheduledAnimationsChanges = false; 327 m_preventScheduledAnimationsChanges = false;
311 #endif 328 #endif
312 startTimer(earliestFireTime, animationFrameDelay); 329 scheduleAnimationFrame(earliestFireTime);
313 return; 330 return;
314 } 331 }
315 332
316 // Apply results to target elements. 333 // Apply results to target elements.
317 for (unsigned i = 0; i < animationsToApplySize; ++i) 334 for (unsigned i = 0; i < animationsToApplySize; ++i)
318 animationsToApply[i]->applyResultsToTarget(); 335 animationsToApply[i]->applyResultsToTarget();
319 336
320 #ifndef NDEBUG 337 #ifndef NDEBUG
321 m_preventScheduledAnimationsChanges = false; 338 m_preventScheduledAnimationsChanges = false;
322 #endif 339 #endif
323 340
324 startTimer(earliestFireTime, animationFrameDelay); 341 scheduleAnimationFrame(earliestFireTime);
325 342
326 for (unsigned i = 0; i < animationsToApplySize; ++i) { 343 for (unsigned i = 0; i < animationsToApplySize; ++i) {
327 if (animationsToApply[i]->inDocument() && animationsToApply[i]->isSVGDis cardElement()) { 344 if (animationsToApply[i]->inDocument() && animationsToApply[i]->isSVGDis cardElement()) {
328 RefPtr<SVGSMILElement> animDiscard = animationsToApply[i]; 345 RefPtr<SVGSMILElement> animDiscard = animationsToApply[i];
329 RefPtr<SVGElement> targetElement = animDiscard->targetElement(); 346 RefPtr<SVGElement> targetElement = animDiscard->targetElement();
330 if (targetElement && targetElement->inDocument()) { 347 if (targetElement && targetElement->inDocument()) {
331 targetElement->remove(IGNORE_EXCEPTION); 348 targetElement->remove(IGNORE_EXCEPTION);
332 ASSERT(!targetElement->inDocument()); 349 ASSERT(!targetElement->inDocument());
333 } 350 }
334 351
335 if (animDiscard->inDocument()) { 352 if (animDiscard->inDocument()) {
336 animDiscard->remove(IGNORE_EXCEPTION); 353 animDiscard->remove(IGNORE_EXCEPTION);
337 ASSERT(!animDiscard->inDocument()); 354 ASSERT(!animDiscard->inDocument());
338 } 355 }
339 } 356 }
340 } 357 }
341 } 358 }
342 359
343 } 360 }
OLDNEW
« no previous file with comments | « Source/core/svg/animation/SMILTimeContainer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698