tests/shell: get rid of static variables

Stop using static variables and clean up when we're done.

[Emilio: update to latest weston_layer API]

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
Reviewed-by: Micah Fedke <micah.fedke@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
[Pekka: fix build after previous commit's fix]
dev
Pekka Paalanen 8 years ago
parent 642bcaf387
commit 7bcec20cc3
  1. 132
      tests/weston-test-desktop-shell.c

@ -45,58 +45,62 @@
#define static_assert(cond, msg) #define static_assert(cond, msg)
#endif #endif
static struct weston_desktop *desktop = NULL; struct desktest_shell {
static struct weston_layer background_layer; struct wl_listener compositor_destroy_listener;
static struct weston_surface *background_surface = NULL; struct weston_desktop *desktop;
static struct weston_view *background_view = NULL; struct weston_layer background_layer;
static struct weston_layer layer; struct weston_surface *background_surface;
static struct weston_view *view = NULL; struct weston_view *background_view;
/* struct weston_layer layer;
* libweston-desktop struct weston_view *view;
*/ };
static void static void
desktop_surface_added(struct weston_desktop_surface *desktop_surface, desktop_surface_added(struct weston_desktop_surface *desktop_surface,
void *shell) void *shell)
{ {
struct desktest_shell *dts = shell;
assert(!view); assert(!dts->view);
view = weston_desktop_surface_create_view(desktop_surface); dts->view = weston_desktop_surface_create_view(desktop_surface);
assert(view); assert(dts->view);
} }
static void static void
desktop_surface_removed(struct weston_desktop_surface *desktop_surface, desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
void *shell) void *shell)
{ {
assert(view); struct desktest_shell *dts = shell;
weston_desktop_surface_unlink_view(view); assert(dts->view);
weston_view_destroy(view);
view = NULL; weston_desktop_surface_unlink_view(dts->view);
weston_view_destroy(dts->view);
dts->view = NULL;
} }
static void static void
desktop_surface_committed(struct weston_desktop_surface *desktop_surface, desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
int32_t sx, int32_t sy, void *data) int32_t sx, int32_t sy, void *shell)
{ {
struct desktest_shell *dts = shell;
struct weston_surface *surface = struct weston_surface *surface =
weston_desktop_surface_get_surface(desktop_surface); weston_desktop_surface_get_surface(desktop_surface);
struct weston_geometry geometry = struct weston_geometry geometry =
weston_desktop_surface_get_geometry(desktop_surface); weston_desktop_surface_get_geometry(desktop_surface);
assert(view); assert(dts->view);
if (weston_surface_is_mapped(surface)) if (weston_surface_is_mapped(surface))
return; return;
surface->is_mapped = true; surface->is_mapped = true;
weston_layer_entry_insert(&layer.view_list, &view->layer_link); weston_layer_entry_insert(&dts->layer.view_list, &dts->view->layer_link);
weston_view_set_position(view, 0 - geometry.x, 0 - geometry.y); weston_view_set_position(dts->view, 0 - geometry.x, 0 - geometry.y);
weston_view_update_transform(view); weston_view_update_transform(dts->view);
view->is_mapped = true; dts->view->is_mapped = true;
} }
static void static void
@ -157,42 +161,74 @@ static const struct weston_desktop_api shell_desktop_api = {
.pong = desktop_surface_pong, .pong = desktop_surface_pong,
}; };
/* ************************ * static void
* end of libweston-desktop * shell_destroy(struct wl_listener *listener, void *data)
* ************************ */ {
struct desktest_shell *dts;
dts = container_of(listener, struct desktest_shell,
compositor_destroy_listener);
weston_desktop_destroy(dts->desktop);
weston_view_destroy(dts->background_view);
weston_surface_destroy(dts->background_surface);
free(dts);
}
WL_EXPORT int WL_EXPORT int
wet_shell_init(struct weston_compositor *ec, wet_shell_init(struct weston_compositor *ec,
int *argc, char *argv[]) int *argc, char *argv[])
{ {
weston_layer_init(&layer, ec); struct desktest_shell *dts;
weston_layer_init(&background_layer, ec);
dts = zalloc(sizeof *dts);
if (!dts)
return -1;
dts->compositor_destroy_listener.notify = shell_destroy;
wl_signal_add(&ec->destroy_signal, &dts->compositor_destroy_listener);
weston_layer_set_position(&layer, weston_layer_init(&dts->layer, ec);
weston_layer_init(&dts->background_layer, ec);
weston_layer_set_position(&dts->layer,
WESTON_LAYER_POSITION_NORMAL); WESTON_LAYER_POSITION_NORMAL);
weston_layer_set_position(&background_layer, weston_layer_set_position(&dts->background_layer,
WESTON_LAYER_POSITION_BACKGROUND); WESTON_LAYER_POSITION_BACKGROUND);
background_surface = weston_surface_create(ec); dts->background_surface = weston_surface_create(ec);
if (background_surface == NULL) if (dts->background_surface == NULL)
return -1; goto out_free;
background_view = weston_view_create(background_surface);
if (background_view == NULL) { dts->background_view = weston_view_create(dts->background_surface);
weston_surface_destroy(background_surface); if (dts->background_view == NULL)
return -1; goto out_surface;
}
weston_surface_set_color(dts->background_surface, 0.0, 0.0, 0.0, 1);
pixman_region32_fini(&dts->background_surface->opaque);
pixman_region32_init_rect(&dts->background_surface->opaque, 0, 0, 2000, 2000);
pixman_region32_fini(&dts->background_surface->input);
pixman_region32_init_rect(&dts->background_surface->input, 0, 0, 2000, 2000);
weston_surface_set_color(background_surface, 0.0, 0.0, 0.0, 1); weston_surface_set_size(dts->background_surface, 2000, 2000);
pixman_region32_fini(&background_surface->opaque); weston_view_set_position(dts->background_view, 0, 0);
pixman_region32_init_rect(&background_surface->opaque, 0, 0, 2000, 2000); weston_layer_entry_insert(&dts->background_layer.view_list, &dts->background_view->layer_link);
pixman_region32_fini(&background_surface->input); weston_view_update_transform(dts->background_view);
pixman_region32_init_rect(&background_surface->input, 0, 0, 2000, 2000);
weston_surface_set_size(background_surface, 2000, 2000); dts->desktop = weston_desktop_create(ec, &shell_desktop_api, dts);
weston_view_set_position(background_view, 0, 0); if (dts->desktop == NULL)
weston_layer_entry_insert(&background_layer.view_list, &background_view->layer_link); goto out_view;
weston_view_update_transform(background_view);
desktop = weston_desktop_create(ec, &shell_desktop_api, NULL); return 0;
return desktop ? 0 : -1;
out_view:
weston_view_destroy(dts->background_view);
out_surface:
weston_surface_destroy(dts->background_surface);
out_free:
free(dts);
return -1;
} }

Loading…
Cancel
Save