Bug 1311425 - Prepare for handling several sources of idleness, r=smaug

--HG--
extra : rebase_source : 7f771167ae460a50715f23c587eea10d5fe7e815
This commit is contained in:
Andreas Farre 2017-05-24 21:11:12 -04:00
parent c2c51793f3
commit 0833711613
3 changed files with 30 additions and 50 deletions

View File

@ -235,12 +235,12 @@ public:
return mLastFireSkipped;
}
Maybe<TimeStamp> GetIdleDeadlineHint()
TimeStamp GetIdleDeadlineHint(TimeStamp aDefault)
{
MOZ_ASSERT(NS_IsMainThread());
if (LastTickSkippedAnyPaints()) {
return Some(TimeStamp());
return TimeStamp::Now();
}
TimeStamp mostRecentRefresh = MostRecentRefresh();
@ -250,11 +250,12 @@ public:
if (idleEnd +
refreshRate * nsLayoutUtils::QuiescentFramesBeforeIdlePeriod() <
TimeStamp::Now()) {
return Nothing();
return aDefault;
}
return Some(idleEnd - TimeDuration::FromMilliseconds(
nsLayoutUtils::IdlePeriodDeadlineLimit()));
idleEnd = idleEnd - TimeDuration::FromMilliseconds(
nsLayoutUtils::IdlePeriodDeadlineLimit());
return idleEnd < aDefault ? idleEnd : aDefault;
}
protected:
@ -2315,13 +2316,14 @@ nsRefreshDriver::CancelPendingEvents(nsIDocument* aDocument)
}
}
/* static */ Maybe<TimeStamp>
nsRefreshDriver::GetIdleDeadlineHint()
/* static */ TimeStamp
nsRefreshDriver::GetIdleDeadlineHint(TimeStamp aDefault)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDefault.IsNull());
if (!sRegularRateTimer) {
return Nothing();
return aDefault;
}
// For computing idleness of refresh drivers we only care about
@ -2330,7 +2332,7 @@ nsRefreshDriver::GetIdleDeadlineHint()
// resulting from a tick on the sRegularRateTimer counts as being
// busy but tasks resulting from a tick on sThrottledRateTimer
// counts as being idle.
return sRegularRateTimer->GetIdleDeadlineHint();
return sRegularRateTimer->GetIdleDeadlineHint(aDefault);
}
void

View File

@ -324,37 +324,14 @@ public:
* Compute the time when the currently active refresh driver timer
* will start its next tick.
*
* Returns 'Nothing' if the refresh driver timer hasn't been
* initialized or if we can't tell when the next tick will happen.
* Expects a non-null default value that is the upper bound of the
* expected deadline. If the next expected deadline is later than
* the default value, the default value is returned.
*
* Returns Some(TimeStamp()), i.e. the null time, if the next tick is late.
*
* Otherwise returns Some(TimeStamp(t)), where t is the time of the next tick.
*
* Using these three types of return values it is possible to
* estimate three different things about the idleness of the
* currently active group of refresh drivers. This information is
* used by nsThread to schedule lower priority "idle tasks".
*
* The 'Nothing' return value indicates to nsThread that the
* currently active refresh drivers will be idle for a time
* significantly longer than the current refresh rate and that it is
* free to schedule longer periods for executing idle tasks. This is the
* expected result when we aren't animating.
* Returning the null time indicates to nsThread that we are very
* busy and that it should definitely not schedule idle tasks at
* all. This is the expected result when we are animating, but
* aren't able to keep up with the animation and hence need to skip
* paints. Since catching up to missed paints will happen as soon as
* possible, this is the expected result if any of the refresh
* drivers attached to the current refresh driver misses a paint.
*
* Returning Some(TimeStamp(t)) indicates to nsThread that we will
* be idle until. This is usually the case when we're animating
* without skipping paints.
* If we're animating and we have skipped paints a time in the past
* is returned.
*/
static mozilla::Maybe<mozilla::TimeStamp> GetIdleDeadlineHint();
static mozilla::TimeStamp GetIdleDeadlineHint(mozilla::TimeStamp aDefault);
bool SkippedPaints() const
{

View File

@ -21,19 +21,20 @@ MainThreadIdlePeriod::GetIdlePeriodHint(TimeStamp* aIdleDeadline)
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aIdleDeadline);
Maybe<TimeStamp> deadline = nsRefreshDriver::GetIdleDeadlineHint();
TimeStamp now = TimeStamp::Now();
TimeStamp currentGuess =
now + TimeDuration::FromMilliseconds(GetLongIdlePeriod());
if (deadline.isSome()) {
// If the idle period is too small, then just return a null time
// to indicate we are busy. Otherwise return the actual deadline.
TimeDuration minIdlePeriod =
TimeDuration::FromMilliseconds(GetMinIdlePeriod());
bool busySoon = deadline.value().IsNull() ||
(TimeStamp::Now() >= (deadline.value() - minIdlePeriod));
*aIdleDeadline = busySoon ? TimeStamp() : deadline.value();
} else {
*aIdleDeadline =
TimeStamp::Now() + TimeDuration::FromMilliseconds(GetLongIdlePeriod());
currentGuess = nsRefreshDriver::GetIdleDeadlineHint(currentGuess);
// If the idle period is too small, then just return a null time
// to indicate we are busy. Otherwise return the actual deadline.
TimeDuration minIdlePeriod =
TimeDuration::FromMilliseconds(GetMinIdlePeriod());
bool busySoon = currentGuess.IsNull() ||
(now >= (currentGuess - minIdlePeriod)) ||
if (!busySoon) {
*aIdleDeadline = currentGuess;
}
return NS_OK;