summaryrefslogtreecommitdiff
path: root/cogl/winsys/cogl-winsys-glx.c
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2013-01-28 12:22:57 -0500
committerRobert Bragg <robert@linux.intel.com>2013-01-30 20:09:49 +0000
commit98e3b57d0db878ffd58d5bef9f818e13416014f3 (patch)
tree54d21e8a55e0efa33b4da0d252dd1175df8686ea /cogl/winsys/cogl-winsys-glx.c
parentd12f39d0e6f9a1f592e556ad805cf71c376b059c (diff)
downloadcogl-98e3b57d0db878ffd58d5bef9f818e13416014f3.tar.gz
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> (cherry picked from commit 9f3735a0c37adcfcffa485f81699b53a4cc0caf8)
Diffstat (limited to 'cogl/winsys/cogl-winsys-glx.c')
-rw-r--r--cogl/winsys/cogl-winsys-glx.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 381c3a88..234e9da0 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -267,6 +267,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)
{
@@ -2563,6 +2599,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,