From f3c58d4ef4c2edb776bdd554502ecec8eed21044 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Mon, 15 Sep 2014 13:47:53 +0200 Subject: [PATCH] surface: add support for GEM buffer exports. Add support for GEM buffer exports. This will only work with VA drivers based off libdrm, e.g. the Intel HD Graphics VA driver. This is needed to support interop with EGL and the "Desktop" GL specification. Indeed, the EXT_image_dma_buf_import extension is not going to be supported in Desktop GL, due to the lack of support for GL_TEXTURE_EXTERNAL_OES targets there. This is useful for implementing VA/EGL interop with legacy Mesa stacks, in Desktop OpenGL context. https://bugzilla.gnome.org/show_bug.cgi?id=736717 --- gst-libs/gst/vaapi/gstvaapibufferproxy.c | 6 ++++++ gst-libs/gst/vaapi/gstvaapibufferproxy.h | 2 ++ gst-libs/gst/vaapi/gstvaapisurface_drm.c | 22 ++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapisurface_drm.h | 3 +++ 4 files changed, 33 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapibufferproxy.c b/gst-libs/gst/vaapi/gstvaapibufferproxy.c index 485d555f74..22e17f2a96 100644 --- a/gst-libs/gst/vaapi/gstvaapibufferproxy.c +++ b/gst-libs/gst/vaapi/gstvaapibufferproxy.c @@ -45,6 +45,9 @@ from_GstVaapiBufferMemoryType (guint type) case GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF: va_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; break; + case GST_VAAPI_BUFFER_MEMORY_TYPE_GEM_BUF: + va_type = VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM; + break; default: va_type = 0; break; @@ -61,6 +64,9 @@ to_GstVaapiBufferMemoryType (guint va_type) case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: type = GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF; break; + case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: + type = GST_VAAPI_BUFFER_MEMORY_TYPE_GEM_BUF; + break; default: type = 0; break; diff --git a/gst-libs/gst/vaapi/gstvaapibufferproxy.h b/gst-libs/gst/vaapi/gstvaapibufferproxy.h index 3a92a2c800..a70d33f419 100644 --- a/gst-libs/gst/vaapi/gstvaapibufferproxy.h +++ b/gst-libs/gst/vaapi/gstvaapibufferproxy.h @@ -60,11 +60,13 @@ typedef struct _GstVaapiBufferProxy GstVaapiBufferProxy; /** * GstVaapiBufferMemoryType: * @GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF: DRM PRIME buffer memory type. + * @GST_VAAPI_BUFFER_MEMORY_TYPE_GEM_BUF: Kernel DRM buffer memory type. * * Set of underlying VA buffer memory types. */ typedef enum { GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF = 1, + GST_VAAPI_BUFFER_MEMORY_TYPE_GEM_BUF, } GstVaapiBufferMemoryType; GstVaapiBufferProxy * diff --git a/gst-libs/gst/vaapi/gstvaapisurface_drm.c b/gst-libs/gst/vaapi/gstvaapisurface_drm.c index 117ad390d0..bebbea1eaf 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface_drm.c +++ b/gst-libs/gst/vaapi/gstvaapisurface_drm.c @@ -75,3 +75,25 @@ gst_vaapi_surface_get_dma_buf_handle (GstVaapiSurface * surface) return gst_vaapi_surface_get_drm_buf_handle (surface, GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF); } + +/** + * gst_vaapi_surface_get_gem_buf_handle: + * @surface: a #GstVaapiSurface + * + * If the underlying VA driver implementation supports it, this + * function allows for returning a suitable GEM buffer handle as a + * #GstVaapiBufferProxy instance. The resulting buffer handle is live + * until the last reference to the proxy gets released. Besides, any + * further change to the parent VA @surface may fail. + * + * Return value: the underlying buffer as a #GstVaapiBufferProxy + * instance. + */ +GstVaapiBufferProxy * +gst_vaapi_surface_get_gem_buf_handle (GstVaapiSurface * surface) +{ + g_return_val_if_fail (surface != NULL, NULL); + + return gst_vaapi_surface_get_drm_buf_handle (surface, + GST_VAAPI_BUFFER_MEMORY_TYPE_GEM_BUF); +} diff --git a/gst-libs/gst/vaapi/gstvaapisurface_drm.h b/gst-libs/gst/vaapi/gstvaapisurface_drm.h index 90a5ebb5c2..cfbccbe11c 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface_drm.h +++ b/gst-libs/gst/vaapi/gstvaapisurface_drm.h @@ -31,6 +31,9 @@ G_BEGIN_DECLS GstVaapiBufferProxy * gst_vaapi_surface_get_dma_buf_handle (GstVaapiSurface * surface); +GstVaapiBufferProxy * +gst_vaapi_surface_get_gem_buf_handle (GstVaapiSurface * surface); + G_END_DECLS #endif /* GST_VAAPI_SURFACE_DRM_H */