Bug 1443943 Allow internal callers of performance.now() to opt-out of clamping/jittering r?bholley draft
authorTom Ritter <tom@mozilla.com>
Fri, 09 Mar 2018 20:12:53 -0600
changeset 767538 c41b5ef2a5445dcdd1fb74e070f9be4560bf3b39
parent 767537 d89b40edc60cb580ee170c7c2e10315722696067
child 767539 6339701b44db5b5393ad221ea647a64a71f44d78
push id102629
push userbmo:tom@mozilla.com
push dateWed, 14 Mar 2018 19:27:31 +0000
reviewersbholley
bugs1443943
milestone61.0a1
Bug 1443943 Allow internal callers of performance.now() to opt-out of clamping/jittering r?bholley PresShell only uses performane.now to track refresh times, and notify internal observers. We can provide more accurate times by not clamping and jittering these numbers. MozReview-Commit-ID: FkDGJhrLeAy
dom/performance/Performance.cpp
dom/performance/Performance.h
layout/base/PresShell.cpp
layout/base/PresShell.h
old mode 100755
new mode 100644
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -86,30 +86,36 @@ Performance::Performance(nsPIDOMWindowIn
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 Performance::~Performance()
 {}
 
 DOMHighResTimeStamp
-Performance::Now() const
+Performance::Now()
 {
-  TimeDuration duration = TimeStamp::Now() - CreationTimeStamp();
-  DOMHighResTimeStamp rawTime = duration.ToMilliseconds();
+  DOMHighResTimeStamp rawTime = NowUnclamped();
   if (mSystemPrincipal) {
     return rawTime;
   }
 
   const double maxResolutionMs = 0.020;
   DOMHighResTimeStamp minimallyClamped = floor(rawTime / maxResolutionMs) * maxResolutionMs;
   return nsRFPService::ReduceTimePrecisionAsMSecs(minimallyClamped);
 }
 
 DOMHighResTimeStamp
+Performance::NowUnclamped() const
+{
+  TimeDuration duration = TimeStamp::Now() - CreationTimeStamp();
+  return duration.ToMilliseconds();
+}
+
+DOMHighResTimeStamp
 Performance::TimeOrigin()
 {
   if (!mPerformanceService) {
     mPerformanceService = PerformanceService::GetOrCreate();
   }
 
   MOZ_ASSERT(mPerformanceService);
   DOMHighResTimeStamp rawTimeOrigin = mPerformanceService->TimeOrigin(CreationTimeStamp());
old mode 100755
new mode 100644
--- a/dom/performance/Performance.h
+++ b/dom/performance/Performance.h
@@ -59,17 +59,19 @@ public:
   virtual void GetEntriesByName(const nsAString& aName,
                                 const Optional<nsAString>& aEntryType,
                                 nsTArray<RefPtr<PerformanceEntry>>& aRetval);
 
   virtual PerformanceStorage* AsPerformanceStorage() = 0;
 
   void ClearResourceTimings();
 
-  DOMHighResTimeStamp Now() const;
+  DOMHighResTimeStamp Now();
+
+  DOMHighResTimeStamp NowUnclamped() const;
 
   DOMHighResTimeStamp TimeOrigin();
 
   void Mark(const nsAString& aName, ErrorResult& aRv);
 
   void ClearMarks(const Optional<nsAString>& aName);
 
   void Measure(const nsAString& aName,
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -8610,47 +8610,47 @@ void
 PresShell::WillDoReflow()
 {
   mDocument->FlushUserFontSet();
 
   mPresContext->FlushCounterStyles();
 
   mPresContext->FlushFontFeatureValues();
 
-  mLastReflowStart = GetPerformanceNow();
+  mLastReflowStart = GetPerformanceNowUnclamped();
 }
 
 void
 PresShell::DidDoReflow(bool aInterruptible)
 {
   HandlePostedReflowCallbacks(aInterruptible);
 
   nsCOMPtr<nsIDocShell> docShell = mPresContext->GetDocShell();
   if (docShell) {
-    DOMHighResTimeStamp now = GetPerformanceNow();
+    DOMHighResTimeStamp now = GetPerformanceNowUnclamped();
     docShell->NotifyReflowObservers(aInterruptible, mLastReflowStart, now);
   }
 
   if (sSynthMouseMove) {
     SynthesizeMouseMove(false);
   }
 
   mPresContext->NotifyMissingFonts();
 }
 
 DOMHighResTimeStamp
-PresShell::GetPerformanceNow()
+PresShell::GetPerformanceNowUnclamped()
 {
   DOMHighResTimeStamp now = 0;
 
   if (nsPIDOMWindowInner* window = mDocument->GetInnerWindow()) {
     Performance* perf = window->GetPerformance();
 
     if (perf) {
-      now = perf->Now();
+      now = perf->NowUnclamped();
     }
   }
 
   return now;
 }
 
 void
 PresShell::sReflowContinueCallback(nsITimer* aTimer, void* aPresShell)
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -708,17 +708,17 @@ private:
                                            nsIWidget *aRootWidget);
 
   void SynthesizeMouseMove(bool aFromScroll) override;
 
   PresShell* GetRootPresShell();
 
   nscolor GetDefaultBackgroundColorToDraw();
 
-  DOMHighResTimeStamp GetPerformanceNow();
+  DOMHighResTimeStamp GetPerformanceNowUnclamped();
 
   // The callback for the mPaintSuppressionTimer timer.
   static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
 
   // The callback for the mReflowContinueTimer timer.
   static void sReflowContinueCallback(nsITimer* aTimer, void* aPresShell);
   bool ScheduleReflowOffTimer();