[PATCH 2/5] buffer: add layout information.

Gwenole Beauchesne gb.devel at gmail.com
Fri Apr 20 07:39:53 PDT 2012


Attach useful information to the buffer so that to determine its pixel
format and how it is organized: line stride in bytes for each plane,
and offset from base buffer to the corresponding plane.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/wayland-server.h |    1 +
 src/wayland-util.c   |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/wayland-util.h   |   22 ++++++++++++++++
 3 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/src/wayland-server.h b/src/wayland-server.h
index 7dcdb1a..af949a0 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -177,6 +177,7 @@ struct wl_buffer {
 	struct wl_resource resource;
 	int32_t width, height;
 	uint32_t busy_count;
+	struct wl_buffer_layout layout;
 };
 
 struct wl_surface {
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 7bf8924..03fed82 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -270,3 +270,70 @@ wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
 	for_each_helper(&map->client_entries, func, data);
 	for_each_helper(&map->server_entries, func, data);
 }
+
+static inline uint32_t
+wl_buffer_layout_get_min_size(const struct wl_buffer_layout *layout)
+{
+	return 4 * 4;
+}
+
+static inline uint32_t
+wl_buffer_layout_get_size(const struct wl_buffer_layout *layout)
+{
+	return (wl_buffer_layout_get_min_size(layout) +
+		layout->num_planes * 2 * 4);
+}
+
+WL_EXPORT void
+wl_array_pack_buffer_layout(struct wl_array *array,
+			    const struct wl_buffer_layout *layout)
+{
+	uint32_t *p, i;
+
+	wl_array_init(array);
+
+	p = wl_array_add(array, wl_buffer_layout_get_size(layout));
+	p[0] = layout->format;
+	p[1] = layout->width;
+	p[2] = layout->height;
+	p[3] = layout->num_planes;
+	p += 4;
+
+	for (i = 0; i < layout->num_planes; i++, p += 2) {
+		p[0] = layout->pitches[i];
+		p[1] = layout->offsets[i];
+	}
+}
+
+WL_EXPORT int
+wl_array_unpack_buffer_layout(struct wl_array *array,
+			      struct wl_buffer_layout *layout)
+{
+	uint32_t *p, i;
+
+	if (!layout)
+		return 0;
+
+	if (!array || array->size < wl_buffer_layout_get_min_size(layout))
+		return 0;
+
+	p = array->data;
+	layout->format     = p[0];
+	layout->width      = p[1];
+	layout->height     = p[2];
+	layout->num_planes = p[3];
+	p += 4;
+
+	if (array->size < wl_buffer_layout_get_size(layout))
+		return 0;
+
+	for (i = 0; i < layout->num_planes; i++, p += 2) {
+		layout->pitches[i] = p[0];
+		layout->offsets[i] = p[1];
+	}
+	for (; i < WL_BUFFER_MAX_PLANES; i++) {
+		layout->pitches[i] = 0;
+		layout->offsets[i] = 0;
+	}
+	return 1;
+}
diff --git a/src/wayland-util.h b/src/wayland-util.h
index 1b8fd4b..6729c30 100644
--- a/src/wayland-util.h
+++ b/src/wayland-util.h
@@ -165,6 +165,28 @@ void wl_array_release(struct wl_array *array);
 void *wl_array_add(struct wl_array *array, size_t size);
 void wl_array_copy(struct wl_array *array, struct wl_array *source);
 
+/* Buffer layout */
+enum {
+	WL_BUFFER_MAX_PLANES = 3,
+};
+
+struct wl_buffer_layout {
+	uint32_t format;
+	uint32_t width;
+	uint32_t height;
+	uint32_t num_planes;
+	uint32_t pitches[WL_BUFFER_MAX_PLANES];
+	uint32_t offsets[WL_BUFFER_MAX_PLANES];
+};
+
+void
+wl_array_pack_buffer_layout(struct wl_array *array,
+			    const struct wl_buffer_layout *layout);
+
+int
+wl_array_unpack_buffer_layout(struct wl_array *array,
+			      struct wl_buffer_layout *layout);
+
 #ifdef  __cplusplus
 }
 #endif
-- 
1.7.5.4



More information about the wayland-devel mailing list