gdk: Use the Cogl visual on Xlib winsys

GDK 3.16 started selecting different visuals, to best comply with the
requirements for OpenGL, and this has broken Clutter on GLX drivers that
are fairly picky in how they select visuals and GLXFBConfig.

GDK selects GLXFBConfig that do not include depth or stencil buffers;
Cogl, on the other hand, needs both depth and stencil buffers, and keeps
selecting the first available visual, assuming that the GLX driver will
give us the best compliant one, as per specification. Sadly, some
drivers will return incompatible configurations, and then bomb out when
you try to embed Clutter inside GTK+, because of mismatched visuals.

Cogl has an old, deprecated, Clutter-only API that allows us to retrieve
the XVisualInfo mapping to the GLXFBConfig it uses; this means we should
look up the GdkVisual for it when creating our own GdkWindows, instead
of relying on the RGBA and system GdkVisuals exposed by GDK — at least
on X11.

https://bugzilla.gnome.org/show_bug.cgi?id=747489
This commit is contained in:
Emmanuele Bassi 2015-06-10 11:55:50 +01:00
parent dd9e43e98d
commit c91621e8c2

View File

@ -29,6 +29,10 @@
#include <cogl/cogl.h>
#ifdef COGL_HAS_XLIB_SUPPORT
#include <cogl/cogl-xlib.h>
#endif
#define GDK_DISABLE_DEPRECATION_WARNINGS
#include <gdk/gdk.h>
@ -183,7 +187,7 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
GdkWindowAttr attributes;
gboolean cursor_visible;
gboolean use_alpha;
gfloat width, height;
gfloat width, height;
if (backend->cogl_context == NULL)
{
@ -191,12 +195,7 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
return FALSE;
}
if (stage_gdk->foreign_window)
{
width = gdk_window_get_width (stage_gdk->window);
height = gdk_window_get_height (stage_gdk->window);
}
else
if (!stage_gdk->foreign_window)
{
if (stage_gdk->window != NULL)
{
@ -239,13 +238,34 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
attributes.cursor = stage_gdk->blank_cursor;
}
attributes.visual = NULL;
/* If the ClutterStage:use-alpha is set, but GDK does not have an
* RGBA visual, then we unset the property on the Stage
*/
if (use_alpha)
{
attributes.visual = gdk_screen_get_rgba_visual (backend_gdk->screen);
if (gdk_screen_get_rgba_visual (backend_gdk->screen) == NULL)
{
clutter_stage_set_use_alpha (stage_cogl->wrapper, FALSE);
use_alpha = FALSE;
}
}
if (attributes.visual == NULL)
clutter_stage_set_use_alpha (stage_cogl->wrapper, FALSE);
#if defined(GDK_WINDOWING_X11) && defined(COGL_HAS_XLIB_SUPPORT)
if (GDK_IS_X11_DISPLAY (backend_gdk->display))
{
XVisualInfo *xvisinfo = cogl_clutter_winsys_xlib_get_visual_info ();
if (xvisinfo != NULL)
{
attributes.visual = gdk_x11_screen_lookup_visual (backend_gdk->screen,
xvisinfo->visualid);
}
}
else
#endif
{
attributes.visual = use_alpha
? gdk_screen_get_rgba_visual (backend_gdk->screen)
: gdk_screen_get_system_visual (backend_gdk->screen);
}
if (attributes.visual == NULL)
@ -263,11 +283,15 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
clutter_stage_gdk_set_gdk_geometry (stage_gdk);
}
else
{
width = gdk_window_get_width (stage_gdk->window);
height = gdk_window_get_height (stage_gdk->window);
}
gdk_window_ensure_native (stage_gdk->window);
g_object_set_data (G_OBJECT (stage_gdk->window),
"clutter-stage-window", stage_gdk);
g_object_set_data (G_OBJECT (stage_gdk->window), "clutter-stage-window", stage_gdk);
stage_cogl->onscreen = cogl_onscreen_new (backend->cogl_context,
width, height);