Bug 1279744 - Improve fallback handling for glXWaitVideoSync. r=lsalzman
authorAndrew Comminos <andrew@comminos.com>
Tue, 14 Jun 2016 13:19:43 +0100
changeset 301951 b4867459589df246d85972669074233b8d2e23b8
parent 301950 a2e4369f86dcf620b453de3da6525a87ea1808fc
child 301952 4e16558233f985125db446de2b3fee7055b2b623
push id19704
push usercbook@mozilla.com
push dateFri, 17 Jun 2016 00:03:56 +0000
treeherderfx-team@5f95858f8ddf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1279744
milestone50.0a1
Bug 1279744 - Improve fallback handling for glXWaitVideoSync. r=lsalzman MozReview-Commit-ID: JXy6yupyd3v
gfx/thebes/gfxPlatformGtk.cpp
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -765,33 +765,42 @@ public:
           MonitorAutoLock lock(mVsyncEnabledLock);
           if (!mVsyncEnabled) {
             mVsyncTask = nullptr;
             return;
           }
         }
 
         TimeStamp lastVsync = TimeStamp::Now();
+        bool useSoftware = false;
+
         // Wait until the video sync counter reaches the next value by waiting
         // until the parity of the counter value changes.
         unsigned int nextSync = syncCounter + 1;
-        if (gl::sGLXLibrary.xWaitVideoSync(2, nextSync % 2,
-                                           &syncCounter) == 0) {
-          if (syncCounter == (nextSync - 1)) {
-            gfxWarning() << "GLX sync counter failed to increment after glXWaitVideoSync!\n";
-            // If we failed to block until the next sync, fallback to software.
-            double remaining = (1000.f / 60.f) -
-                               (TimeStamp::Now() - lastVsync).ToMilliseconds();
-            if (remaining > 0) {
-              PlatformThread::Sleep(remaining);
-            }
+        int status;
+        if ((status = gl::sGLXLibrary.xWaitVideoSync(2, nextSync % 2, &syncCounter)) != 0) {
+          gfxWarningOnce() << "glXWaitVideoSync returned " << status;
+          useSoftware = true;
+        }
+
+        if (syncCounter == (nextSync - 1)) {
+          gfxWarningOnce() << "glXWaitVideoSync failed to increment the sync counter.";
+          useSoftware = true;
+        }
+
+        if (useSoftware) {
+          double remaining = (1000.f / 60.f) -
+            (TimeStamp::Now() - lastVsync).ToMilliseconds();
+          if (remaining > 0) {
+            PlatformThread::Sleep(remaining);
           }
-          lastVsync = TimeStamp::Now();
-          NotifyVsync(lastVsync);
         }
+
+        lastVsync = TimeStamp::Now();
+        NotifyVsync(lastVsync);
       }
     }
 
     void Cleanup() {
       MOZ_ASSERT(!NS_IsMainThread());
 
       mGLContext = nullptr;
       XCloseDisplay(mXDisplay);