mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
texture: add generic helper to create textures.
Add new generic helper functions gst_vaapi_texture_new_wrapped() and gst_vaapi_texture_new() to create a texture without having the caller to uselessly check for the display type himself. i.e. internally, there is now a GstVaapiDisplayClass hook to create textures, and the actual backend implementation fills it in. This is a simplification in view to supporting EGL.
This commit is contained in:
parent
2101685b7d
commit
93418ed5ee
6 changed files with 107 additions and 14 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include "gstvaapidisplay_x11_priv.h"
|
#include "gstvaapidisplay_x11_priv.h"
|
||||||
#include "gstvaapidisplay_glx.h"
|
#include "gstvaapidisplay_glx.h"
|
||||||
#include "gstvaapidisplay_glx_priv.h"
|
#include "gstvaapidisplay_glx_priv.h"
|
||||||
|
#include "gstvaapitexture_glx.h"
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
#include "gstvaapidebug.h"
|
#include "gstvaapidebug.h"
|
||||||
|
@ -54,6 +55,15 @@ gst_vaapi_display_glx_get_display_info (GstVaapiDisplay * display,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstVaapiTexture *
|
||||||
|
gst_vaapi_display_glx_create_texture (GstVaapiDisplay * display, GstVaapiID id,
|
||||||
|
guint target, guint format, guint width, guint height)
|
||||||
|
{
|
||||||
|
return id != GST_VAAPI_ID_INVALID ?
|
||||||
|
gst_vaapi_texture_glx_new_wrapped (display, id, target, format) :
|
||||||
|
gst_vaapi_texture_glx_new (display, target, format, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_display_glx_class_init (GstVaapiDisplayGLXClass * klass)
|
gst_vaapi_display_glx_class_init (GstVaapiDisplayGLXClass * klass)
|
||||||
{
|
{
|
||||||
|
@ -67,6 +77,7 @@ gst_vaapi_display_glx_class_init (GstVaapiDisplayGLXClass * klass)
|
||||||
klass->parent_get_display = dpy_class->get_display;
|
klass->parent_get_display = dpy_class->get_display;
|
||||||
dpy_class->display_types = g_display_types;
|
dpy_class->display_types = g_display_types;
|
||||||
dpy_class->get_display = gst_vaapi_display_glx_get_display_info;
|
dpy_class->get_display = gst_vaapi_display_glx_get_display_info;
|
||||||
|
dpy_class->create_texture = gst_vaapi_display_glx_create_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const GstVaapiDisplayClass *
|
static inline const GstVaapiDisplayClass *
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <gst/vaapi/gstvaapidisplay.h>
|
#include <gst/vaapi/gstvaapidisplay.h>
|
||||||
#include <gst/vaapi/gstvaapidisplaycache.h>
|
#include <gst/vaapi/gstvaapidisplaycache.h>
|
||||||
|
#include <gst/vaapi/gstvaapitexture.h>
|
||||||
#include "gstvaapiminiobject.h"
|
#include "gstvaapiminiobject.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
@ -66,6 +67,9 @@ typedef void (*GstVaapiDisplayGetSizeFunc) (GstVaapiDisplay * display,
|
||||||
guint * pwidth, guint * pheight);
|
guint * pwidth, guint * pheight);
|
||||||
typedef void (*GstVaapiDisplayGetSizeMFunc) (GstVaapiDisplay * display,
|
typedef void (*GstVaapiDisplayGetSizeMFunc) (GstVaapiDisplay * display,
|
||||||
guint * pwidth, guint * pheight);
|
guint * pwidth, guint * pheight);
|
||||||
|
typedef GstVaapiTexture *(*GstVaapiDisplayCreateTextureFunc) (
|
||||||
|
GstVaapiDisplay * display, GstVaapiID id, guint target, guint format,
|
||||||
|
guint width, guint height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GST_VAAPI_DISPLAY_VADISPLAY:
|
* GST_VAAPI_DISPLAY_VADISPLAY:
|
||||||
|
@ -187,6 +191,7 @@ struct _GstVaapiDisplay
|
||||||
* @get_display: virtual function to retrieve the #GstVaapiDisplayInfo
|
* @get_display: virtual function to retrieve the #GstVaapiDisplayInfo
|
||||||
* @get_size: virtual function to retrieve the display dimensions, in pixels
|
* @get_size: virtual function to retrieve the display dimensions, in pixels
|
||||||
* @get_size_mm: virtual function to retrieve the display dimensions, in millimeters
|
* @get_size_mm: virtual function to retrieve the display dimensions, in millimeters
|
||||||
|
* @create_texture: (optional) virtual function to create a texture
|
||||||
*
|
*
|
||||||
* Base class for VA displays.
|
* Base class for VA displays.
|
||||||
*/
|
*/
|
||||||
|
@ -210,6 +215,8 @@ struct _GstVaapiDisplayClass
|
||||||
GstVaapiDisplayGetInfoFunc get_display;
|
GstVaapiDisplayGetInfoFunc get_display;
|
||||||
GstVaapiDisplayGetSizeFunc get_size;
|
GstVaapiDisplayGetSizeFunc get_size;
|
||||||
GstVaapiDisplayGetSizeMFunc get_size_mm;
|
GstVaapiDisplayGetSizeMFunc get_size_mm;
|
||||||
|
|
||||||
|
GstVaapiDisplayCreateTextureFunc create_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialization types */
|
/* Initialization types */
|
||||||
|
|
|
@ -40,11 +40,11 @@
|
||||||
#undef gst_vaapi_texture_replace
|
#undef gst_vaapi_texture_replace
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_texture_init (GstVaapiTexture * texture, guint texture_id,
|
gst_vaapi_texture_init (GstVaapiTexture * texture, GstVaapiID id,
|
||||||
guint target, guint format, guint width, guint height)
|
guint target, guint format, guint width, guint height)
|
||||||
{
|
{
|
||||||
GST_VAAPI_OBJECT_ID (texture) = texture_id;
|
texture->is_wrapped = id != GST_VAAPI_ID_INVALID;
|
||||||
texture->is_wrapped = texture_id != 0;
|
GST_VAAPI_OBJECT_ID (texture) = texture->is_wrapped ? id : 0;
|
||||||
texture->gl_target = target;
|
texture->gl_target = target;
|
||||||
texture->gl_format = format;
|
texture->gl_format = format;
|
||||||
texture->width = width;
|
texture->width = width;
|
||||||
|
@ -58,8 +58,8 @@ gst_vaapi_texture_allocate (GstVaapiTexture * texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
GstVaapiTexture *
|
GstVaapiTexture *
|
||||||
gst_vaapi_texture_new (const GstVaapiTextureClass * klass,
|
gst_vaapi_texture_new_internal (const GstVaapiTextureClass * klass,
|
||||||
GstVaapiDisplay * display, guint texture_id, guint target, guint format,
|
GstVaapiDisplay * display, GstVaapiID id, guint target, guint format,
|
||||||
guint width, guint height)
|
guint width, guint height)
|
||||||
{
|
{
|
||||||
GstVaapiTexture *texture;
|
GstVaapiTexture *texture;
|
||||||
|
@ -73,7 +73,7 @@ gst_vaapi_texture_new (const GstVaapiTextureClass * klass,
|
||||||
if (!texture)
|
if (!texture)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
gst_vaapi_texture_init (texture, texture_id, target, format, width, height);
|
gst_vaapi_texture_init (texture, id, target, format, width, height);
|
||||||
if (!gst_vaapi_texture_allocate (texture))
|
if (!gst_vaapi_texture_allocate (texture))
|
||||||
goto error;
|
goto error;
|
||||||
return texture;
|
return texture;
|
||||||
|
@ -83,6 +83,74 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_vaapi_texture_new:
|
||||||
|
* @display: a #GstVaapiDisplay
|
||||||
|
* @target: the target to which the texture is bound
|
||||||
|
* @format: the format of the pixel data
|
||||||
|
* @width: the requested width, in pixels
|
||||||
|
* @height: the requested height, in pixels
|
||||||
|
*
|
||||||
|
* Creates a texture with the specified dimensions, @target and
|
||||||
|
* @format. Note that only GL_TEXTURE_2D @target and GL_RGBA or
|
||||||
|
* GL_BGRA formats are supported at this time.
|
||||||
|
*
|
||||||
|
* The application shall maintain the live GL context itself.
|
||||||
|
*
|
||||||
|
* Return value: the newly created #GstVaapiTexture object
|
||||||
|
*/
|
||||||
|
GstVaapiTexture *
|
||||||
|
gst_vaapi_texture_new (GstVaapiDisplay * display, guint target, guint format,
|
||||||
|
guint width, guint height)
|
||||||
|
{
|
||||||
|
GstVaapiDisplayClass *dpy_class;
|
||||||
|
|
||||||
|
g_return_val_if_fail (display != NULL, NULL);
|
||||||
|
|
||||||
|
dpy_class = GST_VAAPI_DISPLAY_GET_CLASS (display);
|
||||||
|
if (G_UNLIKELY (!dpy_class->create_texture))
|
||||||
|
return NULL;
|
||||||
|
return dpy_class->create_texture (display, GST_VAAPI_ID_INVALID, target,
|
||||||
|
format, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_vaapi_texture_new_wrapped:
|
||||||
|
* @display: a #GstVaapiDisplay
|
||||||
|
* @texture_id: the foreign GL texture name to use
|
||||||
|
* @target: the target to which the texture is bound
|
||||||
|
* @format: the format of the pixel data
|
||||||
|
* @width: the suggested width, in pixels
|
||||||
|
* @height: the suggested height, in pixels
|
||||||
|
*
|
||||||
|
* Creates a texture with the specified dimensions, @target and
|
||||||
|
* @format. Note that only GL_TEXTURE_2D @target and GL_RGBA or
|
||||||
|
* GL_BGRA formats are supported at this time.
|
||||||
|
*
|
||||||
|
* The size arguments @width and @height are only a suggestion. Should
|
||||||
|
* this be 0x0, then the actual size of the allocated texture storage
|
||||||
|
* would be either inherited from the original texture storage, if any
|
||||||
|
* and/or if possible, or derived from the VA surface in subsequent
|
||||||
|
* gst_vaapi_texture_put_surface() calls.
|
||||||
|
*
|
||||||
|
* The application shall maintain the live GL context itself.
|
||||||
|
*
|
||||||
|
* Return value: the newly created #GstVaapiTexture object
|
||||||
|
*/
|
||||||
|
GstVaapiTexture *
|
||||||
|
gst_vaapi_texture_new_wrapped (GstVaapiDisplay * display, guint id,
|
||||||
|
guint target, guint format, guint width, guint height)
|
||||||
|
{
|
||||||
|
GstVaapiDisplayClass *dpy_class;
|
||||||
|
|
||||||
|
g_return_val_if_fail (display != NULL, NULL);
|
||||||
|
|
||||||
|
dpy_class = GST_VAAPI_DISPLAY_GET_CLASS (display);
|
||||||
|
if (G_UNLIKELY (!dpy_class->create_texture))
|
||||||
|
return NULL;
|
||||||
|
return dpy_class->create_texture (display, id, target, format, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_vaapi_texture_ref:
|
* gst_vaapi_texture_ref:
|
||||||
* @texture: a #GstVaapiTexture
|
* @texture: a #GstVaapiTexture
|
||||||
|
|
|
@ -80,6 +80,14 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct _GstVaapiTexture GstVaapiTexture;
|
typedef struct _GstVaapiTexture GstVaapiTexture;
|
||||||
|
|
||||||
|
GstVaapiTexture *
|
||||||
|
gst_vaapi_texture_new (GstVaapiDisplay * display, guint target, guint format,
|
||||||
|
guint width, guint height);
|
||||||
|
|
||||||
|
GstVaapiTexture *
|
||||||
|
gst_vaapi_texture_new_wrapped (GstVaapiDisplay * display, guint id,
|
||||||
|
guint target, guint format, guint width, guint height);
|
||||||
|
|
||||||
GstVaapiTexture *
|
GstVaapiTexture *
|
||||||
gst_vaapi_texture_ref (GstVaapiTexture * texture);
|
gst_vaapi_texture_ref (GstVaapiTexture * texture);
|
||||||
|
|
||||||
|
|
|
@ -230,10 +230,9 @@ gst_vaapi_texture_glx_new (GstVaapiDisplay * display, guint target,
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_GLX (display), NULL);
|
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_GLX (display), NULL);
|
||||||
|
|
||||||
return
|
return gst_vaapi_texture_new_internal (GST_VAAPI_TEXTURE_CLASS
|
||||||
gst_vaapi_texture_new (GST_VAAPI_TEXTURE_CLASS
|
(gst_vaapi_texture_glx_class ()), display, GST_VAAPI_ID_INVALID, target,
|
||||||
(gst_vaapi_texture_glx_class ()), display, GL_NONE, target, format, width,
|
format, width, height);
|
||||||
height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -264,6 +263,7 @@ gst_vaapi_texture_glx_new_wrapped (GstVaapiDisplay * display,
|
||||||
gboolean success;
|
gboolean success;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_GLX (display), NULL);
|
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_GLX (display), NULL);
|
||||||
|
g_return_val_if_fail (texture_id != GL_NONE, NULL);
|
||||||
g_return_val_if_fail (target != GL_NONE, NULL);
|
g_return_val_if_fail (target != GL_NONE, NULL);
|
||||||
g_return_val_if_fail (format != GL_NONE, NULL);
|
g_return_val_if_fail (format != GL_NONE, NULL);
|
||||||
|
|
||||||
|
@ -286,8 +286,7 @@ gst_vaapi_texture_glx_new_wrapped (GstVaapiDisplay * display,
|
||||||
g_return_val_if_fail (width > 0, NULL);
|
g_return_val_if_fail (width > 0, NULL);
|
||||||
g_return_val_if_fail (height > 0, NULL);
|
g_return_val_if_fail (height > 0, NULL);
|
||||||
|
|
||||||
return
|
return gst_vaapi_texture_new_internal (GST_VAAPI_TEXTURE_CLASS
|
||||||
gst_vaapi_texture_new (GST_VAAPI_TEXTURE_CLASS
|
|
||||||
(gst_vaapi_texture_glx_class ()), display, texture_id, target, format,
|
(gst_vaapi_texture_glx_class ()), display, texture_id, target, format,
|
||||||
width, height);
|
width, height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,8 @@ struct _GstVaapiTextureClass {
|
||||||
};
|
};
|
||||||
|
|
||||||
GstVaapiTexture *
|
GstVaapiTexture *
|
||||||
gst_vaapi_texture_new (const GstVaapiTextureClass * klass,
|
gst_vaapi_texture_new_internal (const GstVaapiTextureClass * klass,
|
||||||
GstVaapiDisplay * display, guint texture_id, guint target, guint format,
|
GstVaapiDisplay * display, GstVaapiID id, guint target, guint format,
|
||||||
guint width, guint height);
|
guint width, guint height);
|
||||||
|
|
||||||
/* Inline reference counting for core libgstvaapi library */
|
/* Inline reference counting for core libgstvaapi library */
|
||||||
|
|
Loading…
Reference in a new issue