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
28G_BEGIN_DECLS
29
30GST_GL_API
31GType 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
40GST_GL_API
41GQuark 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 */
58typedef 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 */
77typedef 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 */
93struct _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/**
121 * GstGLContextClass::get_config:
122 * @context: the #GstGLContext
123 *
124 * Retrieve the configuration in use by this context. See also
125 * gst_gl_context_get_config().
126 *
127 * Returns: (transfer full) (nullable): the configuration chosen for this
128 * #GstGLContext
129 *
130 * Since: 1.20
131 */
132/**
133 * GstGLContextClass::request_config:
134 * @context: the #GstGLContext
135 * @gl_config: (nullable) (transfer full): a configuration structure for
136 * configuring on @context
137 *
138 * Request a configuration for this @context to use.
139 *
140 * Unknown fields within @gl_config should be ignored by subclasses.
141 *
142 * See also gst_gl_context_request_config().
143 *
144 * Returns: Whether @gl_config could be successfull set on @context.
145 *
146 * Since: 1.20
147 */
148struct _GstGLContextClass {
149 GstObjectClass parent_class;
150
151 guintptr (*get_current_context) (void);
152 guintptr (*get_gl_context) (GstGLContext *context);
153 GstGLAPI (*get_gl_api) (GstGLContext *context);
154 GstGLPlatform (*get_gl_platform) (GstGLContext *context);
155 gpointer (*get_proc_address) (GstGLAPI gl_api, const gchar *name);
156 gboolean (*activate) (GstGLContext *context, gboolean activate);
157 gboolean (*choose_format) (GstGLContext *context, GError **error);
158 gboolean (*create_context) (GstGLContext *context, GstGLAPI gl_api,
159 GstGLContext *other_context, GError ** error);
160 void (*destroy_context) (GstGLContext *context);
161 void (*swap_buffers) (GstGLContext *context);
162 gboolean (*check_feature) (GstGLContext *context, const gchar *feature);
163 void (*get_gl_platform_version) (GstGLContext *context, gint *major, gint *minor);
164 GstStructure *(*get_config) (GstGLContext * context);
165 gboolean (*request_config) (GstGLContext * context, GstStructure * gl_config);
166
167 /*< private >*/
168 gpointer _reserved[GST_PADDING-2];
169};
170
171/* methods */
172
173GST_GL_API
174GstGLContext * gst_gl_context_new (GstGLDisplay *display);
175GST_GL_API
176GstGLContext * gst_gl_context_new_wrapped (GstGLDisplay *display,
177 guintptr handle,
178 GstGLPlatform context_type,
179 GstGLAPI available_apis);
180
181GST_GL_API
182GstStructure * gst_gl_context_get_config (GstGLContext * context);
183GST_GL_API
184gboolean gst_gl_context_request_config (GstGLContext * context, GstStructure * gl_config);
185
186GST_GL_API
187gboolean gst_gl_context_activate (GstGLContext *context, gboolean activate);
188GST_GL_API
189GThread * gst_gl_context_get_thread (GstGLContext *context);
190GST_GL_API
191GstGLContext * gst_gl_context_get_current (void);
192
193GST_GL_API
194GstGLDisplay * gst_gl_context_get_display (GstGLContext *context);
195GST_GL_API
196gpointer gst_gl_context_get_proc_address (GstGLContext *context, const gchar *name);
197GST_GL_API
198GstGLPlatform gst_gl_context_get_gl_platform (GstGLContext *context);
199GST_GL_API
200GstGLAPI gst_gl_context_get_gl_api (GstGLContext *context);
201GST_GL_API
202guintptr gst_gl_context_get_gl_context (GstGLContext *context);
203GST_GL_API
204gboolean gst_gl_context_can_share (GstGLContext * context, GstGLContext *other_context);
205GST_GL_API
206void gst_gl_context_swap_buffers (GstGLContext * context);
207
208GST_GL_API
209gboolean gst_gl_context_create (GstGLContext *context, GstGLContext *other_context, GError ** error);
210GST_GL_API
211void gst_gl_context_destroy (GstGLContext *context);
212
213GST_GL_API
214gpointer gst_gl_context_default_get_proc_address (GstGLAPI gl_api, const gchar *name);
215GST_GL_API
216gpointer gst_gl_context_get_proc_address_with_platform (GstGLPlatform context_type, GstGLAPI gl_api, const gchar *name);
217
218GST_GL_API
219gboolean gst_gl_context_set_window (GstGLContext *context, GstGLWindow *window);
220GST_GL_API
221GstGLWindow * gst_gl_context_get_window (GstGLContext *context);
222
223GST_GL_API
224void gst_gl_context_get_gl_version (GstGLContext *context, gint *maj, gint *min);
225GST_GL_API
226gboolean gst_gl_context_check_gl_version (GstGLContext * context, GstGLAPI api, gint maj, gint min);
227GST_GL_API
228gboolean gst_gl_context_check_feature (GstGLContext *context, const gchar *feature);
229GST_GL_API
230void gst_gl_context_get_gl_platform_version (GstGLContext * context, gint * major, gint * minor);
231
232GST_GL_API
233guintptr gst_gl_context_get_current_gl_context (GstGLPlatform context_type);
234GST_GL_API
235GstGLAPI gst_gl_context_get_current_gl_api (GstGLPlatform platform, guint *major, guint *minor);
236
237GST_GL_API
238gboolean gst_gl_context_is_shared (GstGLContext * context);
239GST_GL_API
240void gst_gl_context_set_shared_with (GstGLContext * context, GstGLContext * share);
241
242GST_GL_API
243gboolean gst_gl_context_fill_info (GstGLContext * context, GError ** error);
244
245/* FIXME: remove */
246GST_GL_API
247void gst_gl_context_thread_add (GstGLContext * context,
248 GstGLContextThreadFunc func, gpointer data);
249
250G_END_DECLS
251
252#endif /* __GST_GL_CONTEXT_H__ */
253

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