ma1 pushed to branch mullvad-browser-128.3.0esr-14.0-1 at The Tor Project / Applications / Mullvad Browser
Commits:
-
0375bee4
by Emilio Cobos Álvarez at 2024-10-08T22:01:35+02:00
4 changed files:
- dom/animation/AnimationTimeline.cpp
- dom/animation/DocumentTimeline.cpp
- dom/animation/ScrollTimelineAnimationTracker.cpp
- layout/base/nsRefreshDriver.cpp
Changes:
... | ... | @@ -40,41 +40,33 @@ AnimationTimeline::~AnimationTimeline() { mAnimationOrder.clear(); } |
40 | 40 | bool AnimationTimeline::Tick(TickState& aState) {
|
41 | 41 | bool needsTicks = false;
|
42 | 42 | |
43 | - nsTArray<Animation*> animationsToRemove;
|
|
44 | - |
|
45 | - for (Animation* animation = mAnimationOrder.getFirst(); animation;
|
|
46 | - animation =
|
|
47 | - static_cast<LinkedListElement<Animation>*>(animation)->getNext()) {
|
|
43 | + AutoTArray<RefPtr<Animation>, 32> animationsToTick;
|
|
44 | + for (Animation* animation : mAnimationOrder) {
|
|
48 | 45 | MOZ_ASSERT(mAnimations.Contains(animation),
|
49 | 46 | "The sampling order list should be a subset of the hashset");
|
50 | 47 | MOZ_ASSERT(!animation->IsHiddenByContentVisibility(),
|
51 | 48 | "The sampling order list should not contain any animations "
|
52 | 49 | "that are hidden by content-visibility");
|
50 | + animationsToTick.AppendElement(animation);
|
|
51 | + }
|
|
53 | 52 | |
53 | + for (Animation* animation : animationsToTick) {
|
|
54 | 54 | // Skip any animations that are longer need associated with this timeline.
|
55 | 55 | if (animation->GetTimeline() != this) {
|
56 | - // If animation has some other timeline, it better not be also in the
|
|
57 | - // animation list of this timeline object!
|
|
58 | - MOZ_ASSERT(!animation->GetTimeline());
|
|
59 | - animationsToRemove.AppendElement(animation);
|
|
56 | + RemoveAnimation(animation);
|
|
60 | 57 | continue;
|
61 | 58 | }
|
62 | 59 | |
63 | 60 | needsTicks |= animation->NeedsTicks();
|
64 | - // Even if |animation| doesn't need future ticks, we should still
|
|
65 | - // Tick it this time around since it might just need a one-off tick in
|
|
66 | - // order to dispatch events.
|
|
61 | + // Even if |animation| doesn't need future ticks, we should still Tick it
|
|
62 | + // this time around since it might just need a one-off tick in order to
|
|
63 | + // queue events.
|
|
67 | 64 | animation->Tick(aState);
|
68 | - |
|
69 | 65 | if (!animation->NeedsTicks()) {
|
70 | - animationsToRemove.AppendElement(animation);
|
|
66 | + RemoveAnimation(animation);
|
|
71 | 67 | }
|
72 | 68 | }
|
73 | 69 | |
74 | - for (Animation* animation : animationsToRemove) {
|
|
75 | - RemoveAnimation(animation);
|
|
76 | - }
|
|
77 | - |
|
78 | 70 | return needsTicks;
|
79 | 71 | }
|
80 | 72 | |
... | ... | @@ -90,11 +82,12 @@ void AnimationTimeline::NotifyAnimationUpdated(Animation& aAnimation) { |
90 | 82 | }
|
91 | 83 | |
92 | 84 | void AnimationTimeline::RemoveAnimation(Animation* aAnimation) {
|
93 | - MOZ_ASSERT(!aAnimation->GetTimeline() || aAnimation->GetTimeline() == this);
|
|
94 | - if (static_cast<LinkedListElement<Animation>*>(aAnimation)->isInList()) {
|
|
85 | + if (static_cast<LinkedListElement<Animation>*>(aAnimation)->isInList() &&
|
|
86 | + MOZ_LIKELY(!aAnimation->GetTimeline() ||
|
|
87 | + aAnimation->GetTimeline() == this)) {
|
|
88 | + static_cast<LinkedListElement<Animation>*>(aAnimation)->remove();
|
|
95 | 89 | MOZ_ASSERT(mAnimations.Contains(aAnimation),
|
96 | 90 | "The sampling order list should be a subset of the hashset");
|
97 | - static_cast<LinkedListElement<Animation>*>(aAnimation)->remove();
|
|
98 | 91 | }
|
99 | 92 | mAnimations.Remove(aAnimation);
|
100 | 93 | }
|
... | ... | @@ -160,7 +160,12 @@ void DocumentTimeline::NotifyAnimationUpdated(Animation& aAnimation) { |
160 | 160 | }
|
161 | 161 | |
162 | 162 | void DocumentTimeline::TriggerAllPendingAnimationsNow() {
|
163 | + AutoTArray<RefPtr<Animation>, 32> animationsToTrigger;
|
|
163 | 164 | for (Animation* animation : mAnimationOrder) {
|
165 | + animationsToTrigger.AppendElement(animation);
|
|
166 | + }
|
|
167 | + |
|
168 | + for (Animation* animation : animationsToTrigger) {
|
|
164 | 169 | animation->TryTriggerNow();
|
165 | 170 | }
|
166 | 171 | }
|
... | ... | @@ -188,9 +193,6 @@ void DocumentTimeline::WillRefresh() { |
188 | 193 | // of mDocument's PresShell.
|
189 | 194 | if (nsRefreshDriver* refreshDriver = GetRefreshDriver()) {
|
190 | 195 | refreshDriver->EnsureAnimationUpdate();
|
191 | - } else {
|
|
192 | - MOZ_ASSERT_UNREACHABLE(
|
|
193 | - "Refresh driver should still be valid at end of WillRefresh");
|
|
194 | 196 | }
|
195 | 197 | }
|
196 | 198 |
... | ... | @@ -13,13 +13,10 @@ namespace mozilla { |
13 | 13 | NS_IMPL_CYCLE_COLLECTION(ScrollTimelineAnimationTracker, mPendingSet, mDocument)
|
14 | 14 | |
15 | 15 | void ScrollTimelineAnimationTracker::TriggerPendingAnimations() {
|
16 | - for (auto iter = mPendingSet.begin(), end = mPendingSet.end(); iter != end;
|
|
17 | - ++iter) {
|
|
18 | - dom::Animation* animation = *iter;
|
|
19 | - |
|
16 | + for (RefPtr<dom::Animation>& animation :
|
|
17 | + ToTArray<AutoTArray<RefPtr<dom::Animation>, 32>>(mPendingSet)) {
|
|
20 | 18 | MOZ_ASSERT(animation->GetTimeline() &&
|
21 | 19 | !animation->GetTimeline()->IsMonotonicallyIncreasing());
|
22 | - |
|
23 | 20 | // FIXME: Trigger now may not be correct because the spec says:
|
24 | 21 | // If a user agent determines that animation is immediately ready, it may
|
25 | 22 | // schedule the task (i.e. ResumeAt()) as a microtask such that it runs at
|
... | ... | @@ -39,9 +36,7 @@ void ScrollTimelineAnimationTracker::TriggerPendingAnimations() { |
39 | 36 | // inactive, and this also matches the current spec definition.
|
40 | 37 | continue;
|
41 | 38 | }
|
42 | - |
|
43 | - // Note: Remove() is legitimately called once per entry during the loop.
|
|
44 | - mPendingSet.Remove(iter);
|
|
39 | + mPendingSet.Remove(animation);
|
|
45 | 40 | }
|
46 | 41 | }
|
47 | 42 |
... | ... | @@ -2332,8 +2332,15 @@ void nsRefreshDriver::DetermineProximityToViewportAndNotifyResizeObservers() { |
2332 | 2332 | }
|
2333 | 2333 | |
2334 | 2334 | static CallState UpdateAndReduceAnimations(Document& aDocument) {
|
2335 | - for (DocumentTimeline* timeline : aDocument.Timelines()) {
|
|
2336 | - timeline->WillRefresh();
|
|
2335 | + {
|
|
2336 | + AutoTArray<RefPtr<DocumentTimeline>, 32> timelinesToTick;
|
|
2337 | + for (DocumentTimeline* timeline : aDocument.Timelines()) {
|
|
2338 | + timelinesToTick.AppendElement(timeline);
|
|
2339 | + }
|
|
2340 | + |
|
2341 | + for (DocumentTimeline* tl : timelinesToTick) {
|
|
2342 | + tl->WillRefresh();
|
|
2343 | + }
|
|
2337 | 2344 | }
|
2338 | 2345 | |
2339 | 2346 | if (nsPresContext* pc = aDocument.GetPresContext()) {
|
... | ... | @@ -2363,7 +2370,8 @@ void nsRefreshDriver::UpdateAnimationsAndSendEvents() { |
2363 | 2370 | // [1]:
|
2364 | 2371 | // https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events
|
2365 | 2372 | nsAutoMicroTask mt;
|
2366 | - UpdateAndReduceAnimations(*mPresContext->Document());
|
|
2373 | + RefPtr doc = mPresContext->Document();
|
|
2374 | + UpdateAndReduceAnimations(*doc);
|
|
2367 | 2375 | }
|
2368 | 2376 | |
2369 | 2377 | // Hold all AnimationEventDispatcher in mAnimationEventFlushObservers as
|