Bug 1169880 - Recompute image visibility on a timer if layout or style flushes have occurred. r=tn

This commit is contained in:
Seth Fowler 2015-05-29 23:50:51 -07:00
parent 4881006619
commit 865f2c6620
2 changed files with 40 additions and 0 deletions

View File

@ -78,6 +78,7 @@ static PRLogModuleInfo *gLog = nullptr;
#define DEFAULT_FRAME_RATE 60
#define DEFAULT_THROTTLED_FRAME_RATE 1
#define DEFAULT_RECOMPUTE_VISIBILITY_INTERVAL_MS 1000
// after 10 minutes, stop firing off inactive timers
#define DEFAULT_INACTIVE_TIMER_DISABLE_SECONDS 600
@ -970,6 +971,17 @@ nsRefreshDriver::GetThrottledTimerInterval()
return 1000.0 / rate;
}
/* static */ mozilla::TimeDuration
nsRefreshDriver::GetMinRecomputeVisibilityInterval()
{
int32_t interval =
Preferences::GetInt("layout.visibility.min-recompute-interval-ms", -1);
if (interval <= 0) {
interval = DEFAULT_RECOMPUTE_VISIBILITY_INTERVAL_MS;
}
return TimeDuration::FromMilliseconds(interval);
}
double
nsRefreshDriver::GetRefreshTimerInterval() const
{
@ -1016,7 +1028,9 @@ nsRefreshDriver::nsRefreshDriver(nsPresContext* aPresContext)
mFreezeCount(0),
mThrottledFrameRequestInterval(TimeDuration::FromMilliseconds(
GetThrottledTimerInterval())),
mMinRecomputeVisibilityInterval(GetMinRecomputeVisibilityInterval()),
mThrottled(false),
mNeedToRecomputeVisibility(false),
mTestControllingRefreshes(false),
mViewManagerFlushIsPending(false),
mRequestedHighPrecision(false),
@ -1028,6 +1042,7 @@ nsRefreshDriver::nsRefreshDriver(nsPresContext* aPresContext)
mMostRecentRefresh = TimeStamp::Now();
mMostRecentTick = mMostRecentRefresh;
mNextThrottledFrameRequestTick = mMostRecentTick;
mNextRecomputeVisibilityTick = mMostRecentTick;
}
nsRefreshDriver::~nsRefreshDriver()
@ -1676,6 +1691,8 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
NS_RELEASE(shell);
}
mNeedToRecomputeVisibility = true;
if (tracingStyleFlush) {
profiler_tracing("Paint", "Styles", TRACING_INTERVAL_END);
}
@ -1721,6 +1738,8 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
NS_RELEASE(shell);
}
mNeedToRecomputeVisibility = true;
if (tracingLayoutFlush) {
profiler_tracing("Paint", "Reflow", TRACING_INTERVAL_END);
}
@ -1728,6 +1747,17 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
}
}
// Recompute image visibility if it's necessary and enough time has passed
// since the last time we did it.
if (mNeedToRecomputeVisibility && !mThrottled &&
aNowTime >= mNextRecomputeVisibilityTick &&
!presShell->IsPaintingSuppressed()) {
mNextRecomputeVisibilityTick = aNowTime + mMinRecomputeVisibilityInterval;
mNeedToRecomputeVisibility = false;
presShell->ScheduleImageVisibilityUpdate();
}
/*
* Perform notification to imgIRequests subscribed to listen
* for refresh events.

View File

@ -339,6 +339,8 @@ private:
double GetRegularTimerInterval(bool *outIsDefault = nullptr) const;
static double GetThrottledTimerInterval();
static mozilla::TimeDuration GetMinRecomputeVisibilityInterval();
bool HaveFrameRequestCallbacks() const {
return mFrameRequestCallbackDocs.Length() != 0;
}
@ -367,7 +369,14 @@ private:
// non-visible) documents registered with a non-throttled refresh driver.
const mozilla::TimeDuration mThrottledFrameRequestInterval;
// How long we wait, at a minimum, before recomputing image visibility
// information. This is a minimum because, regardless of this interval, we
// only recompute visibility when we've seen a layout or style flush since the
// last time we did it.
const mozilla::TimeDuration mMinRecomputeVisibilityInterval;
bool mThrottled;
bool mNeedToRecomputeVisibility;
bool mTestControllingRefreshes;
bool mViewManagerFlushIsPending;
bool mRequestedHighPrecision;
@ -386,6 +395,7 @@ private:
mozilla::TimeStamp mMostRecentTick;
mozilla::TimeStamp mTickStart;
mozilla::TimeStamp mNextThrottledFrameRequestTick;
mozilla::TimeStamp mNextRecomputeVisibilityTick;
// separate arrays for each flush type we support
ObserverArray mObservers[3];