[Cogl] [PATCH 1/4] Adds cogl_swap_info_get_refresh_interval api back

Robert Bragg robert at sixbynine.org
Fri Jan 11 08:40:42 PST 2013


From: Robert Bragg <robert at linux.intel.com>

After a discussion on IRC we discussed the fact that some window systems
won't allow us to associate a CoglOutput with a CoglSwapInfo object but
they can report a refresh_interval. This justifies being able to query
the refresh_interval without needing to use
cogl_output_get_refresh_rate().

XXX: One remaining issue here though is why can't we be more consistent
and return a _refresh_rate() instead of a _refresh_interval().

TODO: squash this back into owen's patch
---
 cogl/cogl-swap-info-private.h |    1 +
 cogl/cogl-swap-info.c         |    6 ++++++
 cogl/cogl-swap-info.h         |   20 ++++++++++++++++++++
 cogl/winsys/cogl-winsys-glx.c |   16 ++++++++++++++++
 4 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/cogl/cogl-swap-info-private.h b/cogl/cogl-swap-info-private.h
index 61953fa..2e67fb0 100644
--- a/cogl/cogl-swap-info-private.h
+++ b/cogl/cogl-swap-info-private.h
@@ -34,6 +34,7 @@ struct _CoglSwapInfo
 
   int64_t frame_counter;
   int64_t presentation_time;
+  int64_t refresh_interval;
 
   CoglOutput *output;
 };
diff --git a/cogl/cogl-swap-info.c b/cogl/cogl-swap-info.c
index e8f83bd..dfb0c13 100644
--- a/cogl/cogl-swap-info.c
+++ b/cogl/cogl-swap-info.c
@@ -59,6 +59,12 @@ cogl_swap_info_get_presentation_time (CoglSwapInfo *info)
   return info->presentation_time;
 }
 
+int64_t
+cogl_swap_info_get_refresh_interval (CoglSwapInfo *info)
+{
+  return info->refresh_interval;
+}
+
 CoglOutput *
 cogl_swap_info_get_output (CoglSwapInfo *info)
 {
diff --git a/cogl/cogl-swap-info.h b/cogl/cogl-swap-info.h
index 62728b6..699c845 100644
--- a/cogl/cogl-swap-info.h
+++ b/cogl/cogl-swap-info.h
@@ -82,6 +82,26 @@ int64_t cogl_swap_info_get_frame_counter (CoglSwapInfo *info);
 int64_t cogl_swap_info_get_presentation_time (CoglSwapInfo *info);
 
 /**
+ * cogl_swap_info_get_refresh_interval:
+ * @info: a #CoglSwapInfo object
+ *
+ * Gets the refresh interval for the output that the frame was on at the
+ * time the frame was presented. This is the number of microseconds between
+ * refreshes of the screen, and is equal to 1000000 / refresh_rate.
+ *
+ * <note>Some platforms can't associate a #CoglOutput with a
+ * #CoglSwapInfo object but are able to report a refresh_interval via
+ * this api. Therefore if you need this information then this api is
+ * more reliable than using cogl_swap_info_get_output() followed by
+ * cogl_output_get_refresh_rate().</note>
+ *
+ * Return value: the refresh interval, in microsecoonds.
+ * Since: 2.0
+ * Stability: unstable
+ */
+int64_t cogl_swap_info_get_refresh_interval (CoglSwapInfo *info);
+
+/**
  * cogl_swap_info_get_output:
  * @info: a #CoglSwapInfo object
  *
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 2917b6c..a6528f4 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -1405,6 +1405,19 @@ _cogl_winsys_get_vsync_counter (void)
 }
 
 static void
+set_refresh_interval_from_output (CoglOnscreen *onscreen,
+                                  CoglOutput *output)
+{
+#warning "XXX: why not be consistent and also report a refresh_rate for the SwapInfo?"
+  float refresh_rate = cogl_output_get_refresh_rate (output);
+  if (refresh_rate != 0.0)
+    {
+      CoglSwapInfo *info = g_queue_peek_tail (&onscreen->pending_swap_infos);
+      info->refresh_interval = (int)(0.5 + (1000000. / refresh_rate));
+    }
+}
+
+static void
 _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
                                    const int *user_rectangles,
                                    int n_rectangles)
@@ -1594,6 +1607,9 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
                                                   xlib_onscreen->y + y_min,
                                                   x_max - x_min,
                                                   y_max - y_min);
+
+      if (info->output)
+        set_refresh_interval_from_output (onscreen, info->output);
     }
 }
 
-- 
1.7.7.6



More information about the Cogl mailing list