summaryrefslogtreecommitdiff
path: root/gst-libs/gst/gl/gstgldisplay.h
blob: 313880f85d1d2b5e92ea0eff7af5be2c7a79031d (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
 * GStreamer
 * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
 * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@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_H__
#define __GST_GL_H__

#include <gst/video/video.h>

typedef struct _GstGLUpload GstGLUpload;
typedef struct _GstGLDownload GstGLDownload;
typedef struct _GstGLShader GstGLShader;

#include "gstglwindow.h"
#include "gstglshader.h"
#include "gstglupload.h"
#include "gstgldownload.h"

G_BEGIN_DECLS

GType gst_gl_display_get_type (void);
#define GST_GL_TYPE_DISPLAY (gst_gl_display_get_type())
#define GST_GL_DISPLAY(obj)	(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_GL_TYPE_DISPLAY,GstGLDisplay))
#define GST_GL_DISPLAY_CLASS(klass)	\
  (G_TYPE_CHECK_CLASS_CAST((klass),GST_GL_TYPE_DISPLAY,GstGLDisplayClass))
#define GST_IS_GL_DISPLAY(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_GL_TYPE_DISPLAY))
#define GST_IS_GL_DISPLAY_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_GL_TYPE_DISPLAY))
#define GST_GL_DISPLAY_CAST(obj) ((GstGLDisplay*)(obj))

typedef struct _GstGLDisplay GstGLDisplay;
typedef struct _GstGLDisplayClass GstGLDisplayClass;
typedef struct _GstGLDisplayPrivate GstGLDisplayPrivate;

/**
 * GstGLDisplayConversion:
 *
 * %GST_GL_DISPLAY_CONVERSION_GLSL: Convert using GLSL (shaders)
 * %GST_GL_DISPLAY_CONVERSION_MATRIX: Convert using the ARB_imaging extension (not implemented)
 * %GST_GL_DISPLAY_CONVERSION_MESA: Convert using support in MESA
 */
typedef enum
{
  GST_GL_DISPLAY_CONVERSION_GLSL,
  GST_GL_DISPLAY_CONVERSION_MATRIX,
  GST_GL_DISPLAY_CONVERSION_MESA,
} GstGLDisplayConversion;

/**
 * GstGLDisplayProjection:
 *
 * %GST_GL_DISPLAY_PROJECTION_ORTHO2D: Orthogonal projection
 * %GST_GL_DISPLAY_CONVERSION_MATRIX: Perspective projection 
 */
typedef enum
{
  GST_GL_DISPLAY_PROJECTION_ORTHO2D,
  GST_GL_DISPLAY_PROJECTION_PERSPECTIVE
} GstGLDisplayProjection;

/**
 * CRCB:
 * @width: new width
 * @height: new height:
 * @data: user data
 *
 * client reshape callback
 */
typedef void (*CRCB) (GLuint width, GLuint height, gpointer data);
/**
 * CDCB:
 * @texture: texture to draw
 * @width: new width
 * @height: new height:
 * @data: user data
 *
 * client draw callback
 */
typedef gboolean (*CDCB) (GLuint texture, GLuint width, GLuint height, gpointer data);
/**
 * GstGLDisplayThreadFunc:
 * @display: a #GstGLDisplay
 * @data: user data
 *
 * Represents a function to run in the GL thread
 */
typedef void (*GstGLDisplayThreadFunc) (GstGLDisplay * display, gpointer data);

/**
 * GLCB:
 * @width: the width
 * @height: the height
 * @texture: texture
 * @stuff: user data
 *
 * callback definition for operating on textures
 */
typedef void (*GLCB) (gint, gint, guint, gpointer stuff);
/**
 * GLCB_V2:
 * @stuff: user data
 *
 * callback definition for operating through a Framebuffer object
 */
typedef void (*GLCB_V2) (gpointer stuff);

#define GST_GL_DISPLAY_ERR_MSG(obj) ("%s", GST_GL_DISPLAY_CAST(obj)->error_message)

/**
 * GstGLDisplay:
 *
 * the contents of a #GstGLDisplay are private and should only be accessed
 * through the provided API
 */
struct _GstGLDisplay
{
  GObject        object;

  /* thread safe */
  GMutex        *mutex;

  /* gl context */
  GThread       *gl_thread;
  GstGLWindow   *gl_window;
  gboolean       isAlive;

  /* gl API we are using */
  GstGLAPI       gl_api;

  /* conditions */
  GCond         *cond_create_context;
  GCond         *cond_destroy_context;

  /* generic gl code */
  GstGLDisplayThreadFunc   generic_callback;
  gpointer                 data;

  /* action redisplay */
  GLuint         redisplay_texture;
  GLuint         redisplay_texture_width;
  GLuint         redisplay_texture_height;
  gboolean       keep_aspect_ratio;
#if HAVE_GLES2
  GstGLShader   *redisplay_shader;
  gchar         *redisplay_vertex_shader_str_gles2;
  gchar         *redisplay_fragment_shader_str_gles2;
  GLint          redisplay_attr_position_loc;
  GLint          redisplay_attr_texture_loc;
#endif

  /* action gen and del texture */
  GLuint         gen_texture;
  GLuint         gen_texture_width;
  GLuint         gen_texture_height;
  GstVideoFormat gen_texture_video_format;

  /* client callbacks */
  CRCB           clientReshapeCallback;
  CDCB           clientDrawCallback;
  gpointer       client_data;

  GstGLDisplayConversion colorspace_conversion;

  GSList        *uploads;
  GSList        *downloads;

  /* foreign gl context */
  gulong         external_gl_context;

  /* filter gen fbo */
  GLuint         gen_fbo_width;
  GLuint         gen_fbo_height;
  GLuint         generated_fbo;
  GLuint         generated_depth_buffer;

  /* filter use fbo */
  GLuint         use_fbo;
  GLuint         use_depth_buffer;
  GLuint         use_fbo_texture;
  GLuint         use_fbo_width;
  GLuint         use_fbo_height;
  GLCB           use_fbo_scene_cb;
  GLCB_V2        use_fbo_scene_cb_v2;
  gdouble        use_fbo_proj_param1;
  gdouble        use_fbo_proj_param2;
  gdouble        use_fbo_proj_param3;
  gdouble        use_fbo_proj_param4;
  GstGLDisplayProjection use_fbo_projection;
  gpointer      *use_fbo_stuff;
  GLuint         input_texture_width;
  GLuint         input_texture_height;
  GLuint         input_texture;

  /* filter del fbo */
  GLuint         del_fbo;
  GLuint         del_depth_buffer;

  /* action gen and del shader */
  const gchar   *gen_shader_fragment_source;
  const gchar   *gen_shader_vertex_source;
  GstGLShader   *gen_shader;
  GstGLShader   *del_shader;

  gchar *error_message;

  GstGLDisplayPrivate *priv;
};


struct _GstGLDisplayClass
{
  GObjectClass object_class;
};


/*-----------------------------------------------------------*\
 -------------------- Public declarations -------------------
\*-----------------------------------------------------------*/
GstGLDisplay *gst_gl_display_new (void);

gboolean gst_gl_display_create_context (GstGLDisplay * display,
    gulong external_gl_context);
gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture,
    gint gl_width, gint gl_height, gint window_width, gint window_height,
    gboolean keep_aspect_ratio);

