gstglcontext.h 8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * GStreamer
 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_GL_CONTEXT_H__
#define __GST_GL_CONTEXT_H__

#include <gst/gst.h>

26
#include <gst/gl/gstgl_fwd.h>
27
28
29

G_BEGIN_DECLS

30
GST_EXPORT
31
32
33
34
GType gst_gl_context_get_type       (void);
#define GST_TYPE_GL_CONTEXT         (gst_gl_context_get_type())

/* FIXME: remove this when moving to -base */
35
36
37
/* #ifndef GST_DISABLE_DEPRECATED */
/* #define GST_GL_TYPE_CONTEXT GST_TYPE_GL_CONTEXT */
/* #endif */
38
39
40
41
42
#define GST_GL_CONTEXT(o)           (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_GL_CONTEXT, GstGLContext))
#define GST_GL_CONTEXT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GST_TYPE_GL_CONTEXT, GstGLContextClass))
#define GST_IS_GL_CONTEXT(o)        (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_GL_CONTEXT))
#define GST_IS_GL_CONTEXT_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_GL_CONTEXT))
#define GST_GL_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_GL_CONTEXT, GstGLContextClass))
43

44
GST_EXPORT
45
GQuark gst_gl_context_error_quark (void);
46
47
48
49
50
51
52

/**
 * GST_GL_CONTEXT_ERROR:
 *
 * Error domain for GStreamer's GL context module. Errors in this domain will
 * be from the #GstGLContextError enumeration
 */
53
#define GST_GL_CONTEXT_ERROR (gst_gl_context_error_quark ())
54

55
56
/**
 * GstGLContextThreadFunc:
57
 * @context: a #GstGLContext
58
59
 * @data: user data
 *
60
 * Represents a function to run in the GL thread with @context and @data
61
62
63
 */
typedef void (*GstGLContextThreadFunc) (GstGLContext * context, gpointer data);

64
#define GST_GL_CONTEXT_TYPE_CGL "gst.gl.context.CGL"
65
66
67
#define GST_GL_CONTEXT_TYPE_GLX "gst.gl.context.GLX"
#define GST_GL_CONTEXT_TYPE_EGL "gst.gl.context.EGL"
#define GST_GL_CONTEXT_TYPE_WGL "gst.gl.context.WGL"
68
#define GST_GL_CONTEXT_TYPE_EAGL "gst.gl.context.EAGL"
69

Matthew Waters's avatar
Matthew Waters committed
70
71
72
73
74
75
76
77
78
79
80
/**
 * GstGLContextError:
 * @GST_GL_CONTEXT_ERROR_FAILED: Failed for an unspecified reason
 * @GST_GL_CONTEXT_ERROR_WRONG_CONFIG: The configuration requested is not correct
 * @GST_GL_CONTEXT_ERROR_WRONG_API: The OpenGL API requested is not correct
 * @GST_GL_CONTEXT_ERROR_OLD_LIBS: The OpenGL libraries are too old
 * @GST_GL_CONTEXT_ERROR_CREATE_CONTEXT: glXCreateContext (or similar) failed
 * @GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE: A resource is not available
 *
 * OpenGL context errors.
 */
81
82
83
84
85
86
87
88
89
90
typedef enum
{
  GST_GL_CONTEXT_ERROR_FAILED,
  GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
  GST_GL_CONTEXT_ERROR_WRONG_API,
  GST_GL_CONTEXT_ERROR_OLD_LIBS,
  GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
  GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
} GstGLContextError;

91
92
/**
 * GstGLContext:
Matthew Waters's avatar
Matthew Waters committed
93
 * @gl_vtable: a list of OpenGL function pointers
94
95
96
 *
 * Opaque #GstGLContext object
 */
97
struct _GstGLContext {
Matthew Waters's avatar
Matthew Waters committed
98
  /*< private >*/
99
  GstObject parent;
100

101
  GstGLDisplay *display;
102
103
  GstGLWindow  *window;

Matthew Waters's avatar
Matthew Waters committed
104
  /*< public >*/
105
106
  GstGLFuncs *gl_vtable;

107
  /*< private >*/
108
  GstGLContextPrivate *priv;
109
110

  gpointer _reserved[GST_PADDING];
111
112
};

113
114
115
116
117
118
119
120
121
122
123
/**
 * GstGLContextClass:
 * @get_gl_context: get the backing platform specific OpenGL context
 * @get_gl_api: get the available OpenGL api's that this context can work with
 * @get_proc_address: get an function pointer to an OpenGL function
 * @activate: call eglMakeCurrent or similar
 * @choose_format: choose a format for the framebuffer
 * @create_context: create the OpenGL context
 * @destroy_context: destroy the OpenGL context
 * @swap_buffers: swap the default framebuffer's front/back buffers
 */
