[Mesa-dev] [PATCH 6/8] wayland-drm: Add protocol to create planar buffers

Kristian Høgsberg krh at bitplanet.net
Thu Jul 5 14:50:06 PDT 2012


---
 src/egl/drivers/dri2/egl_dri2.c                    |    8 +-
 .../wayland/wayland-drm/protocol/wayland-drm.xml   |   16 ++++
 src/egl/wayland/wayland-drm/wayland-drm.c          |   77 +++++++++++++++-----
 src/egl/wayland/wayland-drm/wayland-drm.h          |    5 +-
 .../egl/common/native_wayland_drm_bufmgr_helper.c  |    2 +-
 5 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bb30e69..a666711 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1234,6 +1234,12 @@ dri2_wl_reference_buffer(void *user_data, uint32_t name,
    case WL_DRM_FORMAT_XRGB8888:
       buffer->driver_format = __DRI_IMAGE_FORMAT_XRGB8888;
       break;
+   case WL_DRM_FORMAT_YUV420:
+      buffer->driver_format =__DRI_IMAGE_FORMAT_YUV420;
+      break;
+   case WL_DRM_FORMAT_NV12:
+      buffer->driver_format = __DRI_IMAGE_FORMAT_NV12;
+      break;
    default:
       return;
    }
@@ -1243,7 +1249,7 @@ dri2_wl_reference_buffer(void *user_data, uint32_t name,
                                            buffer->buffer.width,
                                            buffer->buffer.height, 
                                            buffer->driver_format, name,
-                                           buffer->stride0 / 4,
+                                           buffer->stride[0] / 4,
                                            NULL);
 }
 
diff --git a/src/egl/wayland/wayland-drm/protocol/wayland-drm.xml b/src/egl/wayland/wayland-drm/protocol/wayland-drm.xml
index 89fd8f0..265d4f8 100644
--- a/src/egl/wayland/wayland-drm/protocol/wayland-drm.xml
+++ b/src/egl/wayland/wayland-drm/protocol/wayland-drm.xml
@@ -119,6 +119,22 @@
       <arg name="format" type="uint"/>
     </request>
 
+    <!-- Create a wayland buffer for the named DRM buffer.  The DRM
+         surface must have a name using the flink ioctl -->
+    <request name="create_planar_buffer">
+      <arg name="id" type="new_id" interface="wl_buffer"/>
+      <arg name="name" type="uint"/>
+      <arg name="width" type="int"/>
+      <arg name="height" type="int"/>
+      <arg name="format" type="uint"/>
+      <arg name="offset0" type="int"/>
+      <arg name="stride0" type="int"/>
+      <arg name="offset1" type="int"/>
+      <arg name="stride1" type="int"/>
+      <arg name="offset2" type="int"/>
+      <arg name="stride2" type="int"/>
+    </request>
+
     <!-- Notification of the path of the drm device which is used by
          the server.  The client should use this device for creating
          local buffers.  Only buffers created from this device should
diff --git a/src/egl/wayland/wayland-drm/wayland-drm.c b/src/egl/wayland/wayland-drm/wayland-drm.c
index af176b7..24e2b9e 100644
--- a/src/egl/wayland/wayland-drm/wayland-drm.c
+++ b/src/egl/wayland/wayland-drm/wayland-drm.c
@@ -92,24 +92,16 @@ const static struct wl_buffer_interface drm_buffer_interface = {
 };
 
 static void
