1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Code to notify things that animate before a refresh, at an appropriate
9 * refresh rate. (Perhaps temporary, until replaced by compositor.)
12 #ifndef nsRefreshDriver_h_
13 #define nsRefreshDriver_h_
15 #include "mozilla/FlushType.h"
16 #include "mozilla/TimeStamp.h"
17 #include "mozilla/UniquePtr.h"
18 #include "mozilla/Vector.h"
19 #include "mozilla/WeakPtr.h"
20 #include "nsTObserverArray.h"
22 #include "nsTHashSet.h"
23 #include "nsClassHashtable.h"
24 #include "nsHashKeys.h"
25 #include "nsRefreshObservers.h"
26 #include "nsThreadUtils.h"
27 #include "mozilla/Attributes.h"
28 #include "mozilla/Maybe.h"
29 #include "mozilla/dom/VisualViewport.h"
30 #include "mozilla/layers/TransactionIdAllocator.h"
31 #include "LayersTypes.h"
33 #include "GeckoProfiler.h" // for ProfileChunkedBuffer
40 struct DocumentFrameCallbacks
;
43 class AnimationEventDispatcher
;
44 class PendingFullscreenEvent
;
46 class RefreshDriverTimer
;
49 } // namespace mozilla
51 class nsRefreshDriver final
: public mozilla::layers::TransactionIdAllocator
,
52 public nsARefreshObserver
{
53 using Document
= mozilla::dom::Document
;
54 using TransactionId
= mozilla::layers::TransactionId
;
55 using VVPResizeEvent
=
56 mozilla::dom::VisualViewport::VisualViewportResizeEvent
;
57 using VVPScrollEvent
=
58 mozilla::dom::VisualViewport::VisualViewportScrollEvent
;
59 using LogPresShellObserver
= mozilla::LogPresShellObserver
;
62 explicit nsRefreshDriver(nsPresContext
* aPresContext
);
66 * Methods for testing, exposed via nsIDOMWindowUtils. See
67 * nsIDOMWindowUtils.advanceTimeAndRefresh for description.
69 void AdvanceTimeAndRefresh(int64_t aMilliseconds
);
70 void RestoreNormalRefresh();
72 bool IsTestControllingRefreshesEnabled() const {
73 return mTestControllingRefreshes
;
77 * Return the time of the most recent refresh. This is intended to be
78 * used by callers who want to start an animation now and want to know
79 * what time to consider the start of the animation. (This helps
80 * ensure that multiple animations started during the same event off
81 * the main event loop have the same start time.)
83 mozilla::TimeStamp
MostRecentRefresh(bool aEnsureTimerStarted
= true) const;
86 * Add / remove refresh observers.
87 * RemoveRefreshObserver returns true if aObserver was found.
89 * The flush type affects:
90 * + the order in which the observers are notified (lowest flush
91 * type to highest, in order registered)
92 * + (in the future) which observers are suppressed when the display
93 * doesn't require current position data or isn't currently
94 * painting, and, correspondingly, which get notified when there
95 * is a flush during such suppression
96 * and it must be FlushType::Style, or FlushType::Display.
98 * The refresh driver does NOT own a reference to these observers;
99 * they must remove themselves before they are destroyed.
101 * The observer will be called even if there is no other activity.
103 void AddRefreshObserver(nsARefreshObserver
* aObserver
,
104 mozilla::FlushType aFlushType
,
105 const char* aObserverDescription
);
106 bool RemoveRefreshObserver(nsARefreshObserver
* aObserver
,
107 mozilla::FlushType aFlushType
);
109 void PostVisualViewportResizeEvent(VVPResizeEvent
* aResizeEvent
);
110 void DispatchVisualViewportResizeEvents();
112 void PostScrollEvent(mozilla::Runnable
* aScrollEvent
, bool aDelayed
= false);
113 void PostScrollEndEvent(mozilla::Runnable
* aScrollEndEvent
,
114 bool aDelayed
= false);
115 void DispatchScrollEvents();
116 void DispatchScrollEndEvents();
118 void PostVisualViewportScrollEvent(VVPScrollEvent
* aScrollEvent
);
119 void DispatchVisualViewportScrollEvents();
121 MOZ_CAN_RUN_SCRIPT
void DispatchResizeEvents();
122 MOZ_CAN_RUN_SCRIPT
void FlushLayoutOnPendingDocsAndFixUpFocus();
125 * Add an observer that will be called after each refresh. The caller
126 * must remove the observer before it is deleted. This does not trigger
127 * refresh driver ticks.
129 void AddPostRefreshObserver(nsAPostRefreshObserver
* aObserver
);
130 void AddPostRefreshObserver(mozilla::ManagedPostRefreshObserver
*) = delete;
131 void RemovePostRefreshObserver(nsAPostRefreshObserver
* aObserver
);
132 void RemovePostRefreshObserver(mozilla::ManagedPostRefreshObserver
*) = delete;
135 * Add/Remove imgIRequest versions of observers.
137 * These are used for hooking into the refresh driver for
138 * controlling animated images.
140 * @note The refresh driver owns a reference to these listeners.
142 * @note Technically, imgIRequest objects are not nsARefreshObservers, but
143 * for controlling animated image repaint events, we subscribe the
144 * imgIRequests to the nsRefreshDriver for notification of paint events.
146 void AddImageRequest(imgIRequest
* aRequest
);
147 void RemoveImageRequest(imgIRequest
* aRequest
);
150 * Marks that we're currently in the middle of processing user input.
151 * Called by EventDispatcher when it's handling an input event.
153 void EnterUserInputProcessing() { mUserInputProcessingCount
++; }
154 void ExitUserInputProcessing() {
155 MOZ_ASSERT(mUserInputProcessingCount
> 0);
156 mUserInputProcessingCount
--;
160 * Add / remove presshells which have pending resize event.
162 void AddResizeEventFlushObserver(mozilla::PresShell
* aPresShell
,
163 bool aDelayed
= false) {
164 MOZ_DIAGNOSTIC_ASSERT(
165 !mResizeEventFlushObservers
.Contains(aPresShell
) &&
166 !mDelayedResizeEventFlushObservers
.Contains(aPresShell
),
167 "Double-adding resize event flush observer");
169 mDelayedResizeEventFlushObservers
.AppendElement(aPresShell
);
171 mResizeEventFlushObservers
.AppendElement(aPresShell
);
172 EnsureTimerStarted();
176 void RemoveResizeEventFlushObserver(mozilla::PresShell
* aPresShell
) {
177 mResizeEventFlushObservers
.RemoveElement(aPresShell
);
178 mDelayedResizeEventFlushObservers
.RemoveElement(aPresShell
);
181 void AddStyleFlushObserver(mozilla::PresShell
* aPresShell
) {
182 MOZ_DIAGNOSTIC_ASSERT(!IsStyleFlushObserver(aPresShell
),
183 "Double-adding style flush observer");
184 LogPresShellObserver::LogDispatch(aPresShell
, this);
185 mStyleFlushObservers
.AppendElement(aPresShell
);
186 EnsureTimerStarted();
188 void RemoveStyleFlushObserver(mozilla::PresShell
* aPresShell
) {
189 mStyleFlushObservers
.RemoveElement(aPresShell
);
191 bool IsStyleFlushObserver(mozilla::PresShell
* aPresShell
) {
192 return mStyleFlushObservers
.Contains(aPresShell
);
196 * "Early Runner" runnables will be called as the first step when refresh
197 * driver tick is triggered. Runners shouldn't keep other objects alive,
198 * since it isn't guaranteed they will ever get called.
200 void AddEarlyRunner(nsIRunnable
* aRunnable
) {
201 mEarlyRunners
.AppendElement(aRunnable
);
202 EnsureTimerStarted();
206 * Remember whether our presshell's view manager needs a flush
208 void ScheduleViewManagerFlush();
209 void RevokeViewManagerFlush() { mViewManagerFlushIsPending
= false; }
210 bool ViewManagerFlushIsPending() { return mViewManagerFlushIsPending
; }
211 bool HasScheduleFlush() { return mHasScheduleFlush
; }
212 void ClearHasScheduleFlush() { mHasScheduleFlush
= false; }
215 * Queue a new fullscreen event to be dispatched in next tick before
218 void ScheduleFullscreenEvent(
219 mozilla::UniquePtr
<mozilla::PendingFullscreenEvent
> aEvent
);
222 * Cancel all pending fullscreen events scheduled by ScheduleFullscreenEvent
223 * which targets any node in aDocument.
225 void CancelPendingFullscreenEvents(Document
* aDocument
);
228 * Queue new animation events to dispatch in next tick.
230 void ScheduleAnimationEventDispatch(
231 mozilla::AnimationEventDispatcher
* aDispatcher
) {
232 NS_ASSERTION(!mAnimationEventFlushObservers
.Contains(aDispatcher
),
233 "Double-adding animation event flush observer");
234 mAnimationEventFlushObservers
.AppendElement(aDispatcher
);
235 EnsureTimerStarted();
239 * Cancel all pending animation events associated with |aDispatcher|.
241 void CancelPendingAnimationEvents(
242 mozilla::AnimationEventDispatcher
* aDispatcher
);
245 * Schedule a frame visibility update "soon", subject to the heuristics and
246 * throttling we apply to visibility updates.
248 void ScheduleFrameVisibilityUpdate() { mNeedToRecomputeVisibility
= true; }
251 * Tell the refresh driver that it is done driving refreshes and
252 * should stop its timer and forget about its pres context. This may
253 * be called from within a refresh.
257 bool IsFrozen() const { return mFreezeCount
> 0; }
259 bool IsThrottled() const { return mThrottled
; }
262 * Freeze the refresh driver. It should stop delivering future
263 * refreshes until thawed. Note that the number of calls to Freeze() must
264 * match the number of calls to Thaw() in order for the refresh driver to
270 * Thaw the refresh driver. If the number of calls to Freeze() matches the
271 * number of calls to this function, the refresh driver should start
272 * delivering refreshes again.
277 * Throttle or unthrottle the refresh driver. This is done if the
278 * corresponding presshell is hidden or shown.
280 void SetActivity(bool aIsActive
);
283 * Return the prescontext we were initialized with
285 nsPresContext
* GetPresContext() const;
287 void CreateVsyncRefreshTimer();
291 * Check whether the given observer is an observer for the given flush type
293 bool IsRefreshObserver(nsARefreshObserver
* aObserver
,
294 mozilla::FlushType aFlushType
);
298 * Default interval the refresh driver uses, in ms.
300 static int32_t DefaultInterval();
303 * Returns 1.0 if a recent rate wasn't smaller than
304 * DefaultInterval(). Otherwise return rate / DefaultInterval();
305 * So the return value is (0-1].
308 static double HighRateMultiplier();
310 bool IsInRefresh() { return mInRefresh
; }
312 void SetIsResizeSuppressed() { mResizeSuppressed
= true; }
313 bool IsResizeSuppressed() const { return mResizeSuppressed
; }
315 // mozilla::layers::TransactionIdAllocator
316 TransactionId
GetTransactionId(bool aThrottle
) override
;
317 TransactionId
LastTransactionId() const override
;
318 void NotifyTransactionCompleted(TransactionId aTransactionId
) override
;
319 void RevokeTransactionId(TransactionId aTransactionId
) override
;
320 void ClearPendingTransactions() override
;
321 void ResetInitialTransactionId(TransactionId aTransactionId
) override
;
322 mozilla::TimeStamp
GetTransactionStart() override
;
323 mozilla::VsyncId
GetVsyncId() override
;
324 mozilla::TimeStamp
GetVsyncStart() override
;
326 bool IsWaitingForPaint(mozilla::TimeStamp aTime
);
328 void ScheduleAutoFocusFlush(Document
* aDocument
);
330 // nsARefreshObserver
331 NS_IMETHOD_(MozExternalRefCountType
) AddRef(void) override
{
332 return TransactionIdAllocator::AddRef();
334 NS_IMETHOD_(MozExternalRefCountType
) Release(void) override
{
335 return TransactionIdAllocator::Release();
337 virtual void WillRefresh(mozilla::TimeStamp aTime
) override
;
340 * Compute the time when the currently active refresh driver timer
341 * will start its next tick.
343 * Expects a non-null default value that is the upper bound of the
344 * expected deadline. If the next expected deadline is later than
345 * the default value, the default value is returned.
347 * If we're animating and we have skipped paints a time in the past
350 * If aCheckType is AllVsyncListeners and we're in the parent process,
351 * which doesn't have a RefreshDriver ticking, but some other process does
352 * have, the return value is
353 * (now + refreshrate - layout.idle_period.time_limit) as an approximation
354 * when something will happen.
355 * This can be useful check when parent process tries to avoid having too
356 * long idle periods for example when it is sending input events to an
357 * active child process.
359 enum IdleCheck
{ OnlyThisProcessRefreshDriver
, AllVsyncListeners
};
360 static mozilla::TimeStamp
GetIdleDeadlineHint(mozilla::TimeStamp aDefault
,
361 IdleCheck aCheckType
);
364 * It returns the expected timestamp of the next tick or nothing if the next
367 static mozilla::Maybe
<mozilla::TimeStamp
> GetNextTickHint();
369 static bool IsRegularRateTimerTicking();
371 static void DispatchIdleTaskAfterTickUnlessExists(mozilla::Task
* aTask
);
372 static void CancelIdleTask(mozilla::Task
* aTask
);
374 // Schedule a refresh so that any delayed events will run soon.
375 void RunDelayedEventsSoon();
377 void InitializeTimer() {
378 MOZ_ASSERT(!mActiveTimer
);
379 EnsureTimerStarted();
382 bool HasPendingTick() const { return mActiveTimer
; }
384 void EnsureIntersectionObservationsUpdateHappens() {
385 // This is enough to make sure that UpdateIntersectionObservations runs at
386 // least once. This is presumably the intent of step 5 in [1]:
388 // Schedule an iteration of the event loop in the root's browsing
391 // Though the wording of it is not quite clear to me...
394 // https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-observe
395 EnsureTimerStarted();
396 mNeedToUpdateIntersectionObservations
= true;
399 void EnsureFrameRequestCallbacksHappen() {
400 EnsureTimerStarted();
401 mNeedToRunFrameRequestCallbacks
= true;
404 void EnsureResizeObserverUpdateHappens() {
405 EnsureTimerStarted();
406 mNeedToUpdateResizeObservers
= true;
409 void EnsureViewTransitionOperationsHappen() {
410 EnsureTimerStarted();
411 mNeedToUpdateViewTransitions
= true;
414 void EnsureAnimationUpdate() {
415 EnsureTimerStarted();
416 mNeedToUpdateAnimations
= true;
419 void ScheduleMediaQueryListenerUpdate() {
420 EnsureTimerStarted();
421 mMightNeedMediaQueryListenerUpdate
= true;
424 void EnsureContentRelevancyUpdateHappens() {
425 EnsureTimerStarted();
426 mNeedToUpdateContentRelevancy
= true;
429 // Register a composition payload that will be forwarded to the layer manager
430 // if the current or upcoming refresh tick does a paint.
431 // If no paint happens, the payload is discarded.
432 // Should only be called on root refresh drivers.
433 void RegisterCompositionPayload(
434 const mozilla::layers::CompositionPayload
& aPayload
);
436 enum class TickReasons
: uint32_t {
438 eHasObservers
= 1 << 0,
439 eHasImageRequests
= 1 << 1,
440 eNeedsToUpdateIntersectionObservations
= 1 << 2,
441 eNeedsToUpdateContentRelevancy
= 1 << 3,
442 eHasVisualViewportResizeEvents
= 1 << 4,
443 eHasScrollEvents
= 1 << 5,
444 eHasVisualViewportScrollEvents
= 1 << 6,
445 eHasPendingMediaQueryListeners
= 1 << 7,
446 eNeedsToNotifyResizeObservers
= 1 << 8,
447 eRootNeedsMoreTicksForUserInput
= 1 << 9,
448 eNeedsToUpdateAnimations
= 1 << 10,
449 eNeedsToRunFrameRequestCallbacks
= 1 << 11,
450 eNeedsToUpdateViewTransitions
= 1 << 12,
453 void AddForceNotifyContentfulPaintPresContext(nsPresContext
* aPresContext
);
454 void FlushForceNotifyContentfulPaintPresContext();
456 // Mark that we've just run a tick from vsync, used to throttle 'extra'
457 // paints to one per vsync (see CanDoExtraTick).
458 void FinishedVsyncTick() { mAttemptedExtraTickSinceLastVsync
= false; }
460 void CancelFlushAutoFocus(Document
* aDocument
);
463 typedef nsTArray
<RefPtr
<VVPResizeEvent
>> VisualViewportResizeEventArray
;
464 typedef nsTArray
<RefPtr
<mozilla::Runnable
>> ScrollEventArray
;
465 typedef nsTArray
<RefPtr
<VVPScrollEvent
>> VisualViewportScrollEventArray
;
466 using RequestTable
= nsTHashSet
<RefPtr
<imgIRequest
>>;
467 struct ImageStartData
{
468 ImageStartData() = default;
470 mozilla::Maybe
<mozilla::TimeStamp
> mStartTime
;
471 RequestTable mEntries
;
473 typedef nsClassHashtable
<nsUint32HashKey
, ImageStartData
> ImageStartTable
;
475 struct ObserverData
{
476 nsARefreshObserver
* mObserver
;
477 const char* mDescription
;
478 mozilla::TimeStamp mRegisterTime
;
479 mozilla::MarkerInnerWindowId mInnerWindowId
;
480 mozilla::UniquePtr
<mozilla::ProfileChunkedBuffer
> mCause
;
481 mozilla::FlushType mFlushType
;
483 bool operator==(nsARefreshObserver
* aObserver
) const {
484 return mObserver
== aObserver
;
486 operator RefPtr
<nsARefreshObserver
>() { return mObserver
; }
488 using ObserverArray
= nsTObserverArray
<ObserverData
>;
490 void FlushAutoFocusDocuments();
491 void RunFullscreenSteps();
492 void UpdateAnimationsAndSendEvents();
495 void RunVideoAndFrameRequestCallbacks(mozilla::TimeStamp aNowTime
);
497 void RunVideoFrameCallbacks(const nsTArray
<RefPtr
<mozilla::dom::Document
>>&,
498 mozilla::TimeStamp aNowTime
);
500 void RunFrameRequestCallbacks(const nsTArray
<RefPtr
<mozilla::dom::Document
>>&,
501 mozilla::TimeStamp aNowTime
);
502 void UpdateIntersectionObservations(mozilla::TimeStamp aNowTime
);
503 void UpdateRemoteFrameEffects();
504 void UpdateRelevancyOfContentVisibilityAutoFrames();
505 void PerformPendingViewTransitionOperations();
506 MOZ_CAN_RUN_SCRIPT
void
507 DetermineProximityToViewportAndNotifyResizeObservers();
508 void MaybeIncreaseMeasuredTicksSinceLoading();
509 void EvaluateMediaQueriesAndReportChanges();
511 enum class IsExtraTick
{
516 // Helper for Tick, to call WillRefresh(aNowTime) on each entry in
517 // mObservers[aIdx] and then potentially do some additional post-notification
518 // work that's associated with the FlushType corresponding to aIdx.
520 // Returns true on success, or false if one of our calls has destroyed our
521 // pres context (in which case our callsite Tick() should immediately bail).
523 bool TickObserverArray(uint32_t aIdx
, mozilla::TimeStamp aNowTime
);
525 MOZ_CAN_RUN_SCRIPT_BOUNDARY
526 void Tick(mozilla::VsyncId aId
, mozilla::TimeStamp aNowTime
,
527 IsExtraTick aIsExtraTick
= IsExtraTick::No
);
529 enum EnsureTimerStartedFlags
{
531 eForceAdjustTimer
= 1 << 0,
532 eAllowTimeToGoBackwards
= 1 << 1,
533 eNeverAdjustTimer
= 1 << 2,
535 void EnsureTimerStarted(EnsureTimerStartedFlags aFlags
= eNone
);
538 void UpdateThrottledState();
540 bool HasObservers() const;
541 void AppendObserverDescriptionsToString(nsACString
& aStr
) const;
542 // Note: This should only be called in the dtor of nsRefreshDriver.
543 uint32_t ObserverCount() const;
544 bool HasImageRequests() const;
545 bool ShouldKeepTimerRunningWhileWaitingForFirstContentfulPaint();
546 bool ShouldKeepTimerRunningAfterPageLoad();
547 ObserverArray
& ArrayFor(mozilla::FlushType aFlushType
);
548 // Trigger a refresh immediately, if haven't been disconnected or frozen.
551 // Starts pending image animations, and refreshes ongoing animations.
552 void UpdateAnimatedImages(mozilla::TimeStamp aPreviousRefresh
,
553 mozilla::TimeStamp aNowTime
);
555 bool HasReasonsToTick() const {
556 return GetReasonsToTick() != TickReasons::eNone
;
558 TickReasons
GetReasonsToTick() const;
559 void AppendTickReasonsToString(TickReasons aReasons
, nsACString
& aStr
) const;
561 double GetRegularTimerInterval() const;
562 static double GetThrottledTimerInterval();
564 static mozilla::TimeDuration
GetMinRecomputeVisibilityInterval();
566 void FinishedWaitingForTransaction();
569 * Returns true if we didn't tick on the most recent vsync, but we think
570 * we could run one now instead in order to reduce latency.
572 bool CanDoCatchUpTick();
574 * Returns true if we think it's possible to run an repeat tick (between
575 * vsyncs) to hopefully replace the original tick's paint on the compositor.
576 * We allow this sometimes for tick requests coming for user input handling
579 bool CanDoExtraTick();
581 bool AtPendingTransactionLimit() {
582 return mPendingTransactions
.Length() == 2;
584 bool TooManyPendingTransactions() {
585 return mPendingTransactions
.Length() >= 2;
588 mozilla::RefreshDriverTimer
* ChooseTimer();
589 mozilla::RefreshDriverTimer
* mActiveTimer
;
590 RefPtr
<mozilla::RefreshDriverTimer
> mOwnTimer
;
591 mozilla::UniquePtr
<mozilla::ProfileChunkedBuffer
> mRefreshTimerStartedCause
;
593 // nsPresContext passed in constructor and unset in Disconnect.
594 mozilla::WeakPtr
<nsPresContext
> mPresContext
;
596 RefPtr
<nsRefreshDriver
> mRootRefresh
;
598 // The most recently allocated transaction id.
599 TransactionId mNextTransactionId
;
600 AutoTArray
<TransactionId
, 3> mPendingTransactions
;
602 uint32_t mFreezeCount
;
603 uint32_t mUserInputProcessingCount
= 0;
605 // How long we wait between ticks for throttled (which generally means
606 // non-visible) documents registered with a non-throttled refresh driver.
607 const mozilla::TimeDuration mThrottledFrameRequestInterval
;
609 // How long we wait, at a minimum, before recomputing approximate frame
610 // visibility information. This is a minimum because, regardless of this
611 // interval, we only recompute visibility when we've seen a layout or style
612 // flush since the last time we did it.
613 const mozilla::TimeDuration mMinRecomputeVisibilityInterval
;
615 mozilla::UniquePtr
<mozilla::ProfileChunkedBuffer
> mViewManagerFlushCause
;
618 bool mNeedToRecomputeVisibility
: 1;
619 bool mTestControllingRefreshes
: 1;
621 // These two fields are almost the same, the only difference is that
622 // mViewManagerFlushIsPending gets cleared right before calling
623 // ProcessPendingUpdates, and mHasScheduleFlush gets cleared right after
624 // calling ProcessPendingUpdates. It is important that mHasScheduleFlush
625 // only gets cleared after, but it's not clear if mViewManagerFlushIsPending
626 // needs to be cleared before.
627 bool mViewManagerFlushIsPending
: 1;
628 bool mHasScheduleFlush
: 1;
632 // True if the refresh driver is suspended waiting for transaction
633 // id's to be returned and shouldn't do any work during Tick().
634 bool mWaitingForTransaction
: 1;
635 // True if Tick() was skipped because of mWaitingForTransaction and
636 // we should schedule a new Tick immediately when resumed instead
637 // of waiting until the next interval.
638 bool mSkippedPaints
: 1;
640 // True if view managers should delay any resize request until the
641 // next tick by the refresh driver. This flag will be reset at the
642 // start of every tick.
643 bool mResizeSuppressed
: 1;
645 // True if we need to flush in order to update intersection observations in
646 // all our documents.
647 bool mNeedToUpdateIntersectionObservations
: 1;
649 // True if we need to flush in order to update resize observations in all
651 bool mNeedToUpdateResizeObservers
: 1;
653 // True if we may need to perform pending view transition operations.
654 bool mNeedToUpdateViewTransitions
: 1;
656 // True if we may need to run any frame callback.
657 bool mNeedToRunFrameRequestCallbacks
: 1;
659 // True if we need to update animations.
660 bool mNeedToUpdateAnimations
: 1;
662 // True if we might need to report media query changes in any of our
664 bool mMightNeedMediaQueryListenerUpdate
: 1;
666 // True if we need to update the relevancy of `content-visibility: auto`
667 // elements in our documents.
668 bool mNeedToUpdateContentRelevancy
: 1;
670 // True if we're currently within the scope of Tick() handling a normal
671 // (timer-driven) tick.
672 bool mInNormalTick
: 1;
674 // True if we attempted an extra tick (see CanDoExtraTick) since the last
675 // vsync and thus shouldn't allow another.
676 bool mAttemptedExtraTickSinceLastVsync
: 1;
678 bool mHasExceededAfterLoadTickPeriod
: 1;
680 bool mHasStartedTimerAtLeastOnce
: 1;
682 mozilla::TimeStamp mMostRecentRefresh
;
683 mozilla::TimeStamp mTickStart
;
684 mozilla::VsyncId mTickVsyncId
;
685 mozilla::TimeStamp mTickVsyncTime
;
686 mozilla::TimeStamp mNextThrottledFrameRequestTick
;
687 mozilla::TimeStamp mNextRecomputeVisibilityTick
;
688 mozilla::TimeStamp mBeforeFirstContentfulPaintTimerRunningLimit
;
690 // separate arrays for each flush type we support
691 ObserverArray mObservers
[3];
692 nsTArray
<mozilla::layers::CompositionPayload
> mCompositionPayloads
;
693 RequestTable mRequests
;
694 ImageStartTable mStartTable
;
695 AutoTArray
<nsCOMPtr
<nsIRunnable
>, 16> mEarlyRunners
;
696 VisualViewportResizeEventArray mVisualViewportResizeEvents
;
697 ScrollEventArray mScrollEvents
;
698 ScrollEventArray mScrollEndEvents
;
699 VisualViewportScrollEventArray mVisualViewportScrollEvents
;
701 // Scroll events on documents that might have events suppressed.
702 ScrollEventArray mDelayedScrollEvents
;
703 ScrollEventArray mDelayedScrollEndEvents
;
705 AutoTArray
<mozilla::PresShell
*, 16> mResizeEventFlushObservers
;
706 AutoTArray
<mozilla::PresShell
*, 16> mDelayedResizeEventFlushObservers
;
707 AutoTArray
<mozilla::PresShell
*, 16> mStyleFlushObservers
;
708 nsTArray
<RefPtr
<Document
>> mAutoFocusFlushDocuments
;
709 nsTObserverArray
<nsAPostRefreshObserver
*> mPostRefreshObservers
;
710 nsTArray
<mozilla::UniquePtr
<mozilla::PendingFullscreenEvent
>>
711 mPendingFullscreenEvents
;
712 AutoTArray
<mozilla::AnimationEventDispatcher
*, 16>
713 mAnimationEventFlushObservers
;
715 // nsPresContexts which `NotifyContentfulPaint` have been called,
716 // however the corresponding paint doesn't come from a regular
717 // rendering steps(aka tick).
719 // For these nsPresContexts, we invoke
720 // `FlushForceNotifyContentfulPaintPresContext` in the next tick
721 // to force notify contentful paint, regardless whether the tick paints
723 nsTArray
<mozilla::WeakPtr
<nsPresContext
>>
724 mForceNotifyContentfulPaintPresContexts
;
726 void BeginRefreshingImages(RequestTable
& aEntries
,
727 mozilla::TimeStamp aDesired
);
729 friend class mozilla::RefreshDriverTimer
;
731 static void Shutdown();
734 #endif /* !defined(nsRefreshDriver_h_) */