• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <stdint.h>
26 #include <stdlib.h>
27 
28 #include "xcb_event_source.h"
29 #include "gstgldisplay_x11.h"
30 #include "gstglwindow_x11.h"
31 
32 G_GNUC_INTERNAL
33     extern gboolean gst_gl_display_x11_handle_event (GstGLDisplayX11 *
34     display_x11);
35 
36 typedef struct _XCBEventSource
37 {
38   GSource source;
39   GPollFD pfd;
40   uint32_t mask;
41   GstGLDisplayX11 *display_x11;
42 } XCBEventSource;
43 
44 static gboolean
xcb_event_source_prepare(GSource * base,gint * timeout)45 xcb_event_source_prepare (GSource * base, gint * timeout)
46 {
47   XCBEventSource *source = (XCBEventSource *) base;
48 
49   xcb_flush (source->display_x11->xcb_connection);
50 
51   *timeout = -1;
52   return FALSE;
53 }
54 
55 static gboolean
xcb_event_source_check(GSource * base)56 xcb_event_source_check (GSource * base)
57 {
58   XCBEventSource *source = (XCBEventSource *) base;
59   gboolean retval;
60 
61   retval = source->pfd.revents;
62 
63   return retval;
64 }
65 
66 static gboolean
xcb_event_source_dispatch(GSource * base,GSourceFunc callback,gpointer data)67 xcb_event_source_dispatch (GSource * base, GSourceFunc callback, gpointer data)
68 {
69   XCBEventSource *source = (XCBEventSource *) base;
70 
71   gboolean ret = gst_gl_display_x11_handle_event (source->display_x11);
72 
73   source->pfd.revents = 0;
74 
75   if (callback)
76     callback (data);
77 
78   return ret;
79 }
80 
81 static GSourceFuncs xcb_event_source_funcs = {
82   xcb_event_source_prepare,
83   xcb_event_source_check,
84   xcb_event_source_dispatch,
85   NULL
86 };
87 
88 GSource *
xcb_event_source_new(GstGLDisplayX11 * display_x11)89 xcb_event_source_new (GstGLDisplayX11 * display_x11)
90 {
91   xcb_connection_t *connection;
92   XCBEventSource *source;
93 
94   connection = display_x11->xcb_connection;
95   g_return_val_if_fail (connection != NULL, NULL);
96 
97   source = (XCBEventSource *)
98       g_source_new (&xcb_event_source_funcs, sizeof (XCBEventSource));
99   source->display_x11 = display_x11;
100   source->pfd.fd = xcb_get_file_descriptor (connection);
101   source->pfd.events = G_IO_IN | G_IO_ERR;
102   g_source_add_poll (&source->source, &source->pfd);
103 
104   return &source->source;
105 }
106