Skip to content

Commit

Permalink
Bug 1923344. a=diannaS
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio authored and hackademix committed Oct 8, 2024
1 parent 1a766e2 commit 0697953
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
35 changes: 14 additions & 21 deletions dom/animation/AnimationTimeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,33 @@ AnimationTimeline::~AnimationTimeline() { mAnimationOrder.clear(); }
bool AnimationTimeline::Tick() {
bool needsTicks = false;

nsTArray<Animation*> animationsToRemove;

for (Animation* animation = mAnimationOrder.getFirst(); animation;
animation =
static_cast<LinkedListElement<Animation>*>(animation)->getNext()) {
AutoTArray<RefPtr<Animation>, 32> animationsToTick;
for (Animation* animation : mAnimationOrder) {
MOZ_ASSERT(mAnimations.Contains(animation),
"The sampling order list should be a subset of the hashset");
MOZ_ASSERT(!animation->IsHiddenByContentVisibility(),
"The sampling order list should not contain any animations "
"that are hidden by content-visibility");
animationsToTick.AppendElement(animation);
}

for (Animation* animation : animationsToTick) {
// Skip any animations that are longer need associated with this timeline.
if (animation->GetTimeline() != this) {
// If animation has some other timeline, it better not be also in the
// animation list of this timeline object!
MOZ_ASSERT(!animation->GetTimeline());
animationsToRemove.AppendElement(animation);
RemoveAnimation(animation);
continue;
}

needsTicks |= animation->NeedsTicks();
// Even if |animation| doesn't need future ticks, we should still
// Tick it this time around since it might just need a one-off tick in
// order to dispatch events.
// Even if |animation| doesn't need future ticks, we should still Tick it
// this time around since it might just need a one-off tick in order to
// dispatch events.
animation->Tick();

if (!animation->NeedsTicks()) {
animationsToRemove.AppendElement(animation);
RemoveAnimation(animation);
}
}

for (Animation* animation : animationsToRemove) {
RemoveAnimation(animation);
}

return needsTicks;
}

Expand All @@ -91,11 +83,12 @@ void AnimationTimeline::NotifyAnimationUpdated(Animation& aAnimation) {
}

void AnimationTimeline::RemoveAnimation(Animation* aAnimation) {
MOZ_ASSERT(!aAnimation->GetTimeline() || aAnimation->GetTimeline() == this);
if (static_cast<LinkedListElement<Animation>*>(aAnimation)->isInList()) {
if (static_cast<LinkedListElement<Animation>*>(aAnimation)->isInList() &&
MOZ_LIKELY(!aAnimation->GetTimeline() ||
aAnimation->GetTimeline() == this)) {
static_cast<LinkedListElement<Animation>*>(aAnimation)->remove();
MOZ_ASSERT(mAnimations.Contains(aAnimation),
"The sampling order list should be a subset of the hashset");
static_cast<LinkedListElement<Animation>*>(aAnimation)->remove();
}
mAnimations.Remove(aAnimation);
}
Expand Down
11 changes: 3 additions & 8 deletions dom/animation/ScrollTimelineAnimationTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ namespace mozilla {
NS_IMPL_CYCLE_COLLECTION(ScrollTimelineAnimationTracker, mPendingSet, mDocument)

void ScrollTimelineAnimationTracker::TriggerPendingAnimations() {
for (auto iter = mPendingSet.begin(), end = mPendingSet.end(); iter != end;
++iter) {
dom::Animation* animation = *iter;

for (RefPtr<dom::Animation>& animation :
ToTArray<AutoTArray<RefPtr<dom::Animation>, 32>>(mPendingSet)) {
MOZ_ASSERT(animation->GetTimeline() &&
!animation->GetTimeline()->IsMonotonicallyIncreasing());

// FIXME: Trigger now may not be correct because the spec says:
// If a user agent determines that animation is immediately ready, it may
// schedule the task (i.e. ResumeAt()) as a microtask such that it runs at
Expand All @@ -39,9 +36,7 @@ void ScrollTimelineAnimationTracker::TriggerPendingAnimations() {
// inactive, and this also matches the current spec definition.
continue;
}

// Note: Remove() is legitimately called once per entry during the loop.
mPendingSet.Remove(iter);
mPendingSet.Remove(animation);
}
}

Expand Down

0 comments on commit 0697953

Please sign in to comment.