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

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

Issue 137443012: [SVG] Apply animations in sorted order based on begin time and document order (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebaselined and worked on review comments Created 6 years, 11 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 | « 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 unsigned timingElementCount = 0; 227 unsigned timingElementCount = 0;
228 for (Element* element = m_ownerSVGElement; element; element = ElementTravers al::next(*element, m_ownerSVGElement)) { 228 for (Element* element = m_ownerSVGElement; element; element = ElementTravers al::next(*element, m_ownerSVGElement)) {
229 if (isSVGSMILElement(*element)) 229 if (isSVGSMILElement(*element))
230 toSVGSMILElement(element)->setDocumentOrderIndex(timingElementCount+ +); 230 toSVGSMILElement(element)->setDocumentOrderIndex(timingElementCount+ +);
231 } 231 }
232 m_documentOrderIndexesDirty = false; 232 m_documentOrderIndexesDirty = false;
233 } 233 }
234 234
235 struct PriorityCompare { 235 struct PriorityCompare {
236 PriorityCompare(SMILTime elapsed) : m_elapsed(elapsed) {} 236 PriorityCompare(SMILTime elapsed) : m_elapsed(elapsed) {}
237 bool operator()(SVGSMILElement* a, SVGSMILElement* b) 237 bool operator()(const RefPtr<SVGSMILElement>& a, const RefPtr<SVGSMILElement >& b)
238 { 238 {
239 // FIXME: This should also consider possible timing relations between th e elements. 239 // FIXME: This should also consider possible timing relations between th e elements.
240 SMILTime aBegin = a->intervalBegin(); 240 SMILTime aBegin = a->intervalBegin();
241 SMILTime bBegin = b->intervalBegin(); 241 SMILTime bBegin = b->intervalBegin();
242 // Frozen elements need to be prioritized based on their previous interv al. 242 // Frozen elements need to be prioritized based on their previous interv al.
243 aBegin = a->isFrozen() && m_elapsed < aBegin ? a->previousIntervalBegin( ) : aBegin; 243 aBegin = a->isFrozen() && m_elapsed < aBegin ? a->previousIntervalBegin( ) : aBegin;
244 bBegin = b->isFrozen() && m_elapsed < bBegin ? b->previousIntervalBegin( ) : bBegin; 244 bBegin = b->isFrozen() && m_elapsed < bBegin ? b->previousIntervalBegin( ) : bBegin;
245 if (aBegin == bBegin) 245 if (aBegin == bBegin)
246 return a->documentOrderIndex() < b->documentOrderIndex(); 246 return a->documentOrderIndex() < b->documentOrderIndex();
247 return aBegin < bBegin; 247 return aBegin < bBegin;
248 } 248 }
249 SMILTime m_elapsed; 249 SMILTime m_elapsed;
250 }; 250 };
251 251
252 void SMILTimeContainer::sortByPriority(Vector<SVGSMILElement*>& smilElements, SM ILTime elapsed)
253 {
254 if (m_documentOrderIndexesDirty)
255 updateDocumentOrderIndexes();
256 std::sort(smilElements.begin(), smilElements.end(), PriorityCompare(elapsed) );
257 }
258
259 void SMILTimeContainer::updateAnimations(SMILTime elapsed, bool seekToTime) 252 void SMILTimeContainer::updateAnimations(SMILTime elapsed, bool seekToTime)
260 { 253 {
261 SMILTime earliestFireTime = SMILTime::unresolved(); 254 SMILTime earliestFireTime = SMILTime::unresolved();
262 255
263 #ifndef NDEBUG 256 #ifndef NDEBUG
264 // This boolean will catch any attempts to schedule/unschedule scheduledAnim ations during this critical section. 257 // This boolean will catch any attempts to schedule/unschedule scheduledAnim ations during this critical section.
265 // Similarly, any elements removed will unschedule themselves, so this will catch modification of animationsToApply. 258 // Similarly, any elements removed will unschedule themselves, so this will catch modification of animationsToApply.
266 m_preventScheduledAnimationsChanges = true; 259 m_preventScheduledAnimationsChanges = true;
267 #endif 260 #endif
268 261
262 if (m_documentOrderIndexesDirty)
263 updateDocumentOrderIndexes();
264
269 Vector<RefPtr<SVGSMILElement> > animationsToApply; 265 Vector<RefPtr<SVGSMILElement> > animationsToApply;
270 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end(); 266 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end();
271 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) { 267 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) {
272 AnimationsVector* scheduled = it->value.get(); 268 AnimationsVector* scheduled = it->value.get();
273 269
274 // Sort according to priority. Elements with later begin time have highe r priority. 270 // Sort according to priority. Elements with later begin time have highe r priority.
275 // In case of a tie, document order decides. 271 // In case of a tie, document order decides.
276 // FIXME: This should also consider timing relationships between the ele ments. Dependents 272 // FIXME: This should also consider timing relationships between the ele ments. Dependents
277 // have higher priority. 273 // have higher priority.
278 sortByPriority(*scheduled, elapsed); 274 std::sort(scheduled->begin(), scheduled->end(), PriorityCompare(elapsed) );
279 275
280 SVGSMILElement* resultElement = 0; 276 SVGSMILElement* resultElement = 0;
281 unsigned size = scheduled->size(); 277 unsigned size = scheduled->size();
282 for (unsigned n = 0; n < size; n++) { 278 for (unsigned n = 0; n < size; n++) {
283 SVGSMILElement* animation = scheduled->at(n); 279 SVGSMILElement* animation = scheduled->at(n);
284 ASSERT(animation->timeContainer() == this); 280 ASSERT(animation->timeContainer() == this);
285 ASSERT(animation->targetElement()); 281 ASSERT(animation->targetElement());
286 ASSERT(animation->hasValidAttributeName()); 282 ASSERT(animation->hasValidAttributeName());
287 283
288 // Results are accumulated to the first animation that animates and contributes to a particular element/attribute pair. 284 // Results are accumulated to the first animation that animates and contributes to a particular element/attribute pair.
(...skipping 10 matching lines...) Expand all
299 295
300 SMILTime nextFireTime = animation->nextProgressTime(); 296 SMILTime nextFireTime = animation->nextProgressTime();
301 if (nextFireTime.isFinite()) 297 if (nextFireTime.isFinite())
302 earliestFireTime = min(nextFireTime, earliestFireTime); 298 earliestFireTime = min(nextFireTime, earliestFireTime);
303 } 299 }
304 300
305 if (resultElement) 301 if (resultElement)
306 animationsToApply.append(resultElement); 302 animationsToApply.append(resultElement);
307 } 303 }
308 304
305 std::sort(animationsToApply.begin(), animationsToApply.end(), PriorityCompar e(elapsed));
306
309 unsigned animationsToApplySize = animationsToApply.size(); 307 unsigned animationsToApplySize = animationsToApply.size();
310 if (!animationsToApplySize) { 308 if (!animationsToApplySize) {
311 #ifndef NDEBUG 309 #ifndef NDEBUG
312 m_preventScheduledAnimationsChanges = false; 310 m_preventScheduledAnimationsChanges = false;
313 #endif 311 #endif
314 startTimer(earliestFireTime, animationFrameDelay); 312 startTimer(earliestFireTime, animationFrameDelay);
315 return; 313 return;
316 } 314 }
317 315
318 // Apply results to target elements. 316 // Apply results to target elements.
(...skipping 17 matching lines...) Expand all
336 334
337 if (animDiscard->inDocument()) { 335 if (animDiscard->inDocument()) {
338 animDiscard->remove(IGNORE_EXCEPTION); 336 animDiscard->remove(IGNORE_EXCEPTION);
339 ASSERT(!animDiscard->inDocument()); 337 ASSERT(!animDiscard->inDocument());
340 } 338 }
341 } 339 }
342 } 340 }
343 } 341 }
344 342
345 } 343 }
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