[PATCH 3/4] simple-touch.c: Adapt to new shm pool helper functions

Andre Heider a.heider at gmail.com
Sat Aug 4 06:23:50 PDT 2012


---
 clients/simple-touch.c |   26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/clients/simple-touch.c b/clients/simple-touch.c
index 6087fe4..91b0e0b 100644
--- a/clients/simple-touch.c
+++ b/clients/simple-touch.c
@@ -26,8 +26,6 @@
 #include <string.h>
 #include <stdbool.h>
 #include <assert.h>
-#include <unistd.h>
-#include <sys/mman.h>
 
 #include <GLES2/gl2.h>
 #include <wayland-client.h>
@@ -55,35 +53,27 @@ struct touch {
 static void
 create_shm_buffer(struct touch *touch)
 {
+	struct wl_shm_pool_helper *pool_helper;
 	struct wl_shm_pool *pool;
-	int fd, size, stride;
+	int size, stride;
 
 	stride = touch->width * 4;
 	size = stride * touch->height;
 
-	fd = os_create_anonymous_file(size);
-	if (fd < 0) {
-		fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
+	pool_helper = wl_shm_pool_helper_create(touch->shm, size);
+	if (!pool_helper) {
+		fprintf(stderr, "creating a shm pool for %d B failed: %m\n",
 			size);
 		exit(1);
 	}
 
-	touch->data =
-		mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-	if (touch->data == MAP_FAILED) {
-		fprintf(stderr, "mmap failed: %m\n");
-		close(fd);
-		exit(1);
-	}
-
-	pool = wl_shm_create_pool(touch->shm, fd, size);
+	touch->data = wl_shm_pool_helper_allocate(pool_helper, size, NULL);
+	pool = wl_shm_pool_helper_get_pool(pool_helper);
 	touch->buffer =
 		wl_shm_pool_create_buffer(pool, 0,
 					  touch->width, touch->height, stride,
 					  WL_SHM_FORMAT_ARGB8888);
-	wl_shm_pool_destroy(pool);
-
-	close(fd);
+	wl_shm_pool_helper_destroy(pool_helper, 0);
 }
 
 static void
-- 
1.7.10.4



More information about the wayland-devel mailing list