void gst_gl_display_thread_add (GstGLDisplay * display,
    GstGLDisplayThreadFunc func, gpointer data);

void gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
    GstVideoFormat v_format, GLint width, GLint height);
void gst_gl_display_gen_texture_thread (GstGLDisplay * display, GLuint * pTexture,
    GstVideoFormat v_format, GLint width, GLint height);
void gst_gl_display_del_texture (GstGLDisplay * display, GLuint * pTexture);

gboolean gst_gl_display_gen_fbo (GstGLDisplay * display, gint width, gint height,
    GLuint * fbo, GLuint * depthbuffer);
gboolean gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
    gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
    GLuint texture_fbo, GLCB cb, gint input_texture_width,
    gint input_texture_height, GLuint input_texture, gdouble proj_param1,
    gdouble proj_param2, gdouble proj_param3, gdouble proj_param4,
    GstGLDisplayProjection projection, gpointer * stuff);
gboolean gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
    gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
    GLuint texture_fbo, GLCB_V2 cb, gpointer * stuff);
void gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo,
    GLuint depth_buffer);

gboolean gst_gl_display_gen_shader (GstGLDisplay * display,
    const gchar * shader_vertex_source,
    const gchar * shader_fragment_source, GstGLShader ** shader);
void gst_gl_display_del_shader (GstGLDisplay * display, GstGLShader * shader);

void gst_gl_display_set_window_id (GstGLDisplay * display, guintptr window_id);
void gst_gl_display_set_client_reshape_callback (GstGLDisplay * display,
    CRCB cb);
void gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb);
void gst_gl_display_set_client_data (GstGLDisplay * display, gpointer data);

gulong gst_gl_display_get_internal_gl_context (GstGLDisplay * display);
void gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate);

/* Must be called inside a lock/unlock on display, or within the glthread */
void gst_gl_display_set_error (GstGLDisplay * display, const char * format, ...);
void gst_gl_display_check_framebuffer_status (void);

void gst_gl_display_lock (GstGLDisplay * display);
void gst_gl_display_unlock (GstGLDisplay * display);
GstGLAPI gst_gl_display_get_gl_api (GstGLDisplay * display);
GstGLAPI gst_gl_display_get_gl_api_unlocked (GstGLDisplay * display);

G_END_DECLS

#endif /* __GST_GL_H__ */