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#ifndef __GST_GL_WINDOW_H__
23#define __GST_GL_WINDOW_H__
24
25#include <gst/gst.h>
26
27#include <gst/gl/gstgl_fwd.h>
28#include <gst/gl/gstglcontext.h>
29#include <gst/gl/gstgldisplay.h>
30
31G_BEGIN_DECLS
32
33GST_GL_API
34GType gst_gl_window_get_type (void);
35#define GST_TYPE_GL_WINDOW (gst_gl_window_get_type())
36
37#define GST_GL_WINDOW(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_GL_WINDOW, GstGLWindow))
38#define GST_GL_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GST_TYPE_GL_WINDOW, GstGLWindowClass))
39#define GST_IS_GL_WINDOW(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_GL_WINDOW))
40#define GST_IS_GL_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_GL_WINDOW))
41#define GST_GL_WINDOW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_GL_WINDOW, GstGLWindowClass))
42
43#define GST_GL_WINDOW_LOCK(w) g_mutex_lock(&GST_GL_WINDOW(w)->lock)
44#define GST_GL_WINDOW_UNLOCK(w) g_mutex_unlock(&GST_GL_WINDOW(w)->lock)
45#define GST_GL_WINDOW_GET_LOCK(w) (&GST_GL_WINDOW(w)->lock)
46
47GST_GL_API
48GQuark gst_gl_window_error_quark (void);
49/**
50 * GST_GL_WINDOW_ERROR:
51 *
52 * Error domain for GStreamer's GL window module. Errors in this domain will be
53 * from the #GstGLWindowError enumeration
54 */
55#define GST_GL_WINDOW_ERROR (gst_gl_window_error_quark ())
56
57/**
58 * GstGLWindowError:
59 * @GST_GL_WINDOW_ERROR_FAILED: failed for a unspecified reason
60 * @GST_GL_WINDOW_ERROR_OLD_LIBS: the implementation is too old
61 * @GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE: no such resource was found
62 */
63typedef enum
64{
65 GST_GL_WINDOW_ERROR_FAILED,
66 GST_GL_WINDOW_ERROR_OLD_LIBS,
67 GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
68} GstGLWindowError;
69
70typedef void (*GstGLWindowCB) (gpointer data);
71typedef void (*GstGLWindowResizeCB) (gpointer data, guint width, guint height);
72
73/**
74 * GST_GL_WINDOW_CB:
75 * @f: the function to cast
76 *
77 * Cast to the current function type for generic window callbacks
78 */
79#define GST_GL_WINDOW_CB(f) ((GstGLWindowCB) (f))
80
81/**
82 * GST_GL_WINDOW_RESIZE_CB:
83 * @f: the function to cast
84 *
85 * Cast to the current function type for window resize callbacks
86 */
87#define GST_GL_WINDOW_RESIZE_CB(f) ((GstGLWindowResizeCB) (f))
88
89/**
90 * GstGLWindow:
91 *
92 * #GstGLWindow is an opaque struct and should only be accessed through the
93 * provided api.
94 */
95struct _GstGLWindow {
96 /*< private >*/
97 GstObject parent;
98
99 GMutex lock;
100
101 GstGLDisplay *display;
102 GWeakRef context_ref;
103
104 /*< protected >*/
105 gboolean is_drawing;
106
107 GstGLWindowCB draw;
108 gpointer draw_data;
109 GDestroyNotify draw_notify;
110 GstGLWindowCB close;
111 gpointer close_data;
112 GDestroyNotify close_notify;
113 GstGLWindowResizeCB resize;
114 gpointer resize_data;
115 GDestroyNotify resize_notify;
116
117 gboolean queue_resize;
118
119 GMainContext *main_context; /* default main_context */
120
121 /*< private >*/
122 GstGLWindowPrivate *priv;
123
124 gpointer _reserved[GST_PADDING];
125};
126
127/**
128 * GstGLWindowClass:
129 * @parent_class: Parent class
130 * @get_display: Gets the current windowing system display connection
131 * @set_window_handle: Set a window handle to render into
132 * @get_window_handle: Gets the current window handle that this #GstGLWindow is
133 * rendering into. This may return a different value to
134 * what is passed into @set_window_handle
135 * @draw: redraw the window with the specified dimensions
136 * @run: run the mainloop
137 * @quit: send a quit to the mainloop
138 * @send_message: invoke a function on the window thread. Required to be reentrant.
139 * @send_message_async: invoke a function on the window thread. @run may or may
140 * not have been called. Required to be reentrant.
141 * @open: open the connection to the display
142 * @close: close the connection to the display
143 * @handle_events: whether to handle 'extra' events from the windowing system.
144 * Basic events like surface moves and resizes are still valid
145 * things to listen for.
146 * @set_preferred_size: request that the window change surface size. The
147 * implementation is free to ignore this information.
148 * @show: request that the window be shown to the user
149 * @set_render_rectangle: request a rectangle to render into. See #GstVideoOverlay
150 * @queue_resize: request a resize to occur when possible
151 * @controls_viewport: Whether the window takes care of glViewport setup.
152 * and the user does not need to deal with viewports
153 * @has_output_surface: Whether the window has output surface or not. (Since: 1.18)
154 */
155struct _GstGLWindowClass {
156 GstObjectClass parent_class;
157
158 guintptr (*get_display) (GstGLWindow *window);
159 void (*set_window_handle) (GstGLWindow *window, guintptr handle);
160 guintptr (*get_window_handle) (GstGLWindow *window);
161 void (*draw) (GstGLWindow *window);
162 void (*run) (GstGLWindow *window);
163 void (*quit) (GstGLWindow *window);
164 void (*send_message) (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
165 void (*send_message_async) (GstGLWindow *window, GstGLWindowCB callback, gpointer data, GDestroyNotify destroy);
166
167 gboolean (*open) (GstGLWindow *window, GError **error);
168 void (*close) (GstGLWindow *window);
169 void (*handle_events) (GstGLWindow *window, gboolean handle_events);
170 void (*set_preferred_size) (GstGLWindow *window, gint width, gint height);
171 void (*show) (GstGLWindow *window);
172 gboolean (*set_render_rectangle)(GstGLWindow *window, gint x, gint y, gint width, gint height);
173 void (*queue_resize) (GstGLWindow *window);
174 gboolean (*controls_viewport) (GstGLWindow *window);
175 gboolean (*has_output_surface) (GstGLWindow *window);
176
177 /*< private >*/
178 gpointer _reserved[GST_PADDING-2];
179};
180
181GST_GL_API
182GstGLWindow * gst_gl_window_new (GstGLDisplay *display);
183
184/* callbacks */
185GST_GL_API
186void gst_gl_window_set_draw_callback (GstGLWindow *window,
187 GstGLWindowCB callback,
188 gpointer data,
189 GDestroyNotify destroy_notify);
190GST_GL_API
191void gst_gl_window_set_resize_callback (GstGLWindow *window,
192 GstGLWindowResizeCB callback,
193 gpointer data,
194 GDestroyNotify destroy_notify);
195GST_GL_API
196void gst_gl_window_set_close_callback (GstGLWindow *window,
197 GstGLWindowCB callback,
198 gpointer data,
199 GDestroyNotify destroy_notify);
200
201GST_GL_API
202void gst_gl_window_set_window_handle (GstGLWindow *window, guintptr handle);
203GST_GL_API
204guintptr gst_gl_window_get_window_handle (GstGLWindow *window);
205
206/* loop/events */
207GST_GL_API
208void gst_gl_window_run (GstGLWindow *window);
209GST_GL_API
210void gst_gl_window_quit (GstGLWindow *window);
211GST_GL_API
212void gst_gl_window_send_message (GstGLWindow *window,
213 GstGLWindowCB callback,
214 gpointer data);
215GST_GL_API
216void gst_gl_window_send_message_async (GstGLWindow *window,
217 GstGLWindowCB callback,
218 gpointer data,
219 GDestroyNotify destroy);
220
221/* navigation */
222GST_GL_API
223void gst_gl_window_handle_events (GstGLWindow * window,
224 gboolean handle_events);
225
226GST_GL_API
227void gst_gl_window_send_key_event (GstGLWindow * window,
228 const char * event_type,
229 const char * key_str);
230GST_GL_API
231void gst_gl_window_send_mouse_event (GstGLWindow * window,
232 const char * event_type,
233 int button,
234 double posx,
235 double posy);
236
237GST_GL_API
238void gst_gl_window_send_scroll_event (GstGLWindow * window,
239 double posx,
240 double posy,
241 double delta_x,
242 double delta_y);
243
244/* surfaces/rendering */
245GST_GL_API
246void gst_gl_window_queue_resize (GstGLWindow *window);
247GST_GL_API
248void gst_gl_window_draw (GstGLWindow *window);
249GST_GL_API
250void gst_gl_window_show (GstGLWindow *window);
251GST_GL_API
252void gst_gl_window_set_preferred_size (GstGLWindow * window,
253 gint width,
254 gint height);
255GST_GL_API
256void gst_gl_window_get_surface_dimensions (GstGLWindow * window,
257 guint * width,
258 guint * height);
259GST_GL_API
260gboolean gst_gl_window_set_render_rectangle (GstGLWindow * window,
261 gint x,
262 gint y,
263 gint width,
264 gint height);
265GST_GL_API
266gboolean gst_gl_window_controls_viewport (GstGLWindow * window);
267
268/* subclass usage only */
269GST_GL_API
270void gst_gl_window_resize (GstGLWindow *window, guint width, guint height);
271
272GST_GL_API
273GstGLContext * gst_gl_window_get_context (GstGLWindow *window);
274GST_GL_API
275guintptr gst_gl_window_get_display (GstGLWindow *window);
276
277GST_GL_API
278gboolean gst_gl_window_has_output_surface (GstGLWindow *window);
279
280G_END_DECLS
281
282#endif /* __GST_GL_WINDOW_H__ */
283

source code of include/gstreamer-1.0/gst/gl/gstglwindow.h