diff options
author | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2012-04-18 18:46:56 +0200 |
---|---|---|
committer | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2012-05-18 17:20:49 +0200 |
commit | 5d8a2b6f785ef3f0979d5f5919875386ac772ec3 (patch) | |
tree | 02194cab37d915deb866bb7e84402fe108aabdb4 | |
parent | 97d4d165175b592c21153fbacd7457a469c991d2 (diff) |
buffer: add layout information.
Define useful information to pixel buffers so that to determine their
format and how they are organized: line stride in bytes for each plane,
and offset from base buffer to the corresponding plane.
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r-- | src/wayland-util.c | 67 | ||||
-rw-r--r-- | src/wayland-util.h | 22 |
2 files changed, 89 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; +} diff --git a/src/wayland-util.h b/src/wayland-util.h index fa5c6c5..439f9c9 100644 --- a/src/wayland-util.h +++ b/src/wayland-util.h @@ -203,6 +203,28 @@ static inline wl_fixed_t wl_fixed_from_int(int i) return i * 256; } +/* 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 |