Commit 30fa2a67 authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

[Reland] Change SMILTimeContainer::scheduled_animations_ to use ephemeron

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iccd919105fd31fbe83b75d87f15f206e5ad30d36
Reviewed-on: https://chromium-review.googlesource.com/1179514
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584356}
parent 71bce329
...@@ -79,9 +79,11 @@ void SMILTimeContainer::Schedule(SVGSMILElement* animation, ...@@ -79,9 +79,11 @@ void SMILTimeContainer::Schedule(SVGSMILElement* animation,
DCHECK(!prevent_scheduled_animations_changes_); DCHECK(!prevent_scheduled_animations_changes_);
#endif #endif
ElementAttributePair key(target, attribute_name); AttributeAnimationsMap& attribute_map =
scheduled_animations_.insert(target, AttributeAnimationsMap())
.stored_value->value;
Member<AnimationsLinkedHashSet>& scheduled = Member<AnimationsLinkedHashSet>& scheduled =
scheduled_animations_.insert(key, nullptr).stored_value->value; attribute_map.insert(attribute_name, nullptr).stored_value->value;
if (!scheduled) if (!scheduled)
scheduled = new AnimationsLinkedHashSet; scheduled = new AnimationsLinkedHashSet;
DCHECK(!scheduled->Contains(animation)); DCHECK(!scheduled->Contains(animation));
...@@ -101,16 +103,20 @@ void SMILTimeContainer::Unschedule(SVGSMILElement* animation, ...@@ -101,16 +103,20 @@ void SMILTimeContainer::Unschedule(SVGSMILElement* animation,
DCHECK(!prevent_scheduled_animations_changes_); DCHECK(!prevent_scheduled_animations_changes_);
#endif #endif
ElementAttributePair key(target, attribute_name); GroupedAnimationsMap::iterator it = scheduled_animations_.find(target);
GroupedAnimationsMap::iterator it = scheduled_animations_.find(key); CHECK(it != scheduled_animations_.end());
DCHECK_NE(it, scheduled_animations_.end()); AttributeAnimationsMap& attribute_map = it->value;
AnimationsLinkedHashSet* scheduled = it->value.Get(); AttributeAnimationsMap::iterator attribute_map_it =
DCHECK(scheduled); attribute_map.find(attribute_name);
DCHECK(attribute_map_it != attribute_map.end());
AnimationsLinkedHashSet* scheduled = attribute_map_it->value;
AnimationsLinkedHashSet::iterator it_animation = scheduled->find(animation); AnimationsLinkedHashSet::iterator it_animation = scheduled->find(animation);
DCHECK(it_animation != scheduled->end()); DCHECK(it_animation != scheduled->end());
scheduled->erase(it_animation); scheduled->erase(it_animation);
if (scheduled->IsEmpty()) if (scheduled->IsEmpty())
attribute_map.erase(attribute_map_it);
if (attribute_map.IsEmpty())
scheduled_animations_.erase(it); scheduled_animations_.erase(it);
} }
...@@ -229,13 +235,13 @@ void SMILTimeContainer::SetElapsed(double elapsed) { ...@@ -229,13 +235,13 @@ void SMILTimeContainer::SetElapsed(double elapsed) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
prevent_scheduled_animations_changes_ = true; prevent_scheduled_animations_changes_ = true;
#endif #endif
for (const auto& entry : scheduled_animations_) { for (const auto& attribute_entry : scheduled_animations_) {
if (!entry.key.first) for (const auto& entry : attribute_entry.value) {
continue; const AnimationsLinkedHashSet* scheduled = entry.value;
for (SVGSMILElement* element : *scheduled) {
AnimationsLinkedHashSet* scheduled = entry.value.Get(); element->Reset();
for (SVGSMILElement* element : *scheduled) }
element->Reset(); }
} }
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
prevent_scheduled_animations_changes_ = false; prevent_scheduled_animations_changes_ = false;
...@@ -428,62 +434,66 @@ SMILTime SMILTimeContainer::UpdateAnimations(double elapsed, ...@@ -428,62 +434,66 @@ SMILTime SMILTimeContainer::UpdateAnimations(double elapsed,
if (document_order_indexes_dirty_) if (document_order_indexes_dirty_)
UpdateDocumentOrderIndexes(); UpdateDocumentOrderIndexes();
HeapHashSet<ElementAttributePair> invalid_keys;
using AnimationsVector = HeapVector<Member<SVGSMILElement>>; using AnimationsVector = HeapVector<Member<SVGSMILElement>>;
AnimationsVector animations_to_apply; AnimationsVector animations_to_apply;
AnimationsVector scheduled_animations_in_same_group; AnimationsVector scheduled_animations_in_same_group;
for (const auto& entry : scheduled_animations_) { for (auto& attribute_entry : scheduled_animations_) {
if (!entry.key.first || entry.value->IsEmpty()) { AttributeAnimationsMap& attribute_map = attribute_entry.value;
invalid_keys.insert(entry.key); Vector<QualifiedName> invalid_keys;
continue; for (const auto& entry : attribute_map) {
} DCHECK(entry.value);
if (entry.value->IsEmpty()) {
// Sort according to priority. Elements with later begin time have higher invalid_keys.push_back(entry.key);
// priority. In case of a tie, document order decides. continue;
// FIXME: This should also consider timing relationships between the
// elements. Dependents have higher priority.
CopyToVector(*entry.value, scheduled_animations_in_same_group);
std::sort(scheduled_animations_in_same_group.begin(),
scheduled_animations_in_same_group.end(),
PriorityCompare(elapsed));
AnimationsVector sandwich;
for (const auto& it_animation : scheduled_animations_in_same_group) {
SVGSMILElement* animation = it_animation.Get();
DCHECK_EQ(animation->TimeContainer(), this);
DCHECK(animation->HasValidTarget());
// This will calculate the contribution from the animation and update
// timing.
if (animation->Progress(elapsed, seek_to_time)) {
sandwich.push_back(animation);
} else {
animation->ClearAnimatedType();
} }
SMILTime next_fire_time = animation->NextProgressTime(); // Sort according to priority. Elements with later begin time have higher
if (next_fire_time.IsFinite()) // priority. In case of a tie, document order decides.
earliest_fire_time = std::min(next_fire_time, earliest_fire_time); // FIXME: This should also consider timing relationships between the
} // elements. Dependents have higher priority.
CopyToVector(*entry.value, scheduled_animations_in_same_group);
std::sort(scheduled_animations_in_same_group.begin(),
scheduled_animations_in_same_group.end(),
PriorityCompare(elapsed));
AnimationsVector sandwich;
for (const auto& it_animation : scheduled_animations_in_same_group) {
SVGSMILElement* animation = it_animation.Get();
DCHECK_EQ(animation->TimeContainer(), this);
DCHECK(animation->HasValidTarget());
// This will calculate the contribution from the animation and update
// timing.
if (animation->Progress(elapsed, seek_to_time)) {
sandwich.push_back(animation);
} else {
animation->ClearAnimatedType();
}
SMILTime next_fire_time = animation->NextProgressTime();
if (next_fire_time.IsFinite())
earliest_fire_time = std::min(next_fire_time, earliest_fire_time);
}
if (!sandwich.IsEmpty()) { if (!sandwich.IsEmpty()) {
// Results are accumulated to the first animation that animates and // Results are accumulated to the first animation that animates and
// contributes to a particular element/attribute pair. // contributes to a particular element/attribute pair.
// Only reset the animated type to the base value once for // Only reset the animated type to the base value once for
// the lowest priority animation that animates and // the lowest priority animation that animates and
// contributes to a particular element/attribute pair. // contributes to a particular element/attribute pair.
SVGSMILElement* result_element = sandwich.front(); SVGSMILElement* result_element = sandwich.front();
result_element->ResetAnimatedType(); result_element->ResetAnimatedType();
// Go through the sandwich from lowest prio to highest and generate // Go through the sandwich from lowest prio to highest and generate
// the animated value (if any.) // the animated value (if any.)
for (const auto& animation : sandwich) for (const auto& animation : sandwich)
animation->UpdateAnimatedValue(result_element); animation->UpdateAnimatedValue(result_element);
animations_to_apply.push_back(result_element); animations_to_apply.push_back(result_element);
}
} }
attribute_map.RemoveAll(invalid_keys);
} }
scheduled_animations_.RemoveAll(invalid_keys);
if (animations_to_apply.IsEmpty()) { if (animations_to_apply.IsEmpty()) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
......
...@@ -135,10 +135,11 @@ class SMILTimeContainer : public GarbageCollectedFinalized<SMILTimeContainer> { ...@@ -135,10 +135,11 @@ class SMILTimeContainer : public GarbageCollectedFinalized<SMILTimeContainer> {
TaskRunnerTimer<SMILTimeContainer> wakeup_timer_; TaskRunnerTimer<SMILTimeContainer> wakeup_timer_;
TaskRunnerTimer<SMILTimeContainer> animation_policy_once_timer_; TaskRunnerTimer<SMILTimeContainer> animation_policy_once_timer_;
using ElementAttributePair = std::pair<WeakMember<SVGElement>, QualifiedName>;
using AnimationsLinkedHashSet = HeapLinkedHashSet<WeakMember<SVGSMILElement>>; using AnimationsLinkedHashSet = HeapLinkedHashSet<WeakMember<SVGSMILElement>>;
using AttributeAnimationsMap =
HeapHashMap<QualifiedName, Member<AnimationsLinkedHashSet>>;
using GroupedAnimationsMap = using GroupedAnimationsMap =
HeapHashMap<ElementAttributePair, Member<AnimationsLinkedHashSet>>; HeapHashMap<WeakMember<SVGElement>, AttributeAnimationsMap>;
GroupedAnimationsMap scheduled_animations_; GroupedAnimationsMap scheduled_animations_;
Member<SVGSVGElement> owner_svg_element_; Member<SVGSVGElement> owner_svg_element_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment