diff options
author | Kristian Høgsberg <[email protected]> | 2012-07-13 11:19:24 -0400 |
---|---|---|
committer | Kristian Høgsberg <[email protected]> | 2012-07-16 16:29:15 -0400 |
commit | 44f066b9ffb7749e872c9cc44ab4d6e2973c2372 (patch) | |
tree | 9c2a9bd9a77bfc6f67c37117ba268cba091032aa /src/gbm | |
parent | 43ccded1e17147c0b705152add11875b560b1c43 (diff) |
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.
Diffstat (limited to 'src/gbm')
-rw-r--r-- | src/gbm/Makefile.am | 4 | ||||
-rw-r--r-- | src/gbm/backends/dri/gbm_dri.c | 90 | ||||
-rw-r--r-- | src/gbm/main/gbm.c | 34 | ||||
-rw-r--r-- | src/gbm/main/gbm.h | 9 | ||||
-rw-r--r-- | src/gbm/main/gbmint.h | 6 |
5 files changed, 95 insertions, 48 deletions
diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am index dede5bc1069..5ca28395a17 100644 --- a/src/gbm/Makefile.am +++ b/src/gbm/Makefile.am @@ -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 = \ diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c index e5ddfb6ce69..3aa0616fe92 100644 --- a/src/gbm/backends/dri/gbm_dri.c +++ b/src/gbm/backends/dri/gbm_dri.c @@ -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; + + switch (type) { +#if HAVE_WAYLAND_PLATFORM + case GBM_BO_IMPORT_WL_BUFFER: + { + struct wl_drm_buffer *wb = (struct wl_drm_buffer *) buffer; + + 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 - (void) egl_dpy; + 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; + } - if (dri->lookup_image == NULL) + 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; diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c index 3994f86aafc..2a830336d45 100644 --- a/src/gbm/main/gbm.c +++ b/src/gbm/main/gbm.c @@ -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); } /** diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h index af5dc5aee8c..52afdf7fd13 100644 --- a/src/gbm/main/gbm.h +++ b/src/gbm/main/gbm.h @@ -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); diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h index 8eb8671aeb2..ab23f0af073 100644 --- a/src/gbm/main/gbmint.h +++ b/src/gbm/main/gbmint.h @@ -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); |