Bug 842967 - Prevent refresh driver re-targeting the same timestamp. r=vladimir
authorAvi Halachmi <avihpit@yahoo.com>
Wed, 20 Feb 2013 14:07:51 -0500
changeset 122478 8fd540d7aa8551f665617e9d1dc355272b555b88
parent 122477 2c9557cd695fc11cbef65578ef3fbbca62280a22
child 122479 8c18e64319054bcb0c5ad02353f3188538002313
push id24342
push userryanvm@gmail.com
push dateThu, 21 Feb 2013 13:05:06 +0000
treeherdermozilla-central@702d2814efbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladimir
bugs842967
milestone22.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
Bug 842967 - Prevent refresh driver re-targeting the same timestamp. r=vladimir
layout/base/nsRefreshDriver.cpp
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -247,16 +247,23 @@ public:
 protected:
   virtual void ScheduleNextTick(TimeStamp aNowTime)
   {
     // The number of (whole) elapsed intervals between the last target
     // time and the actual time.  We want to truncate the double down
     // to an int number of intervals.
     int numElapsedIntervals = static_cast<int>((aNowTime - mTargetTime) / mRateDuration);
 
+    if (numElapsedIntervals < 0) {
+      // It's possible that numElapsedIntervals is negative (e.g. timer compensation
+      // may result in (aNowTime - mTargetTime) < -1.0/mRateDuration, which will result in
+      // negative numElapsedIntervals), so make sure we don't target the same timestamp.
+      numElapsedIntervals = 0;
+    }
+
     // the last "tick" that may or may not have been actually sent was
     // at this time.  For example, if the rate is 15ms, the target
     // time is 200ms, and it's now 225ms, the last effective tick
     // would have been at 215ms.  The next one should then be
     // scheduled for 5 ms from now.
     //
     // We then add another mRateDuration to find the next tick target.
     TimeStamp newTarget = mTargetTime + mRateDuration * (numElapsedIntervals + 1);