diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 9b6f53cc700b..c4df564256a9 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2581,6 +2581,44 @@ void nsJSContext::NotifyDidPaint() { sDidPaintAfterPreviousICCSlice = true; + if (sICCTimer) { + static uint32_t sCount = 0; + // 16 here is the common value for refresh driver tick frequency. + static const uint32_t kTicksPerSliceDelay = kICCIntersliceDelay / 16; + if (++sCount % kTicksPerSliceDelay != 0) { + // Don't trigger CC slice all the time after paint, but often still. + // The key point is to trigger it right after paint, especially when + // we're running RefreshDriver constantly. + return; + } + + sICCTimer->Cancel(); + ICCTimerFired(nullptr, nullptr); + if (sICCTimer) { + sICCTimer->InitWithNamedFuncCallback(ICCTimerFired, nullptr, + kICCIntersliceDelay, + nsITimer::TYPE_REPEATING_SLACK, + "ICCTimerFired"); + } + } else if (sCCTimer) { + static uint32_t sCount = 0; + static const uint32_t kTicksPerForgetSkippableDelay = + NS_CC_SKIPPABLE_DELAY / 16; + if (++sCount % kTicksPerForgetSkippableDelay != 0) { + // The comment above about triggering CC slice applies to forget skippable + // too. + return; + } + + sCCTimer->Cancel(); + CCTimerFired(nullptr, nullptr); + if (sCCTimer) { + sCCTimer->InitWithNamedFuncCallback(CCTimerFired, nullptr, + NS_CC_SKIPPABLE_DELAY, + nsITimer::TYPE_REPEATING_SLACK, + "CCTimerFired"); + } + } } nsScriptNameSpaceManager* diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 74f4c34f53f2..f8c5f2ec2f1e 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -1876,6 +1876,7 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime) } mPresShellsToInvalidateIfHidden.Clear(); + bool notifyGC = false; if (mViewManagerFlushIsPending) { RefPtr timelines = TimelineConsumers::Get(); @@ -1911,10 +1912,7 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime) timelines->AddMarkerForDocShell(docShell, "Paint", MarkerTracingType::END); } - if (nsContentUtils::XPConnect()) { - nsContentUtils::XPConnect()->NotifyDidPaint(); - nsJSContext::NotifyDidPaint(); - } + notifyGC = true; } #ifndef ANDROID /* bug 1142079 */ @@ -1934,6 +1932,11 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime) if (mPresContext->IsRoot() && XRE_IsContentProcess() && gfxPrefs::AlwaysPaint()) { ScheduleViewManagerFlush(); } + + if (notifyGC && nsContentUtils::XPConnect()) { + nsContentUtils::XPConnect()->NotifyDidPaint(); + nsJSContext::NotifyDidPaint(); + } } void