[PATCH 1/4] screenshot.c: Adapt to new shm pool helper functions

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


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

diff --git a/clients/screenshot.c b/clients/screenshot.c
index 7395bf3..b8b866a 100644
--- a/clients/screenshot.c
+++ b/clients/screenshot.c
@@ -25,10 +25,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
-#include <unistd.h>
 #include <limits.h>
 #include <sys/param.h>
-#include <sys/mman.h>
 #include <cairo.h>
 
 #include <wayland-client.h>
@@ -129,33 +127,27 @@ handle_global(struct wl_display *display, uint32_t id,
 static struct wl_buffer *
 create_shm_buffer(int width, int height, 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(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(shm, fd, size);
-	close(fd);
+	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,
 					   WL_SHM_FORMAT_XRGB8888);
-	wl_shm_pool_destroy(pool);
+	wl_shm_pool_helper_destroy(pool_helper, 0);
 
 	*data_out = data;
 
-- 
1.7.10.4



More information about the wayland-devel mailing list