[mutter] tests/wayland: Draw surface with shared helper
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] tests/wayland: Draw surface with shared helper
- Date: Tue, 17 May 2022 08:41:42 +0000 (UTC)
commit f64259ceae6e4f451c6d8816fc49a7ec21e96b85
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Thu May 12 00:11:14 2022 +0200
tests/wayland: Draw surface with shared helper
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2416>
.../invalid-xdg-shell-actions.c | 99 +-------------------
.../subsurface-parent-unmapped.c | 103 +--------------------
.../subsurface-remap-toplevel.c | 101 +-------------------
.../wayland-test-clients/subsurface-reparenting.c | 101 +-------------------
.../wayland-test-client-utils.c | 98 ++++++++++++++++++++
.../wayland-test-client-utils.h | 6 ++
src/tests/wayland-test-clients/xdg-activation.c | 99 +-------------------
src/tests/wayland-test-clients/xdg-apply-limits.c | 101 +-------------------
.../wayland-test-clients/xdg-toplevel-bounds.c | 99 +-------------------
9 files changed, 116 insertions(+), 691 deletions(-)
---
diff --git a/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c
b/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c
index adcca9567b..bd75dc9957 100644
--- a/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c
+++ b/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c
@@ -18,8 +18,6 @@
#include "config.h"
#include <glib.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include <wayland-client.h>
#include "wayland-test-client-utils.h"
@@ -39,105 +37,10 @@ init_surface (void)
wl_surface_commit (surface);
}
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (void)
{
- draw (surface, 700, 500, 0xff00ff00);
+ draw_surface (display, surface, 700, 500, 0xff00ff00);
}
static void
diff --git a/src/tests/wayland-test-clients/subsurface-parent-unmapped.c
b/src/tests/wayland-test-clients/subsurface-parent-unmapped.c
index ccb61e4adf..8dcf040b4d 100644
--- a/src/tests/wayland-test-clients/subsurface-parent-unmapped.c
+++ b/src/tests/wayland-test-clients/subsurface-parent-unmapped.c
@@ -19,8 +19,6 @@
#include <glib.h>
#include <linux/input-event-codes.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include <wayland-client.h>
#include "wayland-test-client-utils.h"
@@ -41,117 +39,22 @@ static struct xdg_popup *xdg_popup;
static struct wl_surface *subsurface_surface;
static struct wl_subsurface *subsurface;
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (void)
{
- draw (toplevel_surface, 200, 200, 0xff00ffff);
+ draw_surface (display, toplevel_surface, 200, 200, 0xff00ffff);
}
static void
draw_popup (void)
{
- draw (popup_surface, 100, 100, 0xff005500);
+ draw_surface (display, popup_surface, 100, 100, 0xff005500);
}
static void
draw_subsurface (void)
{
- draw (subsurface_surface, 100, 50, 0xff001f00);
+ draw_surface (display, subsurface_surface, 100, 50, 0xff001f00);
}
static void
diff --git a/src/tests/wayland-test-clients/subsurface-remap-toplevel.c
b/src/tests/wayland-test-clients/subsurface-remap-toplevel.c
index 5fd958c0b5..e23aacabb6 100644
--- a/src/tests/wayland-test-clients/subsurface-remap-toplevel.c
+++ b/src/tests/wayland-test-clients/subsurface-remap-toplevel.c
@@ -18,8 +18,6 @@
#include "config.h"
#include <glib.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include <wayland-client.h>
#include "wayland-test-client-utils.h"
@@ -87,111 +85,16 @@ reset_surface (void)
state = STATE_WAIT_FOR_ACTOR_DESTROYED;
}
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (void)
{
- draw (surface, 700, 500, 0xff00ff00);
+ draw_surface (display, surface, 700, 500, 0xff00ff00);
}
static void
draw_subsurface (void)
{
- draw (subsurface_surface, 500, 300, 0xff007f00);
+ draw_surface (display, subsurface_surface, 500, 300, 0xff007f00);
}
static void
diff --git a/src/tests/wayland-test-clients/subsurface-reparenting.c
b/src/tests/wayland-test-clients/subsurface-reparenting.c
index 8ab5f6a9df..f537e07277 100644
--- a/src/tests/wayland-test-clients/subsurface-reparenting.c
+++ b/src/tests/wayland-test-clients/subsurface-reparenting.c
@@ -19,8 +19,6 @@
#include "config.h"
#include <glib.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include <wayland-client.h>
#include "wayland-test-client-utils.h"
@@ -51,111 +49,16 @@ static State state;
static void init_surfaces (void);
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (void)
{
- draw (surface, 700, 500, 0xff00ff00);
+ draw_surface (display, surface, 700, 500, 0xff00ff00);
}
static void
draw_subsurface (void)
{
- draw (subsurface_surface, 500, 300, 0xff007f00);
+ draw_surface (display, subsurface_surface, 500, 300, 0xff007f00);
}
static void
diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c
b/src/tests/wayland-test-clients/wayland-test-client-utils.c
index 8e2d776f51..64468e7ff5 100644
--- a/src/tests/wayland-test-clients/wayland-test-client-utils.c
+++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c
@@ -27,6 +27,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <sys/mman.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
@@ -249,3 +250,100 @@ static void
wayland_display_init (WaylandDisplay *display)
{
}
+
+static void
+handle_buffer_release (void *data,
+ struct wl_buffer *buffer)
+{
+ wl_buffer_destroy (buffer);
+}
+
+static const struct wl_buffer_listener buffer_listener = {
+ handle_buffer_release
+};
+
+static gboolean
+create_shm_buffer (WaylandDisplay *display,
+ int width,
+ int height,
+ struct wl_buffer **out_buffer,
+ void **out_data,
+ int *out_size)
+{
+ struct wl_shm_pool *pool;
+ static struct wl_buffer *buffer;
+ int fd, size, stride;
+ int bytes_per_pixel;
+ void *data;
+
+ bytes_per_pixel = 4;
+ stride = width * bytes_per_pixel;
+ size = stride * height;
+
+ fd = create_anonymous_file (size);
+ if (fd < 0)
+ {
+ fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
+ size);
+ return FALSE;
+ }
+
+ 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 FALSE;
+ }
+
+ pool = wl_shm_create_pool (display->shm, fd, size);
+ buffer = wl_shm_pool_create_buffer (pool, 0,
+ width, height,
+ stride,
+ WL_SHM_FORMAT_ARGB8888);
+ wl_buffer_add_listener (buffer, &buffer_listener, buffer);
+ wl_shm_pool_destroy (pool);
+ close (fd);
+
+ *out_buffer = buffer;
+ *out_data = data;
+ *out_size = size;
+
+ return TRUE;
+}
+
+static void
+fill (void *buffer_data,
+ int width,
+ int height,
+ uint32_t color)
+{
+ uint32_t *pixels = buffer_data;
+ int x, y;
+
+ for (y = 0; y < height; y++)
+ {
+ for (x = 0; x < width; x++)
+ pixels[y * width + x] = color;
+ }
+}
+
+void
+draw_surface (WaylandDisplay *display,
+ struct wl_surface *surface,
+ int width,
+ int height,
+ uint32_t color)
+{
+ struct wl_buffer *buffer;
+ void *buffer_data;
+ int size;
+
+ if (!create_shm_buffer (display, width, height,
+ &buffer, &buffer_data, &size))
+ g_error ("Failed to create shm buffer");
+
+ fill (buffer_data, width, height, color);
+
+ wl_surface_attach (surface, buffer, 0, 0);
+}
diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.h
b/src/tests/wayland-test-clients/wayland-test-client-utils.h
index afbf8b1c2b..9a6acbc04b 100644
--- a/src/tests/wayland-test-clients/wayland-test-client-utils.h
+++ b/src/tests/wayland-test-clients/wayland-test-client-utils.h
@@ -38,4 +38,10 @@ int create_anonymous_file (off_t size);
WaylandDisplay * wayland_display_new (WaylandDisplayCapabilities capabilities);
+void draw_surface (WaylandDisplay *display,
+ struct wl_surface *surface,
+ int width,
+ int height,
+ uint32_t color);
+
#endif /* WAYLAND_TEST_CLIENT_UTILS_H */
diff --git a/src/tests/wayland-test-clients/xdg-activation.c b/src/tests/wayland-test-clients/xdg-activation.c
index 05bbed354d..a1e78758f9 100644
--- a/src/tests/wayland-test-clients/xdg-activation.c
+++ b/src/tests/wayland-test-clients/xdg-activation.c
@@ -18,8 +18,6 @@
#include "config.h"
#include <glib.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include <wayland-client.h>
#include "wayland-test-client-utils.h"
@@ -44,105 +42,10 @@ init_surface (const char *token)
wl_surface_commit (surface);
}
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (void)
{
- draw (surface, 700, 500, 0xff00ff00);
+ draw_surface (display, surface, 700, 500, 0xff00ff00);
}
static void
diff --git a/src/tests/wayland-test-clients/xdg-apply-limits.c
b/src/tests/wayland-test-clients/xdg-apply-limits.c
index 1d54cf76fc..c386af2833 100644
--- a/src/tests/wayland-test-clients/xdg-apply-limits.c
+++ b/src/tests/wayland-test-clients/xdg-apply-limits.c
@@ -18,8 +18,6 @@
#include "config.h"
#include <glib.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include "wayland-test-client-utils.h"
@@ -90,111 +88,16 @@ reset_surface (void)
state = STATE_WAIT_FOR_ACTOR_DESTROYED;
}
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (void)
{
- draw (surface, 700, 500, 0xff00ff00);
+ draw_surface (display, surface, 700, 500, 0xff00ff00);
}
static void
draw_subsurface (void)
{
- draw (subsurface_surface, 500, 300, 0xff007f00);
+ draw_surface (display, subsurface_surface, 500, 300, 0xff007f00);
}
static void
diff --git a/src/tests/wayland-test-clients/xdg-toplevel-bounds.c
b/src/tests/wayland-test-clients/xdg-toplevel-bounds.c
index e3208e4323..861ae515b1 100644
--- a/src/tests/wayland-test-clients/xdg-toplevel-bounds.c
+++ b/src/tests/wayland-test-clients/xdg-toplevel-bounds.c
@@ -18,8 +18,6 @@
#include "config.h"
#include <glib.h>
-#include <sys/mman.h>
-#include <unistd.h>
#include <wayland-client.h>
#include "wayland-test-client-utils.h"
@@ -52,106 +50,11 @@ init_surface (void)
wl_surface_commit (surface);
}
-static void
-handle_buffer_release (void *data,
- struct wl_buffer *buffer)
-{
- wl_buffer_destroy (buffer);
-}
-
-static const struct wl_buffer_listener buffer_listener = {
- handle_buffer_release
-};
-
-static gboolean
-create_shm_buffer (int width,
- int height,
- struct wl_buffer **out_buffer,
- void **out_data,
- int *out_size)
-{
- struct wl_shm_pool *pool;
- static struct wl_buffer *buffer;
- int fd, size, stride;
- int bytes_per_pixel;
- void *data;
-
- bytes_per_pixel = 4;
- stride = width * bytes_per_pixel;
- size = stride * height;
-
- fd = create_anonymous_file (size);
- if (fd < 0)
- {
- fprintf (stderr, "Creating a buffer file for %d B failed: %m\n",
- size);
- return FALSE;
- }
-
- 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 FALSE;
- }
-
- pool = wl_shm_create_pool (display->shm, fd, size);
- buffer = wl_shm_pool_create_buffer (pool, 0,
- width, height,
- stride,
- WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener (buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy (pool);
- close (fd);
-
- *out_buffer = buffer;
- *out_data = data;
- *out_size = size;
-
- return TRUE;
-}
-
-static void
-fill (void *buffer_data,
- int width,
- int height,
- uint32_t color)
-{
- uint32_t *pixels = buffer_data;
- int x, y;
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- pixels[y * width + x] = color;
- }
-}
-
-static void
-draw (struct wl_surface *surface,
- int width,
- int height,
- uint32_t color)
-{
- struct wl_buffer *buffer;
- void *buffer_data;
- int size;
-
- if (!create_shm_buffer (width, height,
- &buffer, &buffer_data, &size))
- g_error ("Failed to create shm buffer");
-
- fill (buffer_data, width, height, color);
-
- wl_surface_attach (surface, buffer, 0, 0);
-}
-
static void
draw_main (int width,
int height)
{
- draw (surface, width, height, 0xff00ff00);
+ draw_surface (display, surface, width, height, 0xff00ff00);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]