From ab63b30a9b1812b0e53bcddcd55f00fd507347dc Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 10 Jun 2015 12:02:13 +0100 Subject: [PATCH 2/3] gdk: Add function to retrieve the GdkVisual Straight from Cogl. This allows us to propagate the GdkVisual Cogl and Clutter use to embedding toolkits, like GTK+. The function is annotated as being added to the 1.22 development cycle because it will be backported to the stable branch, so that downstream developers can package up a version of Clutter that does not crash on nVidia. https://bugzilla.gnome.org/show_bug.cgi?id=747489 (cherry picked from commit 2d5b5aa82aacab7cc523e5877afbb864592b7651) Signed-off-by: Emmanuele Bassi --- clutter/gdk/clutter-backend-gdk.c | 48 ++++++++++++++++++++++++++++++ clutter/gdk/clutter-gdk.h | 3 ++ doc/reference/clutter/clutter-sections.txt | 1 + 3 files changed, 52 insertions(+) diff --git a/clutter/gdk/clutter-backend-gdk.c b/clutter/gdk/clutter-backend-gdk.c index 47bd671..01ba8cb 100644 --- a/clutter/gdk/clutter-backend-gdk.c +++ b/clutter/gdk/clutter-backend-gdk.c @@ -498,3 +498,51 @@ clutter_gdk_disable_event_retrieval (void) disable_event_retrieval = TRUE; } + +/** + * clutter_gdk_get_visual: + * + * Retrieves the #GdkVisual used by Clutter. + * + * This function should be used when embedding Clutter inside GDK-based + * foreign toolkits, to ensure that the visual applied to the #GdkWindow + * used to render the #ClutterStage is the correct one. + * + * Returns: (transfer none): a #GdkVisual instance + * + * Since: 1.22 + */ +GdkVisual * +clutter_gdk_get_visual (void) +{ + ClutterBackend *backend = clutter_get_default_backend (); + GdkScreen *screen; + + if (backend == NULL) + { + g_critical ("The Clutter backend has not been initialised"); + return NULL; + } + + if (!CLUTTER_IS_BACKEND_GDK (backend)) + { + g_critical ("The Clutter backend is not a GDK backend"); + return NULL; + } + + screen = CLUTTER_BACKEND_GDK (backend)->screen; + g_assert (screen != NULL); + +#if defined(GDK_WINDOWING_X11) && defined(COGL_HAS_XLIB_SUPPORT) + { + XVisualInfo *xvisinfo = cogl_clutter_winsys_xlib_get_visual_info (); + if (xvisinfo != NULL) + return gdk_x11_screen_lookup_visual (screen, xvisinfo->visualid); + } +#endif + + if (gdk_screen_get_rgba_visual (screen) != NULL) + return gdk_screen_get_rgba_visual (screen); + + return gdk_screen_get_system_visual (screen); +} diff --git a/clutter/gdk/clutter-gdk.h b/clutter/gdk/clutter-gdk.h index a009378..c5b979b 100644 --- a/clutter/gdk/clutter-gdk.h +++ b/clutter/gdk/clutter-gdk.h @@ -61,6 +61,9 @@ ClutterStage * clutter_gdk_get_stage_from_window (GdkWindow *window); CLUTTER_AVAILABLE_IN_1_10 void clutter_gdk_disable_event_retrieval (void); +CLUTTER_AVAILABLE_IN_1_22 +GdkVisual * clutter_gdk_get_visual (void); + G_END_DECLS #endif /* __CLUTTER_GDK_H__ */ diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 327f185..d521dc1 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -1516,6 +1516,7 @@ clutter_gdk_handle_event clutter_gdk_set_display clutter_gdk_get_default_display clutter_gdk_set_stage_foreign +clutter_gdk_get_visual
-- 2.4.3