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 31 G_BEGIN_DECLS 32 33 GST_GL_API 34 GType 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 47 GST_GL_API 48 GQuark 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 */ 63 typedef 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 70 typedef void (*GstGLWindowCB) (gpointer data); 71 typedef 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 currect 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 currect 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 */ 95 struct _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 */ 154 struct _GstGLWindowClass { 155 GstObjectClass parent_class; 156 157 guintptr (*get_display) (GstGLWindow *window); 158 void (*set_window_handle) (GstGLWindow *window, guintptr handle); 159 guintptr (*get_window_handle) (GstGLWindow *window); 160 void (*draw) (GstGLWindow *window); 161 void (*run) (GstGLWindow *window); 162 void (*quit) (GstGLWindow *window); 163 void (*send_message) (GstGLWindow *window, GstGLWindowCB callback, gpointer data); 164 void (*send_message_async) (GstGLWindow *window, GstGLWindowCB callback, gpointer data, GDestroyNotify destroy); 165 166 gboolean (*open) (GstGLWindow *window, GError **error); 167 void (*close) (GstGLWindow *window); 168 void (*handle_events) (GstGLWindow *window, gboolean handle_events); 169 void (*set_preferred_size) (GstGLWindow *window, gint width, gint height); 170 void (*show) (GstGLWindow *window); 171 gboolean (*set_render_rectangle)(GstGLWindow *window, gint x, gint y, gint width, gint height); 172 void (*queue_resize) (GstGLWindow *window); 173 gboolean (*controls_viewport) (GstGLWindow *window); 174 175 /*< private >*/ 176 gpointer _reserved[GST_PADDING-1]; 177 }; 178 179 GST_GL_API 180 GstGLWindow * gst_gl_window_new (GstGLDisplay *display); 181 182 /* callbacks */ 183 GST_GL_API 184 void gst_gl_window_set_draw_callback (GstGLWindow *window, 185 GstGLWindowCB callback, 186 gpointer data, 187 GDestroyNotify destroy_notify); 188 GST_GL_API 189 void gst_gl_window_set_resize_callback (GstGLWindow *window, 190 GstGLWindowResizeCB callback, 191 gpointer data, 192 GDestroyNotify destroy_notify); 193 GST_GL_API 194 void gst_gl_window_set_close_callback (GstGLWindow *window, 195 GstGLWindowCB callback, 196 gpointer data, 197 GDestroyNotify destroy_notify); 198 199 GST_GL_API 200 void gst_gl_window_set_window_handle (GstGLWindow *window, guintptr handle); 201 GST_GL_API 202 guintptr gst_gl_window_get_window_handle (GstGLWindow *window); 203 204 /* loop/events */ 205 GST_GL_API 206 void gst_gl_window_run (GstGLWindow *window); 207 GST_GL_API 208 void gst_gl_window_quit (GstGLWindow *window); 209 GST_GL_API 210 void gst_gl_window_send_message (GstGLWindow *window, 211 GstGLWindowCB callback, 212 gpointer data); 213 GST_GL_API 214 void gst_gl_window_send_message_async (GstGLWindow *window, 215 GstGLWindowCB callback, 216 gpointer data, 217 GDestroyNotify destroy); 218 219 /* navigation */ 220 GST_GL_API 221 void gst_gl_window_handle_events (GstGLWindow * window, 222 gboolean handle_events); 223 224 GST_GL_API 225 void gst_gl_window_send_key_event (GstGLWindow * window, 226 const char * event_type, 227 const char * key_str); 228 GST_GL_API 229 void gst_gl_window_send_mouse_event (GstGLWindow * window, 230 const char * event_type, 231 int button, 232 double posx, 233 double posy); 234 235 /* surfaces/rendering */ 236 GST_GL_API 237 void gst_gl_window_queue_resize (GstGLWindow *window); 238 GST_GL_API 239 void gst_gl_window_draw (GstGLWindow *window); 240 GST_GL_API 241 void gst_gl_window_show (GstGLWindow *window); 242 GST_GL_API 243 void gst_gl_window_set_preferred_size (GstGLWindow * window, 244 gint width, 245 gint height); 246 GST_GL_API 247 void gst_gl_window_get_surface_dimensions (GstGLWindow * window, 248 guint * width, 249 guint * height); 250 GST_GL_API 251 gboolean gst_gl_window_set_render_rectangle (GstGLWindow * window, 252 gint x, 253 gint y, 254 gint width, 255 gint height); 256 GST_GL_API 257 gboolean gst_gl_window_controls_viewport (GstGLWindow * window); 258 259 /* subclass usage only */ 260 GST_GL_API 261 void gst_gl_window_resize (GstGLWindow *window, guint width, guint height); 262 263 GST_GL_API 264 GstGLContext * gst_gl_window_get_context (GstGLWindow *window); 265 GST_GL_API 266 guintptr gst_gl_window_get_display (GstGLWindow *window); 267 268 G_END_DECLS 269 270 #endif /* __GST_GL_WINDOW_H__ */ 271