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 #ifndef __GST_GL_CONTEXT_H__
22 #define __GST_GL_CONTEXT_H__
23 
24 #include <gst/gst.h>
25 
26 #include <gst/gl/gstgl_fwd.h>
27 
28 G_BEGIN_DECLS
29 
30 GST_GL_API
31 GType gst_gl_context_get_type       (void);
32 #define GST_TYPE_GL_CONTEXT         (gst_gl_context_get_type())
33 
34 #define GST_GL_CONTEXT(o)           (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_GL_CONTEXT, GstGLContext))
35 #define GST_GL_CONTEXT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GST_TYPE_GL_CONTEXT, GstGLContextClass))
36 #define GST_IS_GL_CONTEXT(o)        (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_GL_CONTEXT))
37 #define GST_IS_GL_CONTEXT_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_GL_CONTEXT))
38 #define GST_GL_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_GL_CONTEXT, GstGLContextClass))
39 
40 GST_GL_API
41 GQuark gst_gl_context_error_quark (void);
42 
43 /**
44  * GST_GL_CONTEXT_ERROR:
45  *
46  * Error domain for GStreamer's GL context module. Errors in this domain will
47  * be from the #GstGLContextError enumeration
48  */
49 #define GST_GL_CONTEXT_ERROR (gst_gl_context_error_quark ())
50 
51 /**
52  * GstGLContextThreadFunc:
53  * @context: a #GstGLContext
54  * @data: user data
55  *
56  * Represents a function to run in the GL thread with @context and @data
57  */
58 typedef void (*GstGLContextThreadFunc) (GstGLContext * context, gpointer data);
59 
60 #define GST_GL_CONTEXT_TYPE_CGL "gst.gl.context.CGL"
61 #define GST_GL_CONTEXT_TYPE_GLX "gst.gl.context.GLX"
62 #define GST_GL_CONTEXT_TYPE_EGL "gst.gl.context.EGL"
63 #define GST_GL_CONTEXT_TYPE_WGL "gst.gl.context.WGL"
64 #define GST_GL_CONTEXT_TYPE_EAGL "gst.gl.context.EAGL"
65 
66 /**
67  * GstGLContextError:
68  * @GST_GL_CONTEXT_ERROR_FAILED: Failed for an unspecified reason
69  * @GST_GL_CONTEXT_ERROR_WRONG_CONFIG: The configuration requested is not correct
70  * @GST_GL_CONTEXT_ERROR_WRONG_API: The OpenGL API requested is not correct
71  * @GST_GL_CONTEXT_ERROR_OLD_LIBS: The OpenGL libraries are too old
72  * @GST_GL_CONTEXT_ERROR_CREATE_CONTEXT: glXCreateContext (or similar) failed
73  * @GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE: A resource is not available
74  *
75  * OpenGL context errors.
76  */
77 typedef enum
78 {
79   GST_GL_CONTEXT_ERROR_FAILED,
80   GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
81   GST_GL_CONTEXT_ERROR_WRONG_API,
82   GST_GL_CONTEXT_ERROR_OLD_LIBS,
83   GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
84   GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
85 } GstGLContextError;
86 
87 /**
88  * GstGLContext:
89  * @gl_vtable: a list of OpenGL function pointers
90  *
91  * Opaque #GstGLContext object
92  */
93 struct _GstGLContext {
94   /*< private >*/
95   GstObject parent;
96 
97   GstGLDisplay *display;
98   GstGLWindow  *window;
99 
100   /*< public >*/
101   GstGLFuncs *gl_vtable;
102 
103   /*< private >*/
104   GstGLContextPrivate *priv;
105 
106   gpointer _reserved[GST_PADDING];
107 };
108 
109 /**
110  * GstGLContextClass:
111  * @get_gl_context: get the backing platform specific OpenGL context
112  * @get_gl_api: get the available OpenGL api's that this context can work with
113  * @get_proc_address: get an function pointer to an OpenGL function
114  * @activate: call eglMakeCurrent or similar
115  * @choose_format: choose a format for the framebuffer
116  * @create_context: create the OpenGL context
117  * @destroy_context: destroy the OpenGL context
118  * @swap_buffers: swap the default framebuffer's front/back buffers
119  */
120 struct _GstGLContextClass {
121   GstObjectClass parent_class;
122 
123   guintptr      (*get_current_context) (void);
124   guintptr      (*get_gl_context)     (GstGLContext *context);
125   GstGLAPI      (*get_gl_api)         (GstGLContext *context);
126   GstGLPlatform (*get_gl_platform)    (GstGLContext *context);
127   gpointer      (*get_proc_address)   (GstGLAPI gl_api, const gchar *name);
128   gboolean      (*activate)           (GstGLContext *context, gboolean activate);
129   gboolean      (*choose_format)      (GstGLContext *context, GError **error);
130   gboolean      (*create_context)     (GstGLContext *context, GstGLAPI gl_api,
131                                        GstGLContext *other_context, GError ** error);
132   void          (*destroy_context)    (GstGLContext *context);
133   void          (*swap_buffers)       (GstGLContext *context);
134   gboolean      (*check_feature)      (GstGLContext *context, const gchar *feature);
135   void          (*get_gl_platform_version) (GstGLContext *context, gint *major, gint *minor);
136 
137   /*< private >*/
138   gpointer _reserved[GST_PADDING];
139 };
140 
141 /* methods */
142 
143 GST_GL_API
144 GstGLContext * gst_gl_context_new  (GstGLDisplay *display);
145 GST_GL_API
146 GstGLContext * gst_gl_context_new_wrapped (GstGLDisplay *display,
147                                            guintptr handle,
148                                            GstGLPlatform context_type,
149                                            GstGLAPI available_apis);
150 
151 GST_GL_API
152 gboolean      gst_gl_context_activate         (GstGLContext *context, gboolean activate);
153 GST_GL_API
154 GThread *     gst_gl_context_get_thread       (GstGLContext *context);
155 GST_GL_API
156 GstGLContext * gst_gl_context_get_current     (void);
157 
158 GST_GL_API
159 GstGLDisplay * gst_gl_context_get_display (GstGLContext *context);
160 GST_GL_API
161 gpointer      gst_gl_context_get_proc_address (GstGLContext *context, const gchar *name);
162 GST_GL_API
163 GstGLPlatform gst_gl_context_get_gl_platform  (GstGLContext *context);
164 GST_GL_API
165 GstGLAPI      gst_gl_context_get_gl_api       (GstGLContext *context);
166 GST_GL_API
167 guintptr      gst_gl_context_get_gl_context   (GstGLContext *context);
168 GST_GL_API
169 gboolean      gst_gl_context_can_share        (GstGLContext * context, GstGLContext *other_context);
170 GST_GL_API
171 void          gst_gl_context_swap_buffers     (GstGLContext * context);
172 
173 GST_GL_API
174 gboolean      gst_gl_context_create           (GstGLContext *context, GstGLContext *other_context, GError ** error);
175 GST_GL_API
176 void          gst_gl_context_destroy          (GstGLContext *context);
177 
178 GST_GL_API
179 gpointer      gst_gl_context_default_get_proc_address (GstGLAPI gl_api, const gchar *name);
180 GST_GL_API
181 gpointer      gst_gl_context_get_proc_address_with_platform (GstGLPlatform context_type, GstGLAPI gl_api, const gchar *name);
182 
183 GST_GL_API
184 gboolean      gst_gl_context_set_window (GstGLContext *context, GstGLWindow *window);
185 GST_GL_API
186 GstGLWindow * gst_gl_context_get_window (GstGLContext *context);
187 
188 GST_GL_API
189 void          gst_gl_context_get_gl_version (GstGLContext *context, gint *maj, gint *min);
190 GST_GL_API
191 gboolean      gst_gl_context_check_gl_version (GstGLContext * context, GstGLAPI api, gint maj, gint min);
192 GST_GL_API
193 gboolean      gst_gl_context_check_feature (GstGLContext *context, const gchar *feature);
194 GST_GL_API
195 void          gst_gl_context_get_gl_platform_version (GstGLContext * context, gint * major, gint * minor);
196 
197 GST_GL_API
198 guintptr      gst_gl_context_get_current_gl_context     (GstGLPlatform context_type);
199 GST_GL_API
200 GstGLAPI      gst_gl_context_get_current_gl_api         (GstGLPlatform platform, guint *major, guint *minor);
201 
202 GST_GL_API
203 gboolean      gst_gl_context_is_shared                  (GstGLContext * context);
204 GST_GL_API
205 void          gst_gl_context_set_shared_with            (GstGLContext * context, GstGLContext * share);
206 
207 GST_GL_API
208 gboolean gst_gl_context_fill_info (GstGLContext * context, GError ** error);
209 
210 /* FIXME: remove */
211 GST_GL_API
212 void gst_gl_context_thread_add (GstGLContext * context,
213     GstGLContextThreadFunc func, gpointer data);
214 
215 G_END_DECLS
216 
217 #endif /* __GST_GL_CONTEXT_H__ */
218