Debian Codegraph @

clutter/egl/clutter-backend-eglnative.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Copyright (C) 2010,2011 Intel Corporation.
7 * 2011 Giovanni Campagna <[email protected]>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
22 * Authors:
23 * Matthew Allum
24 * Emmanuele Bassi
25 * Robert Bragg
26 * Neil Roberts
27 */
28
29 #include "config.h"
30
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35
36 #include <errno.h>
37
38 #include "clutter-backend-eglnative.h"
39
40 /* This is a Cogl based backend */
41 #include "cogl/clutter-stage-cogl.h"
42
43 #ifdef HAVE_EVDEV
44 #include "evdev/clutter-device-manager-evdev.h"
45 #endif
46
47 #include "clutter-debug.h"
48 #include "clutter-private.h"
49 #include "clutter-main.h"
50 #include "clutter-stage-private.h"
51
52 #ifdef COGL_HAS_EGL_SUPPORT
53 #include "clutter-egl.h"
54 #endif
55
56 #include "clutter-stage-eglnative.h"
57
58 G_DEFINE_TYPE (ClutterBackendEglNative, clutter_backend_egl_native, CLUTTER_TYPE_BACKEND);
59
60 #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
61 static int _kms_fd = -1;
62 #endif
63
64 static void
65 clutter_backend_egl_native_dispose (GObject *gobject)
66 {
67 ClutterBackendEglNative *backend_egl_native = CLUTTER_BACKEND_EGL_NATIVE (gobject);
68
69 if (backend_egl_native->event_timer != NULL)
70 {
71 g_timer_destroy (backend_egl_native->event_timer);
72 backend_egl_native->event_timer = NULL;
73 }
74
75 G_OBJECT_CLASS (clutter_backend_egl_native_parent_class)->dispose (gobject);
76 }
77
78 static CoglRenderer *
79 clutter_backend_egl_native_get_renderer (ClutterBackend *backend,
80 GError **error)
81 {
82 CoglRenderer *renderer;
83
84 renderer = cogl_renderer_new ();
85
86 #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
87 if (_kms_fd > -1)
88 {
89 cogl_renderer_set_winsys_id (renderer, COGL_WINSYS_ID_EGL_KMS);
90 cogl_kms_renderer_set_kms_fd (renderer, _kms_fd);
91 }
92 #endif
93
94 return renderer;
95 }
96
97 static void
98 clutter_backend_egl_native_class_init (ClutterBackendEglNativeClass *klass)
99 {
100 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
101 ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
102
103 gobject_class->dispose = clutter_backend_egl_native_dispose;
104
105 backend_class->stage_window_type = CLUTTER_TYPE_STAGE_EGL_NATIVE;
106
107 backend_class->get_renderer = clutter_backend_egl_native_get_renderer;
108 }
109
110 static void
111 clutter_backend_egl_native_init (ClutterBackendEglNative *backend_egl_native)
112 {
113 backend_egl_native->event_timer = g_timer_new ();
114 }
115
116 ClutterBackend *
117 clutter_backend_egl_native_new (void)
118 {
119 return g_object_new (CLUTTER_TYPE_BACKEND_EGL_NATIVE, NULL);
120 }
121
122 /**
123 * clutter_eglx_display:
124 *
125 * Retrieves the EGL display used by Clutter.
126 *
127 * Return value: the EGL display, or 0
128 *
129 * Since: 0.6
130 *
131 * Deprecated: 1.6: Use clutter_egl_get_egl_display() instead.
132 */
133 EGLDisplay
134 clutter_eglx_display (void)
135 {
136 return clutter_egl_get_egl_display ();
137 }
138
139 /**
140 * clutter_egl_display:
141 *
142 * Retrieves the EGL display used by Clutter.
143 *
144 * Return value: the EGL display used by Clutter, or 0
145 *
146 * Since: 0.6
147 *
148 * Deprecated: 1.6: Use clutter_egl_get_egl_display() instead.
149 */
150 EGLDisplay
151 clutter_egl_display (void)
152 {
153 return clutter_egl_get_egl_display ();
154 }
155
156 /**
157 * clutter_egl_get_egl_display:
158 *
159 * Retrieves the EGL display used by Clutter, if it supports the
160 * EGL windowing system and if it is running using an EGL backend.
161 *
162 * Return value: the EGL display used by Clutter, or 0
163 *
164 * Since: 1.6
165 */
166 EGLDisplay
167 clutter_egl_get_egl_display (void)
168 {
169 ClutterBackend *backend;
170
171 if (!_clutter_context_is_initialized ())
172 {
173 g_critical ("The Clutter backend has not been initialized yet");
174 return 0;
175 }
176
177 backend = clutter_get_default_backend ();
178
179 if (!CLUTTER_IS_BACKEND_EGL_NATIVE (backend))
180 {
181 g_critical ("The Clutter backend is not an EGL backend");
182 return 0;
183 }
184
185 #if COGL_HAS_EGL_SUPPORT
186 return cogl_egl_context_get_egl_display (backend->cogl_context);
187 #else
188 return 0;
189 #endif
190 }
191
192 #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
193 /**
194 * clutter_egl_set_kms_fd:
195 * @fd: The fd to talk to the kms driver with
196 *
197 * Sets the fd that Cogl should use to talk to the kms driver.
198 * Setting this to a negative value effectively reverts this
199 * call, making Cogl open the device itself.
200 *
201 * This can only be called before clutter_init() is called.
202 *
203 * Since: 1.18
204 */
205 void
206 clutter_egl_set_kms_fd (int fd)
207 {
208 _kms_fd = fd;
209 }
210 #endif
211
212 /**
213 * clutter_egl_freeze_master_clock:
214 *
215 * Freezing the master clock makes Clutter stop processing events,
216 * redrawing, and advancing timelines. This is necessary when implementing
217 * a display server, to ensure that Clutter doesn't keep trying to page
218 * flip when DRM master has been dropped, e.g. when VT switched away.
219 *
220 * The master clock starts out running, so if you are VT switched away on
221 * startup, you need to call this immediately.
222 *
223 * If you're also using the evdev backend, make sure to also use
224 * clutter_evdev_release_devices() to make sure that Clutter doesn't also
225 * access revoked evdev devices when VT switched away.
226 *
227 * To unthaw a frozen master clock, use clutter_egl_thaw_master_clock().
228 *
229 * Since: 1.20
230 */
231 void
232 clutter_egl_freeze_master_clock (void)
233 {
234 ClutterMasterClock *master_clock;
235
236 g_return_if_fail (CLUTTER_IS_BACKEND_EGL_NATIVE (clutter_get_default_backend ()));
237
238 master_clock = _clutter_master_clock_get_default ();
239 _clutter_master_clock_set_paused (master_clock, TRUE);
240 }
241
242 /**
243 * clutter_egl_thaw_master_clock:
244 *
245 * Thaws a master clock that has previously been frozen with
246 * clutter_egl_freeze_master_clock(), and start pumping the master clock
247 * again at the next iteration. Note that if you're switching back to your
248 * own VT, you should probably also queue a stage redraw with
249 * clutter_stage_ensure_redraw().
250 *
251 * Since: 1.20
252 */
253 void
254 clutter_egl_thaw_master_clock (void)
255 {
256 ClutterMasterClock *master_clock;
257
258 g_return_if_fail (CLUTTER_IS_BACKEND_EGL_NATIVE (clutter_get_default_backend ()));
259
260 master_clock = _clutter_master_clock_get_default ();
261 _clutter_master_clock_set_paused (master_clock, FALSE);
262
263 _clutter_master_clock_start_running (master_clock);
264 }