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



commit d8926ed5df70772d98952103ab529beb9945af0e
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.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/winsys/cogl-winsys-glx-feature-functions.h |   23 ++++++++++++++++
 cogl/winsys/cogl-winsys-glx.c                   |   33 ++++++++++++++++++-----
 2 files changed, 49 insertions(+), 7 deletions(-)
---
diff --git a/cogl/winsys/cogl-winsys-glx-feature-functions.h b/cogl/winsys/cogl-winsys-glx-feature-functions.h
index 40f7abc..1293af2 100644
--- a/cogl/winsys/cogl-winsys-glx-feature-functions.h
+++ b/cogl/winsys/cogl-winsys-glx-feature-functions.h
@@ -125,6 +125,29 @@ COGL_WINSYS_FEATURE_FUNCTION (int, glXSwapInterval,
 COGL_WINSYS_FEATURE_END ()
 
 COGL_WINSYS_FEATURE_BEGIN (255, 255,
+                           sync_control,
+                           "OML\0",
+                           "sync_control\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 (255, 255,
                            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 ddc1092..2b28420 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -429,7 +429,8 @@ update_base_winsys_features (CoglRenderer *renderer)
                   COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
                   TRUE);
 
-  if (glx_renderer->glXWaitVideoSync)
+  if (glx_renderer->pf_glXWaitVideoSync ||
+      glx_renderer->pf_glXWaitForMsc)
     COGL_FLAGS_SET (glx_renderer->base_winsys_features,
                     COGL_WINSYS_FEATURE_VBLANK_WAIT,
                     TRUE);
@@ -1277,14 +1278,32 @@ _cogl_winsys_wait_for_vblank (CoglContext *ctx)
 
   glx_renderer = ctx->display->renderer->winsys;
 
-  if (glx_renderer->glXGetVideoSync)
+  if (glx_renderer->glXWaitForMsc ||
+      glx_renderer->glXGetVideoSync)
     {
-      uint32_t current_count;
+      if (glx_renderer->glXWaitForMsc)
+        {
+          CoglOnscreenGLX *glx_onscreen = onscreen->winsys;
+          Drawable drawable = glx_onscreen->glxwin;
+          int64_t ust;
+          int64_t msc;
+          int64_t sbc;
+
+          glx_renderer->glXGetSyncValues (xlib_renderer->xdpy, drawable,
+                                          &ust, &msc, &sbc);
+          glx_renderer->glXWaitForMsc (xlib_renderer->xdpy, drawable,
+                                       0, 2, (msc + 1) % 2,
+                                       &ust, &msc, &sbc);
+        }
+      else
+        {
+          uint32_t current_count;
 
-      glx_renderer->glXGetVideoSync (&current_count);
-      glx_renderer->glXWaitVideoSync (2,
-                                      (current_count + 1) % 2,
-                                      &current_count);
+          glx_renderer->glXGetVideoSync (&current_count);
+          glx_renderer->glXWaitVideoSync (2,
+                                          (current_count + 1) % 2,
+                                          &current_count);
+        }
     }
 }
 



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