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
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();