forked from mirrors/gecko-dev
Bug 1865637 - Make sure animation ticks are consistent. r=hiro
This makes ticking the document timeline happens only when we make forward progress. It seems otherwise we can end up with an extra no-op tick which might resolve the ready time unexpectedly. It's also cleaner. Differential Revision: https://phabricator.services.mozilla.com/D194406
This commit is contained in:
parent
8605fa323f
commit
1d44dbc91b
3 changed files with 46 additions and 56 deletions
|
|
@ -47,11 +47,11 @@ DocumentTimeline::DocumentTimeline(Document* aDocument,
|
||||||
mDocument(aDocument),
|
mDocument(aDocument),
|
||||||
mIsObservingRefreshDriver(false),
|
mIsObservingRefreshDriver(false),
|
||||||
mOriginTime(aOriginTime) {
|
mOriginTime(aOriginTime) {
|
||||||
if (mDocument) {
|
mDocument->Timelines().insertBack(this);
|
||||||
mDocument->Timelines().insertBack(this);
|
|
||||||
}
|
|
||||||
// Ensure mLastRefreshDriverTime is valid.
|
// Ensure mLastRefreshDriverTime is valid.
|
||||||
UpdateLastRefreshDriverTime();
|
if (nsDOMNavigationTiming* timing = mDocument->GetNavigationTiming()) {
|
||||||
|
mLastRefreshDriverTime = timing->GetNavigationStartTimeStamp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentTimeline::~DocumentTimeline() {
|
DocumentTimeline::~DocumentTimeline() {
|
||||||
|
|
@ -100,41 +100,28 @@ bool DocumentTimeline::TracksWallclockTime() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeStamp DocumentTimeline::GetCurrentTimeStamp() const {
|
TimeStamp DocumentTimeline::GetCurrentTimeStamp() const {
|
||||||
nsRefreshDriver* refreshDriver = GetRefreshDriver();
|
if (nsRefreshDriver* refreshDriver = GetRefreshDriver()) {
|
||||||
return refreshDriver ? refreshDriver->MostRecentRefresh()
|
auto ts = refreshDriver->MostRecentRefresh();
|
||||||
: mLastRefreshDriverTime;
|
if (ts > mLastRefreshDriverTime) {
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mLastRefreshDriverTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentTimeline::UpdateLastRefreshDriverTime(TimeStamp aKnownTime) {
|
bool DocumentTimeline::MaybeUpdateLastRefreshDriverTime(TimeStamp aTime) {
|
||||||
TimeStamp result = [&] {
|
// If we don't have a refresh driver and we've never had one use the
|
||||||
if (!aKnownTime.IsNull()) {
|
// timeline's zero time.
|
||||||
return aKnownTime;
|
// It's possible that our refresh driver's timestamp is behind from the
|
||||||
}
|
// navigation start time because the refresh driver timestamp is sent
|
||||||
if (auto* rd = GetRefreshDriver()) {
|
// through an IPC call whereas the navigation time is set by calling
|
||||||
return rd->MostRecentRefresh();
|
// TimeStamp::Now() directly. Make sure we only advance.
|
||||||
};
|
if (aTime < mLastRefreshDriverTime) {
|
||||||
return mLastRefreshDriverTime;
|
return false;
|
||||||
}();
|
|
||||||
|
|
||||||
if (nsDOMNavigationTiming* timing = mDocument->GetNavigationTiming()) {
|
|
||||||
// If we don't have a refresh driver and we've never had one use the
|
|
||||||
// timeline's zero time.
|
|
||||||
// In addition, it's possible that our refresh driver's timestamp is behind
|
|
||||||
// from the navigation start time because the refresh driver timestamp is
|
|
||||||
// sent through an IPC call whereas the navigation time is set by calling
|
|
||||||
// TimeStamp::Now() directly. In such cases we also use the timeline's zero
|
|
||||||
// time.
|
|
||||||
// Also, let this time represent the current refresh time. This way we'll
|
|
||||||
// save it as the last refresh time and skip looking up navigation start
|
|
||||||
// time each time.
|
|
||||||
if (result.IsNull() || result < timing->GetNavigationStartTimeStamp()) {
|
|
||||||
result = timing->GetNavigationStartTimeStamp();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.IsNull()) {
|
mLastRefreshDriverTime = aTime;
|
||||||
mLastRefreshDriverTime = result;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable<TimeDuration> DocumentTimeline::ToTimelineTime(
|
Nullable<TimeDuration> DocumentTimeline::ToTimelineTime(
|
||||||
|
|
@ -169,10 +156,26 @@ void DocumentTimeline::NotifyAnimationUpdated(Animation& aAnimation) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentTimeline::MostRecentRefreshTimeUpdated() {
|
void DocumentTimeline::TriggerAllPendingAnimationsNow() {
|
||||||
|
for (Animation* animation : mAnimationOrder) {
|
||||||
|
animation->TryTriggerNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DocumentTimeline::WillRefresh(TimeStamp aTime) { MaybeTick(aTime); }
|
||||||
|
|
||||||
|
void DocumentTimeline::NotifyTimerAdjusted(TimeStamp aTime) {
|
||||||
|
MaybeTick(aTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DocumentTimeline::MaybeTick(TimeStamp aTime) {
|
||||||
|
if (!MaybeUpdateLastRefreshDriverTime(aTime)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(mIsObservingRefreshDriver);
|
MOZ_ASSERT(mIsObservingRefreshDriver);
|
||||||
MOZ_ASSERT(GetRefreshDriver(),
|
MOZ_ASSERT(GetRefreshDriver(),
|
||||||
"Should be able to reach refresh driver from within WillRefresh");
|
"Should be able to reach refresh driver from within the tick");
|
||||||
|
|
||||||
nsAutoAnimationMutationBatch mb(mDocument);
|
nsAutoAnimationMutationBatch mb(mDocument);
|
||||||
|
|
||||||
|
|
@ -200,21 +203,6 @@ void DocumentTimeline::MostRecentRefreshTimeUpdated() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentTimeline::TriggerAllPendingAnimationsNow() {
|
|
||||||
for (Animation* animation : mAnimationOrder) {
|
|
||||||
animation->TryTriggerNow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentTimeline::WillRefresh(TimeStamp aTime) {
|
|
||||||
UpdateLastRefreshDriverTime();
|
|
||||||
MostRecentRefreshTimeUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentTimeline::NotifyTimerAdjusted(TimeStamp aTime) {
|
|
||||||
MostRecentRefreshTimeUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentTimeline::ObserveRefreshDriver(nsRefreshDriver* aDriver) {
|
void DocumentTimeline::ObserveRefreshDriver(nsRefreshDriver* aDriver) {
|
||||||
MOZ_ASSERT(!mIsObservingRefreshDriver);
|
MOZ_ASSERT(!mIsObservingRefreshDriver);
|
||||||
// Set the mIsObservingRefreshDriver flag before calling AddRefreshObserver
|
// Set the mIsObservingRefreshDriver flag before calling AddRefreshObserver
|
||||||
|
|
@ -241,7 +229,7 @@ void DocumentTimeline::NotifyRefreshDriverCreated(nsRefreshDriver* aDriver) {
|
||||||
// could perform a paint before the first refresh driver tick happens. To
|
// could perform a paint before the first refresh driver tick happens. To
|
||||||
// ensure we're in a consistent state in that case we run the first tick
|
// ensure we're in a consistent state in that case we run the first tick
|
||||||
// manually.
|
// manually.
|
||||||
MostRecentRefreshTimeUpdated();
|
MaybeTick(aDriver->MostRecentRefresh());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,8 @@ class DocumentTimeline final : public AnimationTimeline,
|
||||||
|
|
||||||
Document* GetDocument() const override { return mDocument; }
|
Document* GetDocument() const override { return mDocument; }
|
||||||
|
|
||||||
void UpdateLastRefreshDriverTime(TimeStamp aKnownTime = {});
|
bool MaybeUpdateLastRefreshDriverTime(TimeStamp);
|
||||||
|
void MaybeTick(TimeStamp);
|
||||||
|
|
||||||
bool IsMonotonicallyIncreasing() const override { return true; }
|
bool IsMonotonicallyIncreasing() const override { return true; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13515,8 +13515,9 @@ void Document::SetNavigationTiming(nsDOMNavigationTiming* aTiming) {
|
||||||
// If there's already the DocumentTimeline instance, tell it since the
|
// If there's already the DocumentTimeline instance, tell it since the
|
||||||
// DocumentTimeline is based on both the navigation start time stamp and the
|
// DocumentTimeline is based on both the navigation start time stamp and the
|
||||||
// refresh driver timestamp.
|
// refresh driver timestamp.
|
||||||
if (mDocumentTimeline) {
|
if (mDocumentTimeline && mTiming) {
|
||||||
mDocumentTimeline->UpdateLastRefreshDriverTime();
|
mDocumentTimeline->MaybeUpdateLastRefreshDriverTime(
|
||||||
|
mTiming->GetNavigationStartTimeStamp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue