[cogl/fosdem-2012: 12/17] cogl-crate: Optionally use the swap buffers notify mechanism
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/fosdem-2012: 12/17] cogl-crate: Optionally use the swap buffers notify mechanism
- Date: Wed, 4 Jan 2012 20:57:22 +0000 (UTC)
commit 11288a776ea450929e329bcdf613c3402e5f0c7f
Author: Neil Roberts <neil linux intel com>
Date: Mon Dec 19 19:29:47 2011 +0000
cogl-crate: Optionally use the swap buffers notify mechanism
If the swap buffers notify mechanism is advertised then the crate
example will now register a callback for it and call g_poll with the
proper timeout from cogl_context_begin_idle instead of trying to
repaint continuously.
examples/cogl-crate.c | 42 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/examples/cogl-crate.c b/examples/cogl-crate.c
index 393e670..3c9ee43 100644
--- a/examples/cogl-crate.c
+++ b/examples/cogl-crate.c
@@ -24,6 +24,8 @@ typedef struct _Data
GTimer *timer;
+ gboolean swap_ready;
+
} Data;
/* A static identity matrix initialized for convenience. */
@@ -133,6 +135,15 @@ paint (Data *data)
&white, 0);
}
+static void
+swap_notify_cb (CoglFramebuffer *framebuffer,
+ void *user_data)
+{
+ Data *data = user_data;
+
+ data->swap_ready = TRUE;
+}
+
int
main (int argc, char **argv)
{
@@ -144,6 +155,7 @@ main (int argc, char **argv)
PangoRectangle hello_label_size;
float fovy, aspect, z_near, z_2d, z_far;
CoglDepthState depth_state;
+ gboolean has_swap_notify;
g_type_init ();
@@ -270,17 +282,41 @@ main (int argc, char **argv)
cogl_push_framebuffer (fb);
+ data.swap_ready = TRUE;
+
+ has_swap_notify =
+ cogl_has_feature (ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT);
+
+ if (has_swap_notify)
+ cogl_framebuffer_add_swap_buffers_callback (fb,
+ swap_notify_cb,
+ &data);
+
while (1)
{
CoglPollFD *poll_fds;
int n_poll_fds;
gint64 timeout;
- paint (&data);
- cogl_framebuffer_swap_buffers (fb);
+ if (data.swap_ready)
+ {
+ paint (&data);
+ cogl_framebuffer_swap_buffers (fb);
+ }
cogl_poll_get_info (ctx, &poll_fds, &n_poll_fds, &timeout);
- g_poll ((GPollFD *) poll_fds, n_poll_fds, 0);
+
+ if (!has_swap_notify)
+ {
+ /* If the winsys doesn't support swap event notification
+ then we'll just redraw constantly */
+ data.swap_ready = TRUE;
+ timeout = 0;
+ }
+
+ g_poll ((GPollFD *) poll_fds, n_poll_fds,
+ timeout == -1 ? -1 : timeout / 1000);
+
cogl_poll_dispatch (ctx, poll_fds, n_poll_fds);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]