summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-08-15 23:03:21 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-08-16 10:49:48 -0400
commit7d3ccec18eda14a30c3edae608195898262f0d27 (patch)
tree303934f6b6d5f3fc8a1bf3a98b122bc496d24735
parentc855d6eec4c5e63489da5bc08451a2376e6d2aea (diff)
Add wl_shm_buffer_create()
-rw-r--r--src/wayland-server.h5
-rw-r--r--src/wayland-shm.c46
2 files changed, 50 insertions, 1 deletions
diff --git a/src/wayland-server.h b/src/wayland-server.h
index f092145..cd79801 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -440,6 +440,11 @@ wl_buffer_is_shm(struct wl_buffer *buffer);
int
wl_display_init_shm(struct wl_display *display);
+struct wl_buffer *
+wl_shm_buffer_create(struct wl_client *client,
+ uint32_t id, int32_t width, int32_t height,
+ int32_t stride, uint32_t format);
+
void wl_log_set_handler_server(wl_log_func_t handler);
#ifdef __cplusplus
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 2161a71..90c4cf7 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -255,6 +255,47 @@ wl_display_init_shm(struct wl_display *display)
return 0;
}
+WL_EXPORT struct wl_buffer *
+wl_shm_buffer_create(struct wl_client *client,
+ uint32_t id, int32_t width, int32_t height,
+ int32_t stride, uint32_t format)
+{
+ struct wl_shm_buffer *buffer;
+
+ switch (format) {
+ case WL_SHM_FORMAT_ARGB8888:
+ case WL_SHM_FORMAT_XRGB8888:
+ break;
+ default:
+ return NULL;
+ }
+
+ buffer = malloc(sizeof *buffer + stride * height);
+ if (buffer == NULL)
+ return NULL;
+
+ buffer->buffer.width = width;
+ buffer->buffer.height = height;
+ buffer->buffer.busy_count = 0;
+ buffer->format = format;
+ buffer->stride = stride;
+ buffer->offset = 0;
+ buffer->pool = NULL;
+
+ buffer->buffer.resource.object.id = id;
+ buffer->buffer.resource.object.interface = &wl_buffer_interface;
+ buffer->buffer.resource.object.implementation = (void (**)(void))
+ &shm_buffer_interface;
+
+ buffer->buffer.resource.data = buffer;
+ buffer->buffer.resource.client = client;
+ buffer->buffer.resource.destroy = destroy_buffer;
+
+ wl_client_add_resource(client, &buffer->buffer.resource);
+
+ return &buffer->buffer;
+}
+
WL_EXPORT int
wl_buffer_is_shm(struct wl_buffer *buffer)
{
@@ -281,7 +322,10 @@ wl_shm_buffer_get_data(struct wl_buffer *buffer_base)
if (!wl_buffer_is_shm(buffer_base))
return NULL;
- return buffer->pool->data + buffer->offset;
+ if (buffer->pool)
+ return buffer->pool->data + buffer->offset;
+ else
+ return buffer + 1;
}
WL_EXPORT uint32_t