[cogl/cogl-1.14] cogland: Try forcing an EGL context
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/cogl-1.14] cogland: Try forcing an EGL context
- Date: Mon, 22 Apr 2013 12:01:46 +0000 (UTC)
commit 856e9aa5f4bd89284705de50665c0aa323966af3
Author: Neil Roberts <neil linux intel com>
Date: Thu Apr 11 17:02:05 2013 +0100
cogland: Try forcing an EGL context
Cogland works a lot better with an EGL context because then Mesa will
automatically set up the wl_drm object and it can accept DRM buffers.
However Cogland is still useful with GLX because it can gracefully
fallback to accepting only SHM buffers. This patch therefore makes it
first try creating and connecting a renderer with the EGL constraint,
but if that doesn't work it will try again without it.
Reviewed-by: Robert Bragg <robert linux intel com>
(cherry picked from commit 05ddc7d75e77538b5de22d4336d4a444d122063b)
examples/cogland.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 54 insertions(+), 8 deletions(-)
---
diff --git a/examples/cogland.c b/examples/cogland.c
index 0f82d60..ab4f3c1 100644
--- a/examples/cogland.c
+++ b/examples/cogland.c
@@ -93,7 +93,6 @@ struct _CoglandCompositor
struct wl_display *wayland_display;
struct wl_event_loop *wayland_loop;
- CoglDisplay *cogl_display;
CoglContext *cogl_context;
int virtual_width;
@@ -1019,6 +1018,36 @@ bind_shell (struct wl_client *client,
&cogland_shell_interface, id, data);
}
+static CoglContext *
+create_cogl_context (CoglandCompositor *compositor,
+ CoglBool use_egl_constraint,
+ CoglError **error)
+{
+ CoglRenderer *renderer = renderer = cogl_renderer_new ();
+ CoglDisplay *display;
+ CoglContext *context;
+
+ if (use_egl_constraint)
+ cogl_renderer_add_constraint (renderer, COGL_RENDERER_CONSTRAINT_USES_EGL);
+
+ if (!cogl_renderer_connect (renderer, error))
+ {
+ cogl_object_unref (renderer);
+ return NULL;
+ }
+
+ display = cogl_display_new (renderer, NULL);
+ cogl_wayland_display_set_compositor_display (display,
+ compositor->wayland_display);
+
+ context = cogl_context_new (display, error);
+
+ cogl_object_unref (renderer);
+ cogl_object_unref (display);
+
+ return context;
+}
+
int
main (int argc, char **argv)
{
@@ -1062,13 +1091,30 @@ main (int argc, char **argv)
wayland_event_source_new (compositor.wayland_display);
g_source_attach (compositor.wayland_event_source, NULL);
- compositor.cogl_display = cogl_display_new (NULL, NULL);
- cogl_wayland_display_set_compositor_display (compositor.cogl_display,
- compositor.wayland_display);
-
- compositor.cogl_context = cogl_context_new (compositor.cogl_display, &error);
- if (!compositor.cogl_context)
- g_error ("Failed to create a Cogl context: %s\n", error->message);
+ /* We want Cogl to use an EGL renderer because otherwise it won't
+ * set up the wl_drm object and only SHM buffers will work. */
+ compositor.cogl_context =
+ create_cogl_context (&compositor,
+ TRUE /* use EGL constraint */,
+ &error);
+ if (compositor.cogl_context == NULL)
+ {
+ /* If we couldn't get an EGL context then try any type of
+ * context */
+ cogl_error_free (error);
+ error = NULL;
+
+ compositor.cogl_context =
+ create_cogl_context (&compositor,
+ FALSE, /* don't set EGL constraint */
+ &error);
+
+ if (compositor.cogl_context)
+ g_warning ("Failed to create context with EGL constraint, "
+ "falling back");
+ else
+ g_error ("Failed to create a Cogl context: %s\n", error->message);
+ }
compositor.virtual_width = 800;
compositor.virtual_height = 600;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]