[RFC wayland 17/18] protocol: Add a wl_buffer.transmit

Derek Foreman derekf at osg.samsung.com
Tue Feb 9 16:56:04 UTC 2016


This is for sending buffer contents over the network to a compositor.

A rectangle of data is sent in a terribly inefficient way.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
 protocol/wayland.xml | 18 +++++++++++++++++-
 src/wayland-shm.c    | 40 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index 8713f43..c683df8 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -371,7 +371,7 @@
     </event>
   </interface>
 
-  <interface name="wl_buffer" version="1">
+  <interface name="wl_buffer" version="2">
     <description summary="content for a wl_surface">
       A buffer provides the content for a wl_surface. Buffers are
       created through factory interfaces such as wl_drm, wl_shm or
@@ -405,6 +405,22 @@
 	optimization for GL(ES) compositors with wl_shm clients.
       </description>
     </event>
+
+    <!-- Version 2 additions -->
+
+    <request name="transmit" since="2">
+      <description summary="send buffer contents over the network">
+	Send the contents of the buffer over the network.
+      </description>
+
+      <arg name="x" type="uint"/>
+      <arg name="y" type="uint"/>
+      <arg name="w" type="uint"/>
+      <arg name="h" type="uint"/>
+      <arg name="offset" type="uint"/>
+      <arg name="contents" type="array" />
+    </request>
+
   </interface>
 
 
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index d6566bf..f6b6808 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -102,8 +102,44 @@ shm_buffer_destroy(struct wl_client *client, struct wl_resource *resource)
 	wl_resource_destroy(resource);
 }
 
+static void
+shm_buffer_transmit(struct wl_client *client, struct wl_resource *resource,
+		    uint32_t x, uint32_t y,
+		    uint32_t width, uint32_t height,
+		    uint32_t offset,
+		    struct wl_array *contents)
+{
+	unsigned int i, j, count, yo, xo;
+	struct wl_shm_buffer *buffer = wl_resource_get_user_data(resource);
+	struct wl_shm_pool *pool = buffer->pool;
+	char *cptr = pool->data + buffer->offset;
+	unsigned char *aptr = contents->data;
+
+	if (width == 0 || height == 0)
+		return;
+
+	yo = offset / width;
+	xo = offset % width;
+
+	if (yo > height)
+		return;
+
+	for (count = 0, i = y + yo; i < y + height; i++)
+		for (j = x + xo, xo = 0; j < x + width; j++) {
+			if (count + 4> contents->size)
+				break;
+			aptr = contents->data + count;
+			count += 4;
+			*(cptr + i * buffer->stride + 4 *j) = *aptr;
+			*(cptr + i * buffer->stride + 4 *j + 1) = *(aptr + 1);
+			*(cptr + i * buffer->stride + 4 *j + 2) = *(aptr + 2);
+			*(cptr + i * buffer->stride + 4 *j + 3) = *(aptr + 3);
+		}
+}
+
 static const struct wl_buffer_interface shm_buffer_interface = {
-	shm_buffer_destroy
+	shm_buffer_destroy,
+	shm_buffer_transmit
 };
 
 static bool
@@ -168,7 +204,7 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
 	pool->refcount++;
 
 	buffer->resource =
-		wl_resource_create(client, &wl_buffer_interface, 1, id);
+		wl_resource_create(client, &wl_buffer_interface, 2, id);
 	if (buffer->resource == NULL) {
 		wl_client_post_no_memory(client);
 		shm_pool_unref(pool);
-- 
2.7.0



More information about the wayland-devel mailing list