Blame gst-libs/gst/gl/gstglapi.c

Packit 971217
/*
Packit 971217
 * GStreamer
Packit 971217
 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
/**
Packit 971217
 * SECTION:gstglapi
Packit 971217
 * @title: GstGLAPI
Packit 971217
 * @short_description: OpenGL API specific functionality
Packit 971217
 * @see_also: #GstGLDisplay, #GstGLContext
Packit 971217
 *
Packit 971217
 * Provides some helper API for dealing with OpenGL API's and platforms
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include "gstglapi.h"
Packit 971217
Packit 971217
/**
Packit 971217
 * gst_gl_api_to_string:
Packit 971217
 * @api: a #GstGLAPI to stringify
Packit 971217
 *
Packit 971217
 * Returns: A space seperated string of the OpenGL api's enabled in @api
Packit 971217
 */
Packit 971217
gchar *
Packit 971217
gst_gl_api_to_string (GstGLAPI api)
Packit 971217
{
Packit 971217
  GString *str = NULL;
Packit 971217
  gchar *ret;
Packit 971217
Packit 971217
  if (api == GST_GL_API_NONE) {
Packit 971217
    str = g_string_new ("none");
Packit 971217
    goto out;
Packit 971217
  } else if (api == GST_GL_API_ANY) {
Packit 971217
    str = g_string_new ("any");
Packit 971217
    goto out;
Packit 971217
  }
Packit 971217
Packit 971217
  if (api & GST_GL_API_OPENGL) {
Packit 971217
    str = g_string_new (GST_GL_API_OPENGL_NAME);
Packit 971217
  }
Packit 971217
  if (api & GST_GL_API_OPENGL3) {
Packit 971217
    if (str) {
Packit 971217
      g_string_append (str, " " GST_GL_API_OPENGL3_NAME);
Packit 971217
    } else {
Packit 971217
      str = g_string_new (GST_GL_API_OPENGL3_NAME);
Packit 971217
    }
Packit 971217
  }
Packit 971217
  if (api & GST_GL_API_GLES1) {
Packit 971217
    if (str) {
Packit 971217
      g_string_append (str, " " GST_GL_API_GLES1_NAME);
Packit 971217
    } else {
Packit 971217
      str = g_string_new (GST_GL_API_GLES1_NAME);
Packit 971217
    }
Packit 971217
  }
Packit 971217
  if (api & GST_GL_API_GLES2) {
Packit 971217
    if (str) {
Packit 971217
      g_string_append (str, " " GST_GL_API_GLES2_NAME);
Packit 971217
    } else {
Packit 971217
      str = g_string_new (GST_GL_API_GLES2_NAME);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
out:
Packit 971217
  if (!str)
Packit 971217
    str = g_string_new ("unknown");
Packit 971217
Packit 971217
  ret = g_string_free (str, FALSE);
Packit 971217
  return ret;
Packit 971217
}
Packit 971217
Packit 971217
/**
Packit 971217
 * gst_gl_api_from_string:
Packit 971217
 * @api_s: a space seperated string of OpenGL apis
Packit 971217
 *
Packit 971217
 * Returns: The #GstGLAPI represented by @api_s
Packit 971217
 */
Packit 971217
GstGLAPI
Packit 971217
gst_gl_api_from_string (const gchar * apis_s)
Packit 971217
{
Packit 971217
  GstGLAPI ret = GST_GL_API_NONE;
Packit 971217
  gchar *apis = (gchar *) apis_s;
Packit 971217
Packit 971217
  if (!apis || apis[0] == '\0') {
Packit 971217
    ret = GST_GL_API_ANY;
Packit 971217
  } else {
Packit 971217
    while (apis) {
Packit 971217
      if (apis[0] == '\0') {
Packit 971217
        break;
Packit 971217
      } else if (apis[0] == ' ' || apis[0] == ',') {
Packit 971217
        apis = &apis[1];
Packit 971217
      } else if (g_strstr_len (apis, 7, GST_GL_API_OPENGL3_NAME)) {
Packit 971217
        ret |= GST_GL_API_OPENGL3;
Packit 971217
        apis = &apis[7];
Packit 971217
      } else if (g_strstr_len (apis, 6, GST_GL_API_OPENGL_NAME)) {
Packit 971217
        ret |= GST_GL_API_OPENGL;
Packit 971217
        apis = &apis[6];
Packit 971217
      } else if (g_strstr_len (apis, 5, GST_GL_API_GLES1_NAME)) {
Packit 971217
        ret |= GST_GL_API_GLES1;
Packit 971217
        apis = &apis[5];
Packit 971217
      } else if (g_strstr_len (apis, 5, GST_GL_API_GLES2_NAME)) {
Packit 971217
        ret |= GST_GL_API_GLES2;
Packit 971217
        apis = &apis[5];
Packit 971217
      } else {
Packit 971217
        GST_ERROR ("Error parsing \'%s\'", apis);
Packit 971217
        break;
Packit 971217
      }
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  return ret;
Packit 971217
}
Packit 971217
Packit 971217
/**
Packit 971217
 * gst_gl_platform_to_string:
Packit 971217
 * @platform: a #GstGLPlatform to stringify
Packit 971217
 *
Packit 971217
 * Returns: A space seperated string of the OpenGL platforms enabled in @platform
Packit 971217
 */
Packit 971217
gchar *
Packit 971217
gst_gl_platform_to_string (GstGLPlatform platform)
Packit 971217
{
Packit 971217
  GString *str = NULL;
Packit 971217
  gchar *ret;
Packit 971217
Packit 971217
  if (platform == GST_GL_PLATFORM_NONE) {
Packit 971217
    str = g_string_new ("none");
Packit 971217
    goto out;
Packit 971217
  } else if (platform == GST_GL_PLATFORM_ANY) {
Packit 971217
    str = g_string_new ("any");
Packit 971217
    goto out;
Packit 971217
  }
Packit 971217
Packit 971217
  str = g_string_new ("");
Packit 971217
Packit 971217
  if (platform & GST_GL_PLATFORM_GLX) {
Packit 971217
    str = g_string_append (str, "glx ");
Packit 971217
  }
Packit 971217
  if (platform & GST_GL_PLATFORM_EGL) {
Packit 971217
    str = g_string_append (str, "egl ");
Packit 971217
  }
Packit 971217
  if (platform & GST_GL_PLATFORM_WGL) {
Packit 971217
    str = g_string_append (str, "wgl ");
Packit 971217
  }
Packit 971217
  if (platform & GST_GL_PLATFORM_CGL) {
Packit 971217
    str = g_string_append (str, "cgl ");
Packit 971217
  }
Packit 971217
Packit 971217
out:
Packit 971217
  if (!str)
Packit 971217
    str = g_string_new ("unknown");
Packit 971217
Packit 971217
  ret = g_string_free (str, FALSE);
Packit 971217
  return ret;
Packit 971217
}
Packit 971217
Packit 971217
/**
Packit 971217
 * gst_gl_platform_from_string:
Packit 971217
 * @platform_s: a space seperated string of OpenGL platformss
Packit 971217
 *
Packit 971217
 * Returns: The #GstGLPlatform represented by @platform_s
Packit 971217
 */
Packit 971217
GstGLPlatform
Packit 971217
gst_gl_platform_from_string (const gchar * platform_s)
Packit 971217
{
Packit 971217
  GstGLPlatform ret = GST_GL_PLATFORM_NONE;
Packit 971217
  gchar *platform = (gchar *) platform_s;
Packit 971217
Packit 971217
  if (!platform || platform[0] == '\0') {
Packit 971217
    ret = GST_GL_PLATFORM_ANY;
Packit 971217
  } else {
Packit 971217
    while (platform) {
Packit 971217
      if (platform[0] == '\0') {
Packit 971217
        break;
Packit 971217
      } else if (platform[0] == ' ' || platform[0] == ',') {
Packit 971217
        platform = &platform[1];
Packit 971217
      } else if (g_strstr_len (platform, 3, "glx")) {
Packit 971217
        ret |= GST_GL_PLATFORM_GLX;
Packit 971217
        platform = &platform[3];
Packit 971217
      } else if (g_strstr_len (platform, 3, "egl")) {
Packit 971217
        ret |= GST_GL_PLATFORM_EGL;
Packit 971217
        platform = &platform[3];
Packit 971217
      } else if (g_strstr_len (platform, 3, "wgl")) {
Packit 971217
        ret |= GST_GL_PLATFORM_WGL;
Packit 971217
        platform = &platform[3];
Packit 971217
      } else if (g_strstr_len (platform, 3, "cgl")) {
Packit 971217
        ret |= GST_GL_PLATFORM_CGL;
Packit 971217
        platform = &platform[3];
Packit 971217
      } else {
Packit 971217
        GST_ERROR ("Error parsing \'%s\'", platform);
Packit 971217
        break;
Packit 971217
      }
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  return ret;
Packit 971217
}