gbm: Add gbm_bo_import for gallium gbm backend
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 17 Jul 2012 14:41:25 +0000 (10:41 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 17 Jul 2012 14:54:00 +0000 (10:54 -0400)
src/gallium/state_trackers/gbm/Makefile
src/gallium/state_trackers/gbm/gbm_drm.c

index 1d96eb2032d0e31f0e82c2be0d1f45d52dfd1a82..2ebdbfa105e8ee937834b87008258ff09aabda43 100644 (file)
@@ -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
index eb426efa9603c6360f3b0f99ea02051e21cae5f3..8490480652ff83ea44758517ba69870eba6d79f2 100644 (file)
 
 #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;