From f3d9f254c86fb0abb99a125651241ffe7067693f Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 12 Feb 2019 19:09:06 +0000 Subject: [PATCH] Bug 1506976 - Make FirstContentfulPaint timing measure until the composite end of the paint. r=bas Differential Revision: https://phabricator.services.mozilla.com/D18880 --HG-- extra : moz-landing-system : lando --- dom/base/nsDOMNavigationTiming.cpp | 5 +++-- dom/base/nsDOMNavigationTiming.h | 3 ++- layout/base/nsPresContext.cpp | 21 +++++++++++++++------ layout/base/nsPresContext.h | 6 +++++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dom/base/nsDOMNavigationTiming.cpp b/dom/base/nsDOMNavigationTiming.cpp index 9dc4b35f123e..965fb4227019 100644 --- a/dom/base/nsDOMNavigationTiming.cpp +++ b/dom/base/nsDOMNavigationTiming.cpp @@ -414,7 +414,8 @@ void nsDOMNavigationTiming::NotifyNonBlankPaintForRootContentDocument() { } } -void nsDOMNavigationTiming::NotifyContentfulPaintForRootContentDocument() { +void nsDOMNavigationTiming::NotifyContentfulPaintForRootContentDocument( + const mozilla::TimeStamp& aCompositeEndTime) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!mNavigationStart.IsNull()); @@ -422,7 +423,7 @@ void nsDOMNavigationTiming::NotifyContentfulPaintForRootContentDocument() { return; } - mContentfulPaint = TimeStamp::Now(); + mContentfulPaint = aCompositeEndTime; #ifdef MOZ_GECKO_PROFILER if (profiler_is_active() || PAGELOAD_LOG_ENABLED()) { diff --git a/dom/base/nsDOMNavigationTiming.h b/dom/base/nsDOMNavigationTiming.h index 6a3f78c18ae8..476aa096209d 100644 --- a/dom/base/nsDOMNavigationTiming.h +++ b/dom/base/nsDOMNavigationTiming.h @@ -142,7 +142,8 @@ class nsDOMNavigationTiming final : public mozilla::RelativeTimeline { void NotifyLongTask(mozilla::TimeStamp aWhen); void NotifyNonBlankPaintForRootContentDocument(); - void NotifyContentfulPaintForRootContentDocument(); + void NotifyContentfulPaintForRootContentDocument( + const mozilla::TimeStamp& aCompositeEndTime); void NotifyDOMContentFlushedForRootContentDocument(); void NotifyDocShellStateChanged(DocShellState aDocShellState); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index d9321def4fd1..2e780c493190 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -232,7 +232,8 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType) mQuirkSheetAdded(false), mNeedsPrefUpdate(false), mHadNonBlankPaint(false), - mHadContentfulPaint(false) + mHadContentfulPaint(false), + mHadContentfulPaintComposite(false) #ifdef DEBUG , mInitialized(false) @@ -2265,6 +2266,16 @@ void nsPresContext::NotifyRevokingDidPaint(TransactionId aTransactionId) { void nsPresContext::NotifyDidPaintForSubtree( TransactionId aTransactionId, const mozilla::TimeStamp& aTimeStamp) { + if (mFirstContentfulPaintTransactionId && !mHadContentfulPaintComposite) { + if (aTransactionId >= *mFirstContentfulPaintTransactionId) { + mHadContentfulPaintComposite = true; + RefPtr timing = mDocument->GetNavigationTiming(); + if (timing) { + timing->NotifyContentfulPaintForRootContentDocument(aTimeStamp); + } + } + } + if (IsRoot() && mTransactions.IsEmpty()) { return; } @@ -2545,12 +2556,10 @@ void nsPresContext::NotifyContentfulPaint() { if (!mHadContentfulPaint) { mHadContentfulPaint = true; if (IsRootContentDocument()) { - RefPtr timing = mDocument->GetNavigationTiming(); - if (timing) { - timing->NotifyContentfulPaintForRootContentDocument(); + if (nsRootPresContext* rootPresContext = GetRootPresContext()) { + mFirstContentfulPaintTransactionId = + Some(rootPresContext->mRefreshDriver->LastTransactionId().Next()); } - - mFirstContentfulPaintTime = TimeStamp::Now(); } } } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index ccbbc0dcec5d..4876037b3c25 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -1265,14 +1265,16 @@ class nsPresContext : public nsISupports, mozilla::TimeStamp mReflowStartTime; + mozilla::Maybe mFirstContentfulPaintTransactionId; + // Time of various first interaction types, used to report time from // first paint of the top level content pres shell to first interaction. mozilla::TimeStamp mFirstNonBlankPaintTime; - mozilla::TimeStamp mFirstContentfulPaintTime; mozilla::TimeStamp mFirstClickTime; mozilla::TimeStamp mFirstKeyTime; mozilla::TimeStamp mFirstMouseMoveTime; mozilla::TimeStamp mFirstScrollTime; + bool mInteractionTimeEnabled; // last time we did a full style flush @@ -1346,6 +1348,8 @@ class nsPresContext : public nsISupports, unsigned mHadNonBlankPaint : 1; // Has NotifyContentfulPaint been called on this PresContext? unsigned mHadContentfulPaint : 1; + // Has NotifyDidPaintForSubtree been called for a contentful paint? + unsigned mHadContentfulPaintComposite : 1; #ifdef DEBUG unsigned mInitialized : 1;