[Cogl] [PATCH 2/3] Prefer OML_sync_control over SGI_video_sync when waiting for swap

otaylor at redhat.com otaylor at redhat.com
Wed Nov 28 08:47:50 PST 2012


From: "Owen W. Taylor" <otaylor at fishsoup.net>

When we block waiting for the swap, prefer doing that using
glXWaitForMsc() from OML_sync_control because that returns a system
time value for the precise time of the swap.
---
 cogl/winsys/cogl-winsys-glx-feature-functions.h | 23 +++++++++++++++++
 cogl/winsys/cogl-winsys-glx.c                   | 34 ++++++++++++++++++++-----
 2 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/cogl/winsys/cogl-winsys-glx-feature-functions.h b/cogl/winsys/cogl-winsys-glx-feature-functions.h
index 71fd827..837b22b 100644
--- a/cogl/winsys/cogl-winsys-glx-feature-functions.h
+++ b/cogl/winsys/cogl-winsys-glx-feature-functions.h
@@ -84,6 +84,29 @@ COGL_WINSYS_FEATURE_FUNCTION (int, glXSwapInterval,
                               (int interval))
 COGL_WINSYS_FEATURE_END ()
 
+COGL_WINSYS_FEATURE_BEGIN (sync_control,
+                           "OML\0",
+                           "sync_control\0",
+                           0,
+                           0,
+                           0)
+COGL_WINSYS_FEATURE_FUNCTION (Bool, glXGetSyncValues,
+                              (Display* dpy,
+                               GLXDrawable drawable,
+                               int64_t* ust,
+                               int64_t* msc,
+                               int64_t* sbc))
+COGL_WINSYS_FEATURE_FUNCTION (Bool, glXWaitForMsc,
+                              (Display* dpy,
+                               GLXDrawable drawable,
+                               int64_t target_msc,
+                               int64_t divisor,
+                               int64_t remainder,
+                               int64_t* ust,
+                               int64_t* msc,
+                               int64_t* sbc))
+COGL_WINSYS_FEATURE_END ()
+
 COGL_WINSYS_FEATURE_BEGIN (copy_sub_buffer,
                            "MESA\0",
                            "copy_sub_buffer\0",
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index e7f83ab..4714c9a 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -525,7 +525,8 @@ update_winsys_features (CoglContext *context, GError **error)
                       FALSE);
     }
 
-  if (glx_renderer->pf_glXWaitVideoSync)
+  if (glx_renderer->pf_glXWaitVideoSync ||
+      glx_renderer->pf_glXWaitForMsc)
     COGL_FLAGS_SET (context->winsys_features,
                     COGL_WINSYS_FEATURE_VBLANK_WAIT,
                     TRUE);
@@ -1224,14 +1225,33 @@ _cogl_winsys_wait_for_vblank (void)
 
   glx_renderer = ctx->display->renderer->winsys;
 
-  if (glx_renderer->pf_glXGetVideoSync)
+  if (glx_renderer->pf_glXWaitForMsc ||
+      glx_renderer->pf_glXGetVideoSync)
     {
-      uint32_t current_count;
 
-      glx_renderer->pf_glXGetVideoSync (&current_count);
-      glx_renderer->pf_glXWaitVideoSync (2,
-                                         (current_count + 1) % 2,
-                                         &current_count);
+      if (glx_renderer->pf_glXWaitForMsc)
+        {
+          CoglOnscreenGLX *glx_onscreen = onscreen->winsys;
+          Drawable drawable = glx_onscreen->glxwin;
+          int64_t ust;
+          int64_t msc;
+          int64_t sbc;
+
+          glx_renderer->pf_glXGetSyncValues (xlib_renderer->xdpy, drawable,
+                                             &ust, &msc, &sbc);
+          glx_renderer->pf_glXWaitForMsc (xlib_renderer->xdpy, drawable,
+                                          0, 2, (msc + 1) % 2,
+                                          &ust, &msc, &sbc);
+        }
+      else
+        {
+          uint32_t current_count;
+
+          glx_renderer->pf_glXGetVideoSync (&current_count);
+          glx_renderer->pf_glXWaitVideoSync (2,
+                                             (current_count + 1) % 2,
+                                             &current_count);
+        }
     }
 }
 
-- 
1.7.12.1



More information about the Cogl mailing list