tests: export create_shm_buffer() helper
Lets the tests create additional buffers easily. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
8aaef7d48c
commit
32ac9b9245
@@ -264,35 +264,37 @@ static const struct wl_surface_listener surface_listener = {
|
|||||||
surface_leave
|
surface_leave
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
struct wl_buffer *
|
||||||
create_shm_buffer(struct client *client)
|
create_shm_buffer(struct client *client, int width, int height, void **pixels)
|
||||||
{
|
{
|
||||||
struct surface *surface = client->surface;
|
|
||||||
struct wl_shm *shm = client->wl_shm;
|
struct wl_shm *shm = client->wl_shm;
|
||||||
|
int stride = width * 4;
|
||||||
|
int size = stride * height;
|
||||||
struct wl_shm_pool *pool;
|
struct wl_shm_pool *pool;
|
||||||
int fd, size, stride;
|
struct wl_buffer *buffer;
|
||||||
|
int fd;
|
||||||
stride = surface->width * 4;
|
void *data;
|
||||||
size = stride * surface->height;
|
|
||||||
|
|
||||||
fd = os_create_anonymous_file(size);
|
fd = os_create_anonymous_file(size);
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
|
|
||||||
surface->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
fd, 0);
|
if (data == MAP_FAILED) {
|
||||||
if (surface->data == MAP_FAILED) {
|
|
||||||
close(fd);
|
close(fd);
|
||||||
assert(surface->data != MAP_FAILED);
|
assert(data != MAP_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
pool = wl_shm_create_pool(shm, fd, size);
|
pool = wl_shm_create_pool(shm, fd, size);
|
||||||
surface->wl_buffer =
|
buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
|
||||||
wl_shm_pool_create_buffer(pool, 0, surface->width,
|
WL_SHM_FORMAT_ARGB8888);
|
||||||
surface->height, stride,
|
|
||||||
WL_SHM_FORMAT_ARGB8888);
|
|
||||||
wl_shm_pool_destroy(pool);
|
wl_shm_pool_destroy(pool);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
if (pixels)
|
||||||
|
*pixels = data;
|
||||||
|
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -510,7 +512,8 @@ client_create(int x, int y, int width, int height)
|
|||||||
|
|
||||||
surface->width = width;
|
surface->width = width;
|
||||||
surface->height = height;
|
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);
|
memset(surface->data, 64, width * height * 4);
|
||||||
wl_surface_attach(surface->wl_surface, surface->wl_buffer, 0, 0);
|
wl_surface_attach(surface->wl_surface, surface->wl_buffer, 0, 0);
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ struct surface {
|
|||||||
struct client *
|
struct client *
|
||||||
client_create(int x, int y, int width, int height);
|
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
|
int
|
||||||
surface_contains(struct surface *surface, int x, int y);
|
surface_contains(struct surface *surface, int x, int y);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user