Commit 7066c849 authored by Matthew Waters's avatar Matthew Waters

glcontext: add support for influencing the backing configuration

New API:
- gst_gl_context_get_config()
- gst_gl_context_request_config()

A GL context configuration is a GstStructure that has some well-known
names for common values that can also be extended in platform-specific
ways if necessary.

Wrapped OpenGL contexts may be able to retrieve the GL context
configuration depending on the platform.  If that information is
available, GstGLContext will attempt to create an context that matches
the shared OpenGL context config unless gst_gl_context_request_config()
has been called.

A new environment variable 'GST_GL_CONFIG' will be read to influence the
configuration chosen.  The environment variable will only be used as a
fallback if gst_gl_context_request_config() has not been called.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/809>
parent dfd749c5
......@@ -39,6 +39,7 @@ static gboolean gst_gl_context_cocoa_activate (GstGLContext * context, gboolean
static GstGLAPI gst_gl_context_cocoa_get_gl_api (GstGLContext * context);
static GstGLPlatform gst_gl_context_cocoa_get_gl_platform (GstGLContext * context);
static void gst_gl_context_cocoa_swap_buffers (GstGLContext * context);
static GstStructure * gst_gl_context_cocoa_get_config (GstGLContext * context);
GST_DEBUG_CATEGORY_STATIC (gst_gl_context_cocoa_debug);
#define GST_CAT_DEFAULT gst_gl_context_cocoa_debug
......@@ -66,6 +67,8 @@ gst_gl_context_cocoa_class_init (GstGLContextCocoaClass * klass)
GST_DEBUG_FUNCPTR (gst_gl_context_cocoa_get_gl_api);
context_class->get_gl_platform =
GST_DEBUG_FUNCPTR (gst_gl_context_cocoa_get_gl_platform);
context_class->get_config =
GST_DEBUG_FUNCPTR (gst_gl_context_cocoa_get_config);
}
static void
......@@ -170,6 +173,57 @@ gst_gl_context_cocoa_get_pixel_format (GstGLContextCocoa *context)
return context->priv->pixel_format;
}
static GstStructure *
cgl_pixel_format_to_structure (CGLPixelFormatObj fmt)
{
GstStructure *ret;
int val, alpha;
ret = gst_structure_new (GST_GL_CONFIG_STRUCTURE_NAME,
GST_GL_CONFIG_STRUCTURE_SET_ARGS(PLATFORM, GstGLPlatform, GST_GL_PLATFORM_CGL),
NULL);
if (CGLDescribePixelFormat (fmt, 0, kCGLPFAAlphaSize, &alpha) != kCGLNoError)
goto failure;
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(ALPHA_SIZE, int, alpha), NULL);
if (CGLDescribePixelFormat (fmt, 0, kCGLPFADepthSize, &val) != kCGLNoError)
goto failure;
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(DEPTH_SIZE, int, val), NULL);
if (CGLDescribePixelFormat (fmt, 0, kCGLPFAStencilSize, &val) != kCGLNoError)
goto failure;
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(STENCIL_SIZE, int, val), NULL);
if (CGLDescribePixelFormat (fmt, 0, kCGLPFAColorSize, &val) != kCGLNoError)
goto failure;
val -= alpha;
if (val % 3 == 0) {
/* XXX: assumes that bits are evenly distributed */
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(RED_SIZE, int, val / 3), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(GREEN_SIZE, int, val / 3), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(BLUE_SIZE, int, val / 3), NULL);
} else {
GST_WARNING ("Don't know how to split a color size of %u into R,G,B values",
val);
goto failure;
}
if (CGLDescribePixelFormat (fmt, 0, kCGLPFASamples, &val) != kCGLNoError)
goto failure;
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(SAMPLES, int, val), NULL);
if (CGLDescribePixelFormat (fmt, 0, kCGLPFASampleBuffers, &val) != kCGLNoError)
goto failure;
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(SAMPLE_BUFFERS, int, val), NULL);
return ret;
failure:
gst_structure_free (ret);
return NULL;
}
static gboolean
gst_gl_context_cocoa_create_context (GstGLContext *context, GstGLAPI gl_api,
GstGLContext *other_context, GError **error)
......@@ -338,3 +392,13 @@ gst_gl_context_cocoa_get_current_context (void)
{
return (guintptr) CGLGetCurrentContext ();
}
static GstStructure *
gst_gl_context_cocoa_get_config (GstGLContext * context)
{
GstGLContextCocoa *cocoa = GST_GL_CONTEXT_COCOA (context);
g_return_val_if_fail (cocoa->priv->pixel_format, NULL);
return cgl_pixel_format_to_structure (cocoa->priv->pixel_format);
}
......@@ -50,6 +50,7 @@ static void gst_gl_context_eagl_swap_buffers (GstGLContext * context);
static GstGLAPI gst_gl_context_eagl_get_gl_api (GstGLContext * context);
static GstGLPlatform gst_gl_context_eagl_get_gl_platform (GstGLContext *
context);
GstStructure *gst_gl_context_eagl_get_config (GstGLContext * context);
struct _GstGLContextEaglPrivate
{
......@@ -87,6 +88,7 @@ gst_gl_context_eagl_class_init (GstGLContextEaglClass * klass)
GST_DEBUG_FUNCPTR (gst_gl_context_eagl_get_gl_api);
context_class->get_gl_platform =
GST_DEBUG_FUNCPTR (gst_gl_context_eagl_get_gl_platform);
context_class->get_config = GST_DEBUG_FUNCPTR (gst_gl_context_eagl_get_config);
}
static void
......@@ -108,6 +110,71 @@ gst_gl_context_eagl_new (GstGLDisplay * display)
return context;
}
enum EAGLFormat
{
FORMAT_RGBA8 = 1,
FORMAT_RGB565,
};
static GstStructure *
layer_config_to_structure (GstGLContextEagl *eagl, CAEAGLLayer * layer)
{
GstStructure *ret;
NSDictionary *drawableProps = [layer drawableProperties];
NSString *color_format;
enum EAGLFormat eagl_format = FORMAT_RGBA8;
ret = gst_structure_new (GST_GL_CONFIG_STRUCTURE_NAME,
GST_GL_CONFIG_STRUCTURE_SET_ARGS(PLATFORM, GstGLPlatform, GST_GL_PLATFORM_EAGL),
NULL);
color_format = [drawableProps objectForKey:kEAGLDrawablePropertyColorFormat];
if (!color_format)
color_format = [layer contentsFormat];
if (!color_format) {
GST_WARNING_OBJECT (eagl, "Could not retrieve color format from layer %p", layer);
goto failure;
}
if (color_format == kEAGLColorFormatRGBA8 || color_format == kCAContentsFormatRGBA8Uint) {
eagl_format = FORMAT_RGBA8;
} else if (color_format == kEAGLColorFormatRGB565) {
eagl_format = FORMAT_RGB565;
} else {
GST_WARNING_OBJECT (eagl, "unknown drawable format: %s", [color_format UTF8String]);
goto failure;
}
/* XXX: defaults chosen by _update_layer() */
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(DEPTH_SIZE, int, 16), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(STENCIL_SIZE, int, 0), NULL);
switch (eagl_format) {
case FORMAT_RGBA8:
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(RED_SIZE, int, 8), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(GREEN_SIZE, int, 8), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(BLUE_SIZE, int, 8), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(ALPHA_SIZE, int, 8), NULL);
break;
case FORMAT_RGB565:
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(RED_SIZE, int, 5), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(GREEN_SIZE, int, 6), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(BLUE_SIZE, int, 5), NULL);
gst_structure_set (ret, GST_GL_CONFIG_STRUCTURE_SET_ARGS(ALPHA_SIZE, int, 0), NULL);
break;
default:
GST_WARNING_OBJECT (eagl, "Unhandled format!");
goto failure;
}
return ret;
failure:
gst_structure_free (ret);
return NULL;
}
void
gst_gl_context_eagl_resize (GstGLContextEagl * eagl_context)
{
......@@ -167,6 +234,7 @@ gst_gl_context_eagl_update_layer (GstGLContext * context, gpointer layer)
GstGLContextEagl *context_eagl = GST_GL_CONTEXT_EAGL (context);
GstGLContextEaglPrivate *priv = context_eagl->priv;
GstGLWindow *window = gst_gl_context_get_window (context);
GstStructure *fmt;
if (!layer || !gst_gl_window_get_window_handle (window)) {
GST_INFO_OBJECT (context, "window handle not set yet, not updating layer");
......@@ -215,6 +283,12 @@ gst_gl_context_eagl_update_layer (GstGLContext * context, gpointer layer)
priv->color_renderbuffer = color_renderbuffer;
priv->depth_renderbuffer = depth_renderbuffer;
fmt = layer_config_to_structure (context_eagl, eagl_layer);
if (fmt) {
GST_DEBUG_OBJECT (context_eagl, "chosen config %" GST_PTR_FORMAT, fmt);
gst_structure_free (fmt);
}
out:
if (window)
gst_object_unref (window);
......@@ -384,3 +458,14 @@ gst_gl_context_eagl_get_current_context (void)
{
return (guintptr) [EAGLContext currentContext];
}
GstStructure *
gst_gl_context_eagl_get_config (GstGLContext * context)
{
GstGLContextEagl *eagl = GST_GL_CONTEXT_EAGL (context);
if (!eagl->priv->eagl_layer)
return NULL;
return layer_config_to_structure (eagl, (__bridge CAEAGLLayer *) eagl->priv->eagl_layer);
}
This diff is collapsed.
......@@ -67,6 +67,8 @@ struct _GstGLContextEGL
/* Cached handle */
guintptr window_handle;
GstStructure *requested_config;
};
/**
......@@ -89,6 +91,9 @@ guintptr gst_gl_context_egl_get_current_context (void);
G_GNUC_INTERNAL
gpointer gst_gl_context_egl_get_proc_address (GstGLAPI gl_api, const gchar * name);
G_GNUC_INTERNAL
gboolean gst_gl_context_egl_fill_info (GstGLContext * context);
G_END_DECLS
#endif /* __GST_GL_CONTEXT_EGL_H__ */
......@@ -26,6 +26,7 @@
#include <gst/gl/gstglapi.h>
#include <gst/gl/gstglconfig.h>
#include <gst/gl/gstglcontext.h>
#include <gst/gl/gstglcontextconfig.h>
#include <gst/gl/gstgldebug.h>
#include <gst/gl/gstgldisplay.h>
#include <gst/gl/gstglfeature.h>
......
This diff is collapsed.
......@@ -117,6 +117,34 @@ struct _GstGLContext {
* @destroy_context: destroy the OpenGL context
* @swap_buffers: swap the default framebuffer's front/back buffers
*/
/**
* GstGLContextClass::get_config:
* @context: the #GstGLContext
*
* Retrieve the configuration in use by this context. See also
* gst_gl_context_get_config().
*
* Returns: (transfer full) (nullable): the configuration chosen for this
* #GstGLContext
*
* Since: 1.20
*/
/**
* GstGLContextClass::request_config:
* @context: the #GstGLContext
* @gl_config: (nullable) (transfer full): a configuration structure for
* configuring on @context
*
* Request a configuration for this @context to use.
*
* Unknown fields within @gl_config should be ignored by subclasses.
*
* See also gst_gl_context_request_config().
*
* Returns: Whether @gl_config could be successfull set on @context.
*
* Since: 1.20
*/
struct _GstGLContextClass {
GstObjectClass parent_class;
......@@ -133,9 +161,11 @@ struct _GstGLContextClass {
void (*swap_buffers) (GstGLContext *context);
gboolean (*check_feature) (GstGLContext *context, const gchar *feature);
void (*get_gl_platform_version) (GstGLContext *context, gint *major, gint *minor);
GstStructure *(*get_config) (GstGLContext * context);
gboolean (*request_config) (GstGLContext * context, GstStructure * gl_config);
/*< private >*/
gpointer _reserved[GST_PADDING];
gpointer _reserved[GST_PADDING-2];
};
/* methods */
......@@ -148,6 +178,11 @@ GstGLContext * gst_gl_context_new_wrapped (GstGLDisplay *display,
GstGLPlatform context_type,
GstGLAPI available_apis);
GST_GL_API
GstStructure * gst_gl_context_get_config (GstGLContext * context);
GST_GL_API
gboolean gst_gl_context_request_config (GstGLContext * context, GstStructure * gl_config);
GST_GL_API
gboolean gst_gl_context_activate (GstGLContext *context, gboolean activate);
GST_GL_API
......
......@@ -29,6 +29,18 @@ G_GNUC_INTERNAL extern GstDebugCategory *gst_gl_context_debug;
G_GNUC_INTERNAL
gboolean _gst_gl_context_debug_is_enabled (GstGLContext * context);
#define GST_GL_CONTEXT_WRAPPED_GL_CONFIG_NAME "gst.gl.context.wrapped.config"
#define GST_TYPE_GL_WRAPPED_CONTEXT (gst_gl_wrapped_context_get_type())
G_GNUC_INTERNAL
GType gst_gl_wrapped_context_get_type (void);
#define GST_GL_WRAPPED_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_GL_WRAPPED_CONTEXT, GstGLWrappedContext))
#define GST_GL_WRAPPED_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS((k), GST_TYPE_GL_CONTEXT, GstGLContextClass))
#define GST_IS_GL_WRAPPED_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_GL_WRAPPED_CONTEXT))
#define GST_IS_GL_WRAPPED_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_GL_WRAPPED_CONTEXT))
#define GST_GL_WRAPPED_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_GL_WRAPPED_CONTEXT, GstGLWrappedContextClass))
G_END_DECLS
#endif /* __GST_GL_CONTEXT_PRIVATE_H__ */
This diff is collapsed.
/*
* GStreamer
* Copyright (C) 2020 Matthew Waters <matthew@centricular.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.
*/
#ifndef __GST_GL_CONTEXT_CONFIG_H__
#define __GST_GL_CONTEXT_CONFIG_H__
#include <gst/gst.h>
#include <gst/gl/gstgl_fwd.h>
G_BEGIN_DECLS
/**
* GST_GL_CONFIG_STRUCTURE_NAME:
*
* The canonical name of a #GstStructure that contains a configuration for a
* #GstGLContext.
*
* Since: 1.20
*/
#define GST_GL_CONFIG_STRUCTURE_NAME "gst-gl-context-config"
/**
* GST_GL_CONFIG_ATTRIB_NAME:
*
* Get a reference to the variable name of a particular configuration field.
*
* e.g. for `CONFIG_ID`: `GST_GL_CONFIG_ATTRIB_NAME (CONFIG_ID)`
*
* Since: 1.20
*/
#define GST_GL_CONFIG_ATTRIB_NAME(UPPER_NAME) \
G_PASTE(G_PASTE(GST_GL_CONFIG_ATTRIB_,UPPER_NAME),_NAME)
/**
* GST_GL_CONFIG_ATTRIB_GTYPE:
*
* Get a reference to the #GType of a particular configuration field.
*
* e.g. for `CONFIG_ID`: `GST_GL_CONFIG_ATTRIB_GTYPE (CONFIG_ID)`
*
* Since: 1.20
*/
#define GST_GL_CONFIG_ATTRIB_GTYPE(UPPER_NAME) \
G_PASTE(G_PASTE(GST_GL_CONFIG_ATTRIB_,UPPER_NAME),_GTYPE)
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_CONFIG_ID_NAME;
#define GST_GL_CONFIG_ATTRIB_CONFIG_ID_GTYPE G_TYPE_UINT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_PLATFORM_NAME;
#define GST_GL_CONFIG_ATTRIB_PLATFORM_GTYPE GST_TYPE_GL_PLATFORM
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_CAVEAT_NAME;
#define GST_GL_CONFIG_ATTRIB_CAVEAT_GTYPE GST_TYPE_GL_CONFIG_CAVEAT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_SURFACE_TYPE_NAME;
#define GST_GL_CONFIG_ATTRIB_SURFACE_TYPE_GTYPE GST_TYPE_GL_CONFIG_SURFACE_TYPE
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_CONFORMANT_API_NAME;
#define GST_GL_CONFIG_ATTRIB_CONFORMANT_API_GTYPE GST_TYPE_GL_API
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_RENDERABLE_API_NAME;
#define GST_GL_CONFIG_ATTRIB_RENDERABLE_API_GTYPE GST_TYPE_GL_API
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_RED_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_RED_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_GREEN_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_GREEN_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_BLUE_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_BLUE_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_ALPHA_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_ALPHA_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_LUMINANCE_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_LUMINANCE_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_DEPTH_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_DEPTH_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_STENCIL_SIZE_NAME;
#define GST_GL_CONFIG_ATTRIB_STENCIL_SIZE_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_MAX_PBUFFER_WIDTH_NAME;
#define GST_GL_CONFIG_ATTRIB_MAX_PBUFFER_WIDTH_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_MAX_PBUFFER_HEIGHT_NAME;
#define GST_GL_CONFIG_ATTRIB_MAX_PBUFFER_HEIGHT_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_MAX_PBUFFER_PIXELS_NAME;
#define GST_GL_CONFIG_ATTRIB_MAX_PBUFFER_PIXELS_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_SAMPLE_BUFFERS_NAME;
#define GST_GL_CONFIG_ATTRIB_SAMPLE_BUFFERS_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_SAMPLES_NAME;
#define GST_GL_CONFIG_ATTRIB_SAMPLES_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_NATIVE_RENDERABLE_NAME;
#define GST_GL_CONFIG_ATTRIB_NATIVE_RENDERABLE_GTYPE G_TYPE_BOOLEAN
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_NATIVE_VISUAL_ID_NAME;
#define GST_GL_CONFIG_ATTRIB_NATIVE_VISUAL_ID_GTYPE G_TYPE_UINT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_LEVEL_NAME;
#define GST_GL_CONFIG_ATTRIB_LEVEL_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_MIN_SWAP_INTERVAL_NAME;
#define GST_GL_CONFIG_ATTRIB_MIN_SWAP_INTERVAL_GTYPE G_TYPE_INT
GST_GL_API const char * GST_GL_CONFIG_ATTRIB_MAX_SWAP_INTERVAL_NAME;
#define GST_GL_CONFIG_ATTRIB_MAX_SWAP_INTERVAL_GTYPE G_TYPE_INT
/**
* GST_GL_CONFIG_STRUCTURE_SET_ARGS:
*
* Since: 1.20
*/
#define GST_GL_CONFIG_STRUCTURE_SET_ARGS(def_name,ctype,val) \
GST_GL_CONFIG_ATTRIB_NAME(def_name), \
GST_GL_CONFIG_ATTRIB_GTYPE(def_name), \
(ctype) (val)
/**
* GstGLConfigCaveat:
* @GST_GL_CONFIG_CAVEAT_NONE: none
* @GST_GL_CONFIG_CAVEAT_SLOW: slow
* @GST_GL_CONFIG_CAVEAT_NON_CONFORMANT: non-conformant
*
* Since: 1.20
*/
typedef enum
{
GST_GL_CONFIG_CAVEAT_NONE,
GST_GL_CONFIG_CAVEAT_SLOW,
GST_GL_CONFIG_CAVEAT_NON_CONFORMANT,
} GstGLConfigCaveat;
GST_GL_API
const gchar * gst_gl_config_caveat_to_string (GstGLConfigCaveat caveat);
/**
* GstGLConfigSurfaceType:
* @GST_GL_CONFIG_SURFACE_TYPE_NONE: none
* @GST_GL_CONFIG_SURFACE_TYPE_WINDOW: window
* @GST_GL_CONFIG_SURFACE_TYPE_PBUFFER: pbuffer
* @GST_GL_CONFIG_SURFACE_TYPE_PIXMAP: pixmap
*
* Since: 1.20
*/
typedef enum
{
GST_GL_CONFIG_SURFACE_TYPE_NONE = 0,
GST_GL_CONFIG_SURFACE_TYPE_WINDOW = (1 << 0),
GST_GL_CONFIG_SURFACE_TYPE_PBUFFER = (1 << 1),
GST_GL_CONFIG_SURFACE_TYPE_PIXMAP = (1 << 2),
} GstGLConfigSurfaceType;
GST_GL_API
const gchar * gst_gl_config_surface_type_to_string (GstGLConfigSurfaceType surface_type);
G_END_DECLS
#endif /* __GST_GL_CONTEXT_CONFIG_H__ */
......@@ -14,6 +14,7 @@ gl_sources = [
'gstglbuffer.c',
'gstglbufferpool.c',
'gstglcontext.c',
'gstglcontextconfig.c',
'gstgldebug.c',
'gstgldisplay.c',
'gstglfeature.c',
......@@ -51,6 +52,7 @@ gir_gl_headers = [
'gstglbufferpool.h',
'gstglcolorconvert.h',
'gstglcontext.h',
'gstglcontextconfig.h',
'gstgldebug.h',
'gstgldisplay.h',
'gstglfeature.h',
......
......@@ -63,6 +63,7 @@ static GstGLPlatform gst_gl_context_wgl_get_gl_platform (GstGLContext *
context);
static gboolean gst_gl_context_wgl_check_feature (GstGLContext * context,
const gchar * feature);
GstStructure *gst_gl_context_wgl_get_config (GstGLContext * context);
static void
gst_gl_context_wgl_class_init (GstGLContextWGLClass * klass)
......@@ -88,6 +89,7 @@ gst_gl_context_wgl_class_init (GstGLContextWGLClass * klass)
GST_DEBUG_FUNCPTR (gst_gl_context_wgl_get_gl_platform);
context_class->check_feature =
GST_DEBUG_FUNCPTR (gst_gl_context_wgl_check_feature);
context_class->get_config = GST_DEBUG_FUNCPTR (gst_gl_context_wgl_get_config);
}
static void
......@@ -302,6 +304,47 @@ gst_gl_context_wgl_destroy_context (GstGLContext * context)
context_wgl->wgl_context = NULL;
}
static GstGLConfigSurfaceType
pfd_flags_to_surface_type (int flags)
{
GstGLConfigSurfaceType ret = GST_GL_CONFIG_SURFACE_TYPE_NONE;
if (flags & PFD_DRAW_TO_WINDOW)
ret |= GST_GL_CONFIG_SURFACE_TYPE_WINDOW;
if (flags & PFD_DRAW_TO_BITMAP)
ret |= GST_GL_CONFIG_SURFACE_TYPE_PIXMAP;
return ret;
}
static GstStructure *
pixel_format_to_structure (HDC hdc, int pixfmt)
{
GstStructure *ret;
PIXELFORMATDESCRIPTOR pfd;
if (pixfmt == 0)
return NULL;
if (DescribePixelFormat (hdc, pixfmt, sizeof (pfd), &pfd) == 0)
return NULL;
ret = gst_structure_new (GST_GL_CONFIG_STRUCTURE_NAME,
GST_GL_CONFIG_STRUCTURE_SET_ARGS (PLATFORM, GstGLPlatform,
GST_GL_PLATFORM_WGL), GST_GL_CONFIG_STRUCTURE_SET_ARGS (RED_SIZE, int,
pfd.cRedBits), GST_GL_CONFIG_STRUCTURE_SET_ARGS (BLUE_SIZE, int,
pfd.cBlueBits), GST_GL_CONFIG_STRUCTURE_SET_ARGS (GREEN_SIZE, int,
pfd.cGreenBits), GST_GL_CONFIG_STRUCTURE_SET_ARGS (ALPHA_SIZE, int,
pfd.cAlphaBits), GST_GL_CONFIG_STRUCTURE_SET_ARGS (DEPTH_SIZE, int,
pfd.cDepthBits), GST_GL_CONFIG_STRUCTURE_SET_ARGS (STENCIL_SIZE, int,
pfd.cStencilBits), GST_GL_CONFIG_STRUCTURE_SET_ARGS (NATIVE_VISUAL_ID,
guint, pixfmt), GST_GL_CONFIG_STRUCTURE_SET_ARGS (SURFACE_TYPE,
GstGLConfigSurfaceType, pfd_flags_to_surface_type (pfd.dwFlags)),
NULL);
return ret;
}
static gboolean
gst_gl_context_wgl_choose_format (GstGLContext * context, GError ** error)
{
......@@ -310,6 +353,7 @@ gst_gl_context_wgl_choose_format (GstGLContext * context, GError ** error)
gint pixelformat = 0;
gboolean res = FALSE;
HDC device;
GstStructure *config;
window = gst_gl_context_get_window (context);
gst_gl_window_win32_create_window (GST_GL_WINDOW_WIN32 (window), error);
......@@ -353,6 +397,10 @@ gst_gl_context_wgl_choose_format (GstGLContext * context, GError ** error)
return FALSE;
}
config = pixel_format_to_structure (device, pixelformat);
GST_INFO_OBJECT (context, "chosen config %" GST_PTR_FORMAT, config);
gst_structure_free (config);
res = SetPixelFormat (device, pixelformat, &pfd);
return res;
......@@ -437,3 +485,18 @@ gst_gl_context_wgl_get_current_context (void)
{
return (guintptr) wglGetCurrentContext ();
}
GstStructure *
gst_gl_context_wgl_get_config (GstGLContext * context)
{
GstGLWindow *window;
int pixfmt;
HDC hdc;
window = gst_gl_context_get_window (context);
hdc = (HDC) gst_gl_window_get_display (window);
pixfmt = GetPixelFormat (hdc);
return pixel_format_to_structure (hdc, pixfmt);
}
This diff is collapsed.
......@@ -68,6 +68,9 @@ guintptr gst_gl_context_glx_get_current_context (void);
G_GNUC_INTERNAL
gpointer gst_gl_context_glx_get_proc_address (GstGLAPI gl_api, const gchar * name);
G_GNUC_INTERNAL
gboolean gst_gl_context_glx_fill_info (GstGLContext * context);
G_END_DECLS
#endif /* __GST_GL_CONTEXT_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment