gbm: Add new gbm_bo_import entry point
This generalizes and replaces gbm_bo_create_for_egl_image. gbm_bo_import will create a gbm_bo from either an EGLImage or a struct wl_buffer.
This commit is contained in:
parent
43ccded1e1
commit
44f066b9ff
|
@ -912,7 +912,7 @@ struct __DRIdri2ExtensionRec {
|
|||
* extensions.
|
||||
*/
|
||||
#define __DRI_IMAGE "DRI_IMAGE"
|
||||
#define __DRI_IMAGE_VERSION 4
|
||||
#define __DRI_IMAGE_VERSION 5
|
||||
|
||||
/**
|
||||
* These formats correspond to the similarly named MESA_FORMAT_*
|
||||
|
@ -946,6 +946,8 @@ struct __DRIdri2ExtensionRec {
|
|||
#define __DRI_IMAGE_ATTRIB_HANDLE 0x2001
|
||||
#define __DRI_IMAGE_ATTRIB_NAME 0x2002
|
||||
#define __DRI_IMAGE_ATTRIB_FORMAT 0x2003 /* available in versions 3+ */
|
||||
#define __DRI_IMAGE_ATTRIB_WIDTH 0x2004 /* available in versions 5+ */
|
||||
#define __DRI_IMAGE_ATTRIB_HEIGHT 0x2005
|
||||
|
||||
typedef struct __DRIimageRec __DRIimage;
|
||||
typedef struct __DRIimageExtensionRec __DRIimageExtension;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#ifndef WAYLAND_DRM_H
|
||||
#define WAYLAND_DRM_H
|
||||
|
||||
#include "egldisplay.h"
|
||||
#include "eglimage.h"
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include "wayland-drm-server-protocol.h"
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ libgbm_la_SOURCES = \
|
|||
libgbm_la_LDFLAGS = -version-info 1:0
|
||||
libgbm_la_LIBADD = $(LIBUDEV_LIBS) $(DLOPEN_LIBS)
|
||||
|
||||
if HAVE_EGL_PLATFORM_WAYLAND
|
||||
AM_CPPFLAGS = -DHAVE_WAYLAND_PLATFORM
|
||||
endif
|
||||
|
||||
if HAVE_DRI
|
||||
noinst_LTLIBRARIES = libgbm_dri.la
|
||||
libgbm_dri_la_SOURCES = \
|
||||
|
|
|
@ -43,6 +43,11 @@
|
|||
|
||||
#include "gbmint.h"
|
||||
|
||||
/* For importing wl_buffer */
|
||||
#if HAVE_WAYLAND_PLATFORM
|
||||
#include "../../../egl/wayland/wayland-drm/wayland-drm.h"
|
||||
#endif
|
||||
|
||||
static __DRIimage *
|
||||
dri_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
|
||||
{
|
||||
|
@ -340,36 +345,76 @@ gbm_dri_to_gbm_format(uint32_t dri_format)
|
|||
}
|
||||
|
||||
static struct gbm_bo *
|
||||
gbm_dri_bo_create_from_egl_image(struct gbm_device *gbm,
|
||||
void *egl_dpy, void *egl_img,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t usage)
|
||||
gbm_dri_bo_import(struct gbm_device *gbm,
|
||||
uint32_t type, void *buffer, uint32_t usage)
|
||||
{
|
||||
struct gbm_dri_device *dri = gbm_dri_device(gbm);
|
||||
struct gbm_dri_bo *bo;
|
||||
int dri_format;
|
||||
__DRIimage *image;
|
||||
unsigned dri_use = 0;
|
||||
int dri_format, width, height, gbm_format, stride, cpp, offset;
|
||||
|
||||
(void) egl_dpy;
|
||||
switch (type) {
|
||||
#if HAVE_WAYLAND_PLATFORM
|
||||
case GBM_BO_IMPORT_WL_BUFFER:
|
||||
{
|
||||
struct wl_drm_buffer *wb = (struct wl_drm_buffer *) buffer;
|
||||
|
||||
if (dri->lookup_image == NULL)
|
||||
image = wb->driver_buffer;
|
||||
stride = wb->stride[0];
|
||||
offset = wb->offset[0];
|
||||
cpp = 4;
|
||||
switch (wb->format) {
|
||||
case WL_DRM_FORMAT_XRGB8888:
|
||||
dri_format = __DRI_IMAGE_FORMAT_XRGB8888;
|
||||
gbm_format = GBM_FORMAT_XRGB8888;
|
||||
break;
|
||||
case WL_DRM_FORMAT_ARGB8888:
|
||||
dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
break;
|
||||
case WL_DRM_FORMAT_YUYV:
|
||||
dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
|
||||
gbm_format = GBM_FORMAT_YUYV;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case GBM_BO_IMPORT_EGL_IMAGE:
|
||||
{
|
||||
if (dri->lookup_image == NULL)
|
||||
return NULL;
|
||||
|
||||
image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
|
||||
dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
|
||||
gbm_format = gbm_dri_to_gbm_format(dri_format);
|
||||
dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
|
||||
offset = 0;
|
||||
cpp = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bo = calloc(1, sizeof *bo);
|
||||
if (bo == NULL)
|
||||
return NULL;
|
||||
|
||||
bo->base.base.gbm = gbm;
|
||||
bo->base.base.width = width;
|
||||
bo->base.base.height = height;
|
||||
dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_WIDTH, &width);
|
||||
dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, &height);
|
||||
|
||||
bo->image = dri->image->createSubImage(image,
|
||||
width, height, dri_format,
|
||||
offset, stride / cpp, NULL);
|
||||
|
||||
__DRIimage *tmp = dri->lookup_image(dri->screen, egl_img,
|
||||
dri->lookup_user_data);
|
||||
|
||||
bo->image = dri->image->dupImage(tmp, bo);
|
||||
if (bo->image == NULL)
|
||||
return NULL;
|
||||
|
||||
if (usage & GBM_BO_USE_SCANOUT)
|
||||
dri_use |= __DRI_IMAGE_USE_SCANOUT;
|
||||
if (usage & GBM_BO_USE_CURSOR_64X64)
|
||||
|
@ -380,14 +425,13 @@ gbm_dri_bo_create_from_egl_image(struct gbm_device *gbm,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bo->base.base.gbm = gbm;
|
||||
bo->base.base.width = width;
|
||||
bo->base.base.height = height;
|
||||
bo->base.base.pitch = stride;
|
||||
bo->base.base.format = gbm_format;
|
||||
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
|
||||
&bo->base.base.handle.s32);
|
||||
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
|
||||
(int *) &bo->base.base.pitch);
|
||||
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_FORMAT,
|
||||
&dri_format);
|
||||
|
||||
bo->base.base.format = gbm_dri_to_gbm_format(dri_format);
|
||||
|
||||
return &bo->base.base;
|
||||
}
|
||||
|
@ -506,7 +550,7 @@ dri_device_create(int fd)
|
|||
|
||||
dri->base.base.fd = fd;
|
||||
dri->base.base.bo_create = gbm_dri_bo_create;
|
||||
dri->base.base.bo_create_from_egl_image = gbm_dri_bo_create_from_egl_image;
|
||||
dri->base.base.bo_import = gbm_dri_bo_import;
|
||||
dri->base.base.is_format_supported = gbm_dri_is_format_supported;
|
||||
dri->base.base.bo_write = gbm_dri_bo_write;
|
||||
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
|
||||
|
|
|
@ -337,34 +337,34 @@ gbm_bo_create(struct gbm_device *gbm,
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a buffer object representing the contents of an EGLImage
|
||||
* Create a gbm buffer object from an foreign object
|
||||
*
|
||||
* This function imports a foreign object and creates a new gbm bo for it.
|
||||
* This enabled using the foreign object with a display API such as KMS.
|
||||
* Currently two types of foreign objects are supported, indicated by the type
|
||||
* argument:
|
||||
*
|
||||
* GBM_BO_IMPORT_WL_BUFFER
|
||||
* GBM_BO_IMPORT_EGL_IMAGE
|
||||
*
|
||||
* The the gbm bo shares the underlying pixels but its life-time is
|
||||
* independent of the foreign object.
|
||||
*
|
||||
* \param gbm The gbm device returned from gbm_create_device()
|
||||
* \param egl_dpy The EGLDisplay on which the EGLImage was created
|
||||
* \param egl_image The EGLImage to create the buffer from
|
||||
* \param width The width to use in the creation of the buffer object
|
||||
* \param height The height to use in the creation of the buffer object
|
||||
* \param gbm The type of object we're importing
|
||||
* \param gbm Pointer to the external object
|
||||
* \param usage The union of the usage flags for this buffer
|
||||
*
|
||||
* \return A newly allocated buffer object that should be freed with
|
||||
* gbm_bo_destroy() when no longer needed.
|
||||
*
|
||||
* \sa enum gbm_bo_flags for the list of usage flags
|
||||
*
|
||||
* \note The expectation is that this function will use an efficient method
|
||||
* for making the contents of the EGLImage available as a buffer object.
|
||||
*/
|
||||
GBM_EXPORT struct gbm_bo *
|
||||
gbm_bo_create_from_egl_image(struct gbm_device *gbm,
|
||||
void *egl_dpy, void *egl_image,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t usage)
|
||||
gbm_bo_import(struct gbm_device *gbm,
|
||||
uint32_t type, void *buffer, uint32_t usage)
|
||||
{
|
||||
if (width == 0 || height == 0)
|
||||
return NULL;
|
||||
|
||||
return gbm->bo_create_from_egl_image(gbm, egl_dpy, egl_image,
|
||||
width, height, usage);
|
||||
return gbm->bo_import(gbm, type, buffer, usage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -230,11 +230,12 @@ gbm_bo_create(struct gbm_device *gbm,
|
|||
uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
#define GBM_BO_IMPORT_WL_BUFFER 0x5501
|
||||
#define GBM_BO_IMPORT_EGL_IMAGE 0x5502
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create_from_egl_image(struct gbm_device *gbm,
|
||||
void *egl_dpy, void *egl_img,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t usage);
|
||||
gbm_bo_import(struct gbm_device *gbm, uint32_t type,
|
||||
void *buffer, uint32_t usage);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_width(struct gbm_bo *bo);
|
||||
|
|
|
@ -66,10 +66,8 @@ struct gbm_device {
|
|||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
uint32_t usage);
|
||||
struct gbm_bo *(*bo_create_from_egl_image)(struct gbm_device *gbm,
|
||||
void *egl_dpy, void *egl_img,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t usage);
|
||||
struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type,
|
||||
void *buffer, uint32_t usage);
|
||||
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
|
||||
void (*bo_destroy)(struct gbm_bo *bo);
|
||||
|
||||
|
|
|
@ -357,7 +357,13 @@ intel_query_image(__DRIimage *image, int attrib, int *value)
|
|||
case __DRI_IMAGE_ATTRIB_FORMAT:
|
||||
*value = image->dri_format;
|
||||
return true;
|
||||
default:
|
||||
case __DRI_IMAGE_ATTRIB_WIDTH:
|
||||
*value = image->region->width;
|
||||
return true;
|
||||
case __DRI_IMAGE_ATTRIB_HEIGHT:
|
||||
*value = image->region->height;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue