• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * GstGLFuncs:
38  *
39  * Structure containing function pointers to OpenGL functions.
40  *
41  * Each field is named exactly the same as the OpenGL function without the
42  * `gl` prefix.
43  */
44 
45 /**
46  * gst_gl_api_to_string:
47  * @api: a #GstGLAPI to stringify
48  *
49  * Returns: A space separated string of the OpenGL api's enabled in @api
50  */
51 gchar *
gst_gl_api_to_string(GstGLAPI api)52 gst_gl_api_to_string (GstGLAPI api)
53 {
54   GString *str = NULL;
55   gchar *ret;
56 
57   if (api == GST_GL_API_NONE) {
58     str = g_string_new ("none");
59     goto out;
60   } else if (api == GST_GL_API_ANY) {
61     str = g_string_new ("any");
62     goto out;
63   }
64 
65   if (api & GST_GL_API_OPENGL) {
66     str = g_string_new (GST_GL_API_OPENGL_NAME);
67   }
68   if (api & GST_GL_API_OPENGL3) {
69     if (str) {
70       g_string_append (str, " " GST_GL_API_OPENGL3_NAME);
71     } else {
72       str = g_string_new (GST_GL_API_OPENGL3_NAME);
73     }
74   }
75   if (api & GST_GL_API_GLES1) {
76     if (str) {
77       g_string_append (str, " " GST_GL_API_GLES1_NAME);
78     } else {
79       str = g_string_new (GST_GL_API_GLES1_NAME);
80     }
81   }
82   if (api & GST_GL_API_GLES2) {
83     if (str) {
84       g_string_append (str, " " GST_GL_API_GLES2_NAME);
85     } else {
86       str = g_string_new (GST_GL_API_GLES2_NAME);
87     }
88   }
89 
90 out:
91   if (!str)
92     str = g_string_new ("unknown");
93 
94   ret = g_string_free (str, FALSE);
95   return ret;
96 }
97 
98 /**
99  * gst_gl_api_from_string:
100  * @api_s: a space separated string of OpenGL apis
101  *
102  * Returns: The #GstGLAPI represented by @api_s
103  */
104 GstGLAPI
gst_gl_api_from_string(const gchar * apis_s)105 gst_gl_api_from_string (const gchar * apis_s)
106 {
107   GstGLAPI ret = GST_GL_API_NONE;
108   gchar *apis = (gchar *) apis_s;
109 
110   if (!apis || apis[0] == '\0' || g_strcmp0 (apis_s, "any") == 0) {
111     ret = GST_GL_API_ANY;
112   } else if (g_strcmp0 (apis_s, "none") == 0) {
113     ret = GST_GL_API_NONE;
114   } else {
115     while (apis) {
116       if (apis[0] == '\0') {
117         break;
118       } else if (apis[0] == ' ' || apis[0] == ',') {
119         apis = &apis[1];
120       } else if (g_strstr_len (apis, 7, GST_GL_API_OPENGL3_NAME)) {
121         ret |= GST_GL_API_OPENGL3;
122         apis = &apis[7];
123       } else if (g_strstr_len (apis, 6, GST_GL_API_OPENGL_NAME)) {
124         ret |= GST_GL_API_OPENGL;
125         apis = &apis[6];
126       } else if (g_strstr_len (apis, 5, GST_GL_API_GLES1_NAME)) {
127         ret |= GST_GL_API_GLES1;
128         apis = &apis[5];
129       } else if (g_strstr_len (apis, 5, GST_GL_API_GLES2_NAME)) {
130         ret |= GST_GL_API_GLES2;
131         apis = &apis[5];
132       } else {
133         GST_ERROR ("Error parsing \'%s\'", apis);
134         break;
135       }
136     }
137   }
138 
139   return ret;
140 }
141 
142 /**
143  * gst_gl_platform_to_string:
144  * @platform: a #GstGLPlatform to stringify
145  *
146  * Returns: A space separated string of the OpenGL platforms enabled in @platform
147  */
148 gchar *
gst_gl_platform_to_string(GstGLPlatform platform)149 gst_gl_platform_to_string (GstGLPlatform platform)
150 {
151   GString *str = NULL;
152   gboolean first_set = FALSE;
153   gchar *ret;
154 
155   if (platform == GST_GL_PLATFORM_NONE) {
156     str = g_string_new ("none");
157     goto out;
158   } else if (platform == GST_GL_PLATFORM_ANY) {
159     str = g_string_new ("any");
160     goto out;
161   }
162 
163   str = g_string_new ("");
164 
165 #define ADD_PLATFORM(flag,str__) \
166   if (platform & flag) { \
167     if (first_set) \
168       g_string_append_c (str, ' '); \
169     str = g_string_append (str, str__); \
170     first_set = TRUE; \
171   }
172   ADD_PLATFORM (GST_GL_PLATFORM_GLX, "glx");
173   ADD_PLATFORM (GST_GL_PLATFORM_EGL, "egl");
174   ADD_PLATFORM (GST_GL_PLATFORM_WGL, "wgl");
175   ADD_PLATFORM (GST_GL_PLATFORM_CGL, "cgl");
176   ADD_PLATFORM (GST_GL_PLATFORM_EAGL, "eagl");
177 
178 #undef ADD_PLATFORM
179 
180 out:
181   if (g_strcmp0 (str->str, "") == 0)
182     str = g_string_append (str, "unknown");
183 
184   ret = g_string_free (str, FALSE);
185   return ret;
186 }
187 
188 /**
189  * gst_gl_platform_from_string:
190  * @platform_s: a space separated string of OpenGL platformss
191  *
192  * Returns: The #GstGLPlatform represented by @platform_s
193  */
194 GstGLPlatform
gst_gl_platform_from_string(const gchar * platform_s)195 gst_gl_platform_from_string (const gchar * platform_s)
196 {
197   GstGLPlatform ret = GST_GL_PLATFORM_NONE;
198   gchar *platform = (gchar *) platform_s;
199 
200   if (!platform || platform[0] == '\0' || g_strcmp0 (platform_s, "any") == 0) {
201     ret = GST_GL_PLATFORM_ANY;
202   } else if (g_strcmp0 (platform_s, "none") == 0) {
203     ret = GST_GL_PLATFORM_NONE;
204   } else {
205     while (platform) {
206       if (platform[0] == '\0') {
207         break;
208       } else if (platform[0] == ' ' || platform[0] == ',') {
209         platform = &platform[1];
210       } else if (g_strstr_len (platform, 3, "glx")) {
211         ret |= GST_GL_PLATFORM_GLX;
212         platform = &platform[3];
213       } else if (g_strstr_len (platform, 3, "egl")) {
214         ret |= GST_GL_PLATFORM_EGL;
215         platform = &platform[3];
216       } else if (g_strstr_len (platform, 3, "wgl")) {
217         ret |= GST_GL_PLATFORM_WGL;
218         platform = &platform[3];
219       } else if (g_strstr_len (platform, 3, "cgl")) {
220         ret |= GST_GL_PLATFORM_CGL;
221         platform = &platform[3];
222       } else if (g_strstr_len (platform, 4, "eagl")) {
223         ret |= GST_GL_PLATFORM_EAGL;
224         platform = &platform[4];
225       } else {
226         GST_ERROR ("Error parsing \'%s\'", platform);
227         break;
228       }
229     }
230   }
231 
232   return ret;
233 }
234