diff options
author | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2014-12-04 14:36:35 +0100 |
---|---|---|
committer | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2015-01-27 18:11:44 +0100 |
commit | 93418ed5ee1fef86ae5dc78322f8c12c936db85d (patch) | |
tree | 13c9f6d948f08ad17c204dfc44ac5cb86ef2af2e | |
parent | 2101685b7d5f02d05665e85c0ed6d0788a3d25f5 (diff) | |
download | gst-vaapi-93418ed5ee1fef86ae5dc78322f8c12c936db85d.tar.gz |
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.
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapidisplay_glx.c | 11 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapidisplay_priv.h | 7 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapitexture.c | 80 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapitexture.h | 8 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapitexture_glx.c | 11 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapitexture_priv.h | 4 |
6 files changed, 107 insertions, 14 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_glx.c b/gst-libs/gst/vaapi/gstvaapidisplay_glx.c index b1bdef96..5342a6ed 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_glx.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_glx.c @@ -35,6 +35,7 @@ #include "gstvaapidisplay_x11_priv.h" #include "gstvaapidisplay_glx.h" #include "gstvaapidisplay_glx_priv.h" +#include "gstvaapitexture_glx.h" #define DEBUG 1 #include "gstvaapidebug.h" @@ -54,6 +55,15 @@ gst_vaapi_display_glx_get_display_info (GstVaapiDisplay * display, 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 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; dpy_class->display_types = g_display_types; 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 * diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_priv.h b/gst-libs/gst/vaapi/gstvaapidisplay_priv.h index b1e11605..d1bc700a 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_priv.h +++ b/gst-libs/gst/vaapi/gstvaapidisplay_priv.h @@ -27,6 +27,7 @@ #include <gst/vaapi/gstvaapidisplay.h> #include <gst/vaapi/gstvaapidisplaycache.h> +#include <gst/vaapi/gstvaapitexture.h> #include "gstvaapiminiobject.h" G_BEGIN_DECLS @@ -66,6 +67,9 @@ typedef void (*GstVaapiDisplayGetSizeFunc) (GstVaapiDisplay * display, guint * pwidth, guint * pheight); typedef void (*GstVaapiDisplayGetSizeMFunc) (GstVaapiDisplay * display, guint * pwidth, guint * pheight); +typedef GstVaapiTexture *(*GstVaapiDisplayCreateTextureFunc) ( + GstVaapiDisplay * display, GstVaapiID id, guint target, guint format, + guint width, guint height); /** * GST_VAAPI_DISPLAY_VADISPLAY: @@ -187,6 +191,7 @@ struct _GstVaapiDisplay * @get_display: virtual function to retrieve the #GstVaapiDisplayInfo * @get_size: virtual function to retrieve the display dimensions, in pixels * @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. */ @@ -210,6 +215,8 @@ struct _GstVaapiDisplayClass GstVaapiDisplayGetInfoFunc get_display; GstVaapiDisplayGetSizeFunc get_size; GstVaapiDisplayGetSizeMFunc get_size_mm; + + GstVaapiDisplayCreateTextureFunc create_texture; }; /* Initialization types */ diff --git a/gst-libs/gst/vaapi/gstvaapitexture.c b/gst-libs/gst/vaapi/gstvaapitexture.c index 4d0df1c7..33b3e316 100644 --- a/gst-libs/gst/vaapi/gstvaapitexture.c +++ b/gst-libs/gst/vaapi/gstvaapitexture.c @@ -40,11 +40,11 @@ #undef gst_vaapi_texture_replace 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) { - GST_VAAPI_OBJECT_ID (texture) = texture_id; - texture->is_wrapped = texture_id != 0; + texture->is_wrapped = id != GST_VAAPI_ID_INVALID; + GST_VAAPI_OBJECT_ID (texture) = texture->is_wrapped ? id : 0; texture->gl_target = target; texture->gl_format = format; texture->width = width; @@ -58,8 +58,8 @@ gst_vaapi_texture_allocate (GstVaapiTexture * texture) } GstVaapiTexture * -gst_vaapi_texture_new (const GstVaapiTextureClass * klass, - GstVaapiDisplay * display, guint texture_id, guint target, guint format, +gst_vaapi_texture_new_internal (const GstVaapiTextureClass * klass, + GstVaapiDisplay * display, GstVaapiID id, guint target, guint format, guint width, guint height) { GstVaapiTexture *texture; @@ -73,7 +73,7 @@ gst_vaapi_texture_new (const GstVaapiTextureClass * klass, if (!texture) 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)) goto error; return texture; @@ -84,6 +84,74 @@ error: } /** + * 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: * @texture: a #GstVaapiTexture * diff --git a/gst-libs/gst/vaapi/gstvaapitexture.h b/gst-libs/gst/vaapi/gstvaapitexture.h index 3856df87..316d52d0 100644 --- a/gst-libs/gst/vaapi/gstvaapitexture.h +++ b/gst-libs/gst/vaapi/gstvaapitexture.h @@ -81,6 +81,14 @@ G_BEGIN_DECLS 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 * gst_vaapi_texture_ref (GstVaapiTexture * texture); void diff --git a/gst-libs/gst/vaapi/gstvaapitexture_glx.c b/gst-libs/gst/vaapi/gstvaapitexture_glx.c index acaa4f05..ade7bb30 100644 --- a/gst-libs/gst/vaapi/gstvaapitexture_glx.c +++ b/gst-libs/gst/vaapi/gstvaapitexture_glx.c @@ -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); - return - gst_vaapi_texture_new (GST_VAAPI_TEXTURE_CLASS - (gst_vaapi_texture_glx_class ()), display, GL_NONE, target, format, width, - height); + return gst_vaapi_texture_new_internal (GST_VAAPI_TEXTURE_CLASS + (gst_vaapi_texture_glx_class ()), display, GST_VAAPI_ID_INVALID, target, + format, width, height); } /** @@ -264,6 +263,7 @@ gst_vaapi_texture_glx_new_wrapped (GstVaapiDisplay * display, gboolean success; 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 (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 (height > 0, NULL); - return - gst_vaapi_texture_new (GST_VAAPI_TEXTURE_CLASS + return gst_vaapi_texture_new_internal (GST_VAAPI_TEXTURE_CLASS (gst_vaapi_texture_glx_class ()), display, texture_id, target, format, width, height); } diff --git a/gst-libs/gst/vaapi/gstvaapitexture_priv.h b/gst-libs/gst/vaapi/gstvaapitexture_priv.h index 8cf57e60..1f69d220 100644 --- a/gst-libs/gst/vaapi/gstvaapitexture_priv.h +++ b/gst-libs/gst/vaapi/gstvaapitexture_priv.h @@ -126,8 +126,8 @@ struct _GstVaapiTextureClass { }; GstVaapiTexture * -gst_vaapi_texture_new (const GstVaapiTextureClass * klass, - GstVaapiDisplay * display, guint texture_id, guint target, guint format, +gst_vaapi_texture_new_internal (const GstVaapiTextureClass * klass, + GstVaapiDisplay * display, GstVaapiID id, guint target, guint format, guint width, guint height); /* Inline reference counting for core libgstvaapi library */ |