From 603f16c96b2f1e5040d819277602086cc9e03699 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Thu, 11 Feb 2016 16:33:03 -0500 Subject: [PATCH 3/7] CoglWinsysGLX: factor out some duplicated code Add a helper function for repeated calls to clock_gettime(CLOCK_MONOTONIC) --- cogl/winsys/cogl-winsys-glx.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c index 34fb071..ed20e81 100644 --- a/cogl/winsys/cogl-winsys-glx.c +++ b/cogl/winsys/cogl-winsys-glx.c @@ -187,6 +187,15 @@ find_onscreen_for_xid (CoglContext *context, uint32_t xid) return NULL; } +static int64_t +get_monotonic_time_ns (void) +{ + struct timespec ts; + + clock_gettime (CLOCK_MONOTONIC, &ts); + return ts.tv_sec * G_GINT64_CONSTANT (1000000000) + ts.tv_nsec; +} + static void ensure_ust_type (CoglRenderer *renderer, GLXDrawable drawable) @@ -197,7 +206,6 @@ ensure_ust_type (CoglRenderer *renderer, int64_t msc; int64_t sbc; struct timeval tv; - struct timespec ts; int64_t current_system_time; int64_t current_monotonic_time; @@ -227,9 +235,7 @@ ensure_ust_type (CoglRenderer *renderer, /* This is the time source that the newer (fixed) linux drm * drivers use (Linux >= 3.8) */ - clock_gettime (CLOCK_MONOTONIC, &ts); - current_monotonic_time = (ts.tv_sec * G_GINT64_CONSTANT (1000000)) + - (ts.tv_nsec / G_GINT64_CONSTANT (1000)); + current_monotonic_time = get_monotonic_time_ns () / 1000; if (current_monotonic_time > ust - 1000000 && current_monotonic_time < ust + 1000000) @@ -305,10 +311,7 @@ _cogl_winsys_get_clock_time (CoglContext *context) } 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; + return get_monotonic_time_ns (); } } @@ -1636,16 +1639,13 @@ _cogl_winsys_wait_for_vblank (CoglOnscreen *onscreen) else { uint32_t current_count; - struct timespec ts; glx_renderer->glXGetVideoSync (¤t_count); glx_renderer->glXWaitVideoSync (2, (current_count + 1) % 2, ¤t_count); - clock_gettime (CLOCK_MONOTONIC, &ts); - info->presentation_time = - ts.tv_sec * G_GINT64_CONSTANT (1000000000) + ts.tv_nsec; + info->presentation_time = get_monotonic_time_ns (); } } } -- 1.8.3.1