OLD | NEW |
---|---|
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 { | 80 { |
81 ASSERT(animation->timeContainer() == this); | 81 ASSERT(animation->timeContainer() == this); |
82 ASSERT(target); | 82 ASSERT(target); |
83 ASSERT(animation->hasValidAttributeName()); | 83 ASSERT(animation->hasValidAttributeName()); |
84 | 84 |
85 #ifndef NDEBUG | 85 #ifndef NDEBUG |
86 ASSERT(!m_preventScheduledAnimationsChanges); | 86 ASSERT(!m_preventScheduledAnimationsChanges); |
87 #endif | 87 #endif |
88 | 88 |
89 ElementAttributePair key(target, attributeName); | 89 ElementAttributePair key(target, attributeName); |
90 OwnPtr<AnimationsVector>& scheduled = m_scheduledAnimations.add(key, nullptr ).storedValue->value; | 90 OwnPtrWillBeMember<AnimationsLinkedHashSet>& scheduled = m_scheduledAnimatio ns.add(key, nullptr).storedValue->value; |
91 if (!scheduled) | 91 if (!scheduled) |
92 scheduled = adoptPtr(new AnimationsVector); | 92 scheduled = adoptPtrWillBeNoop(new AnimationsLinkedHashSet); |
93 ASSERT(!scheduled->contains(animation)); | 93 ASSERT(!scheduled->contains(animation)); |
94 scheduled->append(animation); | 94 scheduled->add(animation); |
95 | 95 |
96 SMILTime nextFireTime = animation->nextProgressTime(); | 96 SMILTime nextFireTime = animation->nextProgressTime(); |
97 if (nextFireTime.isFinite()) | 97 if (nextFireTime.isFinite()) |
98 notifyIntervalsChanged(); | 98 notifyIntervalsChanged(); |
99 } | 99 } |
100 | 100 |
101 void SMILTimeContainer::unschedule(SVGSMILElement* animation, SVGElement* target , const QualifiedName& attributeName) | 101 void SMILTimeContainer::unschedule(SVGSMILElement* animation, SVGElement* target , const QualifiedName& attributeName) |
102 { | 102 { |
103 ASSERT(animation->timeContainer() == this); | 103 ASSERT(animation->timeContainer() == this); |
104 | 104 |
105 #ifndef NDEBUG | 105 #ifndef NDEBUG |
106 ASSERT(!m_preventScheduledAnimationsChanges); | 106 ASSERT(!m_preventScheduledAnimationsChanges); |
107 #endif | 107 #endif |
108 | 108 |
109 ElementAttributePair key(target, attributeName); | 109 ElementAttributePair key(target, attributeName); |
110 AnimationsVector* scheduled = m_scheduledAnimations.get(key); | 110 GroupedAnimationsMap::iterator it = m_scheduledAnimations.find(key); |
111 ASSERT(it != m_scheduledAnimations.end()); | |
112 AnimationsLinkedHashSet* scheduled = it->value.get(); | |
111 ASSERT(scheduled); | 113 ASSERT(scheduled); |
112 size_t idx = scheduled->find(animation); | 114 AnimationsLinkedHashSet::iterator itAnimation = scheduled->find(animation); |
113 ASSERT(idx != kNotFound); | 115 ASSERT(itAnimation != scheduled->end()); |
114 scheduled->remove(idx); | 116 scheduled->remove(itAnimation); |
117 | |
118 if (scheduled->isEmpty()) | |
119 m_scheduledAnimations.remove(it); | |
115 } | 120 } |
116 | 121 |
117 bool SMILTimeContainer::hasAnimations() const | 122 bool SMILTimeContainer::hasAnimations() const |
118 { | 123 { |
119 return !m_scheduledAnimations.isEmpty(); | 124 return !m_scheduledAnimations.isEmpty(); |
120 } | 125 } |
121 | 126 |
122 bool SMILTimeContainer::hasPendingSynchronization() const | 127 bool SMILTimeContainer::hasPendingSynchronization() const |
123 { | 128 { |
124 return m_frameSchedulingState == SynchronizeAnimations && m_wakeupTimer.isAc tive() && !m_wakeupTimer.nextFireInterval(); | 129 return m_frameSchedulingState == SynchronizeAnimations && m_wakeupTimer.isAc tive() && !m_wakeupTimer.nextFireInterval(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 m_accumulatedActiveTime = time.value(); | 233 m_accumulatedActiveTime = time.value(); |
229 } else { | 234 } else { |
230 m_accumulatedActiveTime = 0; | 235 m_accumulatedActiveTime = 0; |
231 } | 236 } |
232 | 237 |
233 #ifndef NDEBUG | 238 #ifndef NDEBUG |
234 m_preventScheduledAnimationsChanges = true; | 239 m_preventScheduledAnimationsChanges = true; |
235 #endif | 240 #endif |
236 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end(); | 241 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end(); |
237 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) { | 242 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) { |
238 AnimationsVector* scheduled = it->value.get(); | 243 if (!it->key.first) |
239 unsigned size = scheduled->size(); | 244 continue; |
240 for (unsigned n = 0; n < size; n++) | 245 |
241 scheduled->at(n)->reset(); | 246 AnimationsLinkedHashSet* scheduled = it->value.get(); |
247 for (AnimationsLinkedHashSet::const_iterator itAnimation = scheduled->be gin(), itAnimationEnd = scheduled->end(); itAnimation != itAnimationEnd; ++itAni mation) | |
248 (*itAnimation)->reset(); | |
242 } | 249 } |
243 #ifndef NDEBUG | 250 #ifndef NDEBUG |
244 m_preventScheduledAnimationsChanges = false; | 251 m_preventScheduledAnimationsChanges = false; |
245 #endif | 252 #endif |
246 | 253 |
247 updateAnimationsAndScheduleFrameIfNeeded(time, true); | 254 updateAnimationsAndScheduleFrameIfNeeded(time, true); |
248 } | 255 } |
249 | 256 |
250 bool SMILTimeContainer::isTimelineRunning() const | 257 bool SMILTimeContainer::isTimelineRunning() const |
251 { | 258 { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 | 376 |
370 #ifndef NDEBUG | 377 #ifndef NDEBUG |
371 // This boolean will catch any attempts to schedule/unschedule scheduledAnim ations during this critical section. | 378 // This boolean will catch any attempts to schedule/unschedule scheduledAnim ations during this critical section. |
372 // Similarly, any elements removed will unschedule themselves, so this will catch modification of animationsToApply. | 379 // Similarly, any elements removed will unschedule themselves, so this will catch modification of animationsToApply. |
373 m_preventScheduledAnimationsChanges = true; | 380 m_preventScheduledAnimationsChanges = true; |
374 #endif | 381 #endif |
375 | 382 |
376 if (m_documentOrderIndexesDirty) | 383 if (m_documentOrderIndexesDirty) |
377 updateDocumentOrderIndexes(); | 384 updateDocumentOrderIndexes(); |
378 | 385 |
379 WillBeHeapVector<RefPtrWillBeMember<SVGSMILElement> > animationsToApply; | 386 WillBeHeapHashSet<ElementAttributePair> invalidKeys; |
380 GroupedAnimationsMap::iterator end = m_scheduledAnimations.end(); | 387 typedef WillBeHeapVector<RefPtrWillBeMember<SVGSMILElement> > AnimationsVect or; |
381 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it ! = end; ++it) { | 388 AnimationsVector animationsToApply; |
382 AnimationsVector* scheduled = it->value.get(); | 389 for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(), end = m_scheduledAnimations.end(); it != end; ++it) { |
390 if (!it->key.first || it->value->isEmpty()) { | |
391 invalidKeys.add(it->key); | |
392 continue; | |
393 } | |
394 | |
395 AnimationsLinkedHashSet* scheduled = it->value.get(); | |
383 | 396 |
384 // Sort according to priority. Elements with later begin time have highe r priority. | 397 // Sort according to priority. Elements with later begin time have highe r priority. |
385 // In case of a tie, document order decides. | 398 // In case of a tie, document order decides. |
386 // FIXME: This should also consider timing relationships between the ele ments. Dependents | 399 // FIXME: This should also consider timing relationships between the ele ments. Dependents |
387 // have higher priority. | 400 // have higher priority. |
388 std::sort(scheduled->begin(), scheduled->end(), PriorityCompare(elapsed) ); | 401 AnimationsVector scheduledAnimations; |
402 copyToVector(*scheduled, scheduledAnimations); | |
403 std::sort(scheduledAnimations.begin(), scheduledAnimations.end(), Priori tyCompare(elapsed)); | |
389 | 404 |
390 SVGSMILElement* resultElement = 0; | 405 SVGSMILElement* resultElement = 0; |
391 unsigned size = scheduled->size(); | 406 for (AnimationsVector::const_iterator itAnimation = scheduledAnimations. begin(), itAnimationEnd = scheduledAnimations.end(); itAnimation != itAnimationE nd; ++itAnimation) { |
392 for (unsigned n = 0; n < size; n++) { | 407 SVGSMILElement* animation = itAnimation->get(); |
393 SVGSMILElement* animation = scheduled->at(n); | |
394 ASSERT(animation->timeContainer() == this); | 408 ASSERT(animation->timeContainer() == this); |
395 ASSERT(animation->targetElement()); | 409 ASSERT(animation->targetElement()); |
396 ASSERT(animation->hasValidAttributeName()); | 410 ASSERT(animation->hasValidAttributeName()); |
397 | 411 |
398 // Results are accumulated to the first animation that animates and contributes to a particular element/attribute pair. | 412 // Results are accumulated to the first animation that animates and contributes to a particular element/attribute pair. |
399 // FIXME: we should ensure that resultElement is of an appropriate t ype. | 413 // FIXME: we should ensure that resultElement is of an appropriate t ype. |
400 if (!resultElement) { | 414 if (!resultElement) { |
401 if (!animation->hasValidAttributeType()) | 415 if (!animation->hasValidAttributeType()) |
402 continue; | 416 continue; |
403 resultElement = animation; | 417 resultElement = animation; |
404 } | 418 } |
405 | 419 |
406 // This will calculate the contribution from the animation and add i t to the resultsElement. | 420 // This will calculate the contribution from the animation and add i t to the resultsElement. |
407 if (!animation->progress(elapsed, resultElement, seekToTime) && resu ltElement == animation) | 421 if (!animation->progress(elapsed, resultElement, seekToTime) && resu ltElement == animation) |
408 resultElement = 0; | 422 resultElement = 0; |
409 | 423 |
410 SMILTime nextFireTime = animation->nextProgressTime(); | 424 SMILTime nextFireTime = animation->nextProgressTime(); |
411 if (nextFireTime.isFinite()) | 425 if (nextFireTime.isFinite()) |
412 earliestFireTime = min(nextFireTime, earliestFireTime); | 426 earliestFireTime = min(nextFireTime, earliestFireTime); |
413 } | 427 } |
414 | 428 |
415 if (resultElement) | 429 if (resultElement) |
416 animationsToApply.append(resultElement); | 430 animationsToApply.append(resultElement); |
417 } | 431 } |
432 m_scheduledAnimations.removeAll(invalidKeys); | |
Erik Corry
2014/05/28 14:00:09
I just realized that this will never remove anythi
| |
418 | 433 |
419 std::sort(animationsToApply.begin(), animationsToApply.end(), PriorityCompar e(elapsed)); | 434 std::sort(animationsToApply.begin(), animationsToApply.end(), PriorityCompar e(elapsed)); |
420 | 435 |
421 unsigned animationsToApplySize = animationsToApply.size(); | 436 unsigned animationsToApplySize = animationsToApply.size(); |
422 if (!animationsToApplySize) { | 437 if (!animationsToApplySize) { |
423 #ifndef NDEBUG | 438 #ifndef NDEBUG |
424 m_preventScheduledAnimationsChanges = false; | 439 m_preventScheduledAnimationsChanges = false; |
425 #endif | 440 #endif |
426 return earliestFireTime; | 441 return earliestFireTime; |
427 } | 442 } |
(...skipping 17 matching lines...) Expand all Loading... | |
445 | 460 |
446 if (animDiscard->inDocument()) { | 461 if (animDiscard->inDocument()) { |
447 animDiscard->remove(IGNORE_EXCEPTION); | 462 animDiscard->remove(IGNORE_EXCEPTION); |
448 ASSERT(!animDiscard->inDocument()); | 463 ASSERT(!animDiscard->inDocument()); |
449 } | 464 } |
450 } | 465 } |
451 } | 466 } |
452 return earliestFireTime; | 467 return earliestFireTime; |
453 } | 468 } |
454 | 469 |
470 void SMILTimeContainer::trace(Visitor* visitor) | |
471 { | |
472 visitor->trace(m_scheduledAnimations); | |
455 } | 473 } |
474 | |
475 } | |
OLD | NEW |