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 */
120struct _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
143GST_GL_API
144GstGLContext * gst_gl_context_new (GstGLDisplay *display);
145GST_GL_API
146GstGLContext * gst_gl_context_new_wrapped (GstGLDisplay *display,
147 guintptr handle,
148 GstGLPlatform context_type,
149 GstGLAPI available_apis);
150
151GST_GL_API
152gboolean gst_gl_context_activate (GstGLContext *context, gboolean activate);
153GST_GL_API
154GThread * gst_gl_context_get_thread (GstGLContext *context);
155GST_GL_API
156GstGLContext * gst_gl_context_get_current (void);
157
158GST_GL_API
159GstGLDisplay * gst_gl_context_get_display (GstGLContext *context);
160GST_GL_API
161gpointer gst_gl_context_get_proc_address (GstGLContext *context, const gchar *name);
162GST_GL_API
163GstGLPlatform gst_gl_context_get_gl_platform (GstGLContext *context);
164GST_GL_API
165GstGLAPI gst_gl_context_get_gl_api (GstGLContext *context);
166GST_GL_API
167guintptr gst_gl_context_get_gl_context (GstGLContext *context);
168GST_GL_API
169gboolean gst_gl_context_can_share (GstGLContext * context, GstGLContext *other_context);
170GST_GL_API
171void gst_gl_context_swap_buffers (GstGLContext * context);
172
173GST_GL_API
174gboolean gst_gl_context_create (GstGLContext *context, GstGLContext *other_context, GError ** error);
175GST_GL_API
176void gst_gl_context_destroy (GstGLContext *context);
177
178GST_GL_API
179gpointer gst_gl_context_default_get_proc_address (GstGLAPI gl_api, const gchar *name);
180GST_GL_API
181gpointer gst_gl_context_get_proc_address_with_platform (GstGLPlatform context_type, GstGLAPI gl_api, const gchar *name);
182
183GST_GL_API
184gboolean gst_gl_context_set_window (GstGLContext *context, GstGLWindow *window);
185GST_GL_API
186GstGLWindow * gst_gl_context_get_window (GstGLContext *context);
187
188GST_GL_API
189void gst_gl_context_get_gl_version (GstGLContext *context, gint *maj, gint *min);
190GST_GL_API
191gboolean gst_gl_context_check_gl_version (GstGLContext * context, GstGLAPI api, gint maj, gint min);
192GST_GL_API
193gboolean gst_gl_context_check_feature (GstGLContext *context, const gchar *feature);
194GST_GL_API
195void gst_gl_context_get_gl_platform_version (GstGLContext * context, gint * major, gint * minor);
196
197GST_GL_API
198guintptr gst_gl_context_get_current_gl_context (GstGLPlatform context_type);
199GST_GL_API
200GstGLAPI gst_gl_context_get_current_gl_api (GstGLPlatform platform, guint *major, guint *minor);
201
202GST_GL_API
203gboolean gst_gl_context_is_shared (GstGLContext * context);
204GST_GL_API
205void gst_gl_context_set_shared_with (GstGLContext * context, GstGLContext * share);
206
207GST_GL_API
208gboolean gst_gl_context_fill_info (GstGLContext * context, GError ** error);
209
210/* FIXME: remove */
211GST_GL_API
212void gst_gl_context_thread_add (GstGLContext * context,
213 GstGLContextThreadFunc func, gpointer data);
214
215G_END_DECLS
216
217#endif /* __GST_GL_CONTEXT_H__ */
218