[PATCH wayland 2/3] Change SHM wl_buffer functions to use the wl_shm_buffer structure

Jason Ekstrand jason at jlekstrand.net
Thu Jun 20 18:36:48 PDT 2013


This commit does not break ABI.  It merely changes the types of some things
and adds a wl_shm_buffer_get function.

Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 src/wayland-server.h | 15 ++++++++++-----
 src/wayland-shm.c    | 36 +++++++++++++++---------------------
 2 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/wayland-server.h b/src/wayland-server.h
index 72a4833..b8f1349 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -285,20 +285,25 @@ struct wl_listener *
 wl_resource_get_destroy_listener(struct wl_resource *resource,
 				 wl_notify_func_t notify);
 
+struct wl_shm_buffer;
+
+struct wl_shm_buffer *
+wl_shm_buffer_get(struct wl_resource *resource);
+
 void *
-wl_shm_buffer_get_data(struct wl_buffer *buffer);
+wl_shm_buffer_get_data(struct wl_shm_buffer *buffer);
 
 int32_t
-wl_shm_buffer_get_stride(struct wl_buffer *buffer);
+wl_shm_buffer_get_stride(struct wl_shm_buffer *buffer);
 
 uint32_t
-wl_shm_buffer_get_format(struct wl_buffer *buffer);
+wl_shm_buffer_get_format(struct wl_shm_buffer *buffer);
 
 int32_t
-wl_shm_buffer_get_width(struct wl_buffer *buffer);
+wl_shm_buffer_get_width(struct wl_shm_buffer *buffer);
 
 int32_t
-wl_shm_buffer_get_height(struct wl_buffer *buffer);
+wl_shm_buffer_get_height(struct wl_shm_buffer *buffer);
 
 int
 wl_buffer_is_shm(struct wl_buffer *buffer);
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index dc169ae..e2705b8 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -288,6 +288,16 @@ wl_shm_buffer_create(struct wl_client *client,
 	return &buffer->buffer;
 }
 
+WL_EXPORT struct wl_shm_buffer *
+wl_shm_buffer_get(struct wl_resource *resource)
+{
+	if (wl_resource_instance_of(resource, &wl_buffer_interface,
+				    &shm_buffer_interface))
+		return wl_resource_get_user_data(resource);
+	else
+		return NULL;
+}
+
 WL_EXPORT int
 wl_buffer_is_shm(struct wl_buffer *buffer)
 {
@@ -296,24 +306,14 @@ wl_buffer_is_shm(struct wl_buffer *buffer)
 }
 
 WL_EXPORT int32_t
-wl_shm_buffer_get_stride(struct wl_buffer *buffer_base)
+wl_shm_buffer_get_stride(struct wl_shm_buffer *buffer)
 {
-	struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
-
-	if (!wl_buffer_is_shm(buffer_base))
-		return 0;
-
 	return buffer->stride;
 }
 
 WL_EXPORT void *
-wl_shm_buffer_get_data(struct wl_buffer *buffer_base)
+wl_shm_buffer_get_data(struct wl_shm_buffer *buffer)
 {
-	struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
-
-	if (!wl_buffer_is_shm(buffer_base))
-		return NULL;
-
 	if (buffer->pool)
 		return buffer->pool->data + buffer->offset;
 	else
@@ -321,25 +321,19 @@ wl_shm_buffer_get_data(struct wl_buffer *buffer_base)
 }
 
 WL_EXPORT uint32_t
-wl_shm_buffer_get_format(struct wl_buffer *buffer_base)
+wl_shm_buffer_get_format(struct wl_shm_buffer *buffer)
 {
-	struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
-
 	return buffer->format;
 }
 
 WL_EXPORT int32_t
-wl_shm_buffer_get_width(struct wl_buffer *buffer_base)
+wl_shm_buffer_get_width(struct wl_shm_buffer *buffer)
 {
-	struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
-
 	return buffer->buffer.width;
 }
 
 WL_EXPORT int32_t
-wl_shm_buffer_get_height(struct wl_buffer *buffer_base)
+wl_shm_buffer_get_height(struct wl_shm_buffer *buffer)
 {
-	struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
-
 	return buffer->buffer.height;
 }
-- 
1.8.1.4



More information about the wayland-devel mailing list