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

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


---
 clients/simple-shm.c |   24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/clients/simple-shm.c b/clients/simple-shm.c
index 252e040..0e5a32e 100644
--- a/clients/simple-shm.c
+++ b/clients/simple-shm.c
@@ -26,8 +26,6 @@
 #include <string.h>
 #include <stdbool.h>
 #include <assert.h>
-#include <unistd.h>
-#include <sys/mman.h>
 #include <signal.h>
 
 #include <wayland-client.h>
@@ -56,33 +54,27 @@ static struct wl_buffer *
 create_shm_buffer(struct display *display,
 		  int width, int height, uint32_t format, void **data_out)
 {
+	struct wl_shm_pool_helper *pool_helper;
 	struct wl_shm_pool *pool;
 	struct wl_buffer *buffer;
-	int fd, size, stride;
+	int size, stride;
 	void *data;
 
 	stride = width * 4;
 	size = stride * 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(display->shm, size);
+	if (!pool_helper) {
+		fprintf(stderr, "creating a shm pool for %d B failed: %m\n",
 			size);
 		return NULL;
 	}
 
-	data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-	if (data == MAP_FAILED) {
-		fprintf(stderr, "mmap failed: %m\n");
-		close(fd);
-		return NULL;
-	}
-
-	pool = wl_shm_create_pool(display->shm, fd, size);
+	data = wl_shm_pool_helper_allocate(pool_helper, size, NULL);
+	pool = wl_shm_pool_helper_get_pool(pool_helper);
 	buffer = wl_shm_pool_create_buffer(pool, 0,
 					   width, height, stride, format);
-	wl_shm_pool_destroy(pool);
-	close(fd);
+	wl_shm_pool_helper_destroy(pool_helper, 0);
 
 	*data_out = data;
 
-- 
1.7.10.4



More information about the wayland-devel mailing list