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)
This commit is contained in:
Owen W. Taylor 2013-01-28 12:22:57 -05:00 committed by Robert Bragg
parent d12f39d0e6
commit 98e3b57d0d
4 changed files with 75 additions and 0 deletions

View File

@ -756,4 +756,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;
}

View File

@ -319,6 +319,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

View File

@ -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,

View File

@ -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,