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 /**
22 * SECTION:gstglapi
23 * @title: GstGLAPI
24 * @short_description: OpenGL API specific functionality
25 * @see_also: #GstGLDisplay, #GstGLContext
26 *
27 * Provides some helper API for dealing with OpenGL API's and platforms
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include "gstglapi.h"
35
36 /**
37 * gst_gl_api_to_string:
38 * @api: a #GstGLAPI to stringify
39 *
40 * Returns: A space seperated string of the OpenGL api's enabled in @api
41 */
42 gchar *
gst_gl_api_to_string(GstGLAPI api)43 gst_gl_api_to_string (GstGLAPI api)
44 {
45 GString *str = NULL;
46 gchar *ret;
47
48 if (api == GST_GL_API_NONE) {
49 str = g_string_new ("none");
50 goto out;
51 } else if (api == GST_GL_API_ANY) {
52 str = g_string_new ("any");
53 goto out;
54 }
55
56 if (api & GST_GL_API_OPENGL) {
57 str = g_string_new (GST_GL_API_OPENGL_NAME);
58 }
59 if (api & GST_GL_API_OPENGL3) {
60 if (str) {
61 g_string_append (str, " " GST_GL_API_OPENGL3_NAME);
62 } else {
63 str = g_string_new (GST_GL_API_OPENGL3_NAME);
64 }
65 }
66 if (api & GST_GL_API_GLES1) {
67 if (str) {
68 g_string_append (str, " " GST_GL_API_GLES1_NAME);
69 } else {
70 str = g_string_new (GST_GL_API_GLES1_NAME);
71 }
72 }
73 if (api & GST_GL_API_GLES2) {
74 if (str) {
75 g_string_append (str, " " GST_GL_API_GLES2_NAME);
76 } else {
77 str = g_string_new (GST_GL_API_GLES2_NAME);
78 }
79 }
80
81 out:
82 if (!str)
83 str = g_string_new ("unknown");
84
85 ret = g_string_free (str, FALSE);
86 return ret;
87 }
88
89 /**
90 * gst_gl_api_from_string:
91 * @api_s: a space seperated string of OpenGL apis
92 *
93 * Returns: The #GstGLAPI represented by @api_s
94 */
95 GstGLAPI
gst_gl_api_from_string(const gchar * apis_s)96 gst_gl_api_from_string (const gchar * apis_s)
97 {
98 GstGLAPI ret = GST_GL_API_NONE;
99 gchar *apis = (gchar *) apis_s;
100
101 if (!apis || apis[0] == '\0') {
102 ret = GST_GL_API_ANY;
103 } else {
104 while (apis) {
105 if (apis[0] == '\0') {
106 break;
107 } else if (apis[0] == ' ' || apis[0] == ',') {
108 apis = &apis[1];
109 } else if (g_strstr_len (apis, 7, GST_GL_API_OPENGL3_NAME)) {
110 ret |= GST_GL_API_OPENGL3;
111 apis = &apis[7];
112 } else if (g_strstr_len (apis, 6, GST_GL_API_OPENGL_NAME)) {
113 ret |= GST_GL_API_OPENGL;
114 apis = &apis[6];
115 } else if (g_strstr_len (apis, 5, GST_GL_API_GLES1_NAME)) {
116 ret |= GST_GL_API_GLES1;
117 apis = &apis[5];
118 } else if (g_strstr_len (apis, 5, GST_GL_API_GLES2_NAME)) {
119 ret |= GST_GL_API_GLES2;
120 apis = &apis[5];
121 } else {
122 GST_ERROR ("Error parsing \'%s\'", apis);
123 break;
124 }
125 }
126 }
127
128 return ret;
129 }
130
131 /**
132 * gst_gl_platform_to_string:
133 * @platform: a #GstGLPlatform to stringify
134 *
135 * Returns: A space seperated string of the OpenGL platforms enabled in @platform
136 */
137 gchar *
gst_gl_platform_to_string(GstGLPlatform platform)138 gst_gl_platform_to_string (GstGLPlatform platform)
139 {
140 GString *str = NULL;
141 gchar *ret;
142
143 if (platform == GST_GL_PLATFORM_NONE) {
144 str = g_string_new ("none");
145 goto out;
146 } else if (platform == GST_GL_PLATFORM_ANY) {
147 str = g_string_new ("any");
148 goto out;
149 }
150
151 str = g_string_new ("");
152
153 if (platform & GST_GL_PLATFORM_GLX) {
154 str = g_string_append (str, "glx ");
155 }
156 if (platform & GST_GL_PLATFORM_EGL) {
157 str = g_string_append (str, "egl ");
158 }
159 if (platform & GST_GL_PLATFORM_WGL) {
160 str = g_string_append (str, "wgl ");
161 }
162 if (platform & GST_GL_PLATFORM_CGL) {
163 str = g_string_append (str, "cgl ");
164 }
165
166 out:
167 if (!str)
168 str = g_string_new ("unknown");
169
170 ret = g_string_free (str, FALSE);
171 return ret;
172 }
173
174 /**
175 * gst_gl_platform_from_string:
176 * @platform_s: a space seperated string of OpenGL platformss
177 *
178 * Returns: The #GstGLPlatform represented by @platform_s
179 */
180 GstGLPlatform
gst_gl_platform_from_string(const gchar * platform_s)181 gst_gl_platform_from_string (const gchar * platform_s)
182 {
183 GstGLPlatform ret = GST_GL_PLATFORM_NONE;
184 gchar *platform = (gchar *) platform_s;
185
186 if (!platform || platform[0] == '\0') {
187 ret = GST_GL_PLATFORM_ANY;
188 } else {
189 while (platform) {
190 if (platform[0] == '\0') {
191 break;
192 } else if (platform[0] == ' ' || platform[0] == ',') {
193 platform = &platform[1];
194 } else if (g_strstr_len (platform, 3, "glx")) {
195 ret |= GST_GL_PLATFORM_GLX;
196 platform = &platform[3];
197 } else if (g_strstr_len (platform, 3, "egl")) {
198 ret |= GST_GL_PLATFORM_EGL;
199 platform = &platform[3];
200 } else if (g_strstr_len (platform, 3, "wgl")) {
201 ret |= GST_GL_PLATFORM_WGL;
202 platform = &platform[3];
203 } else if (g_strstr_len (platform, 3, "cgl")) {
204 ret |= GST_GL_PLATFORM_CGL;
205 platform = &platform[3];
206 } else {
207 GST_ERROR ("Error parsing \'%s\'", platform);
208 break;
209 }
210 }
211 }
212
213 return ret;
214 }
215