124
struct _GstGLContextClass {
125
  GstObjectClass parent_class;
126

127
  guintptr      (*get_current_context) (void);
128
129
130
  guintptr      (*get_gl_context)     (GstGLContext *context);
  GstGLAPI      (*get_gl_api)         (GstGLContext *context);
  GstGLPlatform (*get_gl_platform)    (GstGLContext *context);
131
  gpointer      (*get_proc_address)   (GstGLAPI gl_api, const gchar *name);
132
133
134
135
136
137
  gboolean      (*activate)           (GstGLContext *context, gboolean activate);
  gboolean      (*choose_format)      (GstGLContext *context, GError **error);
  gboolean      (*create_context)     (GstGLContext *context, GstGLAPI gl_api,
                                       GstGLContext *other_context, GError ** error);
  void          (*destroy_context)    (GstGLContext *context);
  void          (*swap_buffers)       (GstGLContext *context);
138
  gboolean      (*check_feature)      (GstGLContext *context, const gchar *feature);
139
  void          (*get_gl_platform_version) (GstGLContext *context, gint *major, gint *minor);
140
141
142
143
144
145
146

  /*< private >*/
  gpointer _reserved[GST_PADDING];
};

/* methods */

147
GST_EXPORT
148
GstGLContext * gst_gl_context_new  (GstGLDisplay *display);
149
GST_EXPORT
150
151
152
153
GstGLContext * gst_gl_context_new_wrapped (GstGLDisplay *display,
                                           guintptr handle,
                                           GstGLPlatform context_type,
                                           GstGLAPI available_apis);
154

155
GST_EXPORT
156
gboolean      gst_gl_context_activate         (GstGLContext *context, gboolean activate);
157
GST_EXPORT
158
GThread *     gst_gl_context_get_thread       (GstGLContext *context);
159
GST_EXPORT
160
GstGLContext * gst_gl_context_get_current     (void);
161

162
GST_EXPORT
163
GstGLDisplay * gst_gl_context_get_display (GstGLContext *context);
164
GST_EXPORT
165
gpointer      gst_gl_context_get_proc_address (GstGLContext *context, const gchar *name);
166
GST_EXPORT
167
GstGLPlatform gst_gl_context_get_gl_platform  (GstGLContext *context);
168
GST_EXPORT
169
GstGLAPI      gst_gl_context_get_gl_api       (GstGLContext *context);
170
GST_EXPORT
171
guintptr      gst_gl_context_get_gl_context   (GstGLContext *context);
172
GST_EXPORT
173
gboolean      gst_gl_context_can_share        (GstGLContext * context, GstGLContext *other_context);
174
175
GST_EXPORT
void          gst_gl_context_swap_buffers     (GstGLContext * context);
176

177
GST_EXPORT
178
gboolean      gst_gl_context_create           (GstGLContext *context, GstGLContext *other_context, GError ** error);
179
GST_EXPORT
180
void          gst_gl_context_destroy          (GstGLContext *context);
181

182
GST_EXPORT
183
gpointer      gst_gl_context_default_get_proc_address (GstGLAPI gl_api, const gchar *name);
184
GST_EXPORT
Matthew Waters's avatar
Matthew Waters committed
185
gpointer      gst_gl_context_get_proc_address_with_platform (GstGLPlatform context_type, GstGLAPI gl_api, const gchar *name);
186

187
GST_EXPORT
188
gboolean      gst_gl_context_set_window (GstGLContext *context, GstGLWindow *window);
189
GST_EXPORT
190
191
GstGLWindow * gst_gl_context_get_window (GstGLContext *context);

192
GST_EXPORT
193
void          gst_gl_context_get_gl_version (GstGLContext *context, gint *maj, gint *min);
194
GST_EXPORT
195
gboolean      gst_gl_context_check_gl_version (GstGLContext * context, GstGLAPI api, gint maj, gint min);
196
GST_EXPORT
197
gboolean      gst_gl_context_check_feature (GstGLContext *context, const gchar *feature);
198
199
GST_EXPORT
void          gst_gl_context_get_gl_platform_version (GstGLContext * context, gint * major, gint * minor);
200

201
GST_EXPORT
Matthew Waters's avatar
Matthew Waters committed
202
guintptr      gst_gl_context_get_current_gl_context     (GstGLPlatform context_type);
203
GST_EXPORT
204
GstGLAPI      gst_gl_context_get_current_gl_api         (GstGLPlatform platform, guint *major, guint *minor);
205

206
GST_EXPORT
207
gboolean      gst_gl_context_is_shared                  (GstGLContext * context);
208
GST_EXPORT
209
void          gst_gl_context_set_shared_with            (GstGLContext * context, GstGLContext * share);
210

211
GST_EXPORT
212
213
gboolean gst_gl_context_fill_info (GstGLContext * context, GError ** error);

214
/* FIXME: remove */
215
GST_EXPORT
216
void gst_gl_context_thread_add (GstGLContext * context,
217
218
    GstGLContextThreadFunc func, gpointer data);

219
220
221
G_END_DECLS

#endif /* __GST_GL_CONTEXT_H__ */