diff options
author | Kristian Høgsberg <[email protected]> | 2012-07-17 10:41:25 -0400 |
---|---|---|
committer | Kristian Høgsberg <[email protected]> | 2012-07-17 10:54:00 -0400 |
commit | 2023bf996ed5c3797233b8d70670c28e15bdff75 (patch) | |
tree | 5d297ed5570a8623bde0a3dbd0708589fbd5e70f /src/gallium/state_trackers/gbm | |
parent | 1f2c87cc8f50d0a0ec3c9be1ddf6cf035002e5c7 (diff) |
gbm: Add gbm_bo_import for gallium gbm backend
Diffstat (limited to 'src/gallium/state_trackers/gbm')
-rw-r--r-- | src/gallium/state_trackers/gbm/Makefile | 4 | ||||
-rw-r--r-- | src/gallium/state_trackers/gbm/gbm_drm.c | 58 |
2 files changed, 49 insertions, 13 deletions
diff --git a/src/gallium/state_trackers/gbm/Makefile b/src/gallium/state_trackers/gbm/Makefile index 1d96eb2032d..2ebdbfa105e 100644 --- a/src/gallium/state_trackers/gbm/Makefile +++ b/src/gallium/state_trackers/gbm/Makefile @@ -17,6 +17,10 @@ ALL_SOURCES = $(gbm_SOURCES) GBM_OBJECTS = $(gbm_OBJECTS) GBM_CPPFLAGS = $(gbm_INCLUDES) +ifneq ($(findstring wayland, $(EGL_PLATFORMS)),) +GBM_CPPFLAGS += -DHAVE_WAYLAND_PLATFORM +endif + ##### TARGETS ##### default: depend libgbm.a diff --git a/src/gallium/state_trackers/gbm/gbm_drm.c b/src/gallium/state_trackers/gbm/gbm_drm.c index eb426efa960..8490480652f 100644 --- a/src/gallium/state_trackers/gbm/gbm_drm.c +++ b/src/gallium/state_trackers/gbm/gbm_drm.c @@ -35,6 +35,11 @@ #include "gbm_gallium_drmint.h" +/* For importing wl_buffer */ +#if HAVE_WAYLAND_PLATFORM +#include "../../../egl/wayland/wayland-drm/wayland-drm.h" +#endif + static INLINE enum pipe_format gbm_format_to_gallium(enum gbm_bo_format format) { @@ -99,32 +104,59 @@ gbm_gallium_drm_bo_destroy(struct gbm_bo *_bo) } static struct gbm_bo * -gbm_gallium_drm_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_gallium_drm_bo_import(struct gbm_device *gbm, + uint32_t type, void *buffer, uint32_t usage) { struct gbm_gallium_drm_device *gdrm = gbm_gallium_drm_device(gbm); struct gbm_gallium_drm_bo *bo; struct winsys_handle whandle; + struct pipe_resource *resource; + + switch (type) { +#if HAVE_WAYLAND_PLATFORM + case GBM_BO_IMPORT_WL_BUFFER: + { + struct wl_drm_buffer *wb = (struct wl_drm_buffer *) buffer; + + resource = wb->driver_buffer; + break; + } +#endif - if (!gdrm->lookup_egl_image) + case GBM_BO_IMPORT_EGL_IMAGE: + if (!gdrm->lookup_egl_image) + return NULL; + + resource = gdrm->lookup_egl_image(gdrm->lookup_egl_image_data, buffer); + if (resource == NULL) + return NULL; + break; + + default: return NULL; + } bo = CALLOC_STRUCT(gbm_gallium_drm_bo); if (bo == NULL) return NULL; - bo->resource = gdrm->lookup_egl_image(gdrm->lookup_egl_image_data, - egl_image); - if (bo->resource == NULL) { + bo->base.base.gbm = gbm; + bo->base.base.width = resource->width0; + bo->base.base.height = resource->height0; + + switch (resource->format) { + case PIPE_FORMAT_B8G8R8X8_UNORM: + bo->base.base.format = GBM_BO_FORMAT_XRGB8888; + break; + case PIPE_FORMAT_B8G8R8A8_UNORM: + bo->base.base.format = GBM_BO_FORMAT_ARGB8888; + break; + default: FREE(bo); return NULL; } - bo->base.base.gbm = gbm; - bo->base.base.width = width; - bo->base.base.height = height; + pipe_resource_reference(&bo->resource, resource); memset(&whandle, 0, sizeof(whandle)); whandle.type = DRM_API_HANDLE_TYPE_KMS; @@ -154,6 +186,7 @@ gbm_gallium_drm_bo_create(struct gbm_device *gbm, bo->base.base.gbm = gbm; bo->base.base.width = width; bo->base.base.height = height; + bo->base.base.format = format; pf = gbm_format_to_gallium(format); if (pf == PIPE_FORMAT_NONE) @@ -204,8 +237,7 @@ gbm_gallium_drm_device_create(int fd) gdrm->base.base.fd = fd; gdrm->base.base.bo_create = gbm_gallium_drm_bo_create; - gdrm->base.base.bo_create_from_egl_image = - gbm_gallium_drm_bo_create_from_egl_image; + gdrm->base.base.bo_import = gbm_gallium_drm_bo_import; gdrm->base.base.bo_destroy = gbm_gallium_drm_bo_destroy; gdrm->base.base.is_format_supported = gbm_gallium_drm_is_format_supported; gdrm->base.base.destroy = gbm_gallium_drm_destroy; |