-drm_create_buffer(struct wl_client *client, struct wl_resource *resource,
-		  uint32_t id, uint32_t name, int32_t width, int32_t height,
-		  uint32_t stride, uint32_t format)
+create_buffer(struct wl_client *client, struct wl_resource *resource,
+              uint32_t id, uint32_t name, int32_t width, int32_t height,
+              uint32_t format,
+              int32_t offset0, int32_t stride0,
+              int32_t offset1, int32_t stride1,
+              int32_t offset2, int32_t stride2)
 {
 	struct wl_drm *drm = resource->data;
 	struct wl_drm_buffer *buffer;
 
-	switch (format) {
-	case WL_DRM_FORMAT_ARGB8888:
-	case WL_DRM_FORMAT_XRGB8888:
-		break;
-	default:
-		wl_resource_post_error(resource,
-				       WL_DRM_ERROR_INVALID_FORMAT,
-				       "invalid format");
-		return;
-	}
-
 	buffer = calloc(1, sizeof *buffer);
 	if (buffer == NULL) {
 		wl_resource_post_no_memory(resource);
@@ -120,8 +112,12 @@ 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->offset[0] = offset0;
+	buffer->stride[0] = stride0;
+	buffer->offset[1] = offset1;
+	buffer->stride[1] = stride1;
+	buffer->offset[2] = offset2;
+	buffer->stride[2] = stride2;
 
         drm->callbacks->reference_buffer(drm->user_data, name, buffer);
 	if (buffer->driver_buffer == NULL) {
@@ -144,6 +140,50 @@ drm_create_buffer(struct wl_client *client, struct wl_resource *resource,
 }
 
 static void
+drm_create_buffer(struct wl_client *client, struct wl_resource *resource,
+		  uint32_t id, uint32_t name, int32_t width, int32_t height,
+		  uint32_t stride, uint32_t format)
+{
+        switch (format) {
+        case WL_DRM_FORMAT_ARGB8888:
+        case WL_DRM_FORMAT_XRGB8888:
+                break;
+        default:
+                wl_resource_post_error(resource,
+                                       WL_DRM_ERROR_INVALID_FORMAT,
+                                       "invalid format");
+           return;
+        }
+
+        create_buffer(client, resource, id,
+                      name, width, height, format, 0, stride, 0, 0, 0, 0);
+}
+
+static void
+drm_create_planar_buffer(struct wl_client *client,
+                         struct wl_resource *resource,
+                         uint32_t id, uint32_t name,
+                         int32_t width, int32_t height, uint32_t format,
+                         int32_t offset0, int32_t stride0,
+                         int32_t offset1, int32_t stride1,
+                         int32_t offset2, int32_t stride2)
+{
+        switch (format) {
+        case WL_DRM_FORMAT_YUV420:
+        case WL_DRM_FORMAT_NV12:
+                break;
+        default:
+                wl_resource_post_error(resource,
+                                       WL_DRM_ERROR_INVALID_FORMAT,
+                                       "invalid format");
+           return;
+        }
+
+        create_buffer(client, resource, id, name, width, height, format,
+                      offset0, stride0, offset1, stride1, offset2, stride2);
+}
+
+static void
 drm_authenticate(struct wl_client *client,
 		 struct wl_resource *resource, uint32_t id)
 {
@@ -159,7 +199,8 @@ drm_authenticate(struct wl_client *client,
 
 const static struct wl_drm_interface drm_interface = {
 	drm_authenticate,
-	drm_create_buffer
+	drm_create_buffer,
+        drm_create_planar_buffer
 };
 
 static void
@@ -175,6 +216,8 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
 			       WL_DRM_FORMAT_ARGB8888);
 	wl_resource_post_event(resource, WL_DRM_FORMAT,
 			       WL_DRM_FORMAT_XRGB8888);
+        wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV420);
+        wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12);
 }
 
 struct wl_drm *
diff --git a/src/egl/wayland/wayland-drm/wayland-drm.h b/src/egl/wayland/wayland-drm/wayland-drm.h
index f3df7ee..46aab69 100644
--- a/src/egl/wayland/wayland-drm/wayland-drm.h
+++ b/src/egl/wayland/wayland-drm/wayland-drm.h
@@ -14,9 +14,8 @@ struct wl_drm_buffer {
 	struct wl_drm *drm;
 	uint32_t format;
 	uint32_t driver_format;
-        int32_t offset0;
-        int32_t stride0;
-
+        int32_t offset[3];
+        int32_t stride[3];
 	void *driver_buffer;
 };
 
diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
index 6d72ce1..c520b53 100644
--- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
+++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
@@ -47,7 +47,7 @@ egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name,
 
    memset(&wsh, 0, sizeof(wsh));
    wsh.handle = name;
-   wsh.stride = buffer->stride0;
+   wsh.stride = buffer->stride[0];
 
    buffer->driver_buffer =
       ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
-- 
1.7.10.2



More information about the mesa-dev mailing list