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
|
/*
* 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.
*/
/**
* SECTION:gstglapi
* @title: GstGLAPI
* @short_description: OpenGL API specific functionality
* @see_also: #GstGLDisplay, #GstGLContext
*
* Provides some helper API for dealing with OpenGL API's and platforms
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstglapi.h"
/**
* GstGLFuncs:
*
* Structure containing function pointers to OpenGL functions.
*
* Each field is named exactly the same as the OpenGL function without the
* `gl` prefix.
*/
/**
* gst_gl_api_to_string:
* @api: a #GstGLAPI to stringify
*
* Returns: A space seperated string of the OpenGL api's enabled in @api
*/
gchar *
gst_gl_api_to_string (GstGLAPI api)
{
GString *str = NULL;
gchar *ret;
if (api == GST_GL_API_NONE) {
str = g_string_new ("none");
goto out;
} else if (api == GST_GL_API_ANY) {
str = g_string_new ("any");
goto out;
}
if (api & GST_GL_API_OPENGL) {
str = g_string_new (GST_GL_API_OPENGL_NAME);
}
if (api & GST_GL_API_OPENGL3) {
if (str) {
g_string_append (str, " " GST_GL_API_OPENGL3_NAME);
} else {
str = g_string_new (GST_GL_API_OPENGL3_NAME);
}
}
if (api & GST_GL_API_GLES1) {
if (str) {
g_string_append (str, " " GST_GL_API_GLES1_NAME);
} else {
str = g_string_new (GST_GL_API_GLES1_NAME);
}
}
if (api & GST_GL_API_GLES2) {
if (str) {
g_string_append (str, " " GST_GL_API_GLES2_NAME);
} else {
str = g_string_new (GST_GL_API_GLES2_NAME);
}
}
out:
if (!str)
str = g_string_new ("unknown");
ret = g_string_free (str, FALSE);
return ret;
}
/**
* gst_gl_api_from_string:
* @api_s: a space seperated string of OpenGL apis
*
* Returns: The #GstGLAPI represented by @api_s
*/
GstGLAPI
gst_gl_api_from_string (const gchar * apis_s)
{
GstGLAPI ret = GST_GL_API_NONE;
gchar *apis = (gchar *) apis_s;
if (!apis || apis[0] == '\0') {
ret = GST_GL_API_ANY;
} else {
while (apis) {
if (apis[0] == '\0') {
break;
} else if (apis[0] == ' ' || apis[0] == ',') {
apis = &apis[1];
} else if (g_strstr_len (apis, 7, GST_GL_API_OPENGL3_NAME)) {
ret |= GST_GL_API_OPENGL3;
apis = &apis[7];
} else if (g_strstr_len (apis, 6, GST_GL_API_OPENGL_NAME)) {
ret |= GST_GL_API_OPENGL;
apis = &apis[6];
} else if (g_strstr_len (apis, 5, GST_GL_API_GLES1_NAME)) {
ret |= GST_GL_API_GLES1;
apis = &apis[5];
} else if (g_strstr_len (apis, 5, GST_GL_API_GLES2_NAME)) {
ret |= GST_GL_API_GLES2;
apis = &apis[5];
} else {
GST_ERROR ("Error parsing \'%s\'", apis);
break;
}
}
}
return ret;
}
/**
* gst_gl_platform_to_string:
* @platform: a #GstGLPlatform to stringify
*
* Returns: A space seperated string of the OpenGL platforms enabled in @platform
*/
gchar *
gst_gl_platform_to_string (GstGLPlatform platform)
{
GString *str = NULL;
gchar *ret;
if (platform == GST_GL_PLATFORM_NONE) {
str = g_string_new ("none");
goto out;
} else if (platform == GST_GL_PLATFORM_ANY) {
str = g_string_new ("any");
goto out;
}
str = g_string_new ("");
if (platform & GST_GL_PLATFORM_GLX) {
str = g_string_append (str, "glx ");
}
if (platform & GST_GL_PLATFORM_EGL) {
str = g_string_append (str, "egl ");
}
if (platform & GST_GL_PLATFORM_WGL) {
str = g_string_append (str, "wgl ");
}
if (platform & GST_GL_PLATFORM_CGL) {
str = g_string_append (str, "cgl ");
}
out:
if (!str)
str = g_string_new ("unknown");
ret = g_string_free (str, FALSE);
return ret;
}
/**
* gst_gl_platform_from_string:
* @platform_s: a space seperated string of OpenGL platformss
*
* Returns: The #GstGLPlatform represented by @platform_s
*/
GstGLPlatform
gst_gl_platform_from_string (const gchar * platform_s)
{
GstGLPlatform ret = GST_GL_PLATFORM_NONE;
gchar *platform = (gchar *) platform_s;
if (!platform || platform[0] == '\0') {
ret = GST_GL_PLATFORM_ANY;
} else {
while (platform) {
if (platform[0] == '\0') {
break;
} else if (platform[0] == ' ' || platform[0] == ',') {
platform = &platform[1];
} else if (g_strstr_len (platform, 3, "glx")) {
ret |= GST_GL_PLATFORM_GLX;
platform = &platform[3];
} else if (g_strstr_len (platform, 3, "egl")) {
ret |= GST_GL_PLATFORM_EGL;
platform = &platform[3];
} else if (g_strstr_len (platform, 3, "wgl")) {
ret |= GST_GL_PLATFORM_WGL;
platform = &platform[3];
} else if (g_strstr_len (platform, 3, "cgl")) {
ret |= GST_GL_PLATFORM_CGL;
platform = &platform[3];
} else {
GST_ERROR ("Error parsing \'%s\'", platform);
break;
}
}
}
return ret;
}
|