wayland-drm: Pass struct wl_drm_buffer to the driver
authorKristian Høgsberg <krh@bitplanet.net>
Thu, 5 Jul 2012 18:19:48 +0000 (14:19 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 11 Jul 2012 19:28:35 +0000 (15:28 -0400)
We're going to extend this to support multi-plane buffers, so pass this
to the driver so it can access the details.

src/egl/drivers/dri2/egl_dri2.c
src/egl/wayland/wayland-drm/wayland-drm.c
src/egl/wayland/wayland-drm/wayland-drm.h
src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h

index e2dee798d60c3bbd3112bec8f8203b071a5907c7..bb30e699fe4335ac2216acd60ce76e192aefd7c3 100644 (file)
@@ -1220,43 +1220,40 @@ dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
 
 #ifdef HAVE_WAYLAND_PLATFORM
 
-static void *
+static void
 dri2_wl_reference_buffer(void *user_data, uint32_t name,
-                        int32_t width, int32_t height,
-                        uint32_t stride, uint32_t format)
+                         struct wl_drm_buffer *buffer)
 {
    _EGLDisplay *disp = user_data;
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-   __DRIimage *image;
-   int dri_format;
 
-   switch (format) {
+   switch (buffer->format) {
    case WL_DRM_FORMAT_ARGB8888:
-      dri_format =__DRI_IMAGE_FORMAT_ARGB8888;
+      buffer->driver_format =__DRI_IMAGE_FORMAT_ARGB8888;
       break;
    case WL_DRM_FORMAT_XRGB8888:
-      dri_format = __DRI_IMAGE_FORMAT_XRGB8888;
+      buffer->driver_format = __DRI_IMAGE_FORMAT_XRGB8888;
       break;
    default:
-      return NULL;        
+      return;
    }
 
-   image = dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
-                                               width, height, 
-                                               dri_format, name, stride / 4,
-                                               NULL);
-
-   return image;
+   buffer->driver_buffer =
+      dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
+                                           buffer->buffer.width,
+                                           buffer->buffer.height, 
+                                           buffer->driver_format, name,
+                                           buffer->stride0 / 4,
+                                           NULL);
 }
 
 static void
-dri2_wl_release_buffer(void *user_data, void *buffer)
+dri2_wl_release_buffer(void *user_data, struct wl_drm_buffer *buffer)
 {
    _EGLDisplay *disp = user_data;
-   __DRIimage *image = buffer;
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
 
-   dri2_dpy->image->destroyImage(image);
+   dri2_dpy->image->destroyImage(buffer->driver_buffer);
 }
 
 static struct wayland_drm_callbacks wl_drm_callbacks = {
index 5f831b3487f615353ed711b8b5f792d8bce65fbc..af176b72d125ec105ddde5dc8b645f41ef2dab6c 100644 (file)
@@ -56,22 +56,13 @@ struct wl_drm {
        struct wayland_drm_callbacks *callbacks;
 };
 
-struct wl_drm_buffer {
-       struct wl_buffer buffer;
-       struct wl_drm *drm;
-       uint32_t format;
-
-       void *driver_buffer;
-};
-
 static void
 destroy_buffer(struct wl_resource *resource)
 {
        struct wl_drm_buffer *buffer = resource->data;
        struct wl_drm *drm = buffer->drm;
 
-       drm->callbacks->release_buffer(drm->user_data,
-                                      buffer->driver_buffer);
+       drm->callbacks->release_buffer(drm->user_data, buffer);
        free(buffer);
 }
 
@@ -129,12 +120,10 @@ drm_create_buffer(struct wl_client *client, struct wl_resource *resource,
        buffer->buffer.width = width;
        buffer->buffer.height = height;
        buffer->format = format;
+       buffer->offset0 = 0;
+       buffer->stride0 = stride;
 
-       buffer->driver_buffer =
-               drm->callbacks->reference_buffer(drm->user_data, name,
-                                                width, height,
-                                                stride, format);
-
+        drm->callbacks->reference_buffer(drm->user_data, name, buffer);
        if (buffer->driver_buffer == NULL) {
                wl_resource_post_error(resource,
                                       WL_DRM_ERROR_INVALID_NAME,
index bec50a5539fc02babe79e3bd277532f5326d28c1..f3df7eeaddd2cb3beccb27d0049fd7e5fd4c9cb1 100644 (file)
@@ -9,14 +9,24 @@
 
 struct wl_drm;
 
+struct wl_drm_buffer {
+       struct wl_buffer buffer;
+       struct wl_drm *drm;
+       uint32_t format;
+       uint32_t driver_format;
+        int32_t offset0;
+        int32_t stride0;
+
+       void *driver_buffer;
+};
+
 struct wayland_drm_callbacks {
        int (*authenticate)(void *user_data, uint32_t id);
 
-       void *(*reference_buffer)(void *user_data, uint32_t name,
-                                 int32_t width, int32_t height,
-                                 uint32_t stride, uint32_t format);
+       void (*reference_buffer)(void *user_data, uint32_t name,
+                                 struct wl_drm_buffer *buffer);
 
-       void (*release_buffer)(void *user_data, void *buffer);
+       void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
 };
 
 struct wl_drm *
index 80b3f227d0b1c1310f62a3af4fed20e584706b8c..6d72ce14774cc524a73cc86116d9e483acc51091 100644 (file)
 
 #include "native_wayland_drm_bufmgr_helper.h"
 
-void *
+void
 egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name,
-                                       int32_t width, int32_t height,
-                                       uint32_t stride, uint32_t format)
+                                       struct wl_drm_buffer *buffer)
 {
    struct native_display *ndpy = user_data;
    struct pipe_resource templ;
    struct winsys_handle wsh;
    enum pipe_format pf;
 
-   switch (format) {
+   switch (buffer->format) {
    case WL_DRM_FORMAT_ARGB8888:
       pf = PIPE_FORMAT_B8G8R8A8_UNORM;
       break;
@@ -35,28 +34,30 @@ egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name,
    }
 
    if (pf == PIPE_FORMAT_NONE)
-      return NULL;
+      return;
 
    memset(&templ, 0, sizeof(templ));
    templ.target = PIPE_TEXTURE_2D;
    templ.format = pf;
    templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
-   templ.width0 = width;
-   templ.height0 = height;
+   templ.width0 = buffer->buffer.width;
+   templ.height0 = buffer->buffer.height;
    templ.depth0 = 1;
    templ.array_size = 1;
 
    memset(&wsh, 0, sizeof(wsh));
    wsh.handle = name;
-   wsh.stride = stride;
+   wsh.stride = buffer->stride0;
 
-   return ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
+   buffer->driver_buffer =
+      ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
 }
 
 void
-egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer)
+egl_g3d_wl_drm_helper_unreference_buffer(void *user_data,
+                                         struct wl_drm_buffer *buffer)
 {
-   struct pipe_resource *resource = buffer;
+   struct pipe_resource *resource = buffer->driver_buffer;
 
    pipe_resource_reference(&resource, NULL);
 }
index 6085875f0980e0c3c4ba61d86a14907561ac42ce..e7a21717aebfc011326fe5a8c1604d7782792709 100644 (file)
 
 #include "wayland-drm.h"
 
-void *
+void
 egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name,
-                                       int32_t width, int32_t height,
-                                       uint32_t stride, uint32_t format);
+                                       struct wl_drm_buffer *buffer);
 
 void
-egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer);
+egl_g3d_wl_drm_helper_unreference_buffer(void *user_data,
+                                         struct wl_drm_buffer *buffer);
 
 struct pipe_resource *
 egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy,