2020-11-11 09:49:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
|
|
|
#include "wayland-test-client-utils.h"
|
|
|
|
|
2022-05-11 21:18:36 +00:00
|
|
|
static WaylandDisplay *display;
|
2020-11-11 09:49:25 +00:00
|
|
|
|
|
|
|
static struct wl_surface *surface;
|
|
|
|
static struct xdg_surface *xdg_surface;
|
|
|
|
static struct xdg_toplevel *xdg_toplevel;
|
|
|
|
|
|
|
|
static gboolean running;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_surface (void)
|
|
|
|
{
|
|
|
|
xdg_toplevel_set_title (xdg_toplevel, "bogus window geometry");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-05-11 21:18:36 +00:00
|
|
|
pool = wl_shm_create_pool (display->shm, fd, size);
|
2020-11-11 09:49:25 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_xdg_toplevel_configure (void *data,
|
|
|
|
struct xdg_toplevel *xdg_toplevel,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
struct wl_array *state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_xdg_toplevel_close (void *data,
|
|
|
|
struct xdg_toplevel *xdg_toplevel)
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
|
|
|
handle_xdg_toplevel_configure,
|
|
|
|
handle_xdg_toplevel_close,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_xdg_surface_configure (void *data,
|
|
|
|
struct xdg_surface *xdg_surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
2021-11-25 09:21:05 +00:00
|
|
|
static gboolean sent_invalid_once = FALSE;
|
|
|
|
|
|
|
|
if (sent_invalid_once)
|
|
|
|
return;
|
|
|
|
|
2020-11-11 09:49:25 +00:00
|
|
|
xdg_surface_set_window_geometry (xdg_surface, 0, 0, 0, 0);
|
|
|
|
draw_main ();
|
|
|
|
wl_surface_commit (surface);
|
|
|
|
|
2021-11-25 09:21:05 +00:00
|
|
|
sent_invalid_once = TRUE;
|
|
|
|
|
2022-05-11 21:18:36 +00:00
|
|
|
g_assert_cmpint (wl_display_roundtrip (display->display), !=, -1);
|
2020-11-11 09:49:25 +00:00
|
|
|
running = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
|
|
|
handle_xdg_surface_configure,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_empty_window_geometry (void)
|
|
|
|
{
|
2022-05-11 21:18:36 +00:00
|
|
|
display = wayland_display_new (WAYLAND_DISPLAY_CAPABILITY_NONE);
|
2020-11-11 09:49:25 +00:00
|
|
|
|
2022-05-11 21:18:36 +00:00
|
|
|
surface = wl_compositor_create_surface (display->compositor);
|
|
|
|
xdg_surface = xdg_wm_base_get_xdg_surface (display->xdg_wm_base, surface);
|
2020-11-11 09:49:25 +00:00
|
|
|
xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL);
|
|
|
|
xdg_toplevel = xdg_surface_get_toplevel (xdg_surface);
|
|
|
|
xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL);
|
|
|
|
|
|
|
|
init_surface ();
|
|
|
|
|
|
|
|
running = TRUE;
|
|
|
|
while (running)
|
|
|
|
{
|
2022-05-11 21:18:36 +00:00
|
|
|
if (wl_display_dispatch (display->display) == -1)
|
2020-11-11 09:49:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_pointer (&xdg_toplevel, xdg_toplevel_destroy);
|
|
|
|
g_clear_pointer (&xdg_surface, xdg_surface_destroy);
|
2022-05-11 21:18:36 +00:00
|
|
|
g_clear_pointer (&display, wayland_display_free);
|
2020-11-11 09:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
test_empty_window_geometry ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|