summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapiutils_egl.h
blob: 2dcdf6836b6a994109a8f002ef895181994d9701 (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
/*
 * gstvaapiutils_egl.h - EGL utilities
 *
 * Copyright (C) 2014 Intel Corporation
 *   Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301
 */

#ifndef GST_VAAPI_UTILS_EGL_H
#define GST_VAAPI_UTILS_EGL_H

#include <gmodule.h>
#include <gst/gstinfo.h>
#include <gst/video/video-format.h>
#include "egl_compat.h"
#include "gstvaapiminiobject.h"

typedef union egl_handle_s                      EglHandle;
typedef struct egl_object_s                     EglObject;
typedef struct egl_object_class_s               EglObjectClass;
typedef struct egl_vtable_s                     EglVTable;
typedef struct egl_display_s                    EglDisplay;
typedef struct egl_config_s                     EglConfig;
typedef struct egl_context_state_s              EglContextState;
typedef struct egl_context_s                    EglContext;
typedef struct egl_surface_s                    EglSurface;
typedef struct egl_program_s                    EglProgram;
typedef struct egl_window_s                     EglWindow;

#define EGL_PROTO_BEGIN(NAME, TYPE, EXTENSION) \
  typedef TYPE (*GL_PROTO_GEN_CONCAT3(Egl,NAME,Proc))
#define EGL_PROTO_END()                         ;
#define GL_PROTO_BEGIN(NAME, TYPE, EXTENSION) \
  typedef TYPE (*GL_PROTO_GEN_CONCAT3(Gl,NAME,Proc))
#define GL_PROTO_ARG_LIST(...)                  (__VA_ARGS__)
#define GL_PROTO_ARG(NAME, TYPE)                TYPE NAME
#define GL_PROTO_END()                          ;
#include "egl_vtable.h"

enum {
  EGL_PLATFORM_UNKNOWN,
  EGL_PLATFORM_X11,
  EGL_PLATFORM_WAYLAND,
};

union egl_handle_s
{
  gpointer p;
  guintptr u;
  gintptr i;
};

struct egl_object_s
{
  /*< private >*/
  GstVaapiMiniObject parent_instance;

  EglHandle handle;
  guint is_wrapped:1;
  guint is_valid:1;
};

struct egl_object_class_s
{
  /*< private >*/
  GstVaapiMiniObjectClass parent_class;
};

struct egl_vtable_s
{
  EglObject base;

  gchar **egl_extensions;
  guint num_egl_symbols;
  gchar **gl_extensions;
  guint num_gl_symbols;
  guint gles_version;

#define EGL_PROTO_BEGIN(NAME, TYPE, EXTENSION) \
  GL_PROTO_BEGIN_I(NAME, TYPE, EXTENSION, Egl, egl)
#define GL_PROTO_BEGIN(NAME, TYPE, EXTENSION) \
  GL_PROTO_BEGIN_I(NAME, TYPE, EXTENSION,  Gl,  gl)
#define GL_PROTO_BEGIN_I(NAME, TYPE, EXTENSION, Prefix, prefix) \
  GL_PROTO_GEN_CONCAT3(Prefix,NAME,Proc) GL_PROTO_GEN_CONCAT(prefix,NAME);
#include "egl_vtable.h"

#define EGL_DEFINE_EXTENSION(EXTENSION) \
  GL_DEFINE_EXTENSION_I(EXTENSION, EGL)
#define GL_DEFINE_EXTENSION(EXTENSION) \
  GL_DEFINE_EXTENSION_I(EXTENSION,  GL)
#define GL_DEFINE_EXTENSION_I(EXTENSION, PREFIX) \
  guint GL_PROTO_GEN_CONCAT4(has_,PREFIX,_,EXTENSION);
#include "egl_vtable.h"
};

struct egl_display_s
{
  EglObject base;

  gchar *gl_vendor_string;
  gchar *gl_version_string;
  gchar *gl_apis_string;
  guint gl_apis;                /* EGL_*_BIT mask */
  guint gl_platform;

  GMutex mutex;
  GThread *gl_thread;
  GCond gl_thread_ready;
  volatile gboolean gl_thread_cancel;
  GAsyncQueue *gl_queue;
};

struct egl_config_s
{
  EglObject base;

  EglDisplay *display;
  guint gl_api;                 /* EGL_*_API value */
  guint gles_version;
  gint config_id;
  gint visual_id;
};

typedef void (*EglContextRunFunc) (gpointer args);

struct egl_context_state_s
{
  EGLDisplay display;
  EGLContext context;
  EGLSurface read_surface;
  EGLSurface draw_surface;
};

struct egl_context_s
{
  EglObject base;

  EglVTable *vtable;
  EglDisplay *display;
  EglConfig *config;
  EglSurface *read_surface;
  EglSurface *draw_surface;
};

struct egl_surface_s
{
  EglObject base;

  EglDisplay *display;
};

/* Defined to the maximum number of uniforms for a shader program */
#define EGL_MAX_UNIFORMS 16

struct egl_program_s
{
  EglObject base;

  EglVTable *vtable;
  guint frag_shader;
  guint vert_shader;
  gint uniforms[EGL_MAX_UNIFORMS];
};

struct egl_window_s
{
  EglObject base;

  EglContext *context;
  EglSurface *surface;
};

#define egl_object_ref(obj) \
  ((gpointer)gst_vaapi_mini_object_ref ((GstVaapiMiniObject *)(obj)))
#define egl_object_unref(obj) \
  gst_vaapi_mini_object_unref ((GstVaapiMiniObject *)(obj))
#define egl_object_replace(old_obj_ptr, new_obj) \
  gst_vaapi_mini_object_replace ((GstVaapiMiniObject **)(old_obj_ptr), \
      (GstVaapiMiniObject *)(new_obj))

G_GNUC_INTERNAL
EglDisplay *
egl_display_new (gpointer native_display, guint gl_platform);

G_GNUC_INTERNAL
EglDisplay *
egl_display_new_wrapped (EGLDisplay gl_display);

G_GNUC_INTERNAL
EglConfig *
egl_config_new (EglDisplay * display, guint gles_version,
    GstVideoFormat format);

G_GNUC_INTERNAL
EglConfig *
egl_config_new_with_attribs (EglDisplay * display, const EGLint * attribs);

G_GNUC_INTERNAL
EglContext *
egl_context_new (EglDisplay * display, EglConfig * config, EglContext * parent);

G_GNUC_INTERNAL
EglContext *
egl_context_new_wrapped (EglDisplay * display, EGLContext gl_context);

G_GNUC_INTERNAL
EglVTable *
egl_context_get_vtable (EglContext * ctx, gboolean need_gl_symbols);

G_GNUC_INTERNAL
gboolean
egl_context_set_current (EglContext * ctx, gboolean activate,
    EglContextState * old_cs);

G_GNUC_INTERNAL
gboolean
egl_context_run (EglContext * ctx, EglContextRunFunc func, gpointer args);

G_GNUC_INTERNAL
EglProgram *
egl_program_new (EglContext * ctx, const gchar * frag_shader_text,
    const gchar * vert_shader_text);

G_GNUC_INTERNAL
EglWindow *
egl_window_new (EglContext * ctx, gpointer native_window);

G_GNUC_INTERNAL
guint
egl_create_texture (EglContext * ctx, guint target, guint format,
    guint width, guint height);

G_GNUC_INTERNAL
void
egl_destroy_texture (EglContext * ctx, guint texture);

G_GNUC_INTERNAL
void
egl_matrix_set_identity (gfloat m[16]);

#endif /* GST_VAAPI_UTILS_EGL_H */