[cogl/wip/frame-synchronization] Add cogl_clock_get_time()
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/frame-synchronization] Add cogl_clock_get_time()
- Date: Mon, 28 Jan 2013 17:28:42 +0000 (UTC)
commit 312e0651a273c3cbc32838b40d51186bc28f00be
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Mon Jan 28 12:22:57 2013 -0500
Add cogl_clock_get_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.
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 5f3453f..15e78c5 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -748,4 +748,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 ae306d6..5e44fa9 100644
--- a/cogl/cogl-context.h
+++ b/cogl/cogl-context.h
@@ -322,6 +322,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);
+
#endif /* COGL_ENABLE_EXPERIMENTAL_API */
COGL_END_DECLS
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 4e1c91c..895b612 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -281,6 +281,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_complete_pending (CoglOnscreen *onscreen)
{
@@ -2516,6 +2552,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 36f4401..745ea6d 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]