summaryrefslogtreecommitdiff
path: root/src/wayland-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wayland-util.c')
-rw-r--r--src/wayland-util.c67
1 files changed, 67 insertions, 0 deletions
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;
+}