[Cogl] [PATCH] cogland: Listen for Expose events when Cogl is using X
Robert Bragg
robert at sixbynine.org
Mon May 13 09:17:54 PDT 2013
This looks good to land to me, though it does highlight that it could
be worthwhile having a portable way for applications to be notified of
expose events. Cogl seems like the right place to handle this since
it's so tightly related to knowing when you must redraw something.
As a separate piece of work we could aim to add a
cogl_onscreen_add_expose_callback() api that will report expose
rectangles to applications when we are using X11, SDL or win32.
Reviewed-by: Robert Bragg <robert at linux.intel.com>
thanks,
- Robert
On Mon, May 13, 2013 at 5:01 PM, Neil Roberts <neil at linux.intel.com> wrote:
> Since 906e1b5eb535a86 Cogland no longer redraws constantly but instead
> only draws once at startup and then again whenever a client attaches a
> new buffer. Sometimes however it seems that the first paint will get
> lost perhaps because it is sent before the window is fully mapped. As
> it was previously not handling expose events it would not paint again
> until the first client is connected so there would be a blank window
> which looks broken.
>
> This patch makes it handle Expose events when it detects that Cogl is
> using an X backend. On other backends it will resort to queuing a
> redraw every 16ms as it did before.
>
> Although this is probably a bit overkill for such a small example, it
> seems like a good idea to only redraw when we think it's necessary so
> that we can be sure that the mechanism works. Handling the expose
> events means we can have at least one platform where we can test this.
> ---
> examples/cogland.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 77 insertions(+), 1 deletion(-)
>
> diff --git a/examples/cogland.c b/examples/cogland.c
> index c9c78d8..928a735 100644
> --- a/examples/cogland.c
> +++ b/examples/cogland.c
> @@ -8,6 +8,10 @@
>
> #include <wayland-server.h>
>
> +#ifdef COGL_HAS_XLIB_SUPPORT
> +#include <cogl/cogl-xlib.h>
> +#endif
> +
> typedef struct _CoglandCompositor CoglandCompositor;
>
> typedef struct
> @@ -1047,6 +1051,78 @@ create_cogl_context (CoglandCompositor *compositor,
> return context;
> }
>
> +#ifdef COGL_HAS_XLIB_SUPPORT
> +
> +static CoglFilterReturn
> +x_event_cb (XEvent *event,
> + void *data)
> +{
> + CoglandCompositor *compositor = data;
> +
> + if (event->type == Expose)
> + cogland_queue_redraw (compositor);
> +
> + return COGL_FILTER_CONTINUE;
> +}
> +
> +#endif /* COGL_HAS_XLIB_SUPPORT */
> +
> +static gboolean
> +timeout_cb (void *data)
> +{
> + cogland_queue_redraw (data);
> +
> + return TRUE;
> +}
> +
> +static void
> +init_redraws (CoglandCompositor *compositor)
> +{
> +#ifdef COGL_HAS_XLIB_SUPPORT
> + CoglRenderer *renderer = cogl_context_get_renderer (compositor->cogl_context);
> + CoglWinsysID winsys = cogl_renderer_get_winsys_id (renderer);
> +
> + /* If Cogl is using X then we can listen for Expose events to know
> + * when to repaint the window. Otherwise we don't have any code to
> + * know when the contents of the window is dirty so we'll just
> + * redraw constantly */
> + switch (winsys)
> + {
> + case COGL_WINSYS_ID_GLX:
> + case COGL_WINSYS_ID_EGL_XLIB:
> + {
> + Display *display = cogl_xlib_renderer_get_display (renderer);
> + GList *l;
> +
> + for (l = compositor->outputs; l; l = l->next)
> + {
> + CoglandOutput *output = l->data;
> + XWindowAttributes win_attribs;
> + Window win;
> +
> + win = cogl_x11_onscreen_get_window_xid (output->onscreen);
> + if (XGetWindowAttributes (display, win, &win_attribs))
> + {
> + XSelectInput (display,
> + win,
> + win_attribs.your_event_mask | ExposureMask);
> + cogl_xlib_renderer_add_filter (renderer,
> + x_event_cb,
> + compositor);
> +
> + }
> + }
> + }
> + return;
> +
> + default:
> + break;
> + }
> +#endif /* COGL_HAS_XLIB_SUPPORT */
> +
> + g_timeout_add (16, timeout_cb, compositor);
> +}
> +
> int
> main (int argc, char **argv)
> {
> @@ -1153,7 +1229,7 @@ main (int argc, char **argv)
>
> g_source_attach (cogl_source, NULL);
>
> - cogland_queue_redraw (&compositor);
> + init_redraws (&compositor);
>
> g_main_loop_run (loop);
>
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl
More information about the Cogl
mailing list