b=823091; 2nd tab in a window opens without animation (timers reporting wrong current time); r=roc,bz
authorVladimir Vukicevic <vladimir@pobox.com>
Sun, 23 Dec 2012 19:29:23 -0500
changeset 116981 aa8b7e9cc8e542ec6286e03fd8cf43343d24b5eb
parent 116980 9db20066eb63dbfbf0ebe0f5182ff2669477f521
child 116982 3af8b1ebd83ae0112e0476ead81299f84f7c6a3e
push id24077
push userryanvm@gmail.com
push dateMon, 24 Dec 2012 13:05:31 +0000
treeherdermozilla-central@dc2abccc2adb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, bz
bugs823091
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
b=823091; 2nd tab in a window opens without animation (timers reporting wrong current time); r=roc,bz
layout/base/nsRefreshDriver.cpp
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -203,20 +203,24 @@ public:
   {
     StopTimer();
   }
 
 protected:
 
   virtual void StartTimer()
   {
+    // pretend we just fired, and we schedule the next tick normally
+    mLastFireEpoch = JS_Now();
     mLastFireTime = TimeStamp::Now();
-    mTargetTime = mLastFireTime;
+
+    mTargetTime = mLastFireTime + mRateDuration;
 
-    mTimer->InitWithFuncCallback(TimerTick, this, 0, nsITimer::TYPE_ONE_SHOT);
+    uint32_t delay = static_cast<uint32_t>(mRateMilliseconds);
+    mTimer->InitWithFuncCallback(TimerTick, this, delay, nsITimer::TYPE_ONE_SHOT);
   }
 
   virtual void StopTimer()
   {
     mTimer->Cancel();
   }
 
   nsRefPtr<nsITimer> mTimer;
@@ -273,16 +277,17 @@ protected:
 
     // log info & lateness
     LOG("[%p] precise timer last tick late by %f ms, next tick in %d ms",
         this,
         (aNowTime - mTargetTime).ToMilliseconds(),
         delay);
 
     // then schedule the timer
+    LOG("[%p] scheduling callback for %d ms (2)", this, delay);
     mTimer->InitWithFuncCallback(TimerTick, this, delay, nsITimer::TYPE_ONE_SHOT);
 
     mTargetTime = newTarget;
   }
 };
 
 /*
  * A RefreshDriverTimer for inactive documents.  When a new refresh driver is
@@ -335,20 +340,23 @@ public:
 
     StopTimer();
     StartTimer();
   }
 
 protected:
   virtual void StartTimer()
   {
+    mLastFireEpoch = JS_Now();
     mLastFireTime = TimeStamp::Now();
-    mTargetTime = mLastFireTime;
+
+    mTargetTime = mLastFireTime + mRateDuration;
 
-    mTimer->InitWithFuncCallback(TimerTickOne, this, 0, nsITimer::TYPE_ONE_SHOT);
+    uint32_t delay = static_cast<uint32_t>(mRateMilliseconds);
+    mTimer->InitWithFuncCallback(TimerTickOne, this, delay, nsITimer::TYPE_ONE_SHOT);
   }
 
   virtual void StopTimer()
   {
     mTimer->Cancel();
   }
 
   virtual void ScheduleNextTick(TimeStamp aNowTime)
@@ -558,22 +566,26 @@ nsRefreshDriver::RestoreNormalRefresh()
 {
   mTestControllingRefreshes = false;
   EnsureTimerStarted(false);
 }
 
 TimeStamp
 nsRefreshDriver::MostRecentRefresh() const
 {
+  const_cast<nsRefreshDriver*>(this)->EnsureTimerStarted(false);
+
   return mMostRecentRefresh;
 }
 
 int64_t
 nsRefreshDriver::MostRecentRefreshEpochTime() const
 {
+  const_cast<nsRefreshDriver*>(this)->EnsureTimerStarted(false);
+
   return mMostRecentRefreshEpochTime;
 }
 
 bool
 nsRefreshDriver::AddRefreshObserver(nsARefreshObserver* aObserver,
                                     mozFlushType aFlushType)
 {
   ObserverArray& array = ArrayFor(aFlushType);
@@ -636,16 +648,19 @@ nsRefreshDriver::EnsureTimerStarted(bool
   // prehaps removing it from a previously-set one.
   RefreshDriverTimer *newTimer = ChooseTimer();
   if (newTimer != mActiveTimer) {
     if (mActiveTimer)
       mActiveTimer->RemoveRefreshDriver(this);
     mActiveTimer = newTimer;
     mActiveTimer->AddRefreshDriver(this);
   }
+
+  mMostRecentRefresh = mActiveTimer->MostRecentRefresh();
+  mMostRecentRefreshEpochTime = mActiveTimer->MostRecentRefreshEpochTime();
 }
 
 void
 nsRefreshDriver::StopTimer()
 {
   if (!mActiveTimer)
     return;