mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 04:22:05 +00:00
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. Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
cbbac5a2f5
commit
e28db24f7d
@ -24,6 +24,8 @@ typedef struct _Data
|
|||||||
|
|
||||||
GTimer *timer;
|
GTimer *timer;
|
||||||
|
|
||||||
|
gboolean swap_ready;
|
||||||
|
|
||||||
} Data;
|
} Data;
|
||||||
|
|
||||||
/* A static identity matrix initialized for convenience. */
|
/* A static identity matrix initialized for convenience. */
|
||||||
@ -133,6 +135,15 @@ paint (Data *data)
|
|||||||
&white, 0);
|
&white, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
swap_notify_cb (CoglFramebuffer *framebuffer,
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
Data *data = user_data;
|
||||||
|
|
||||||
|
data->swap_ready = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -144,6 +155,7 @@ main (int argc, char **argv)
|
|||||||
PangoRectangle hello_label_size;
|
PangoRectangle hello_label_size;
|
||||||
float fovy, aspect, z_near, z_2d, z_far;
|
float fovy, aspect, z_near, z_2d, z_far;
|
||||||
CoglDepthState depth_state;
|
CoglDepthState depth_state;
|
||||||
|
gboolean has_swap_notify;
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
@ -270,17 +282,41 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
cogl_push_framebuffer (fb);
|
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)
|
while (1)
|
||||||
{
|
{
|
||||||
CoglPollFD *poll_fds;
|
CoglPollFD *poll_fds;
|
||||||
int n_poll_fds;
|
int n_poll_fds;
|
||||||
gint64 timeout;
|
gint64 timeout;
|
||||||
|
|
||||||
paint (&data);
|
if (data.swap_ready)
|
||||||
cogl_framebuffer_swap_buffers (fb);
|
{
|
||||||
|
paint (&data);
|
||||||
|
cogl_framebuffer_swap_buffers (fb);
|
||||||
|
}
|
||||||
|
|
||||||
cogl_poll_get_info (ctx, &poll_fds, &n_poll_fds, &timeout);
|
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);
|
cogl_poll_dispatch (ctx, poll_fds, n_poll_fds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user