[cogl/wip/rib/frame-synchronization: 4/12] Prefer OML_sync_control over SGI_video_sync when waiting for swap



commit 96d5fce547f459e4cf02052e028d9809454dbf79
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Mon Nov 12 11:52:31 2012 -0500

    Prefer OML_sync_control over SGI_video_sync when waiting for swap
    
    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 f52304d..3a3988f 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -529,7 +529,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);
@@ -1228,14 +1229,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);
+        }
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]