Bug 1295214. Correct for negative vsync timestamps on windows. r=jrmuizel a=ritu
authorMason Chang <mchang@mozilla.com>
Thu, 25 Aug 2016 08:53:07 -0700
changeset 332957 d46712bc4455
parent 332956 aaa878146a67
child 332958 4c1c760f05a8
push id9959
push userkwierso@gmail.com
push dateTue, 30 Aug 2016 17:44:34 +0000
treeherdermozilla-aurora@5ed3f227fe0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, ritu
bugs1295214
milestone50.0a2
Bug 1295214. Correct for negative vsync timestamps on windows. r=jrmuizel a=ritu
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -1873,26 +1873,32 @@ public:
           // Windows 10 and Intel HD vsync timestamps are messy and
           // all over the place once in a while. Most of the time,
           // it reports the upcoming vsync. Sometimes, that upcoming
           // vsync is in the past. Sometimes that upcoming vsync is before
           // the previously seen vsync.
           // In these error cases, normalize to Now();
           if (vsync >= now) {
             vsync = vsync - mVsyncRate;
-            return vsync <= now ? vsync : now;
           }
         }
 
         // On Windows 7 and 8, DwmFlush wakes up AFTER qpcVBlankTime
         // from DWMGetCompositionTimingInfo. We can return the adjusted vsync.
-        // If we got here on Windows 10, it means we got a weird timestamp.
         if (vsync >= now) {
             vsync = now;
         }
+
+        // Our vsync time is some time very far in the past, adjust to Now.
+        // 4 ms is arbitrary, so feel free to pick something else if this isn't
+        // working. See the comment above within IsWin10OrLater().
+        if ((now - vsync).ToMilliseconds() > 4.0) {
+            vsync = now;
+        }
+
         return vsync;
       }
 
       void VBlankLoop()
       {
         MOZ_ASSERT(IsInVsyncThread());
         MOZ_ASSERT(sizeof(int64_t) == sizeof(QPC_TIME));
 
@@ -1948,16 +1954,22 @@ public:
               // DWMFlush woke up very early, so readjust our times again
               vsync = GetVBlankTime();
             }
 
             if (vsync <= mPrevVsync) {
               vsync = TimeStamp::Now();
             }
 
+            if ((now - vsync).ToMilliseconds() > 2.0) {
+              // Account for time drift here where vsync never quite catches up to
+              // Now and we'd fall ever so slightly further behind Now().
+              vsync = GetVBlankTime();
+            }
+
             mPrevVsync = vsync;
           }
         } // end for
       }
 
     private:
       virtual ~D3DVsyncDisplay()
       {