[PATCH weston 2/3] tests: export create_shm_buffer() helper

Pekka Paalanen ppaalanen at gmail.com
Fri Feb 8 07:01:26 PST 2013


Lets the tests create additional buffers easily.

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 tests/weston-test-client-helper.c | 35 +++++++++++++++++++----------------
 tests/weston-test-client-helper.h |  3 +++
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 8d846ff..1234c62 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -264,35 +264,37 @@ static const struct wl_surface_listener surface_listener = {
 	surface_leave
 };
 
-static void
-create_shm_buffer(struct client *client)
+struct wl_buffer *
+create_shm_buffer(struct client *client, int width, int height, void **pixels)
 {
-	struct surface *surface = client->surface;
 	struct wl_shm *shm = client->wl_shm;
+	int stride = width * 4;
+	int size = stride * height;
 	struct wl_shm_pool *pool;
-	int fd, size, stride;
-
-	stride = surface->width * 4;
-	size = stride * surface->height;
+	struct wl_buffer *buffer;
+	int fd;
+	void *data;
 
 	fd = os_create_anonymous_file(size);
 	assert(fd >= 0);
 
-	surface->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
-			     fd, 0);
-	if (surface->data == MAP_FAILED) {
+	data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+	if (data == MAP_FAILED) {
 		close(fd);
-		assert(surface->data != MAP_FAILED);
+		assert(data != MAP_FAILED);
 	}
 
 	pool = wl_shm_create_pool(shm, fd, size);
-	surface->wl_buffer =
-		wl_shm_pool_create_buffer(pool, 0, surface->width,
-					  surface->height, stride,
-					  WL_SHM_FORMAT_ARGB8888);
+	buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
+					   WL_SHM_FORMAT_ARGB8888);
 	wl_shm_pool_destroy(pool);
 
 	close(fd);
+
+	if (pixels)
+		*pixels = data;
+
+	return buffer;
 }
 
 static void
@@ -510,7 +512,8 @@ client_create(int x, int y, int width, int height)
 
 	surface->width = width;
 	surface->height = height;
-	create_shm_buffer(client);
+	surface->wl_buffer = create_shm_buffer(client, width, height,
+					       &surface->data);
 
 	memset(surface->data, 64, width * height * 4);
 	wl_surface_attach(surface->wl_surface, surface->wl_buffer, 0, 0);
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index c576dcd..a5edca9 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -101,6 +101,9 @@ struct surface {
 struct client *
 client_create(int x, int y, int width, int height);
 
+struct wl_buffer *
+create_shm_buffer(struct client *client, int width, int height, void **pixels);
+
 int
 surface_contains(struct surface *surface, int x, int y);
 
-- 
1.7.12.4



More information about the wayland-devel mailing list