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)
This commit is contained in:
parent
20d64cbb39
commit
856e9aa5f4
@ -93,7 +93,6 @@ struct _CoglandCompositor
|
|||||||
struct wl_display *wayland_display;
|
struct wl_display *wayland_display;
|
||||||
struct wl_event_loop *wayland_loop;
|
struct wl_event_loop *wayland_loop;
|
||||||
|
|
||||||
CoglDisplay *cogl_display;
|
|
||||||
CoglContext *cogl_context;
|
CoglContext *cogl_context;
|
||||||
|
|
||||||
int virtual_width;
|
int virtual_width;
|
||||||
@ -1019,6 +1018,36 @@ bind_shell (struct wl_client *client,
|
|||||||
&cogland_shell_interface, id, data);
|
&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
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -1062,13 +1091,30 @@ main (int argc, char **argv)
|
|||||||
wayland_event_source_new (compositor.wayland_display);
|
wayland_event_source_new (compositor.wayland_display);
|
||||||
g_source_attach (compositor.wayland_event_source, NULL);
|
g_source_attach (compositor.wayland_event_source, NULL);
|
||||||
|
|
||||||
compositor.cogl_display = cogl_display_new (NULL, NULL);
|
/* We want Cogl to use an EGL renderer because otherwise it won't
|
||||||
cogl_wayland_display_set_compositor_display (compositor.cogl_display,
|
* set up the wl_drm object and only SHM buffers will work. */
|
||||||
compositor.wayland_display);
|
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 = cogl_context_new (compositor.cogl_display, &error);
|
compositor.cogl_context =
|
||||||
if (!compositor.cogl_context)
|
create_cogl_context (&compositor,
|
||||||
g_error ("Failed to create a Cogl context: %s\n", error->message);
|
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_width = 800;
|
||||||
compositor.virtual_height = 600;
|
compositor.virtual_height = 600;
|
||||||
|
Loading…
Reference in New Issue
Block a user