Blame SOURCES/0003-CoglWinsysGLX-factor-out-some-duplicated-code.patch

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