1 /*
2 * GStreamer
3 * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
4 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #define GLIB_DISABLE_DEPRECATION_WARNINGS
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29 #include <locale.h>
30
31 #include "gstglwindow_x11.h"
32 #include "gstgldisplay_x11.h"
33
34 #include "../gstglwindow_private.h"
35
36 /* for XkbKeycodeToKeysym */
37 #include <X11/XKBlib.h>
38
39 #define GST_CAT_DEFAULT gst_gl_window_debug
40
41 G_GNUC_INTERNAL
42 gboolean gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11,
43 xcb_generic_event_t * event);
44
45 /* X error trap */
46 static int TrappedErrorCode = 0;
47 static int (*old_error_handler) (Display *, XErrorEvent *);
48
49 enum
50 {
51 ARG_0,
52 ARG_DISPLAY
53 };
54
55 struct _GstGLWindowX11Private
56 {
57 gboolean activate;
58 gboolean activate_result;
59
60 gint preferred_width;
61 gint preferred_height;
62
63 gboolean handle_events;
64
65 GstVideoRectangle render_rect;
66 };
67
68 #define gst_gl_window_x11_parent_class parent_class
69 G_DEFINE_TYPE_WITH_PRIVATE (GstGLWindowX11, gst_gl_window_x11,
70 GST_TYPE_GL_WINDOW);
71
72 static guintptr gst_gl_window_x11_get_display (GstGLWindow * window);
73 guintptr gst_gl_window_x11_get_gl_context (GstGLWindow * window);
74 gboolean gst_gl_window_x11_activate (GstGLWindow * window, gboolean activate);
75 static void gst_gl_window_x11_set_window_handle (GstGLWindow * window,
76 guintptr handle);
77 static gboolean gst_gl_window_x11_set_render_rectangle (GstGLWindow * window,
78 int x, int y, int width, int height);
79 static guintptr gst_gl_window_x11_get_window_handle (GstGLWindow * window);
80 static void gst_gl_window_x11_set_preferred_size (GstGLWindow * window,
81 gint width, gint height);
82 static void gst_gl_window_x11_show (GstGLWindow * window);
83 static void gst_gl_window_x11_draw (GstGLWindow * window);
84 gboolean gst_gl_window_x11_create_context (GstGLWindow * window,
85 GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
86 static gboolean gst_gl_window_x11_open (GstGLWindow * window, GError ** error);
87 static void gst_gl_window_x11_close (GstGLWindow * window);
88 static void gst_gl_window_x11_handle_events (GstGLWindow * window,
89 gboolean handle_events);
90
91 static void
gst_gl_window_x11_finalize(GObject * object)92 gst_gl_window_x11_finalize (GObject * object)
93 {
94 G_OBJECT_CLASS (parent_class)->finalize (object);
95 }
96
97 static void
gst_gl_window_x11_class_init(GstGLWindowX11Class * klass)98 gst_gl_window_x11_class_init (GstGLWindowX11Class * klass)
99 {
100 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
101 GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
102
103 obj_class->finalize = gst_gl_window_x11_finalize;
104
105 window_class->get_display = GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_display);
106 window_class->set_window_handle =
107 GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_window_handle);
108 window_class->set_render_rectangle =
109 GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_render_rectangle);
110 window_class->get_window_handle =
111 GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_window_handle);
112 window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_x11_draw);
113 window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_x11_open);
114 window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_x11_close);
115 window_class->handle_events =
116 GST_DEBUG_FUNCPTR (gst_gl_window_x11_handle_events);
117 window_class->set_preferred_size =
118 GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_preferred_size);
119 window_class->show = GST_DEBUG_FUNCPTR (gst_gl_window_x11_show);
120 }
121
122 static void
gst_gl_window_x11_init(GstGLWindowX11 * window)123 gst_gl_window_x11_init (GstGLWindowX11 * window)
124 {
125 window->priv = gst_gl_window_x11_get_instance_private (window);
126 }
127
128 /* Must be called in the gl thread */
129 GstGLWindowX11 *
gst_gl_window_x11_new(GstGLDisplay * display)130 gst_gl_window_x11_new (GstGLDisplay * display)
131 {
132 GstGLWindowX11 *window;
133
134 if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_X11)
135 == GST_GL_DISPLAY_TYPE_NONE) {
136 GST_INFO ("Wrong display type %u for this window type %u", display->type,
137 GST_GL_DISPLAY_TYPE_X11);
138 return NULL;
139 }
140
141 window = g_object_new (GST_TYPE_GL_WINDOW_X11, NULL);
142 gst_object_ref_sink (window);
143
144 return window;
145 }
146
147 static gboolean
gst_gl_window_x11_open(GstGLWindow * window,GError ** error)148 gst_gl_window_x11_open (GstGLWindow * window, GError ** error)
149 {
150 GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
151 GstGLDisplayX11 *display_x11 = (GstGLDisplayX11 *) window->display;
152
153 window_x11->device = display_x11->display;
154 // window_x11->device = XOpenDisplay (display_x11->name);
155 if (window_x11->device == NULL) {
156 g_set_error (error, GST_GL_WINDOW_ERROR,
157 GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
158 "Failed to connect to X display server");
159 goto failure;
160 }
161
162 GST_LOG ("gl device id: %ld", (gulong) window_x11->device);
163
164 window_x11->screen = DefaultScreenOfDisplay (window_x11->device);
165 window_x11->screen_num = DefaultScreen (window_x11->device);
166 window_x11->visual =
167 DefaultVisual (window_x11->device, window_x11->screen_num);
168 window_x11->root = DefaultRootWindow (window_x11->device);
169 window_x11->white = XWhitePixel (window_x11->device, window_x11->screen_num);
170 window_x11->black = XBlackPixel (window_x11->device, window_x11->screen_num);
171 window_x11->depth = DefaultDepthOfScreen (window_x11->screen);
172
173 GST_LOG ("gl root id: %lud", (gulong) window_x11->root);
174
175 window_x11->device_width =
176 DisplayWidth (window_x11->device, window_x11->screen_num);
177 window_x11->device_height =
178 DisplayHeight (window_x11->device, window_x11->screen_num);
179
180 window_x11->allow_extra_expose_events = TRUE;
181
182 return GST_GL_WINDOW_CLASS (parent_class)->open (window, error);
183
184 failure:
185 return FALSE;
186 }
187
188 gboolean
gst_gl_window_x11_create_window(GstGLWindowX11 * window_x11)189 gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11)
190 {
191 XSetWindowAttributes win_attr;
192 XTextProperty text_property;
193 XWMHints wm_hints;
194 unsigned long mask;
195 const gchar *title = "OpenGL renderer";
196 Atom wm_atoms[1];
197 gint x = 0, y = 0, width = 1, height = 1;
198
199 if (window_x11->visual_info->visual != window_x11->visual)
200 GST_LOG ("selected visual is different from the default");
201
202 GST_LOG ("visual XID:%d, screen:%d, visualid:%d, depth:%d, class:%d, "
203 "red_mask:%ld, green_mask:%ld, blue_mask:%ld bpp:%d",
204 (gint) XVisualIDFromVisual (window_x11->visual_info->visual),
205 window_x11->visual_info->screen, (gint) window_x11->visual_info->visualid,
206 window_x11->visual_info->depth, window_x11->visual_info->class,
207 window_x11->visual_info->red_mask, window_x11->visual_info->green_mask,
208 window_x11->visual_info->blue_mask,
209 window_x11->visual_info->bits_per_rgb);
210
211 win_attr.event_mask =
212 StructureNotifyMask | ExposureMask | VisibilityChangeMask;
213 win_attr.do_not_propagate_mask = NoEventMask;
214
215 win_attr.background_pixmap = None;
216 win_attr.background_pixel = 0;
217 win_attr.border_pixel = 0;
218
219 win_attr.colormap =
220 XCreateColormap (window_x11->device, window_x11->root,
221 window_x11->visual_info->visual, AllocNone);
222
223 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
224
225 window_x11->internal_win_id =
226 XCreateWindow (window_x11->device,
227 window_x11->parent_win ? window_x11->parent_win : window_x11->root,
228 x, y, width, height, 0,
229 window_x11->visual_info->depth, InputOutput,
230 window_x11->visual_info->visual, mask, &win_attr);
231
232 gst_gl_window_x11_handle_events (GST_GL_WINDOW (window_x11),
233 window_x11->priv->handle_events);
234
235 XSync (window_x11->device, FALSE);
236
237 XSetWindowBackgroundPixmap (window_x11->device,
238 window_x11->internal_win_id, None);
239
240 GST_LOG ("gl window id: %lud", (gulong) window_x11->internal_win_id);
241 GST_LOG ("gl window props: x:%d y:%d", x, y);
242
243 wm_atoms[0] = XInternAtom (window_x11->device, "WM_DELETE_WINDOW", True);
244 if (wm_atoms[0] == None)
245 GST_DEBUG ("Cannot create WM_DELETE_WINDOW");
246
247 XSetWMProtocols (window_x11->device, window_x11->internal_win_id,
248 wm_atoms, 1);
249
250 wm_hints.flags = StateHint;
251 wm_hints.initial_state = NormalState;
252 wm_hints.input = False;
253
254 XStringListToTextProperty ((char **) &title, 1, &text_property);
255
256 XSetWMProperties (window_x11->device, window_x11->internal_win_id,
257 &text_property, &text_property, 0, 0, NULL, &wm_hints, NULL);
258
259 XFree (text_property.value);
260
261 return TRUE;
262 }
263
264 static void
gst_gl_window_x11_close(GstGLWindow * window)265 gst_gl_window_x11_close (GstGLWindow * window)
266 {
267 GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
268
269 if (window_x11->device) {
270 if (window_x11->internal_win_id) {
271 XUnmapWindow (window_x11->device, window_x11->internal_win_id);
272
273 XDestroyWindow (window_x11->device, window_x11->internal_win_id);
274
275 /* Ensure everything is sent immediatly */
276 XSync (window_x11->device, FALSE);
277 }
278 XFree (window_x11->visual_info);
279
280 GST_DEBUG ("display receiver closed");
281 }
282
283 window_x11->running = FALSE;
284
285 GST_GL_WINDOW_CLASS (parent_class)->close (window);
286 }
287
288 /* called by the gl thread */
289 static void
gst_gl_window_x11_set_window_handle(GstGLWindow * window,guintptr id)290 gst_gl_window_x11_set_window_handle (GstGLWindow * window, guintptr id)
291 {
292 GstGLWindowX11 *window_x11;
293 gint x, y, width, height;
294
295 window_x11 = GST_GL_WINDOW_X11 (window);
296
297 window_x11->parent_win = (Window) id;
298
299 if (window_x11->priv->render_rect.w > 0 &&
300 window_x11->priv->render_rect.h > 0) {
301 x = window_x11->priv->render_rect.x;
302 y = window_x11->priv->render_rect.y;
303 width = window_x11->priv->render_rect.w;
304 height = window_x11->priv->render_rect.h;
305 } else {
306 x = y = 0;
307 if (window_x11->parent_win) {
308 XWindowAttributes attr;
309
310 XGetWindowAttributes (window_x11->device, window_x11->parent_win, &attr);
311 width = attr.width;
312 height = attr.height;
313 } else {
314 width = window_x11->priv->preferred_width;
315 height = window_x11->priv->preferred_height;
316 }
317 }
318
319 XResizeWindow (window_x11->device, window_x11->internal_win_id,
320 width, height);
321
322 XReparentWindow (window_x11->device, window_x11->internal_win_id,
323 window_x11->parent_win, x, y);
324
325 XSync (window_x11->device, FALSE);
326 }
327
328 struct SetRenderRectangle
329 {
330 GstGLWindowX11 *window_x11;
331 GstVideoRectangle rect;
332 };
333
334 static void
_free_set_render_rectangle(struct SetRenderRectangle * render)335 _free_set_render_rectangle (struct SetRenderRectangle *render)
336 {
337 if (render) {
338 if (render->window_x11)
339 gst_object_unref (render->window_x11);
340 g_free (render);
341 }
342 }
343
344 static void
_set_render_rectangle(gpointer data)345 _set_render_rectangle (gpointer data)
346 {
347 struct SetRenderRectangle *render = data;
348
349 GST_LOG_OBJECT (render->window_x11, "setting render rectangle %i,%i+%ix%i",
350 render->rect.x, render->rect.y, render->rect.w, render->rect.h);
351
352 if (render->window_x11->internal_win_id)
353 XMoveResizeWindow (render->window_x11->device,
354 render->window_x11->internal_win_id, render->rect.x, render->rect.y,
355 render->rect.w, render->rect.h);
356
357 if (render->window_x11->device)
358 XSync (render->window_x11->device, FALSE);
359
360 render->window_x11->priv->render_rect = render->rect;
361 }
362
363 static gboolean
gst_gl_window_x11_set_render_rectangle(GstGLWindow * window,int x,int y,int width,int height)364 gst_gl_window_x11_set_render_rectangle (GstGLWindow * window,
365 int x, int y, int width, int height)
366 {
367 GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
368 struct SetRenderRectangle *render;
369
370 render = g_new0 (struct SetRenderRectangle, 1);
371 render->window_x11 = gst_object_ref (window_x11);
372 render->rect.x = x;
373 render->rect.y = y;
374 render->rect.w = width;
375 render->rect.h = height;
376
377 gst_gl_window_send_message_async (window,
378 (GstGLWindowCB) _set_render_rectangle, render,
379 (GDestroyNotify) _free_set_render_rectangle);
380
381 return TRUE;
382 }
383
384 static guintptr
gst_gl_window_x11_get_window_handle(GstGLWindow * window)385 gst_gl_window_x11_get_window_handle (GstGLWindow * window)
386 {
387 GstGLWindowX11 *window_x11;
388
389 window_x11 = GST_GL_WINDOW_X11 (window);
390
391 return window_x11->internal_win_id;
392 }
393
394 static void
gst_gl_window_x11_set_preferred_size(GstGLWindow * window,gint width,gint height)395 gst_gl_window_x11_set_preferred_size (GstGLWindow * window, gint width,
396 gint height)
397 {
398 GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
399
400 window_x11->priv->preferred_width = width;
401 window_x11->priv->preferred_height = height;
402 }
403
404 static void
_show_window(GstGLWindow * window)405 _show_window (GstGLWindow * window)
406 {
407 GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
408 guint width = window_x11->priv->preferred_width;
409 guint height = window_x11->priv->preferred_height;
410
411 if (!window_x11->visible) {
412 if (!window_x11->parent_win) {
413 XResizeWindow (window_x11->device, window_x11->internal_win_id,
414 width, height);
415
416 gst_gl_window_resize (window, width, height);
417 }
418
419 XMapWindow (window_x11->device, window_x11->internal_win_id);
420 XSync (window_x11->device, FALSE);
421 window_x11->visible = TRUE;
422 }
423 }
424
425 static void
gst_gl_window_x11_show(GstGLWindow * window)426 gst_gl_window_x11_show (GstGLWindow * window)
427 {
428 gst_gl_window_send_message (window, (GstGLWindowCB) _show_window, window);
429 }
430
431 static void
_context_draw(GstGLContext * context,GstGLWindow * window)432 _context_draw (GstGLContext * context, GstGLWindow * window)
433 {
434 window->draw (window->draw_data);
435 gst_gl_context_swap_buffers (context);
436
437 gst_object_unref (context);
438 }
439
440 static void
draw_cb(gpointer data)441 draw_cb (gpointer data)
442 {
443 GstGLWindowX11 *window_x11 = data;
444 GstGLWindow *window = GST_GL_WINDOW (window_x11);
445 guint width, height;
446 XWindowAttributes attr;
447
448 if (window_x11->internal_win_id) {
449 gboolean need_resize = FALSE;
450
451 XGetWindowAttributes (window_x11->device, window_x11->internal_win_id,
452 &attr);
453 GST_TRACE_OBJECT (window, "window size %ux%u", attr.width, attr.height);
454
455 if (window_x11->parent_win &&
456 (window_x11->priv->render_rect.w <= 0 ||
457 window_x11->priv->render_rect.h <= 0)) {
458 XWindowAttributes attr_parent;
459 XGetWindowAttributes (window_x11->device, window_x11->parent_win,
460 &attr_parent);
461 GST_TRACE_OBJECT (window, "parent window size %ux%u", attr_parent.width,
462 attr_parent.height);
463
464 if (attr.width != attr_parent.width || attr.height != attr_parent.height) {
465 XMoveResizeWindow (window_x11->device, window_x11->internal_win_id,
466 0, 0, attr_parent.width, attr_parent.height);
467 XSync (window_x11->device, FALSE);
468
469 attr.width = attr_parent.width;
470 attr.height = attr_parent.height;
471
472 GST_LOG ("parent resize: %d, %d",
473 attr_parent.width, attr_parent.height);
474 need_resize = TRUE;
475 }
476 }
477
478 gst_gl_window_get_surface_dimensions (window, &width, &height);
479 if (attr.width != width || attr.height != height)
480 need_resize = TRUE;
481
482 if (need_resize)
483 gst_gl_window_queue_resize (window);
484
485 if (window_x11->allow_extra_expose_events) {
486 if (window->queue_resize)
487 gst_gl_window_resize (window, width, height);
488
489 if (window->draw) {
490 GstGLContext *context = gst_gl_window_get_context (window);
491
492 _context_draw (context, window);
493 }
494 }
495 }
496 }
497
498 /* Not called by the gl thread */
499 static void
gst_gl_window_x11_draw(GstGLWindow * window)500 gst_gl_window_x11_draw (GstGLWindow * window)
501 {
502 gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, window);
503 }
504
505 static void
gst_gl_window_x11_handle_events(GstGLWindow * window,gboolean handle_events)506 gst_gl_window_x11_handle_events (GstGLWindow * window, gboolean handle_events)
507 {
508 GstGLWindowX11 *window_x11;
509
510 g_return_if_fail (window != NULL);
511
512 window_x11 = GST_GL_WINDOW_X11 (window);
513
514 window_x11->priv->handle_events = handle_events;
515
516 if (window_x11->internal_win_id) {
517 if (handle_events) {
518 XSelectInput (window_x11->device, window_x11->internal_win_id,
519 StructureNotifyMask | ExposureMask | VisibilityChangeMask |
520 PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
521 ButtonReleaseMask);
522 } else {
523 XSelectInput (window_x11->device, window_x11->internal_win_id,
524 StructureNotifyMask | ExposureMask | VisibilityChangeMask);
525 }
526 }
527 }
528
529 gboolean
gst_gl_window_x11_handle_event(GstGLWindowX11 * window_x11,xcb_generic_event_t * event)530 gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11,
531 xcb_generic_event_t * event)
532 {
533 GstGLWindow *window = GST_GL_WINDOW (window_x11);
534 GstGLDisplayX11 *display_x11 = GST_GL_DISPLAY_X11 (window->display);
535 xcb_connection_t *connection = display_x11->xcb_connection;
536 uint8_t event_code = event->response_type & 0x7f;
537
538 switch (event_code) {
539 case XCB_CLIENT_MESSAGE:{
540 xcb_client_message_event_t *client_event;
541 xcb_intern_atom_cookie_t cookie;
542 xcb_intern_atom_reply_t *reply;
543
544 client_event = (xcb_client_message_event_t *) event;
545 cookie = xcb_intern_atom (connection, 0, 16, "WM_DELETE_WINDOW");
546 reply = xcb_intern_atom_reply (connection, cookie, 0);
547
548 if (client_event->data.data32[0] == reply->atom) {
549 GST_INFO_OBJECT (window_x11, "Close requested");
550
551 if (window->close)
552 window->close (window->close_data);
553
554 gst_gl_display_remove_window (GST_GL_DISPLAY (display_x11),
555 GST_GL_WINDOW (window_x11));
556 }
557
558 g_free (reply);
559 break;
560 }
561 case XCB_CONFIGURE_NOTIFY:{
562 xcb_configure_notify_event_t *configure_event;
563
564 configure_event = (xcb_configure_notify_event_t *) event;
565
566 gst_gl_window_resize (window, configure_event->width,
567 configure_event->height);
568
569 gst_gl_window_draw (window);
570 break;
571 }
572 case XCB_EXPOSE:{
573 xcb_expose_event_t *expose_event = (xcb_expose_event_t *) event;
574 /* non-zero means that other Expose follows
575 * so just wait for the last one
576 * in theory we should not receive non-zero because
577 * we have no sub areas here but just in case */
578 if (expose_event->count != 0)
579 break;
580
581 gst_gl_window_draw (window);
582 break;
583 }
584 case XCB_KEY_PRESS:
585 case XCB_KEY_RELEASE:{
586 xcb_key_press_event_t *kp = (xcb_key_press_event_t *) event;
587 const gchar *event_type_str;
588 gchar *key_str;
589 KeySym keysym;
590
591 keysym = XkbKeycodeToKeysym (window_x11->device, kp->detail, 0, 0);
592 key_str = XKeysymToString (keysym);
593
594 if (event_code == XCB_KEY_PRESS)
595 event_type_str = "key-press";
596 else
597 event_type_str = "key-release";
598
599 gst_gl_window_send_key_event (window, event_type_str, key_str);
600 break;
601 }
602 case XCB_BUTTON_PRESS:
603 case XCB_BUTTON_RELEASE:{
604 xcb_button_press_event_t *bp = (xcb_button_press_event_t *) event;
605 const gchar *event_type_str;
606
607 if (event_code == XCB_BUTTON_PRESS)
608 event_type_str = "mouse-button-press";
609 else
610 event_type_str = "mouse-button-release";
611
612 gst_gl_window_send_mouse_event (window, event_type_str, bp->detail,
613 (double) bp->event_x, (double) bp->event_y);
614 break;
615 }
616 case XCB_MOTION_NOTIFY:{
617 xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event;
618
619 gst_gl_window_send_mouse_event (window, "mouse-move", 0,
620 (double) motion->event_x, (double) motion->event_y);
621 break;
622 }
623 default:
624 GST_TRACE ("unhandled XCB event: %u", event_code);
625 break;
626 }
627
628 return TRUE;
629 }
630
631 static int
error_handler(Display * xdpy,XErrorEvent * error)632 error_handler (Display * xdpy, XErrorEvent * error)
633 {
634 TrappedErrorCode = error->error_code;
635 return 0;
636 }
637
638 /**
639 * gst_gl_window_x11_trap_x_errors:
640 *
641 * Traps every X error until gst_gl_window_x11_untrap_x_errors() is called.
642 */
643 void
gst_gl_window_x11_trap_x_errors(void)644 gst_gl_window_x11_trap_x_errors (void)
645 {
646 TrappedErrorCode = 0;
647 old_error_handler = XSetErrorHandler (error_handler);
648 }
649
650 /**
651 * gst_gl_window_x11_untrap_x_errors:
652 *
653 * Removes the X error trap and returns the current status.
654 *
655 * Return value: the trapped error code, or 0 for success
656 */
657 gint
gst_gl_window_x11_untrap_x_errors(void)658 gst_gl_window_x11_untrap_x_errors (void)
659 {
660 XSetErrorHandler (old_error_handler);
661
662 return TrappedErrorCode;
663 }
664
665 static guintptr
gst_gl_window_x11_get_display(GstGLWindow * window)666 gst_gl_window_x11_get_display (GstGLWindow * window)
667 {
668 GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
669
670 return (guintptr) window_x11->device;
671 }
672