summaryrefslogtreecommitdiff
blob: d157ac1ee690837bc679ef3f54abedf84a64d0cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
From ab63b30a9b1812b0e53bcddcd55f00fd507347dc Mon Sep 17 00:00:00 2001
From: Emmanuele Bassi <ebassi@gnome.org>
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 <ebassi@gnome.org>
---
 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
 </SECTION>
 
 <SECTION>
-- 
2.4.3