[cogl/wip/rib/frame-synchronization: 4/4] Add cogl_get_clock_time()



commit 117d41ba275b280f7c17de94c1c38571bc1d5306
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Mon Jan 28 12:22:57 2013 -0500

    Add cogl_get_clock_time()
    
    Add an API to get the current time in the time system that Cogl
    is reporting timestamps. This is to be used to convert timestamps
    into a different time system.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/cogl-context.c               |   12 ++++++++++++
 cogl/cogl-context.h               |   23 +++++++++++++++++++++++
 cogl/winsys/cogl-winsys-glx.c     |   37 +++++++++++++++++++++++++++++++++++++
 cogl/winsys/cogl-winsys-private.h |    3 +++
 4 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 6eab423..24052c9 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -676,4 +676,16 @@ _cogl_context_get_gl_version (CoglContext *context)
     return _cogl_config_override_gl_version;
   else
     return (const char *) context->glGetString (GL_VERSION);
+
+}
+
+int64_t
+cogl_get_clock_time (CoglContext *context)
+{
+  const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context);
+
+  if (winsys->context_get_clock_time)
+    return winsys->context_get_clock_time (context);
+  else
+    return 0;
 }
diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h
index 810e653..1b6b878 100644
--- a/cogl/cogl-context.h
+++ b/cogl/cogl-context.h
@@ -313,6 +313,29 @@ cogl_foreach_feature (CoglContext *context,
                       CoglFeatureCallback callback,
                       void *user_data);
 
+/**
+ * cogl_get_clock_time:
+ * @context: a #CoglContext pointer
+ *
+ * Returns the current time value from Cogl's internal clock. This
+ * clock is used for measuring times such as the presentation time
+ * in a #CoglFrameInfo.
+ *
+ * This method is meant for converting timestamps retrieved from Cogl
+ * to other time systems, and is not meant to be used as a standalone
+ * timing system. For that reason, if this function is called without
+ * having retrieved a valid (non-zero) timestamp from Cogl first, it
+ * may return 0 to indicate that Cogl has no active internal clock.
+ *
+ * Return value: the time value for the Cogl clock, in nanoseconds
+ *  from an arbitrary point in time, or 0 if Cogl doesn't have an
+ *  active internal clock.
+ * Since: 1.14
+ * Stability: unstable
+ */
+int64_t
+cogl_get_clock_time (CoglContext *context);
+
 COGL_END_DECLS
 
 #endif /* __COGL_CONTEXT_H__ */
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 10f0d9a..f559f15 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -264,6 +264,42 @@ ust_to_nanoseconds (CoglRenderer *renderer,
   return 0;
 }
 
+static int64_t
+_cogl_winsys_get_clock_time (CoglContext *context)
+{
+  CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
+
+  /* We don't call ensure_ust_type() because we don't have a drawable
+   * to work with. cogl_get_clock_time() is documented to only work
+   * once a valid, non-zero, timestamp has been retrieved from Cogl.
+   */
+
+  switch (glx_renderer->ust_type)
+    {
+    case COGL_GLX_UST_IS_UNKNOWN:
+    case COGL_GLX_UST_IS_OTHER:
+      return 0;
+    case COGL_GLX_UST_IS_GETTIMEOFDAY:
+      {
+        struct timeval tv;
+
+        gettimeofday(&tv, NULL);
+        return tv.tv_sec * G_GINT64_CONSTANT (1000000000) +
+          tv.tv_usec * G_GINT64_CONSTANT (1000);
+      }
+    case COGL_GLX_UST_IS_MONOTONIC_TIME:
+      {
+        struct timespec ts;
+
+        clock_gettime (CLOCK_MONOTONIC, &ts);
+        return ts.tv_sec * G_GINT64_CONSTANT (1000000000) + ts.tv_nsec;
+      }
+    }
+
+  g_assert_not_reached();
+  return 0;
+}
+
 static void
 set_sync_pending (CoglOnscreen *onscreen)
 {
@@ -2554,6 +2590,7 @@ static CoglWinsysVtable _cogl_winsys_vtable =
     .display_destroy = _cogl_winsys_display_destroy,
     .context_init = _cogl_winsys_context_init,
     .context_deinit = _cogl_winsys_context_deinit,
+    .context_get_clock_time = _cogl_winsys_get_clock_time,
     .xlib_get_visual_info = _cogl_winsys_xlib_get_visual_info,
     .onscreen_init = _cogl_winsys_onscreen_init,
     .onscreen_deinit = _cogl_winsys_onscreen_deinit,
diff --git a/cogl/winsys/cogl-winsys-private.h b/cogl/winsys/cogl-winsys-private.h
index fe87e06..36676e3 100644
--- a/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/winsys/cogl-winsys-private.h
@@ -122,6 +122,9 @@ typedef struct _CoglWinsysVtable
 
   /* Optional functions */
 
+  int64_t
+  (*context_get_clock_time) (CoglContext *context);
+
   void
   (*onscreen_swap_region) (CoglOnscreen *onscreen,
                            const int *rectangles,



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