From c27fd1e1ee9826ea0668d2bb5aa8644daec29a7f Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 9 Mar 2018 10:29:22 +0100 Subject: rootston: add view_map and view_unmap --- rootston/desktop.c | 58 ++++++++++++++++++++++++++++++++++--------------- rootston/wl_shell.c | 10 +++------ rootston/xdg_shell.c | 11 +++------- rootston/xdg_shell_v6.c | 11 +++------- rootston/xwayland.c | 43 +++++------------------------------- 5 files changed, 55 insertions(+), 78 deletions(-) (limited to 'rootston') diff --git a/rootston/desktop.c b/rootston/desktop.c index 3628b051..66c7ac2b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -23,13 +23,15 @@ #include "rootston/view.h" #include "rootston/xcursor.h" - -struct roots_view *view_create() { +struct roots_view *view_create(struct roots_desktop *desktop) { struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { return NULL; } + view->desktop = desktop; view->alpha = 1.0f; + wl_signal_init(&view->events.destroy); + wl_list_init(&view->children); return view; } @@ -402,20 +404,18 @@ struct roots_subsurface *subsurface_create(struct roots_view *view, return subsurface; } -void view_finish(struct roots_view *view) { - view_damage_whole(view); - wl_signal_emit(&view->events.destroy, view); - - wl_list_remove(&view->new_subsurface.link); - - struct roots_view_child *child, *tmp; - wl_list_for_each_safe(child, tmp, &view->children, link) { - child->destroy(child); +void view_destroy(struct roots_view *view) { + if (view == NULL) { + return; } - if (view->fullscreen_output) { - view->fullscreen_output->fullscreen_view = NULL; + if (view->wlr_surface != NULL) { + view_unmap(view); } + + wl_signal_emit(&view->events.destroy, view); + + free(view); } static void view_handle_new_subsurface(struct wl_listener *listener, @@ -425,12 +425,10 @@ static void view_handle_new_subsurface(struct wl_listener *listener, subsurface_create(view, wlr_subsurface); } -void view_init(struct roots_view *view, struct roots_desktop *desktop) { - assert(view->wlr_surface); +void view_map(struct roots_view *view, struct wlr_surface *surface) { + assert(view->wlr_surface == NULL); - view->desktop = desktop; - wl_signal_init(&view->events.destroy); - wl_list_init(&view->children); + view->wlr_surface = surface; struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list, @@ -442,7 +440,31 @@ void view_init(struct roots_view *view, struct roots_desktop *desktop) { wl_signal_add(&view->wlr_surface->events.new_subsurface, &view->new_subsurface); + wl_list_insert(&view->desktop->views, &view->link); + view_damage_whole(view); +} + +void view_unmap(struct roots_view *view) { + assert(view->wlr_surface != NULL); + view_damage_whole(view); + wl_list_remove(&view->link); + + wl_list_remove(&view->new_subsurface.link); + + struct roots_view_child *child, *tmp; + wl_list_for_each_safe(child, tmp, &view->children, link) { + child->destroy(child); + } + + if (view->fullscreen_output != NULL) { + output_damage_whole(view->fullscreen_output); + view->fullscreen_output->fullscreen_view = NULL; + view->fullscreen_output = NULL; + } + + view->wlr_surface = NULL; + view->width = view->height = 0; } void view_initial_focus(struct roots_view *view) { diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 899df1c6..6326d9d7 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -181,9 +181,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->request_fullscreen.link); wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->surface_commit.link); - wl_list_remove(&roots_surface->view->link); - view_finish(roots_surface->view); - free(roots_surface->view); + view_destroy(roots_surface->view); free(roots_surface); } @@ -227,7 +225,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (!view) { free(roots_surface); return; @@ -238,13 +236,11 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->wl_shell_surface = surface; view->roots_wl_shell_surface = roots_surface; - view->wlr_surface = surface->surface; view->resize = resize; view->close = close; roots_surface->view = view; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); + view_map(view, surface->surface); view_setup(view); if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) { diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 9368ce0b..1733eb4e 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -287,9 +287,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); wl_list_remove(&roots_xdg_surface->request_fullscreen.link); - wl_list_remove(&roots_xdg_surface->view->link); - view_finish(roots_xdg_surface->view); - free(roots_xdg_surface->view); + view_destroy(roots_xdg_surface->view); free(roots_xdg_surface); } @@ -333,7 +331,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (!view) { free(roots_surface); return; @@ -342,7 +340,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->xdg_surface = surface; view->roots_xdg_surface = roots_surface; - view->wlr_surface = surface->surface; view->activate = activate; view->resize = resize; view->move_resize = move_resize; @@ -356,8 +353,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->width = box.width; view->height = box.height; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); - + view_map(view, surface->surface); view_setup(view); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index eda349cb..c49bd911 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -287,9 +287,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); wl_list_remove(&roots_xdg_surface->request_fullscreen.link); - wl_list_remove(&roots_xdg_surface->view->link); - view_finish(roots_xdg_surface->view); - free(roots_xdg_surface->view); + view_destroy(roots_xdg_surface->view); free(roots_xdg_surface); } @@ -333,7 +331,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (!view) { free(roots_surface); return; @@ -342,7 +340,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->xdg_surface_v6 = surface; view->roots_xdg_surface_v6 = roots_surface; - view->wlr_surface = surface->surface; view->activate = activate; view->resize = resize; view->move_resize = move_resize; @@ -356,8 +353,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->width = box.width; view->height = box.height; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); - + view_map(view, surface->surface); view_setup(view); } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 56f068ea..f95e5f81 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -109,8 +109,6 @@ static void set_fullscreen(struct roots_view *view, bool fullscreen) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); - struct wlr_xwayland_surface *xwayland_surface = - roots_surface->view->xwayland_surface; wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_configure.link); wl_list_remove(&roots_surface->request_move.link); @@ -118,11 +116,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->request_maximize.link); wl_list_remove(&roots_surface->map_notify.link); wl_list_remove(&roots_surface->unmap_notify.link); - if (xwayland_surface->mapped) { - wl_list_remove(&roots_surface->view->link); - } - view_finish(roots_surface->view); - free(roots_surface->view); + view_destroy(roots_surface->view); free(roots_surface); } @@ -231,22 +225,13 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_surface, map_notify); struct wlr_xwayland_surface *xsurface = data; struct roots_view *view = roots_surface->view; - struct roots_desktop *desktop = view->desktop; - view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; view->width = xsurface->surface->current->width; view->height = xsurface->surface->current->height; - wl_list_insert(&desktop->views, &view->link); - struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list, - parent_link) { - subsurface_create(view, subsurface); - } - - view_damage_whole(view); + view_map(view, xsurface->surface); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, @@ -260,22 +245,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->surface_commit.link); - view_damage_whole(view); - - struct roots_view_child *child, *tmp; - wl_list_for_each_safe(child, tmp, &view->children, link) { - child->destroy(child); - } - - if (view->fullscreen_output != NULL) { - output_damage_whole(view->fullscreen_output); - view->fullscreen_output->fullscreen_view = NULL; - view->fullscreen_output = NULL; - } - - view->wlr_surface = NULL; - view->width = view->height = 0; - wl_list_remove(&view->link); + view_unmap(view); } void handle_xwayland_surface(struct wl_listener *listener, void *data) { @@ -317,7 +287,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (view == NULL) { free(roots_surface); return; @@ -330,7 +300,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->xwayland_surface = surface; view->roots_xwayland_surface = roots_surface; - view->wlr_surface = surface->surface; view->activate = activate; view->resize = resize; view->move = move; @@ -339,8 +308,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->set_fullscreen = set_fullscreen; view->close = close; roots_surface->view = view; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); + + view_map(view, surface->surface); if (!surface->override_redirect) { if (surface->decorations == WLR_XWAYLAND_SURFACE_DECORATIONS_ALL) { -- cgit v1.2.3 From 3f072bedd98969974ec1d3e8ffd9bae4150e52d4 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 10 Mar 2018 11:18:50 +0100 Subject: xdg-shell-v6: add map signal --- include/rootston/view.h | 2 ++ include/wlr/types/wlr_xdg_shell_v6.h | 5 +++-- rootston/desktop.c | 16 ++++++++++++--- rootston/output.c | 7 ++++++- rootston/xdg_shell_v6.c | 38 ++++++++++++++++++++++++++++-------- types/wlr_xdg_shell_v6.c | 18 +++++++++++++++-- 6 files changed, 70 insertions(+), 16 deletions(-) (limited to 'rootston') diff --git a/include/rootston/view.h b/include/rootston/view.h index 66a0cb3d..0844a6da 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -27,6 +27,8 @@ struct roots_xdg_surface_v6 { struct wl_listener destroy; struct wl_listener new_popup; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 7dc746ce..959d420f 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -107,8 +107,7 @@ struct wlr_xdg_surface_v6 { struct wl_list popups; // wlr_xdg_popup_v6::link - bool configured; - bool added; + bool added, configured, mapped; uint32_t configure_serial; struct wl_event_source *configure_idle; uint32_t configure_next_serial; @@ -127,6 +126,8 @@ struct wlr_xdg_surface_v6 { struct wl_signal destroy; struct wl_signal ping_timeout; struct wl_signal new_popup; + struct wl_signal map; + struct wl_signal unmap; struct wl_signal request_maximize; struct wl_signal request_fullscreen; diff --git a/rootston/desktop.c b/rootston/desktop.c index 66c7ac2b..278f4fea 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -54,7 +54,8 @@ void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { box->height += (view->border_width * 2 + view->titlebar_height); } -enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy) { +enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, + double sy) { if (!view->decorated) { return ROOTS_DECO_PART_NONE; } @@ -94,9 +95,15 @@ enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, doub static void view_update_output(const struct roots_view *view, const struct wlr_box *before) { struct roots_desktop *desktop = view->desktop; - struct roots_output *output; + + if (view->wlr_surface == NULL) { + return; + } + struct wlr_box box; view_get_box(view, &box); + + struct roots_output *output; wl_list_for_each(output, &desktop->outputs, link) { bool intersected = before != NULL && wlr_output_layout_intersects( desktop->layout, output->wlr_output, before); @@ -479,7 +486,10 @@ void view_initial_focus(struct roots_view *view) { void view_setup(struct roots_view *view) { view_initial_focus(view); - view_center(view); + if (view->fullscreen_output == NULL) { + view_center(view); + } + view_update_output(view, NULL); } diff --git a/rootston/output.c b/rootston/output.c index 4d0a9c05..adcbb961 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -501,7 +501,9 @@ static void render_output(struct roots_output *output) { goto renderer_end; } - view_for_each_surface(view, render_surface, &data); + if (view->wlr_surface != NULL) { + view_for_each_surface(view, render_surface, &data); + } // During normal rendering the xwayland window tree isn't traversed // because all windows are rendered. Here we only want to render @@ -570,6 +572,9 @@ void output_damage_whole(struct roots_output *output) { static bool view_accept_damage(struct roots_output *output, struct roots_view *view) { + if (view->wlr_surface == NULL) { + return false; + } if (output->fullscreen_view == NULL) { return true; } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index c49bd911..4591f642 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -243,6 +243,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (!surface->mapped) { + return; + } + view_apply_damage(view); struct wlr_box size; @@ -277,6 +281,28 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { popup_create(roots_xdg_surface->view, wlr_popup); } +static void handle_map(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, map); + struct roots_view *view = roots_xdg_surface->view; + + struct wlr_box box; + get_size(view, &box); + view->width = box.width; + view->height = box.height; + + view_map(view, view->xdg_surface_v6->surface); + view_setup(view); +} + +static void handle_unmap(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, unmap); + struct roots_view *view = roots_xdg_surface->view; + + view_unmap(view); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); @@ -317,6 +343,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { &roots_surface->surface_commit); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + roots_surface->map.notify = handle_map; + wl_signal_add(&surface->events.map, &roots_surface->map); + roots_surface->unmap.notify = handle_unmap; + wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; @@ -347,12 +377,4 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->set_fullscreen = set_fullscreen; view->close = close; roots_surface->view = view; - - struct wlr_box box; - get_size(view, &box); - view->width = box.width; - view->height = box.height; - - view_map(view, surface->surface); - view_setup(view); } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index e07d78a1..18f7393d 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -481,6 +481,7 @@ static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { + // TODO: don't destroy the surface, unmap it xdg_surface_destroy(surface); } } @@ -792,6 +793,7 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { + // TODO: don't destroy the surface, unmap it xdg_surface_destroy(surface); } } @@ -1172,9 +1174,19 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, break; } - if (surface->configured && !surface->added) { + if (!surface->added) { surface->added = true; - wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + surface); + } + if (surface->configured && wlr_surface_has_buffer(surface->surface) && + !surface->mapped) { + surface->mapped = true; + wlr_signal_emit_safe(&surface->events.map, surface); + } + if (surface->configured && !wlr_surface_has_buffer(surface->surface) && + surface->mapped) { + // TODO: unmap the surface } } @@ -1249,6 +1261,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.new_popup); + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); wl_signal_add(&surface->surface->events.destroy, &surface->surface_destroy_listener); -- cgit v1.2.3 From 1f8854f2172b124572f53976b9067fc4ef33a8a1 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 09:00:59 +0100 Subject: rootston: remove xdg-shell-v6 map/unmap listeners on destroy --- rootston/xdg_shell_v6.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rootston') diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 4591f642..12e22afb 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -309,6 +309,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->surface_commit.link); wl_list_remove(&roots_xdg_surface->destroy.link); wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->map.link); + wl_list_remove(&roots_xdg_surface->unmap.link); wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); -- cgit v1.2.3 From 6ac3534df6ce1ac35932fb71584675d32507fed7 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 09:17:06 +0100 Subject: rootston: add destroy to view interface --- include/rootston/view.h | 1 + rootston/desktop.c | 4 ++++ rootston/wl_shell.c | 22 ++++++++++++++-------- rootston/xdg_shell.c | 21 +++++++++++++-------- rootston/xdg_shell_v6.c | 30 +++++++++++++++++------------- rootston/xwayland.c | 14 ++++++++++---- 6 files changed, 59 insertions(+), 33 deletions(-) (limited to 'rootston') diff --git a/include/rootston/view.h b/include/rootston/view.h index 0844a6da..1e5c0933 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -142,6 +142,7 @@ struct roots_view { void (*maximize)(struct roots_view *view, bool maximized); void (*set_fullscreen)(struct roots_view *view, bool fullscreen); void (*close)(struct roots_view *view); + void (*destroy)(struct roots_view *view); }; struct roots_view_child { diff --git a/rootston/desktop.c b/rootston/desktop.c index 278f4fea..19b7768c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -422,6 +422,10 @@ void view_destroy(struct roots_view *view) { wl_signal_emit(&view->events.destroy, view); + if (view->destroy) { + view->destroy(view); + } + free(view); } diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 6326d9d7..d58f030a 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -78,6 +78,19 @@ static void close(struct roots_view *view) { wl_client_destroy(surf->client); } +static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_WL_SHELL_VIEW); + struct roots_wl_shell_surface *roots_surface = view->roots_wl_shell_surface; + wl_list_remove(&roots_surface->destroy.link); + wl_list_remove(&roots_surface->request_move.link); + wl_list_remove(&roots_surface->request_resize.link); + wl_list_remove(&roots_surface->request_maximize.link); + wl_list_remove(&roots_surface->request_fullscreen.link); + wl_list_remove(&roots_surface->set_state.link); + wl_list_remove(&roots_surface->surface_commit.link); + free(roots_surface); +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, request_move); @@ -174,15 +187,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); - wl_list_remove(&roots_surface->destroy.link); - wl_list_remove(&roots_surface->request_move.link); - wl_list_remove(&roots_surface->request_resize.link); - wl_list_remove(&roots_surface->request_maximize.link); - wl_list_remove(&roots_surface->request_fullscreen.link); - wl_list_remove(&roots_surface->set_state.link); - wl_list_remove(&roots_surface->surface_commit.link); view_destroy(roots_surface->view); - free(roots_surface); } void handle_wl_shell_surface(struct wl_listener *listener, void *data) { @@ -238,6 +243,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->roots_wl_shell_surface = roots_surface; view->resize = resize; view->close = close; + view->destroy = destroy; roots_surface->view = view; view_map(view, surface->surface); diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 1733eb4e..24c57bd5 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -180,6 +180,18 @@ static void close(struct roots_view *view) { } } +static void destroy(struct roots_view *view) { + struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface; + wl_list_remove(&roots_xdg_surface->surface_commit.link); + wl_list_remove(&roots_xdg_surface->destroy.link); + wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->request_move.link); + wl_list_remove(&roots_xdg_surface->request_resize.link); + wl_list_remove(&roots_xdg_surface->request_maximize.link); + wl_list_remove(&roots_xdg_surface->request_fullscreen.link); + free(roots_xdg_surface); +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xdg_surface *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, request_move); @@ -280,15 +292,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); - wl_list_remove(&roots_xdg_surface->surface_commit.link); - wl_list_remove(&roots_xdg_surface->destroy.link); - wl_list_remove(&roots_xdg_surface->new_popup.link); - wl_list_remove(&roots_xdg_surface->request_move.link); - wl_list_remove(&roots_xdg_surface->request_resize.link); - wl_list_remove(&roots_xdg_surface->request_maximize.link); - wl_list_remove(&roots_xdg_surface->request_fullscreen.link); view_destroy(roots_xdg_surface->view); - free(roots_xdg_surface); } void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { @@ -346,6 +350,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->maximize = maximize; view->set_fullscreen = set_fullscreen; view->close = close; + view->destroy = destroy; roots_surface->view = view; struct wlr_box box; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 12e22afb..1f6f25eb 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -180,6 +180,21 @@ static void close(struct roots_view *view) { } } +static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct roots_xdg_surface_v6 *roots_xdg_surface = view->roots_xdg_surface_v6; + wl_list_remove(&roots_xdg_surface->surface_commit.link); + wl_list_remove(&roots_xdg_surface->destroy.link); + wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->map.link); + wl_list_remove(&roots_xdg_surface->unmap.link); + wl_list_remove(&roots_xdg_surface->request_move.link); + wl_list_remove(&roots_xdg_surface->request_resize.link); + wl_list_remove(&roots_xdg_surface->request_maximize.link); + wl_list_remove(&roots_xdg_surface->request_fullscreen.link); + free(roots_xdg_surface); +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, request_move); @@ -298,25 +313,13 @@ static void handle_map(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, unmap); - struct roots_view *view = roots_xdg_surface->view; - - view_unmap(view); + view_unmap(roots_xdg_surface->view); } static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); - wl_list_remove(&roots_xdg_surface->surface_commit.link); - wl_list_remove(&roots_xdg_surface->destroy.link); - wl_list_remove(&roots_xdg_surface->new_popup.link); - wl_list_remove(&roots_xdg_surface->map.link); - wl_list_remove(&roots_xdg_surface->unmap.link); - wl_list_remove(&roots_xdg_surface->request_move.link); - wl_list_remove(&roots_xdg_surface->request_resize.link); - wl_list_remove(&roots_xdg_surface->request_maximize.link); - wl_list_remove(&roots_xdg_surface->request_fullscreen.link); view_destroy(roots_xdg_surface->view); - free(roots_xdg_surface); } void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { @@ -378,5 +381,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->maximize = maximize; view->set_fullscreen = set_fullscreen; view->close = close; + view->destroy = destroy; roots_surface->view = view; } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index f95e5f81..53331b1f 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -106,9 +106,9 @@ static void set_fullscreen(struct roots_view *view, bool fullscreen) { wlr_xwayland_surface_set_fullscreen(view->xwayland_surface, fullscreen); } -static void handle_destroy(struct wl_listener *listener, void *data) { - struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, destroy); +static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + struct roots_xwayland_surface *roots_surface = view->roots_xwayland_surface; wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_configure.link); wl_list_remove(&roots_surface->request_move.link); @@ -116,10 +116,15 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->request_maximize.link); wl_list_remove(&roots_surface->map_notify.link); wl_list_remove(&roots_surface->unmap_notify.link); - view_destroy(roots_surface->view); free(roots_surface); } +static void handle_destroy(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, destroy); + view_destroy(roots_surface->view); +} + static void handle_request_configure(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, request_configure); @@ -307,6 +312,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->maximize = maximize; view->set_fullscreen = set_fullscreen; view->close = close; + view->destroy = destroy; roots_surface->view = view; view_map(view, surface->surface); -- cgit v1.2.3 From 42637a52cf2779ec05f0fdb97df416e21438a77b Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 10:42:41 +0100 Subject: rootston: don't segfault when getting size of an unmapped xdg-shell view --- rootston/xdg_shell_v6.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rootston') diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 1f6f25eb..c81cd16a 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -63,9 +63,11 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { if (surface->geometry->width > 0 && surface->geometry->height > 0) { box->width = surface->geometry->width; box->height = surface->geometry->height; - } else { + } else if (view->wlr_surface != NULL) { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; + } else { + box->width = box->height = 0; } } -- cgit v1.2.3 From c1c88bfe5d88b7f6330f5ce5be04ef6951123c3d Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 12:31:45 +0100 Subject: rootston: destroy seat view on unmap --- include/rootston/seat.h | 1 + include/rootston/view.h | 1 + rootston/desktop.c | 1 + rootston/seat.c | 9 +++++++++ 4 files changed, 12 insertions(+) (limited to 'rootston') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index cc0293b5..0b1dbe2d 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -39,6 +39,7 @@ struct roots_seat_view { struct wl_list link; // roots_seat::views + struct wl_listener view_unmap; struct wl_listener view_destroy; }; diff --git a/include/rootston/view.h b/include/rootston/view.h index 1e5c0933..92d1feb5 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -130,6 +130,7 @@ struct roots_view { struct wl_listener new_subsurface; struct { + struct wl_signal unmap; struct wl_signal destroy; } events; diff --git a/rootston/desktop.c b/rootston/desktop.c index 19b7768c..afe2c221 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -30,6 +30,7 @@ struct roots_view *view_create(struct roots_desktop *desktop) { } view->desktop = desktop; view->alpha = 1.0f; + wl_signal_init(&view->events.unmap); wl_signal_init(&view->events.destroy); wl_list_init(&view->children); return view; diff --git a/rootston/seat.c b/rootston/seat.c index 9acbb737..c4535c7c 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -645,6 +645,7 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) { seat->cursor->pointer_view = NULL; } + wl_list_remove(&seat_view->view_unmap.link); wl_list_remove(&seat_view->view_destroy.link); wl_list_remove(&seat_view->link); free(seat_view); @@ -657,6 +658,12 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) { } } +static void seat_view_handle_unmap(struct wl_listener *listener, void *data) { + struct roots_seat_view *seat_view = + wl_container_of(listener, seat_view, view_unmap); + seat_view_destroy(seat_view); +} + static void seat_view_handle_destroy(struct wl_listener *listener, void *data) { struct roots_seat_view *seat_view = wl_container_of(listener, seat_view, view_destroy); @@ -675,6 +682,8 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat, wl_list_insert(seat->views.prev, &seat_view->link); + seat_view->view_unmap.notify = seat_view_handle_unmap; + wl_signal_add(&view->events.unmap, &seat_view->view_unmap); seat_view->view_destroy.notify = seat_view_handle_destroy; wl_signal_add(&view->events.destroy, &seat_view->view_destroy); -- cgit v1.2.3 From 125138f1a0448927c26c0f8a2761fed2df09b6ad Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 12:34:29 +0100 Subject: rootston: unmap view after emitting destroy signal in view_destroy --- rootston/desktop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rootston') diff --git a/rootston/desktop.c b/rootston/desktop.c index afe2c221..b1e6f874 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -417,12 +417,12 @@ void view_destroy(struct roots_view *view) { return; } + wl_signal_emit(&view->events.destroy, view); + if (view->wlr_surface != NULL) { view_unmap(view); } - wl_signal_emit(&view->events.destroy, view); - if (view->destroy) { view->destroy(view); } -- cgit v1.2.3 From e74ddaaf10f1c8078cf078f55428b9e86776ca93 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 19:57:21 +0100 Subject: xdg-shell-v6: redesign the configure/ack_configure workflow --- include/wlr/types/wlr_xdg_shell_v6.h | 23 ++++++++-------------- rootston/output.c | 3 ++- rootston/xdg_shell_v6.c | 7 +++++++ types/wlr_xdg_shell_v6.c | 38 +++++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 30 deletions(-) (limited to 'rootston') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 959d420f..86a42181 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -62,19 +62,10 @@ enum wlr_xdg_surface_v6_role { }; struct wlr_xdg_toplevel_v6_state { - bool maximized; - bool fullscreen; - bool resizing; - bool activated; - - uint32_t width; - uint32_t height; - - uint32_t max_width; - uint32_t max_height; - - uint32_t min_width; - uint32_t min_height; + bool maximized, fullscreen, resizing, activated; + uint32_t width, height; + uint32_t max_width, max_height; + uint32_t min_width, min_height; }; struct wlr_xdg_toplevel_v6 { @@ -90,7 +81,8 @@ struct wlr_xdg_toplevel_v6 { struct wlr_xdg_surface_v6_configure { struct wl_list link; // wlr_xdg_surface_v6::configure_list uint32_t serial; - struct wlr_xdg_toplevel_v6_state state; + + struct wlr_xdg_toplevel_v6_state toplevel_state; // TODO: should be null-able }; struct wlr_xdg_surface_v6 { @@ -100,6 +92,7 @@ struct wlr_xdg_surface_v6 { struct wl_list link; // wlr_xdg_client_v6::surfaces enum wlr_xdg_surface_v6_role role; + // TODO: the _state prefix should be dropped union { struct wlr_xdg_toplevel_v6 *toplevel_state; struct wlr_xdg_popup_v6 *popup_state; @@ -118,7 +111,7 @@ struct wlr_xdg_surface_v6 { bool has_next_geometry; struct wlr_box *next_geometry; - struct wlr_box *geometry; + struct wlr_box *geometry; // TODO: should not be a pointer struct wl_listener surface_destroy_listener; diff --git a/rootston/output.c b/rootston/output.c index adcbb961..f772ea24 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -433,7 +433,8 @@ static void render_output(struct roots_output *output) { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; // Check if we can delegate the fullscreen surface to the output - if (output->fullscreen_view != NULL) { + if (output->fullscreen_view != NULL && + output->fullscreen_view->wlr_surface != NULL) { struct roots_view *view = output->fullscreen_view; // Make sure the view is centered on screen diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index c81cd16a..84c76d16 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -385,4 +385,11 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->close = close; view->destroy = destroy; roots_surface->view = view; + + if (surface->toplevel_state->next.maximized) { + view_maximize(view, true); + } + if (surface->toplevel_state->next.fullscreen) { + view_set_fullscreen(view, true, NULL); + } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 5da25f62..8c2e9d58 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -868,9 +868,15 @@ static void wlr_xdg_toplevel_v6_ack_configure( struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->next = configure->state; - surface->toplevel_state->pending.width = 0; - surface->toplevel_state->pending.height = 0; + + surface->toplevel_state->current.maximized = + configure->toplevel_state.maximized; + surface->toplevel_state->current.fullscreen = + configure->toplevel_state.fullscreen; + surface->toplevel_state->current.resizing = + configure->toplevel_state.resizing; + surface->toplevel_state->current.activated = + configure->toplevel_state.activated; } static void xdg_surface_handle_ack_configure(struct wl_client *client, @@ -982,9 +988,9 @@ static bool wlr_xdg_surface_v6_toplevel_state_compare( } else { struct wlr_xdg_surface_v6_configure *configure = wl_container_of(state->base->configure_list.prev, configure, link); - configured.state = configure->state; - configured.width = configure->state.width; - configured.height = configure->state.height; + configured.state = configure->toplevel_state; + configured.width = configure->toplevel_state.width; + configured.height = configure->toplevel_state.height; } if (state->pending.activated != configured.state.activated) { @@ -1019,7 +1025,7 @@ static void wlr_xdg_toplevel_v6_send_configure( uint32_t *s; struct wl_array states; - configure->state = surface->toplevel_state->pending; + configure->toplevel_state = surface->toplevel_state->pending; wl_array_init(&states); if (surface->toplevel_state->pending.maximized) { @@ -1160,8 +1166,7 @@ static void wlr_xdg_surface_v6_toplevel_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - if (!wlr_surface_has_buffer(surface->surface) - && !surface->toplevel_state->added) { + if (!surface->toplevel_state->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_v6_schedule_configure(surface); @@ -1169,11 +1174,15 @@ static void wlr_xdg_surface_v6_toplevel_committed( return; } - if (!wlr_surface_has_buffer(surface->surface)) { - return; - } - - surface->toplevel_state->current = surface->toplevel_state->next; + // update state that doesn't need compositor approval + surface->toplevel_state->current.max_width = + surface->toplevel_state->next.max_width; + surface->toplevel_state->current.min_width = + surface->toplevel_state->next.min_width; + surface->toplevel_state->current.max_height = + surface->toplevel_state->next.max_height; + surface->toplevel_state->current.min_height = + surface->toplevel_state->next.min_height; } static void wlr_xdg_surface_v6_popup_committed( @@ -1482,6 +1491,7 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); surface->toplevel_state->pending.width = width; surface->toplevel_state->pending.height = height; + wlr_log(L_DEBUG, "wlr_xdg_toplevel_v6_set_size %d", width); return wlr_xdg_surface_v6_schedule_configure(surface); } -- cgit v1.2.3 From 149209b72ed069f3c6026e6bf7ffb4ffff0de190 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 22:09:44 +0100 Subject: xdg-shell-v6: rename toplevel and popup fields in wlr_xdg_surface_v6 for consistency --- include/wlr/types/wlr_xdg_shell_v6.h | 5 +- rootston/xdg_shell_v6.c | 8 +- types/wlr_xdg_shell_v6.c | 172 +++++++++++++++++------------------ 3 files changed, 92 insertions(+), 93 deletions(-) (limited to 'rootston') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 9140fa64..2358feec 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -92,10 +92,9 @@ struct wlr_xdg_surface_v6 { struct wl_list link; // wlr_xdg_client_v6::surfaces enum wlr_xdg_surface_v6_role role; - // TODO: the _state prefix should be dropped union { - struct wlr_xdg_toplevel_v6 *toplevel_state; - struct wlr_xdg_popup_v6 *popup_state; + struct wlr_xdg_toplevel_v6 *toplevel; + struct wlr_xdg_popup_v6 *popup; }; struct wl_list popups; // wlr_xdg_popup_v6::link diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 84c76d16..59637105 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -85,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface, *dest_width = width; *dest_height = height; - struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current; + struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel->current; if (width < state->min_width) { *dest_width = state->min_width; } else if (state->max_width > 0 && @@ -236,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { return; } - view_maximize(view, surface->toplevel_state->next.maximized); + view_maximize(view, surface->toplevel->next.maximized); } static void handle_request_fullscreen(struct wl_listener *listener, @@ -386,10 +386,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->destroy = destroy; roots_surface->view = view; - if (surface->toplevel_state->next.maximized) { + if (surface->toplevel->next.maximized) { view_maximize(view, true); } - if (surface->toplevel_state->next.fullscreen) { + if (surface->toplevel->next.fullscreen) { view_set_fullscreen(view, true, NULL); } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 5ea1fb8b..214f818c 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -166,20 +166,20 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { wlr_signal_emit_safe(&surface->events.unmap, surface); if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wl_resource_set_user_data(surface->toplevel_state->resource, NULL); - free(surface->toplevel_state); - surface->toplevel_state = NULL; + wl_resource_set_user_data(surface->toplevel->resource, NULL); + free(surface->toplevel); + surface->toplevel = NULL; } if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { - wl_resource_set_user_data(surface->popup_state->resource, NULL); + wl_resource_set_user_data(surface->popup->resource, NULL); - if (surface->popup_state->seat) { + if (surface->popup->seat) { struct wlr_xdg_popup_grab_v6 *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup_state->seat); + surface->popup->seat); - wl_list_remove(&surface->popup_state->grab_link); + wl_list_remove(&surface->popup->grab_link); if (wl_list_empty(&grab->popups)) { if (grab->seat->pointer_state.grab == &grab->pointer_grab) { @@ -191,9 +191,9 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { } } - wl_list_remove(&surface->popup_state->link); - free(surface->popup_state); - surface->popup_state = NULL; + wl_list_remove(&surface->popup->link); + free(surface->popup); + surface->popup = NULL; } surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; @@ -452,8 +452,8 @@ static void xdg_popup_handle_grab(struct wl_client *client, struct wlr_seat_client *seat_client = wlr_seat_client_from_resource(seat_resource); - if (surface->popup_state->committed) { - wl_resource_post_error(surface->popup_state->resource, + if (surface->popup->committed) { + wl_resource_post_error(surface->popup->resource, ZXDG_POPUP_V6_ERROR_INVALID_GRAB, "xdg_popup is already mapped"); return; @@ -465,10 +465,10 @@ static void xdg_popup_handle_grab(struct wl_client *client, struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(popup_grab); bool parent_is_toplevel = - surface->popup_state->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; + surface->popup->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; if ((topmost == NULL && !parent_is_toplevel) || - (topmost != NULL && topmost != surface->popup_state->parent)) { + (topmost != NULL && topmost != surface->popup->parent)) { wl_resource_post_error(surface->client->resource, ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, "xdg_popup was not created on the topmost popup"); @@ -476,9 +476,9 @@ static void xdg_popup_handle_grab(struct wl_client *client, } popup_grab->client = surface->client->client; - surface->popup_state->seat = seat_client->seat; + surface->popup->seat = seat_client->seat; - wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link); + wl_list_insert(&popup_grab->popups, &surface->popup->grab_link); wlr_seat_pointer_start_grab(seat_client->seat, &popup_grab->pointer_grab); @@ -492,7 +492,7 @@ static void xdg_popup_handle_destroy(struct wl_client *client, xdg_surface_from_xdg_popup_resource(resource); struct wlr_xdg_popup_grab_v6 *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup_state->seat); + surface->popup->seat); struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(grab); @@ -552,33 +552,33 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, return; } - surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6)); - if (!surface->popup_state) { + surface->popup = calloc(1, sizeof(struct wlr_xdg_popup_v6)); + if (!surface->popup) { wl_resource_post_no_memory(resource); return; } - surface->popup_state->resource = + surface->popup->resource = wl_resource_create(client, &zxdg_popup_v6_interface, wl_resource_get_version(resource), id); - if (surface->popup_state->resource == NULL) { - free(surface->popup_state); + if (surface->popup->resource == NULL) { + free(surface->popup); wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_V6_ROLE_POPUP; - surface->popup_state->base = surface; - surface->popup_state->parent = parent; - surface->popup_state->geometry = + surface->popup->base = surface; + surface->popup->parent = parent; + surface->popup->geometry = xdg_positioner_get_geometry(positioner, surface, parent); - wl_list_insert(&parent->popups, &surface->popup_state->link); + wl_list_insert(&parent->popups, &surface->popup->link); - wl_resource_set_implementation(surface->popup_state->resource, + wl_resource_set_implementation(surface->popup->resource, &zxdg_popup_v6_implementation, surface, xdg_popup_resource_destroy); - wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state); + wlr_signal_emit_safe(&parent->events.new_popup, surface->popup); } @@ -601,7 +601,7 @@ static void xdg_toplevel_handle_set_parent(struct wl_client *client, parent = xdg_surface_from_xdg_toplevel_resource(parent_resource); } - surface->toplevel_state->parent = parent; + surface->toplevel->parent = parent; } static void xdg_toplevel_handle_set_title(struct wl_client *client, @@ -641,7 +641,7 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -672,7 +672,7 @@ static void xdg_toplevel_handle_move(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -701,7 +701,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -726,23 +726,23 @@ static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.max_width = width; - surface->toplevel_state->next.max_height = height; + surface->toplevel->next.max_width = width; + surface->toplevel->next.max_height = height; } static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.min_width = width; - surface->toplevel_state->next.min_height = height; + surface->toplevel->next.min_width = width; + surface->toplevel->next.min_height = height; } static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = true; + surface->toplevel->next.maximized = true; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } @@ -750,7 +750,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = false; + surface->toplevel->next.maximized = false; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } @@ -764,7 +764,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, output = wlr_output_from_resource(output_resource); } - surface->toplevel_state->next.fullscreen = true; + surface->toplevel->next.fullscreen = true; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { .surface = surface, @@ -780,7 +780,7 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.fullscreen = false; + surface->toplevel->next.fullscreen = false; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { .surface = surface, @@ -840,24 +840,24 @@ static void xdg_surface_handle_get_toplevel(struct wl_client *client, return; } - surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); - if (surface->toplevel_state == NULL) { + surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); + if (surface->toplevel == NULL) { wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; - surface->toplevel_state->base = surface; + surface->toplevel->base = surface; struct wl_resource *toplevel_resource = wl_resource_create(client, &zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id); if (toplevel_resource == NULL) { - free(surface->toplevel_state); + free(surface->toplevel); wl_resource_post_no_memory(resource); return; } - surface->toplevel_state->resource = toplevel_resource; + surface->toplevel->resource = toplevel_resource; wl_resource_set_implementation(toplevel_resource, &zxdg_toplevel_v6_implementation, surface, @@ -870,13 +870,13 @@ static void wlr_xdg_toplevel_v6_ack_configure( assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(configure->toplevel_state != NULL); - surface->toplevel_state->current.maximized = + surface->toplevel->current.maximized = configure->toplevel_state->maximized; - surface->toplevel_state->current.fullscreen = + surface->toplevel->current.fullscreen = configure->toplevel_state->fullscreen; - surface->toplevel_state->current.resizing = + surface->toplevel->current.resizing = configure->toplevel_state->resizing; - surface->toplevel_state->current.activated = + surface->toplevel->current.activated = configure->toplevel_state->activated; free(configure->toplevel_state); @@ -1034,10 +1034,10 @@ static void wlr_xdg_toplevel_v6_send_configure( wlr_log(L_ERROR, "Allocation failed"); return; } - *configure->toplevel_state = surface->toplevel_state->pending; + *configure->toplevel_state = surface->toplevel->pending; wl_array_init(&states); - if (surface->toplevel_state->pending.maximized) { + if (surface->toplevel->pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -1045,7 +1045,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; } - if (surface->toplevel_state->pending.fullscreen) { + if (surface->toplevel->pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -1053,7 +1053,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; } - if (surface->toplevel_state->pending.resizing) { + if (surface->toplevel->pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -1061,7 +1061,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; } - if (surface->toplevel_state->pending.activated) { + if (surface->toplevel->pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -1070,15 +1070,15 @@ static void wlr_xdg_toplevel_v6_send_configure( *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; } - uint32_t width = surface->toplevel_state->pending.width; - uint32_t height = surface->toplevel_state->pending.height; + uint32_t width = surface->toplevel->pending.width; + uint32_t height = surface->toplevel->pending.height; if (width == 0 || height == 0) { width = surface->geometry->width; height = surface->geometry->height; } - zxdg_toplevel_v6_send_configure(surface->toplevel_state->resource, width, + zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, &states); wl_array_release(&states); @@ -1086,7 +1086,7 @@ static void wlr_xdg_toplevel_v6_send_configure( error_out: wl_array_release(&states); - wl_resource_post_no_memory(surface->toplevel_state->resource); + wl_resource_post_no_memory(surface->toplevel->resource); } static void wlr_xdg_surface_send_configure(void *user_data) { @@ -1112,11 +1112,11 @@ static void wlr_xdg_surface_send_configure(void *user_data) { wlr_xdg_toplevel_v6_send_configure(surface, configure); break; case WLR_XDG_SURFACE_V6_ROLE_POPUP: - zxdg_popup_v6_send_configure(surface->popup_state->resource, - surface->popup_state->geometry.x, - surface->popup_state->geometry.y, - surface->popup_state->geometry.width, - surface->popup_state->geometry.height); + zxdg_popup_v6_send_configure(surface->popup->resource, + surface->popup->geometry.x, + surface->popup->geometry.y, + surface->popup->geometry.width, + surface->popup->geometry.height); break; } @@ -1135,7 +1135,7 @@ static uint32_t wlr_xdg_surface_v6_schedule_configure( break; case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: pending_same = - wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel_state); + wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel); break; case WLR_XDG_SURFACE_V6_ROLE_POPUP: break; @@ -1175,32 +1175,32 @@ static void wlr_xdg_surface_v6_toplevel_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - if (!surface->toplevel_state->added) { + if (!surface->toplevel->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_v6_schedule_configure(surface); - surface->toplevel_state->added = true; + surface->toplevel->added = true; return; } // update state that doesn't need compositor approval - surface->toplevel_state->current.max_width = - surface->toplevel_state->next.max_width; - surface->toplevel_state->current.min_width = - surface->toplevel_state->next.min_width; - surface->toplevel_state->current.max_height = - surface->toplevel_state->next.max_height; - surface->toplevel_state->current.min_height = - surface->toplevel_state->next.min_height; + surface->toplevel->current.max_width = + surface->toplevel->next.max_width; + surface->toplevel->current.min_width = + surface->toplevel->next.min_width; + surface->toplevel->current.max_height = + surface->toplevel->next.max_height; + surface->toplevel->current.min_height = + surface->toplevel->next.min_height; } static void wlr_xdg_surface_v6_popup_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); - if (!surface->popup_state->committed) { + if (!surface->popup->committed) { wlr_xdg_surface_v6_schedule_configure(surface); - surface->popup_state->committed = true; + surface->popup->committed = true; } } @@ -1498,8 +1498,8 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) { uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.width = width; - surface->toplevel_state->pending.height = height; + surface->toplevel->pending.width = width; + surface->toplevel->pending.height = height; wlr_log(L_DEBUG, "wlr_xdg_toplevel_v6_set_size %d", width); return wlr_xdg_surface_v6_schedule_configure(surface); @@ -1508,7 +1508,7 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.activated = activated; + surface->toplevel->pending.activated = activated; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1516,7 +1516,7 @@ uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.maximized = maximized; + surface->toplevel->pending.maximized = maximized; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1524,7 +1524,7 @@ uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.fullscreen = fullscreen; + surface->toplevel->pending.fullscreen = fullscreen; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1532,23 +1532,23 @@ uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.resizing = resizing; + surface->toplevel->pending.resizing = resizing; return wlr_xdg_surface_v6_schedule_configure(surface); } void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - zxdg_toplevel_v6_send_close(surface->toplevel_state->resource); + zxdg_toplevel_v6_send_close(surface->toplevel->resource); } void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, double *popup_sx, double *popup_sy) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); - struct wlr_xdg_surface_v6 *parent = surface->popup_state->parent; - *popup_sx = parent->geometry->x + surface->popup_state->geometry.x - + struct wlr_xdg_surface_v6 *parent = surface->popup->parent; + *popup_sx = parent->geometry->x + surface->popup->geometry.x - surface->geometry->x; - *popup_sy = parent->geometry->y + surface->popup_state->geometry.y - + *popup_sy = parent->geometry->y + surface->popup->geometry.y - surface->geometry->y; } -- cgit v1.2.3 From ace738dbca9cadb9b9bc5e15aeac19131bab3998 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 22:17:25 +0100 Subject: xdg-shell-v6: next_geometry and geometry fields are not longer pointers in wlr_xdg_surface_v6 --- include/wlr/types/wlr_xdg_shell_v6.h | 4 +- rootston/xdg_shell_v6.c | 6 +-- types/wlr_xdg_shell_v6.c | 78 +++++++++++++----------------------- 3 files changed, 32 insertions(+), 56 deletions(-) (limited to 'rootston') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 2358feec..d8503d28 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -109,8 +109,8 @@ struct wlr_xdg_surface_v6 { char *app_id; bool has_next_geometry; - struct wlr_box *next_geometry; - struct wlr_box *geometry; // TODO: should not be a pointer + struct wlr_box next_geometry; + struct wlr_box geometry; struct wl_listener surface_destroy_listener; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 59637105..13d25331 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -60,9 +60,9 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (surface->geometry->width > 0 && surface->geometry->height > 0) { - box->width = surface->geometry->width; - box->height = surface->geometry->height; + if (surface->geometry.width > 0 && surface->geometry.height > 0) { + box->width = surface->geometry.width; + box->height = surface->geometry.height; } else if (view->wlr_surface != NULL) { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 214f818c..aabd9f2b 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -217,8 +217,8 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { } surface->has_next_geometry = false; - memset(surface->geometry, 0, sizeof(struct wlr_box)); - memset(surface->next_geometry, 0, sizeof(struct wlr_box)); + memset(&surface->geometry, 0, sizeof(struct wlr_box)); + memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); } static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { @@ -232,8 +232,6 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); - free(surface->geometry); - free(surface->next_geometry); free(surface); } @@ -945,10 +943,10 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client, } surface->has_next_geometry = true; - surface->next_geometry->height = height; - surface->next_geometry->width = width; - surface->next_geometry->x = x; - surface->next_geometry->y = y; + surface->next_geometry.height = height; + surface->next_geometry.width = width; + surface->next_geometry.x = x; + surface->next_geometry.y = y; } static void xdg_surface_handle_destroy(struct wl_client *client, @@ -1073,11 +1071,6 @@ static void wlr_xdg_toplevel_v6_send_configure( uint32_t width = surface->toplevel->pending.width; uint32_t height = surface->toplevel->pending.height; - if (width == 0 || height == 0) { - width = surface->geometry->width; - height = surface->geometry->height; - } - zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, &states); @@ -1217,10 +1210,10 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (surface->has_next_geometry) { surface->has_next_geometry = false; - surface->geometry->x = surface->next_geometry->x; - surface->geometry->y = surface->next_geometry->y; - surface->geometry->width = surface->next_geometry->width; - surface->geometry->height = surface->next_geometry->height; + surface->geometry.x = surface->next_geometry.x; + surface->geometry.y = surface->next_geometry.y; + surface->geometry.width = surface->next_geometry.width; + surface->geometry.height = surface->next_geometry.height; } switch (surface->role) { @@ -1268,21 +1261,9 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, struct wlr_xdg_client_v6 *client = xdg_client_from_resource(client_resource); - struct wlr_xdg_surface_v6 *surface; - if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface_v6)))) { - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface); - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface->geometry); - free(surface); + struct wlr_xdg_surface_v6 *surface = + calloc(1, sizeof(struct wlr_xdg_surface_v6)); + if (surface == NULL) { wl_client_post_no_memory(wl_client); return; } @@ -1294,8 +1275,6 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, &zxdg_surface_v6_interface, wl_resource_get_version(client_resource), id); if (surface->resource == NULL) { - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_client_post_no_memory(wl_client); return; @@ -1303,8 +1282,6 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, if (wlr_surface_has_buffer(surface->surface)) { wl_resource_destroy(surface->resource); - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_resource_post_error(surface_resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, @@ -1500,7 +1477,6 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); surface->toplevel->pending.width = width; surface->toplevel->pending.height = height; - wlr_log(L_DEBUG, "wlr_xdg_toplevel_v6_set_size %d", width); return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1546,10 +1522,10 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, double *popup_sx, double *popup_sy) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); struct wlr_xdg_surface_v6 *parent = surface->popup->parent; - *popup_sx = parent->geometry->x + surface->popup->geometry.x - - surface->geometry->x; - *popup_sy = parent->geometry->y + surface->popup->geometry.y - - surface->geometry->y; + *popup_sx = parent->geometry.x + surface->popup->geometry.x - + surface->geometry.x; + *popup_sy = parent->geometry.y + surface->popup->geometry.y - + surface->geometry.y; } struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( @@ -1563,30 +1539,30 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *popup = popup_state->base; double _popup_sx = - surface->geometry->x + popup_state->geometry.x; + surface->geometry.x + popup_state->geometry.x; double _popup_sy = - surface->geometry->y + popup_state->geometry.y; + surface->geometry.y + popup_state->geometry.y; int popup_width = popup_state->geometry.width; int popup_height = popup_state->geometry.height; struct wlr_xdg_surface_v6 *_popup = wlr_xdg_surface_v6_popup_at(popup, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, popup_sx, popup_sy); if (_popup) { - *popup_sx = *popup_sx + _popup_sx - popup->geometry->x; - *popup_sy = *popup_sy + _popup_sy - popup->geometry->y; + *popup_sx = *popup_sx + _popup_sx - popup->geometry.x; + *popup_sy = *popup_sy + _popup_sy - popup->geometry.y; return _popup; } if ((sx > _popup_sx && sx < _popup_sx + popup_width) && (sy > _popup_sy && sy < _popup_sy + popup_height)) { if (pixman_region32_contains_point(&popup->surface->current->input, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, NULL)) { - *popup_sx = _popup_sx - popup->geometry->x; - *popup_sy = _popup_sy - popup->geometry->y; + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, NULL)) { + *popup_sx = _popup_sx - popup->geometry.x; + *popup_sy = _popup_sy - popup->geometry.y; return popup; } } -- cgit v1.2.3 From dd8a7a29e19f4e304e2620aa1665dd6761a1370e Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 14 Mar 2018 00:01:28 +0100 Subject: rootston: don't center view if maximized --- rootston/desktop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rootston') diff --git a/rootston/desktop.c b/rootston/desktop.c index b1e6f874..e9a9425c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -491,7 +491,7 @@ void view_initial_focus(struct roots_view *view) { void view_setup(struct roots_view *view) { view_initial_focus(view); - if (view->fullscreen_output == NULL) { + if (view->fullscreen_output == NULL && !view->maximized) { view_center(view); } -- cgit v1.2.3 From b6a3f240c7621d1ebb5774fcdf7784d976500ee1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 09:11:03 +0100 Subject: matrix: move to types/ --- backend/drm/drm.c | 2 +- backend/drm/renderer.c | 2 +- examples/multi-pointer.c | 2 +- examples/output-layout.c | 2 +- examples/pointer.c | 2 +- examples/rotation.c | 2 +- examples/tablet.c | 2 +- examples/touch.c | 2 +- include/wlr/render/matrix.h | 22 ----- include/wlr/types/wlr_matrix.h | 22 +++++ render/gles2/renderer.c | 2 +- render/gles2/texture.c | 2 +- render/matrix.c | 210 ----------------------------------------- render/meson.build | 1 - rootston/output.c | 2 +- types/meson.build | 3 +- types/wlr_matrix.c | 210 +++++++++++++++++++++++++++++++++++++++++ types/wlr_output.c | 2 +- types/wlr_surface.c | 2 +- 19 files changed, 247 insertions(+), 247 deletions(-) delete mode 100644 include/wlr/render/matrix.h create mode 100644 include/wlr/types/wlr_matrix.h delete mode 100644 render/matrix.c create mode 100644 types/wlr_matrix.c (limited to 'rootston') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 0d1d527d..af701c6a 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 7ee13843..13311df3 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "backend/drm/drm.h" #include "glapi.h" diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index d3d425f2..6e56bfdc 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/output-layout.c b/examples/output-layout.c index 45257be9..8ba77861 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/pointer.c b/examples/pointer.c index 0dbd02d2..e80b346a 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/rotation.c b/examples/rotation.c index 1158ccc4..e38d53f4 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/tablet.c b/examples/tablet.c index 5bfa1271..aa02c6f4 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/touch.c b/examples/touch.c index 278252cc..7b4559b9 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/wlr/render/matrix.h b/include/wlr/render/matrix.h deleted file mode 100644 index a333bf0f..00000000 --- a/include/wlr/render/matrix.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef WLR_RENDER_MATRIX_H -#define WLR_RENDER_MATRIX_H - -#include -#include - -void wlr_matrix_identity(float (*output)[16]); -void wlr_matrix_translate(float (*output)[16], float x, float y, float z); -void wlr_matrix_scale(float (*output)[16], float x, float y, float z); -void wlr_matrix_rotate(float (*output)[16], float radians); -void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]); - -enum wl_output_transform; -void wlr_matrix_transform(float mat[static 16], - enum wl_output_transform transform); -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, - enum wl_output_transform transform); -void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, - enum wl_output_transform transform, float rotation, float - (*projection)[16]); - -#endif diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h new file mode 100644 index 00000000..498b643c --- /dev/null +++ b/include/wlr/types/wlr_matrix.h @@ -0,0 +1,22 @@ +#ifndef WLR_TYPES_WLR_MATRIX_H +#define WLR_TYPES_WLR_MATRIX_H + +#include +#include + +void wlr_matrix_identity(float (*output)[16]); +void wlr_matrix_translate(float (*output)[16], float x, float y, float z); +void wlr_matrix_scale(float (*output)[16], float x, float y, float z); +void wlr_matrix_rotate(float (*output)[16], float radians); +void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]); + +enum wl_output_transform; +void wlr_matrix_transform(float mat[static 16], + enum wl_output_transform transform); +void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, + enum wl_output_transform transform); +void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, + enum wl_output_transform transform, float rotation, float + (*projection)[16]); + +#endif diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index ad739cf8..5b1395fb 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "render/gles2.h" #include "glapi.h" diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 241b94a8..7a180446 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include "render/gles2.h" #include "util/signal.h" diff --git a/render/matrix.c b/render/matrix.c deleted file mode 100644 index d5d7f49d..00000000 --- a/render/matrix.c +++ /dev/null @@ -1,210 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* Obtains the index for the given row/column */ -static inline int mind(int row, int col) { - return (row - 1) * 4 + col - 1; -} - -void wlr_matrix_identity(float (*output)[16]) { - static const float identity[16] = { - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - }; - memcpy(*output, identity, sizeof(identity)); -} - -void wlr_matrix_translate(float (*output)[16], float x, float y, float z) { - wlr_matrix_identity(output); - (*output)[mind(1, 4)] = x; - (*output)[mind(2, 4)] = y; - (*output)[mind(3, 4)] = z; -} - -void wlr_matrix_scale(float (*output)[16], float x, float y, float z) { - wlr_matrix_identity(output); - (*output)[mind(1, 1)] = x; - (*output)[mind(2, 2)] = y; - (*output)[mind(3, 3)] = z; -} - -void wlr_matrix_rotate(float (*output)[16], float radians) { - wlr_matrix_identity(output); - float _cos = cosf(radians); - float _sin = sinf(radians); - (*output)[mind(1, 1)] = _cos; - (*output)[mind(1, 2)] = _sin; - (*output)[mind(2, 1)] = -_sin; - (*output)[mind(2, 2)] = _cos; -} - -void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]) { - float _product[16] = { - (*x)[mind(1, 1)] * (*y)[mind(1, 1)] + (*x)[mind(1, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(1, 3)] * (*y)[mind(3, 1)] + (*x)[mind(1, 4)] * (*y)[mind(4, 1)], - (*x)[mind(1, 1)] * (*y)[mind(1, 2)] + (*x)[mind(1, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(1, 3)] * (*y)[mind(3, 2)] + (*x)[mind(1, 4)] * (*y)[mind(4, 2)], - (*x)[mind(1, 1)] * (*y)[mind(1, 3)] + (*x)[mind(1, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(1, 3)] * (*y)[mind(3, 3)] + (*x)[mind(1, 4)] * (*y)[mind(4, 3)], - (*x)[mind(1, 1)] * (*y)[mind(1, 4)] + (*x)[mind(1, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(1, 4)] * (*y)[mind(3, 4)] + (*x)[mind(1, 4)] * (*y)[mind(4, 4)], - - (*x)[mind(2, 1)] * (*y)[mind(1, 1)] + (*x)[mind(2, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(2, 3)] * (*y)[mind(3, 1)] + (*x)[mind(2, 4)] * (*y)[mind(4, 1)], - (*x)[mind(2, 1)] * (*y)[mind(1, 2)] + (*x)[mind(2, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(2, 3)] * (*y)[mind(3, 2)] + (*x)[mind(2, 4)] * (*y)[mind(4, 2)], - (*x)[mind(2, 1)] * (*y)[mind(1, 3)] + (*x)[mind(2, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(2, 3)] * (*y)[mind(3, 3)] + (*x)[mind(2, 4)] * (*y)[mind(4, 3)], - (*x)[mind(2, 1)] * (*y)[mind(1, 4)] + (*x)[mind(2, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(2, 4)] * (*y)[mind(3, 4)] + (*x)[mind(2, 4)] * (*y)[mind(4, 4)], - - (*x)[mind(3, 1)] * (*y)[mind(1, 1)] + (*x)[mind(3, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(3, 3)] * (*y)[mind(3, 1)] + (*x)[mind(3, 4)] * (*y)[mind(4, 1)], - (*x)[mind(3, 1)] * (*y)[mind(1, 2)] + (*x)[mind(3, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(3, 3)] * (*y)[mind(3, 2)] + (*x)[mind(3, 4)] * (*y)[mind(4, 2)], - (*x)[mind(3, 1)] * (*y)[mind(1, 3)] + (*x)[mind(3, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(3, 3)] * (*y)[mind(3, 3)] + (*x)[mind(3, 4)] * (*y)[mind(4, 3)], - (*x)[mind(3, 1)] * (*y)[mind(1, 4)] + (*x)[mind(3, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(3, 4)] * (*y)[mind(3, 4)] + (*x)[mind(3, 4)] * (*y)[mind(4, 4)], - - (*x)[mind(4, 1)] * (*y)[mind(1, 1)] + (*x)[mind(4, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(4, 3)] * (*y)[mind(3, 1)] + (*x)[mind(4, 4)] * (*y)[mind(4, 1)], - (*x)[mind(4, 1)] * (*y)[mind(1, 2)] + (*x)[mind(4, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(4, 3)] * (*y)[mind(3, 2)] + (*x)[mind(4, 4)] * (*y)[mind(4, 2)], - (*x)[mind(4, 1)] * (*y)[mind(1, 3)] + (*x)[mind(4, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(4, 3)] * (*y)[mind(3, 3)] + (*x)[mind(4, 4)] * (*y)[mind(4, 3)], - (*x)[mind(4, 1)] * (*y)[mind(1, 4)] + (*x)[mind(4, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(4, 4)] * (*y)[mind(3, 4)] + (*x)[mind(4, 4)] * (*y)[mind(4, 4)], - }; - memcpy(*product, _product, sizeof(_product)); -} - -static const float transforms[][4] = { - [WL_OUTPUT_TRANSFORM_NORMAL] = { - 1.0f, 0.0f, - 0.0f, 1.0f, - }, - [WL_OUTPUT_TRANSFORM_90] = { - 0.0f, -1.0f, - 1.0f, 0.0f, - }, - [WL_OUTPUT_TRANSFORM_180] = { - -1.0f, 0.0f, - 0.0f, -1.0f, - }, - [WL_OUTPUT_TRANSFORM_270] = { - 0.0f, 1.0f, - -1.0f, 0.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED] = { - -1.0f, 0.0f, - 0.0f, 1.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { - 0.0f, -1.0f, - -1.0f, 0.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { - 1.0f, 0.0f, - 0.0f, -1.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { - 0.0f, 1.0f, - 1.0f, 0.0f, - }, -}; - -void wlr_matrix_transform(float mat[static 16], - enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); - - const float *t = transforms[transform]; - - // Rotation + reflection - mat[0] = t[0]; - mat[1] = t[1]; - mat[4] = t[2]; - mat[5] = t[3]; - - // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; -} - -// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, - enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); - - const float *t = transforms[transform]; - float x = 2.0f / width; - float y = 2.0f / height; - - // Rotation + reflection - mat[0] = x * t[0]; - mat[1] = x * t[1]; - mat[4] = y * -t[2]; - mat[5] = y * -t[3]; - - // Translation - mat[3] = -copysign(1.0f, mat[0] + mat[1]); - mat[7] = -copysign(1.0f, mat[4] + mat[5]); - - // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; -} - -void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, - enum wl_output_transform transform, float rotation, - float (*projection)[16]) { - int x = box->x; - int y = box->y; - int width = box->width; - int height = box->height; - - wlr_matrix_translate(mat, x, y, 0); - - if (rotation != 0) { - float translate_center[16]; - wlr_matrix_translate(&translate_center, width/2, height/2, 0); - - float rotate[16]; - wlr_matrix_rotate(&rotate, rotation); - - float translate_origin[16]; - wlr_matrix_translate(&translate_origin, -width/2, -height/2, 0); - - wlr_matrix_mul(mat, &translate_center, mat); - wlr_matrix_mul(mat, &rotate, mat); - wlr_matrix_mul(mat, &translate_origin, mat); - } - - float scale[16]; - wlr_matrix_scale(&scale, width, height, 1); - - wlr_matrix_mul(mat, &scale, mat); - - if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { - float surface_translate_center[16]; - wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); - - float surface_transform[16]; - wlr_matrix_transform(surface_transform, transform); - - float surface_translate_origin[16]; - wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); - - wlr_matrix_mul(mat, &surface_translate_center, mat); - wlr_matrix_mul(mat, &surface_transform, mat); - wlr_matrix_mul(mat, &surface_translate_origin, mat); - } - - wlr_matrix_mul(projection, mat, mat); -} diff --git a/render/meson.build b/render/meson.build index 8aa70cea..4fe9ea67 100644 --- a/render/meson.build +++ b/render/meson.build @@ -15,7 +15,6 @@ lib_wlr_render = static_library( 'gles2/shaders.c', 'gles2/texture.c', 'gles2/util.c', - 'matrix.c', 'wlr_renderer.c', 'wlr_texture.c', ), diff --git a/rootston/output.c b/rootston/output.c index 4d0a9c05..bdf025ad 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/types/meson.build b/types/meson.build index 703b06ca..91b4326d 100644 --- a/types/meson.build +++ b/types/meson.build @@ -6,10 +6,12 @@ lib_wlr_types = static_library( 'wlr_cursor.c', 'wlr_data_device.c', 'wlr_gamma_control.c', + 'wlr_idle_inhibit_v1.c', 'wlr_idle.c', 'wlr_input_device.c', 'wlr_keyboard.c', 'wlr_list.c', + 'wlr_matrix.c', 'wlr_output_damage.c', 'wlr_output_layout.c', 'wlr_output.c', @@ -27,7 +29,6 @@ lib_wlr_types = static_library( 'wlr_xcursor_manager.c', 'wlr_xdg_shell_v6.c', 'wlr_xdg_shell.c', - 'wlr_idle_inhibit_v1.c', ), include_directories: wlr_inc, dependencies: [pixman, xkbcommon, wayland_server, wlr_protos], diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c new file mode 100644 index 00000000..f3546e0e --- /dev/null +++ b/types/wlr_matrix.c @@ -0,0 +1,210 @@ +#include +#include +#include +#include +#include +#include + +/* Obtains the index for the given row/column */ +static inline int mind(int row, int col) { + return (row - 1) * 4 + col - 1; +} + +void wlr_matrix_identity(float (*output)[16]) { + static const float identity[16] = { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + }; + memcpy(*output, identity, sizeof(identity)); +} + +void wlr_matrix_translate(float (*output)[16], float x, float y, float z) { + wlr_matrix_identity(output); + (*output)[mind(1, 4)] = x; + (*output)[mind(2, 4)] = y; + (*output)[mind(3, 4)] = z; +} + +void wlr_matrix_scale(float (*output)[16], float x, float y, float z) { + wlr_matrix_identity(output); + (*output)[mind(1, 1)] = x; + (*output)[mind(2, 2)] = y; + (*output)[mind(3, 3)] = z; +} + +void wlr_matrix_rotate(float (*output)[16], float radians) { + wlr_matrix_identity(output); + float _cos = cosf(radians); + float _sin = sinf(radians); + (*output)[mind(1, 1)] = _cos; + (*output)[mind(1, 2)] = _sin; + (*output)[mind(2, 1)] = -_sin; + (*output)[mind(2, 2)] = _cos; +} + +void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]) { + float _product[16] = { + (*x)[mind(1, 1)] * (*y)[mind(1, 1)] + (*x)[mind(1, 2)] * (*y)[mind(2, 1)] + + (*x)[mind(1, 3)] * (*y)[mind(3, 1)] + (*x)[mind(1, 4)] * (*y)[mind(4, 1)], + (*x)[mind(1, 1)] * (*y)[mind(1, 2)] + (*x)[mind(1, 2)] * (*y)[mind(2, 2)] + + (*x)[mind(1, 3)] * (*y)[mind(3, 2)] + (*x)[mind(1, 4)] * (*y)[mind(4, 2)], + (*x)[mind(1, 1)] * (*y)[mind(1, 3)] + (*x)[mind(1, 2)] * (*y)[mind(2, 3)] + + (*x)[mind(1, 3)] * (*y)[mind(3, 3)] + (*x)[mind(1, 4)] * (*y)[mind(4, 3)], + (*x)[mind(1, 1)] * (*y)[mind(1, 4)] + (*x)[mind(1, 2)] * (*y)[mind(2, 4)] + + (*x)[mind(1, 4)] * (*y)[mind(3, 4)] + (*x)[mind(1, 4)] * (*y)[mind(4, 4)], + + (*x)[mind(2, 1)] * (*y)[mind(1, 1)] + (*x)[mind(2, 2)] * (*y)[mind(2, 1)] + + (*x)[mind(2, 3)] * (*y)[mind(3, 1)] + (*x)[mind(2, 4)] * (*y)[mind(4, 1)], + (*x)[mind(2, 1)] * (*y)[mind(1, 2)] + (*x)[mind(2, 2)] * (*y)[mind(2, 2)] + + (*x)[mind(2, 3)] * (*y)[mind(3, 2)] + (*x)[mind(2, 4)] * (*y)[mind(4, 2)], + (*x)[mind(2, 1)] * (*y)[mind(1, 3)] + (*x)[mind(2, 2)] * (*y)[mind(2, 3)] + + (*x)[mind(2, 3)] * (*y)[mind(3, 3)] + (*x)[mind(2, 4)] * (*y)[mind(4, 3)], + (*x)[mind(2, 1)] * (*y)[mind(1, 4)] + (*x)[mind(2, 2)] * (*y)[mind(2, 4)] + + (*x)[mind(2, 4)] * (*y)[mind(3, 4)] + (*x)[mind(2, 4)] * (*y)[mind(4, 4)], + + (*x)[mind(3, 1)] * (*y)[mind(1, 1)] + (*x)[mind(3, 2)] * (*y)[mind(2, 1)] + + (*x)[mind(3, 3)] * (*y)[mind(3, 1)] + (*x)[mind(3, 4)] * (*y)[mind(4, 1)], + (*x)[mind(3, 1)] * (*y)[mind(1, 2)] + (*x)[mind(3, 2)] * (*y)[mind(2, 2)] + + (*x)[mind(3, 3)] * (*y)[mind(3, 2)] + (*x)[mind(3, 4)] * (*y)[mind(4, 2)], + (*x)[mind(3, 1)] * (*y)[mind(1, 3)] + (*x)[mind(3, 2)] * (*y)[mind(2, 3)] + + (*x)[mind(3, 3)] * (*y)[mind(3, 3)] + (*x)[mind(3, 4)] * (*y)[mind(4, 3)], + (*x)[mind(3, 1)] * (*y)[mind(1, 4)] + (*x)[mind(3, 2)] * (*y)[mind(2, 4)] + + (*x)[mind(3, 4)] * (*y)[mind(3, 4)] + (*x)[mind(3, 4)] * (*y)[mind(4, 4)], + + (*x)[mind(4, 1)] * (*y)[mind(1, 1)] + (*x)[mind(4, 2)] * (*y)[mind(2, 1)] + + (*x)[mind(4, 3)] * (*y)[mind(3, 1)] + (*x)[mind(4, 4)] * (*y)[mind(4, 1)], + (*x)[mind(4, 1)] * (*y)[mind(1, 2)] + (*x)[mind(4, 2)] * (*y)[mind(2, 2)] + + (*x)[mind(4, 3)] * (*y)[mind(3, 2)] + (*x)[mind(4, 4)] * (*y)[mind(4, 2)], + (*x)[mind(4, 1)] * (*y)[mind(1, 3)] + (*x)[mind(4, 2)] * (*y)[mind(2, 3)] + + (*x)[mind(4, 3)] * (*y)[mind(3, 3)] + (*x)[mind(4, 4)] * (*y)[mind(4, 3)], + (*x)[mind(4, 1)] * (*y)[mind(1, 4)] + (*x)[mind(4, 2)] * (*y)[mind(2, 4)] + + (*x)[mind(4, 4)] * (*y)[mind(3, 4)] + (*x)[mind(4, 4)] * (*y)[mind(4, 4)], + }; + memcpy(*product, _product, sizeof(_product)); +} + +static const float transforms[][4] = { + [WL_OUTPUT_TRANSFORM_NORMAL] = { + 1.0f, 0.0f, + 0.0f, 1.0f, + }, + [WL_OUTPUT_TRANSFORM_90] = { + 0.0f, -1.0f, + 1.0f, 0.0f, + }, + [WL_OUTPUT_TRANSFORM_180] = { + -1.0f, 0.0f, + 0.0f, -1.0f, + }, + [WL_OUTPUT_TRANSFORM_270] = { + 0.0f, 1.0f, + -1.0f, 0.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED] = { + -1.0f, 0.0f, + 0.0f, 1.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { + 0.0f, -1.0f, + -1.0f, 0.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { + 1.0f, 0.0f, + 0.0f, -1.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { + 0.0f, 1.0f, + 1.0f, 0.0f, + }, +}; + +void wlr_matrix_transform(float mat[static 16], + enum wl_output_transform transform) { + memset(mat, 0, sizeof(*mat) * 16); + + const float *t = transforms[transform]; + + // Rotation + reflection + mat[0] = t[0]; + mat[1] = t[1]; + mat[4] = t[2]; + mat[5] = t[3]; + + // Identity + mat[10] = 1.0f; + mat[15] = 1.0f; +} + +// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied +void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, + enum wl_output_transform transform) { + memset(mat, 0, sizeof(*mat) * 16); + + const float *t = transforms[transform]; + float x = 2.0f / width; + float y = 2.0f / height; + + // Rotation + reflection + mat[0] = x * t[0]; + mat[1] = x * t[1]; + mat[4] = y * -t[2]; + mat[5] = y * -t[3]; + + // Translation + mat[3] = -copysign(1.0f, mat[0] + mat[1]); + mat[7] = -copysign(1.0f, mat[4] + mat[5]); + + // Identity + mat[10] = 1.0f; + mat[15] = 1.0f; +} + +void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, + enum wl_output_transform transform, float rotation, + float (*projection)[16]) { + int x = box->x; + int y = box->y; + int width = box->width; + int height = box->height; + + wlr_matrix_translate(mat, x, y, 0); + + if (rotation != 0) { + float translate_center[16]; + wlr_matrix_translate(&translate_center, width/2, height/2, 0); + + float rotate[16]; + wlr_matrix_rotate(&rotate, rotation); + + float translate_origin[16]; + wlr_matrix_translate(&translate_origin, -width/2, -height/2, 0); + + wlr_matrix_mul(mat, &translate_center, mat); + wlr_matrix_mul(mat, &rotate, mat); + wlr_matrix_mul(mat, &translate_origin, mat); + } + + float scale[16]; + wlr_matrix_scale(&scale, width, height, 1); + + wlr_matrix_mul(mat, &scale, mat); + + if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { + float surface_translate_center[16]; + wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); + + float surface_transform[16]; + wlr_matrix_transform(surface_transform, transform); + + float surface_translate_origin[16]; + wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); + + wlr_matrix_mul(mat, &surface_translate_center, mat); + wlr_matrix_mul(mat, &surface_transform, mat); + wlr_matrix_mul(mat, &surface_translate_origin, mat); + } + + wlr_matrix_mul(projection, mat, mat); +} diff --git a/types/wlr_output.c b/types/wlr_output.c index 7f19d1fe..21343a68 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 23966cd1..5d52fd2a 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3 From d26b67cb06509fb39d9ed473a5d27b1f241ff635 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 11:10:56 +0100 Subject: matrix: unify API, don't use array pointers --- backend/drm/drm.c | 4 +- backend/drm/renderer.c | 2 +- examples/output-layout.c | 8 +-- examples/rotation.c | 8 +-- examples/tablet.c | 19 +++--- examples/touch.c | 10 +-- include/wlr/render.h | 12 ++-- include/wlr/render/interface.h | 13 ++-- include/wlr/types/wlr_matrix.h | 21 +++--- include/wlr/types/wlr_surface.h | 7 +- render/gles2/renderer.c | 21 +++--- render/gles2/texture.c | 14 ++-- render/wlr_renderer.c | 9 +-- render/wlr_texture.c | 4 +- rootston/output.c | 14 ++-- types/wlr_matrix.c | 147 ++++++++++++++++++++-------------------- types/wlr_output.c | 16 ++--- types/wlr_surface.c | 16 ++--- 18 files changed, 175 insertions(+), 170 deletions(-) (limited to 'rootston') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index af701c6a..1e78d301 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -648,9 +648,9 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, glClear(GL_COLOR_BUFFER_BIT); float matrix[16]; - wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0); + wlr_texture_get_matrix(plane->wlr_tex, matrix, plane->matrix, 0, 0); wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, - &matrix, 1.0f); + matrix, 1.0f); glFinish(); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 13311df3..ab56e6c2 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -239,7 +239,7 @@ struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, glViewport(0, 0, dest->width, dest->height); glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); - wlr_render_with_matrix(dest->renderer->wlr_rend, tex, &matrix, 1.0f); + wlr_render_with_matrix(dest->renderer->wlr_rend, tex, matrix, 1.0f); return wlr_drm_surface_swap_buffers(dest, NULL); } diff --git a/examples/output-layout.c b/examples/output-layout.c index 8ba77861..f4df73a0 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -102,7 +102,7 @@ static void handle_output_frame(struct output_state *output, wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); animate_cat(sample, output->output); @@ -119,10 +119,10 @@ static void handle_output_frame(struct output_state *output, wlr_output_layout_output_coords(sample->layout, output->output, &local_x, &local_y); - wlr_texture_get_matrix(sample->cat_texture, &matrix, - &wlr_output->transform_matrix, local_x, local_y); + wlr_texture_get_matrix(sample->cat_texture, matrix, + wlr_output->transform_matrix, local_x, local_y); wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix, 1.0f); + sample->cat_texture, matrix, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/examples/rotation.c b/examples/rotation.c index e38d53f4..0b0c6adf 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -44,15 +44,15 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { for (int x = -128 + (int)odata->x_offs; x < width; x += 128) { - wlr_texture_get_matrix(sample->cat_texture, &matrix, - &wlr_output->transform_matrix, x, y); + wlr_texture_get_matrix(sample->cat_texture, matrix, + wlr_output->transform_matrix, x, y); wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix, 1.0f); + sample->cat_texture, matrix, 1.0f); } } diff --git a/examples/tablet.c b/examples/tablet.c index aa02c6f4..82f86553 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -47,7 +47,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; float distance = 0.8f * (1 - sample->distance); @@ -65,9 +65,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts .x = left, .y = top, .width = pad_width, .height = pad_height, }; - wlr_matrix_project_box(&matrix, &box, 0, 0, - &wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, &sample->pad_color, &matrix); + wlr_matrix_project_box(matrix, &box, 0, 0, wlr_output->transform_matrix); + wlr_render_colored_quad(sample->renderer, sample->pad_color, matrix); if (sample->proximity) { struct wlr_box box = { @@ -76,16 +75,16 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts .width = 16 * (sample->pressure + 1), .height = 16 * (sample->pressure + 1), }; - wlr_matrix_project_box(&matrix, &box, 0, sample->ring, - &wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, &tool_color, &matrix); + wlr_matrix_project_box(matrix, &box, 0, sample->ring, + wlr_output->transform_matrix); + wlr_render_colored_quad(sample->renderer, tool_color, matrix); box.x += sample->x_tilt; box.y += sample->y_tilt; box.width /= 2; box.height /= 2; - wlr_matrix_project_box(&matrix, &box, 0, 0, - &wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, &tool_color, &matrix); + wlr_matrix_project_box(matrix, &box, 0, 0, + wlr_output->transform_matrix); + wlr_render_colored_quad(sample->renderer, tool_color, matrix); } wlr_renderer_end(sample->renderer); diff --git a/examples/touch.c b/examples/touch.c index 7b4559b9..6f4821ad 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -43,17 +43,17 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; struct touch_point *p; wl_list_for_each(p, &sample->touch_points, link) { - wlr_texture_get_matrix(sample->cat_texture, &matrix, - &wlr_output->transform_matrix, + wlr_texture_get_matrix(sample->cat_texture, matrix, + wlr_output->transform_matrix, (int)(p->x * width) - sample->cat_texture->width / 2, (int)(p->y * height) - sample->cat_texture->height / 2); - wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix, 1.0f); + wlr_render_with_matrix(sample->renderer, sample->cat_texture, + matrix, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/include/wlr/render.h b/include/wlr/render.h index 747603da..50c2dd13 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -13,7 +13,7 @@ struct wlr_renderer; void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); void wlr_renderer_end(struct wlr_renderer *r); -void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]); +void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); /** * Defines a scissor box. Only pixels that lie within the scissor box can be * modified by drawing functions. Providing a NULL `box` disables the scissor @@ -38,18 +38,18 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); * This will render the texture at <123, 321> with an alpha channel of 0.5. */ bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float (*matrix)[16], float alpha); + struct wlr_texture *texture, const float matrix[static 16], float alpha); /** * Renders a solid quad in the specified color. */ void wlr_render_colored_quad(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); /** * Renders a solid ellipse in the specified color. */ void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); /** * Returns a list of pixel formats supported by this renderer. */ @@ -139,8 +139,8 @@ bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, * width) and [0, height], and the x and y coordinates provided are used as * such. */ -void wlr_texture_get_matrix(struct wlr_texture *texture, - float (*matrix)[16], const float (*projection)[16], int x, int y); +void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 16], + const float projection[static 16], int x, int y); /** * Destroys this wlr_texture. */ diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index eda5af1c..4d81bdf9 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -18,15 +18,16 @@ struct wlr_renderer { struct wlr_renderer_impl { void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output); void (*end)(struct wlr_renderer *renderer); - void (*clear)(struct wlr_renderer *renderer, const float (*color)[4]); + void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); bool (*render_with_matrix)(struct wlr_renderer *renderer, - struct wlr_texture *texture, const float (*matrix)[16], float alpha); + struct wlr_texture *texture, const float matrix[static 16], + float alpha); void (*render_quad)(struct wlr_renderer *renderer, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); void (*render_ellipse)(struct wlr_renderer *renderer, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); const enum wl_shm_format *(*formats)( struct wlr_renderer *renderer, size_t *len); bool (*buffer_is_drm)(struct wlr_renderer *renderer, @@ -58,8 +59,8 @@ struct wlr_texture_impl { struct wl_resource *drm_buf); bool (*upload_eglimage)(struct wlr_texture *texture, EGLImageKHR image, uint32_t width, uint32_t height); - void (*get_matrix)(struct wlr_texture *state, - float (*matrix)[16], const float (*projection)[16], int x, int y); + void (*get_matrix)(struct wlr_texture *state, float mat[static 16], + const float projection[static 16], int x, int y); void (*get_buffer_size)(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height); void (*bind)(struct wlr_texture *texture); diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h index 498b643c..cf5ad20d 100644 --- a/include/wlr/types/wlr_matrix.h +++ b/include/wlr/types/wlr_matrix.h @@ -4,19 +4,20 @@ #include #include -void wlr_matrix_identity(float (*output)[16]); -void wlr_matrix_translate(float (*output)[16], float x, float y, float z); -void wlr_matrix_scale(float (*output)[16], float x, float y, float z); -void wlr_matrix_rotate(float (*output)[16], float radians); -void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]); +void wlr_matrix_identity(float mat[static 16]); +void wlr_matrix_translate(float mat[static 16], float x, float y, float z); +void wlr_matrix_scale(float mat[static 16], float x, float y, float z); +void wlr_matrix_rotate(float mat[static 16], float radians); +void wlr_matrix_mul(float mat[static 16], const float x[static 16], + const float y[static 16]); enum wl_output_transform; void wlr_matrix_transform(float mat[static 16], - enum wl_output_transform transform); + enum wl_output_transform transform); void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, - enum wl_output_transform transform); -void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, - enum wl_output_transform transform, float rotation, float - (*projection)[16]); + enum wl_output_transform transform); +void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, + enum wl_output_transform transform, float rotation, + const float projection[static 16]); #endif diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 203345bd..1d4c1f01 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -99,6 +99,7 @@ struct wlr_surface { struct wlr_renderer; struct wlr_surface *wlr_surface_create(struct wl_resource *res, struct wlr_renderer *renderer); + /** * Gets a matrix you can pass into wlr_render_with_matrix to display this * surface. `matrix` is the output matrix, `projection` is the wlr_output @@ -108,9 +109,9 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, * from 0 to 1 in both dimensions. */ void wlr_surface_get_matrix(struct wlr_surface *surface, - float (*matrix)[16], - const float (*projection)[16], - const float (*transform)[16]); + float mat[static 16], + const float projection[static 16], + const float transform[static 16]); /** diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 5b1395fb..9134a2fd 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -122,8 +122,8 @@ static void wlr_gles2_end(struct wlr_renderer *wlr_renderer) { } static void wlr_gles2_clear(struct wlr_renderer *wlr_renderer, - const float (*color)[4]) { - glClearColor((*color)[0], (*color)[1], (*color)[2], (*color)[3]); + const float color[static 4]) { + glClearColor(color[0], color[1], color[2], color[3]); glClear(GL_COLOR_BUFFER_BIT); } @@ -171,14 +171,15 @@ static void draw_quad() { } static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, - struct wlr_texture *texture, const float (*matrix)[16], float alpha) { + struct wlr_texture *texture, const float matrix[static 16], + float alpha) { if (!texture || !texture->valid) { wlr_log(L_ERROR, "attempt to render invalid texture"); return false; } wlr_texture_bind(texture); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix)); + GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); GL_CALL(glUniform1f(2, alpha)); draw_quad(); return true; @@ -186,18 +187,18 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { GL_CALL(glUseProgram(shaders.quad)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix)); - GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3])); + GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); + GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { GL_CALL(glUseProgram(shaders.ellipse)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix)); - GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3])); + GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, matrix)); + GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 7a180446..0dfebc48 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -227,16 +227,16 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex, } static void gles2_texture_get_matrix(struct wlr_texture *_texture, - float (*matrix)[16], const float (*projection)[16], int x, int y) { + float mat[static 16], const float projection[static 16], int x, int y) { struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture; float world[16]; - wlr_matrix_identity(matrix); - wlr_matrix_translate(&world, x, y, 0); - wlr_matrix_mul(matrix, &world, matrix); - wlr_matrix_scale(&world, + wlr_matrix_identity(mat); + wlr_matrix_translate(world, x, y, 0); + wlr_matrix_mul(mat, mat, world); + wlr_matrix_scale(world, texture->wlr_texture.width, texture->wlr_texture.height, 1); - wlr_matrix_mul(matrix, &world, matrix); - wlr_matrix_mul(projection, matrix, matrix); + wlr_matrix_mul(mat, mat, world); + wlr_matrix_mul(mat, projection, mat); } static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index ce8fbe36..372e4caf 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -23,7 +23,7 @@ void wlr_renderer_end(struct wlr_renderer *r) { r->impl->end(r); } -void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]) { +void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]) { r->impl->clear(r, color); } @@ -36,17 +36,18 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { } bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float (*matrix)[16], float alpha) { + struct wlr_texture *texture, const float matrix[static 16], + float alpha) { return r->impl->render_with_matrix(r, texture, matrix, alpha); } void wlr_render_colored_quad(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { r->impl->render_quad(r, color, matrix); } void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { r->impl->render_ellipse(r, color, matrix); } diff --git a/render/wlr_texture.c b/render/wlr_texture.c index a82a16b2..0bfac32c 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -54,8 +54,8 @@ bool wlr_texture_upload_eglimage(struct wlr_texture *texture, } void wlr_texture_get_matrix(struct wlr_texture *texture, - float (*matrix)[16], const float (*projection)[16], int x, int y) { - texture->impl->get_matrix(texture, matrix, projection, x, y); + float mat[static 16], const float projection[static 16], int x, int y) { + texture->impl->get_matrix(texture, mat, projection, x, y); } void wlr_texture_get_buffer_size(struct wlr_texture *texture, struct wl_resource diff --git a/rootston/output.c b/rootston/output.c index bdf025ad..47236720 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -290,14 +290,14 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, float matrix[16]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); - wlr_matrix_project_box(&matrix, &box, transform, rotation, - &output->wlr_output->transform_matrix); + wlr_matrix_project_box(matrix, &box, transform, rotation, + output->wlr_output->transform_matrix); int nrects; pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_with_matrix(renderer, surface->texture, &matrix, data->alpha); + wlr_render_with_matrix(renderer, surface->texture, matrix, data->alpha); } damage_finish: @@ -354,8 +354,8 @@ static void render_decorations(struct roots_view *view, } float matrix[16]; - wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, - view->rotation, &output->wlr_output->transform_matrix); + wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, + view->rotation, output->wlr_output->transform_matrix); float color[] = { 0.2, 0.2, 0.2, view->alpha }; int nrects; @@ -363,7 +363,7 @@ static void render_decorations(struct roots_view *view, pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_colored_quad(renderer, &color, &matrix); + wlr_render_colored_quad(renderer, color, matrix); } damage_finish: @@ -489,7 +489,7 @@ static void render_output(struct roots_output *output) { pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_renderer_clear(renderer, &clear_color); + wlr_renderer_clear(renderer, clear_color); } // If a view is fullscreen on this output, render it diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index f3546e0e..a6be9908 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -10,79 +10,80 @@ static inline int mind(int row, int col) { return (row - 1) * 4 + col - 1; } -void wlr_matrix_identity(float (*output)[16]) { +void wlr_matrix_identity(float mat[static 16]) { static const float identity[16] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f + 0.0f, 0.0f, 0.0f, 1.0f, }; - memcpy(*output, identity, sizeof(identity)); + memcpy(mat, identity, sizeof(identity)); } -void wlr_matrix_translate(float (*output)[16], float x, float y, float z) { - wlr_matrix_identity(output); - (*output)[mind(1, 4)] = x; - (*output)[mind(2, 4)] = y; - (*output)[mind(3, 4)] = z; +void wlr_matrix_translate(float mat[static 16], float x, float y, float z) { + wlr_matrix_identity(mat); + mat[mind(1, 4)] = x; + mat[mind(2, 4)] = y; + mat[mind(3, 4)] = z; } -void wlr_matrix_scale(float (*output)[16], float x, float y, float z) { - wlr_matrix_identity(output); - (*output)[mind(1, 1)] = x; - (*output)[mind(2, 2)] = y; - (*output)[mind(3, 3)] = z; +void wlr_matrix_scale(float mat[static 16], float x, float y, float z) { + wlr_matrix_identity(mat); + mat[mind(1, 1)] = x; + mat[mind(2, 2)] = y; + mat[mind(3, 3)] = z; } -void wlr_matrix_rotate(float (*output)[16], float radians) { - wlr_matrix_identity(output); +void wlr_matrix_rotate(float mat[static 16], float radians) { + wlr_matrix_identity(mat); float _cos = cosf(radians); float _sin = sinf(radians); - (*output)[mind(1, 1)] = _cos; - (*output)[mind(1, 2)] = _sin; - (*output)[mind(2, 1)] = -_sin; - (*output)[mind(2, 2)] = _cos; + mat[mind(1, 1)] = _cos; + mat[mind(1, 2)] = _sin; + mat[mind(2, 1)] = -_sin; + mat[mind(2, 2)] = _cos; } -void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]) { - float _product[16] = { - (*x)[mind(1, 1)] * (*y)[mind(1, 1)] + (*x)[mind(1, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(1, 3)] * (*y)[mind(3, 1)] + (*x)[mind(1, 4)] * (*y)[mind(4, 1)], - (*x)[mind(1, 1)] * (*y)[mind(1, 2)] + (*x)[mind(1, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(1, 3)] * (*y)[mind(3, 2)] + (*x)[mind(1, 4)] * (*y)[mind(4, 2)], - (*x)[mind(1, 1)] * (*y)[mind(1, 3)] + (*x)[mind(1, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(1, 3)] * (*y)[mind(3, 3)] + (*x)[mind(1, 4)] * (*y)[mind(4, 3)], - (*x)[mind(1, 1)] * (*y)[mind(1, 4)] + (*x)[mind(1, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(1, 4)] * (*y)[mind(3, 4)] + (*x)[mind(1, 4)] * (*y)[mind(4, 4)], - - (*x)[mind(2, 1)] * (*y)[mind(1, 1)] + (*x)[mind(2, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(2, 3)] * (*y)[mind(3, 1)] + (*x)[mind(2, 4)] * (*y)[mind(4, 1)], - (*x)[mind(2, 1)] * (*y)[mind(1, 2)] + (*x)[mind(2, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(2, 3)] * (*y)[mind(3, 2)] + (*x)[mind(2, 4)] * (*y)[mind(4, 2)], - (*x)[mind(2, 1)] * (*y)[mind(1, 3)] + (*x)[mind(2, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(2, 3)] * (*y)[mind(3, 3)] + (*x)[mind(2, 4)] * (*y)[mind(4, 3)], - (*x)[mind(2, 1)] * (*y)[mind(1, 4)] + (*x)[mind(2, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(2, 4)] * (*y)[mind(3, 4)] + (*x)[mind(2, 4)] * (*y)[mind(4, 4)], - - (*x)[mind(3, 1)] * (*y)[mind(1, 1)] + (*x)[mind(3, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(3, 3)] * (*y)[mind(3, 1)] + (*x)[mind(3, 4)] * (*y)[mind(4, 1)], - (*x)[mind(3, 1)] * (*y)[mind(1, 2)] + (*x)[mind(3, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(3, 3)] * (*y)[mind(3, 2)] + (*x)[mind(3, 4)] * (*y)[mind(4, 2)], - (*x)[mind(3, 1)] * (*y)[mind(1, 3)] + (*x)[mind(3, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(3, 3)] * (*y)[mind(3, 3)] + (*x)[mind(3, 4)] * (*y)[mind(4, 3)], - (*x)[mind(3, 1)] * (*y)[mind(1, 4)] + (*x)[mind(3, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(3, 4)] * (*y)[mind(3, 4)] + (*x)[mind(3, 4)] * (*y)[mind(4, 4)], - - (*x)[mind(4, 1)] * (*y)[mind(1, 1)] + (*x)[mind(4, 2)] * (*y)[mind(2, 1)] + - (*x)[mind(4, 3)] * (*y)[mind(3, 1)] + (*x)[mind(4, 4)] * (*y)[mind(4, 1)], - (*x)[mind(4, 1)] * (*y)[mind(1, 2)] + (*x)[mind(4, 2)] * (*y)[mind(2, 2)] + - (*x)[mind(4, 3)] * (*y)[mind(3, 2)] + (*x)[mind(4, 4)] * (*y)[mind(4, 2)], - (*x)[mind(4, 1)] * (*y)[mind(1, 3)] + (*x)[mind(4, 2)] * (*y)[mind(2, 3)] + - (*x)[mind(4, 3)] * (*y)[mind(3, 3)] + (*x)[mind(4, 4)] * (*y)[mind(4, 3)], - (*x)[mind(4, 1)] * (*y)[mind(1, 4)] + (*x)[mind(4, 2)] * (*y)[mind(2, 4)] + - (*x)[mind(4, 4)] * (*y)[mind(3, 4)] + (*x)[mind(4, 4)] * (*y)[mind(4, 4)], +void wlr_matrix_mul(float mat[static 16], const float x[static 16], + const float y[static 16]) { + float product[16] = { + x[mind(1, 1)] * y[mind(1, 1)] + x[mind(1, 2)] * y[mind(2, 1)] + + x[mind(1, 3)] * y[mind(3, 1)] + x[mind(1, 4)] * y[mind(4, 1)], + x[mind(1, 1)] * y[mind(1, 2)] + x[mind(1, 2)] * y[mind(2, 2)] + + x[mind(1, 3)] * y[mind(3, 2)] + x[mind(1, 4)] * y[mind(4, 2)], + x[mind(1, 1)] * y[mind(1, 3)] + x[mind(1, 2)] * y[mind(2, 3)] + + x[mind(1, 3)] * y[mind(3, 3)] + x[mind(1, 4)] * y[mind(4, 3)], + x[mind(1, 1)] * y[mind(1, 4)] + x[mind(1, 2)] * y[mind(2, 4)] + + x[mind(1, 4)] * y[mind(3, 4)] + x[mind(1, 4)] * y[mind(4, 4)], + + x[mind(2, 1)] * y[mind(1, 1)] + x[mind(2, 2)] * y[mind(2, 1)] + + x[mind(2, 3)] * y[mind(3, 1)] + x[mind(2, 4)] * y[mind(4, 1)], + x[mind(2, 1)] * y[mind(1, 2)] + x[mind(2, 2)] * y[mind(2, 2)] + + x[mind(2, 3)] * y[mind(3, 2)] + x[mind(2, 4)] * y[mind(4, 2)], + x[mind(2, 1)] * y[mind(1, 3)] + x[mind(2, 2)] * y[mind(2, 3)] + + x[mind(2, 3)] * y[mind(3, 3)] + x[mind(2, 4)] * y[mind(4, 3)], + x[mind(2, 1)] * y[mind(1, 4)] + x[mind(2, 2)] * y[mind(2, 4)] + + x[mind(2, 4)] * y[mind(3, 4)] + x[mind(2, 4)] * y[mind(4, 4)], + + x[mind(3, 1)] * y[mind(1, 1)] + x[mind(3, 2)] * y[mind(2, 1)] + + x[mind(3, 3)] * y[mind(3, 1)] + x[mind(3, 4)] * y[mind(4, 1)], + x[mind(3, 1)] * y[mind(1, 2)] + x[mind(3, 2)] * y[mind(2, 2)] + + x[mind(3, 3)] * y[mind(3, 2)] + x[mind(3, 4)] * y[mind(4, 2)], + x[mind(3, 1)] * y[mind(1, 3)] + x[mind(3, 2)] * y[mind(2, 3)] + + x[mind(3, 3)] * y[mind(3, 3)] + x[mind(3, 4)] * y[mind(4, 3)], + x[mind(3, 1)] * y[mind(1, 4)] + x[mind(3, 2)] * y[mind(2, 4)] + + x[mind(3, 4)] * y[mind(3, 4)] + x[mind(3, 4)] * y[mind(4, 4)], + + x[mind(4, 1)] * y[mind(1, 1)] + x[mind(4, 2)] * y[mind(2, 1)] + + x[mind(4, 3)] * y[mind(3, 1)] + x[mind(4, 4)] * y[mind(4, 1)], + x[mind(4, 1)] * y[mind(1, 2)] + x[mind(4, 2)] * y[mind(2, 2)] + + x[mind(4, 3)] * y[mind(3, 2)] + x[mind(4, 4)] * y[mind(4, 2)], + x[mind(4, 1)] * y[mind(1, 3)] + x[mind(4, 2)] * y[mind(2, 3)] + + x[mind(4, 3)] * y[mind(3, 3)] + x[mind(4, 4)] * y[mind(4, 3)], + x[mind(4, 1)] * y[mind(1, 4)] + x[mind(4, 2)] * y[mind(2, 4)] + + x[mind(4, 4)] * y[mind(3, 4)] + x[mind(4, 4)] * y[mind(4, 4)], }; - memcpy(*product, _product, sizeof(_product)); + memcpy(mat, product, sizeof(product)); } static const float transforms[][4] = { @@ -161,9 +162,9 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, mat[15] = 1.0f; } -void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, +void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, enum wl_output_transform transform, float rotation, - float (*projection)[16]) { + const float projection[static 16]) { int x = box->x; int y = box->y; int width = box->width; @@ -173,38 +174,38 @@ void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, if (rotation != 0) { float translate_center[16]; - wlr_matrix_translate(&translate_center, width/2, height/2, 0); + wlr_matrix_translate(translate_center, width/2, height/2, 0); float rotate[16]; - wlr_matrix_rotate(&rotate, rotation); + wlr_matrix_rotate(rotate, rotation); float translate_origin[16]; - wlr_matrix_translate(&translate_origin, -width/2, -height/2, 0); + wlr_matrix_translate(translate_origin, -width/2, -height/2, 0); - wlr_matrix_mul(mat, &translate_center, mat); - wlr_matrix_mul(mat, &rotate, mat); - wlr_matrix_mul(mat, &translate_origin, mat); + wlr_matrix_mul(mat, mat, translate_center); + wlr_matrix_mul(mat, mat, rotate); + wlr_matrix_mul(mat, mat, translate_origin); } float scale[16]; - wlr_matrix_scale(&scale, width, height, 1); + wlr_matrix_scale(scale, width, height, 1); - wlr_matrix_mul(mat, &scale, mat); + wlr_matrix_mul(mat, mat, scale); if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { float surface_translate_center[16]; - wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); + wlr_matrix_translate(surface_translate_center, 0.5, 0.5, 0); float surface_transform[16]; wlr_matrix_transform(surface_transform, transform); float surface_translate_origin[16]; - wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); + wlr_matrix_translate(surface_translate_origin, -0.5, -0.5, 0); - wlr_matrix_mul(mat, &surface_translate_center, mat); - wlr_matrix_mul(mat, &surface_transform, mat); - wlr_matrix_mul(mat, &surface_translate_origin, mat); + wlr_matrix_mul(mat, mat, surface_translate_center); + wlr_matrix_mul(mat, mat, surface_transform); + wlr_matrix_mul(mat, mat, surface_translate_origin); } - wlr_matrix_mul(projection, mat, mat); + wlr_matrix_mul(mat, projection, mat); } diff --git a/types/wlr_output.c b/types/wlr_output.c index 21343a68..a9fb01c5 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -368,7 +368,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output, assert(renderer); if (!wlr_surface_has_buffer(surface)) { - wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0}); + wlr_renderer_clear(renderer, (float[]){0, 0, 0, 0}); return; } @@ -378,15 +378,15 @@ static void output_fullscreen_surface_render(struct wlr_output *output, float matrix[16]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); - wlr_matrix_project_box(&matrix, &box, transform, 0, - &output->transform_matrix); + wlr_matrix_project_box(matrix, &box, transform, 0, + output->transform_matrix); int nrects; pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); for (int i = 0; i < nrects; ++i) { output_scissor(output, &rects[i]); - wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0}); - wlr_render_with_matrix(surface->renderer, surface->texture, &matrix, 1.0f); + wlr_renderer_clear(renderer, (float[]){0, 0, 0, 0}); + wlr_render_with_matrix(surface->renderer, surface->texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); @@ -436,14 +436,14 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, } float matrix[16]; - wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, - &cursor->output->transform_matrix); + wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + cursor->output->transform_matrix); int nrects; pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects); for (int i = 0; i < nrects; ++i) { output_scissor(cursor->output, &rects[i]); - wlr_render_with_matrix(renderer, texture, &matrix, 1.0f); + wlr_render_with_matrix(renderer, texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 5d52fd2a..04dcb141 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -625,19 +625,19 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, } void wlr_surface_get_matrix(struct wlr_surface *surface, - float (*matrix)[16], - const float (*projection)[16], - const float (*transform)[16]) { + float mat[static 16], + const float projection[static 16], + const float transform[static 16]) { int width = surface->texture->width; int height = surface->texture->height; float scale[16]; - wlr_matrix_identity(matrix); + wlr_matrix_identity(mat); if (transform) { - wlr_matrix_mul(matrix, transform, matrix); + wlr_matrix_mul(mat, mat, transform); } - wlr_matrix_scale(&scale, width, height, 1); - wlr_matrix_mul(matrix, &scale, matrix); - wlr_matrix_mul(projection, matrix, matrix); + wlr_matrix_scale(scale, width, height, 1); + wlr_matrix_mul(mat, mat, scale); + wlr_matrix_mul(mat, projection, mat); } bool wlr_surface_has_buffer(struct wlr_surface *surface) { -- cgit v1.2.3 From eb4337b5eea47e5f3ec337639d2f62c2bae15797 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 11 Mar 2018 19:05:11 +0100 Subject: Wire up linux_dmabuf in rootston --- include/rootston/desktop.h | 2 ++ rootston/desktop.c | 3 +++ types/wlr_linux_dmabuf.c | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'rootston') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 467de8ab..db8a088e 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ struct roots_desktop { struct wlr_primary_selection_device_manager *primary_selection_device_manager; struct wlr_idle *idle; struct wlr_idle_inhibit_manager_v1 *idle_inhibit; + struct wlr_linux_dmabuf *linux_dmabuf; struct wl_listener new_output; struct wl_listener layout_change; diff --git a/rootston/desktop.c b/rootston/desktop.c index 3628b051..a130fe38 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -729,6 +730,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->idle = wlr_idle_create(server->wl_display); desktop->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display); + struct wlr_egl *egl = wlr_backend_get_egl(server->backend); + desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display, egl); return desktop; } diff --git a/types/wlr_linux_dmabuf.c b/types/wlr_linux_dmabuf.c index 407a5717..3b86166e 100644 --- a/types/wlr_linux_dmabuf.c +++ b/types/wlr_linux_dmabuf.c @@ -176,7 +176,7 @@ static void params_create_common(struct wl_client *client, } if ((uint64_t)buffer->attributes.offset[0] + - (uint64_t) buffer->attributes.stride[0] * height > UINT32_MAX) { + (uint64_t)buffer->attributes.stride[0] * height > UINT32_MAX) { wl_resource_post_error(params_resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS, "size overflow for plane"); @@ -205,15 +205,15 @@ static void params_create_common(struct wl_client *client, wl_resource_post_error(params_resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS, "invalid buffer stride or height for plane"); - goto err_out; + goto err_out; } } /* reject unknown flags */ if (buffer->attributes.flags & ~ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT) { wl_resource_post_error(params_resource, - ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, - "Unknown dmabuf flags %"PRIu32, buffer->attributes.flags); + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, + "Unknown dmabuf flags %"PRIu32, buffer->attributes.flags); goto err_out; } -- cgit v1.2.3 From 824a95ad19062e867178593f0937d14049422989 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 15:33:58 +0100 Subject: matrix: use 2D matrices --- backend/drm/drm.c | 4 +- backend/drm/renderer.c | 20 ++-- examples/output-layout.c | 6 +- examples/rotation.c | 4 +- examples/tablet.c | 2 +- examples/touch.c | 4 +- include/backend/drm/drm.h | 2 +- include/wlr/render.h | 20 ++-- include/wlr/render/interface.h | 12 +-- include/wlr/types/wlr_matrix.h | 24 ++--- include/wlr/types/wlr_output.h | 2 +- include/wlr/types/wlr_surface.h | 10 +- render/gles2/renderer.c | 24 +++-- render/gles2/shaders.c | 67 ++++++------ render/gles2/texture.c | 13 +-- render/wlr_renderer.c | 10 +- render/wlr_texture.c | 2 +- rootston/output.c | 6 +- types/wlr_matrix.c | 227 ++++++++++++++++------------------------ types/wlr_output.c | 8 +- types/wlr_surface.c | 16 ++- 21 files changed, 214 insertions(+), 269 deletions(-) (limited to 'rootston') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 1e78d301..e956f280 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -647,9 +647,9 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); - float matrix[16]; + float matrix[9]; wlr_texture_get_matrix(plane->wlr_tex, matrix, plane->matrix, 0, 0); - wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, + wlr_render_texture_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, matrix, 1.0f); glFinish(); diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index ab56e6c2..f700dd59 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -226,20 +227,21 @@ struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, wlr_drm_surface_make_current(dest, NULL); struct wlr_texture *tex = get_tex_for_bo(dest->renderer, src); + assert(tex); - static const float matrix[16] = { + static const float color[] = {0.0, 0.0, 0.0, 1.0}; + + static const float mat[9] = { [0] = 2.0f, - [3] = -1.0f, - [5] = 2.0f, - [7] = -1.0f, - [10] = 1.0f, - [15] = 1.0f, + [2] = -1.0f, + [4] = 2.0f, + [5] = -1.0f, + [8] = 1.0f, }; glViewport(0, 0, dest->width, dest->height); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - wlr_render_with_matrix(dest->renderer->wlr_rend, tex, matrix, 1.0f); + wlr_renderer_clear(dest->renderer->wlr_rend, color); + wlr_render_texture_with_matrix(dest->renderer->wlr_rend, tex, mat, 1.0f); return wlr_drm_surface_swap_buffers(dest, NULL); } diff --git a/examples/output-layout.c b/examples/output-layout.c index f4df73a0..9c914137 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -111,7 +111,7 @@ static void handle_output_frame(struct output_state *output, .width = 128, .height = 128, }; if (wlr_output_layout_intersects(sample->layout, output->output, &box)) { - float matrix[16]; + float matrix[9]; // transform global coordinates to local coordinates double local_x = sample->x_offs; @@ -121,8 +121,8 @@ static void handle_output_frame(struct output_state *output, wlr_texture_get_matrix(sample->cat_texture, matrix, wlr_output->transform_matrix, local_x, local_y); - wlr_render_with_matrix(sample->renderer, - sample->cat_texture, matrix, 1.0f); + wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, + matrix, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/examples/rotation.c b/examples/rotation.c index 0b0c6adf..4431f60a 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -46,12 +46,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[16]; + float matrix[9]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { for (int x = -128 + (int)odata->x_offs; x < width; x += 128) { wlr_texture_get_matrix(sample->cat_texture, matrix, wlr_output->transform_matrix, x, y); - wlr_render_with_matrix(sample->renderer, + wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, matrix, 1.0f); } } diff --git a/examples/tablet.c b/examples/tablet.c index 82f86553..521447b9 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -49,7 +49,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[16]; + float matrix[9]; float distance = 0.8f * (1 - sample->distance); float tool_color[4] = { distance, distance, distance, 1 }; for (size_t i = 0; sample->button && i < 4; ++i) { diff --git a/examples/touch.c b/examples/touch.c index 6f4821ad..47bbebc2 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -45,14 +45,14 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[16]; + float matrix[9]; struct touch_point *p; wl_list_for_each(p, &sample->touch_points, link) { wlr_texture_get_matrix(sample->cat_texture, matrix, wlr_output->transform_matrix, (int)(p->x * width) - sample->cat_texture->width / 2, (int)(p->y * height) - sample->cat_texture->height / 2); - wlr_render_with_matrix(sample->renderer, sample->cat_texture, + wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, matrix, 1.0f); } diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index ee3fd38e..26189340 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -26,7 +26,7 @@ struct wlr_drm_plane { struct wlr_drm_surface mgpu_surf; // Only used by cursor - float matrix[16]; + float matrix[9]; struct wlr_texture *wlr_tex; struct gbm_bo *cursor_bo; bool cursor_enabled; diff --git a/include/wlr/render.h b/include/wlr/render.h index 50c2dd13..d1498b07 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -30,26 +30,26 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); * * struct wlr_renderer *renderer; * struct wlr_texture *texture; - * float projection[16]; - * float matrix[16]; - * wlr_texture_get_matrix(texture, &matrix, &projection, 123, 321); - * wlr_render_with_matrix(renderer, texture, &matrix, 0.5f); + * float projection[9]; + * float matrix[9]; + * wlr_texture_get_matrix(texture, matrix, projection, 123, 321); + * wlr_render_texture_with_matrix(renderer, texture, matrix, 0.5f); * * This will render the texture at <123, 321> with an alpha channel of 0.5. */ -bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float matrix[static 16], float alpha); +bool wlr_render_texture_with_matrix(struct wlr_renderer *r, + struct wlr_texture *texture, const float matrix[static 9], float alpha); /** * Renders a solid quad in the specified color. */ void wlr_render_colored_quad(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); /** * Renders a solid ellipse in the specified color. */ void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); /** * Returns a list of pixel formats supported by this renderer. */ @@ -139,8 +139,8 @@ bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, * width) and [0, height], and the x and y coordinates provided are used as * such. */ -void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 16], - const float projection[static 16], int x, int y); +void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 9], + const float projection[static 9], int x, int y); /** * Destroys this wlr_texture. */ diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 4d81bdf9..03b8309f 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -21,13 +21,13 @@ struct wlr_renderer_impl { void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); - bool (*render_with_matrix)(struct wlr_renderer *renderer, - struct wlr_texture *texture, const float matrix[static 16], + bool (*render_texture_with_matrix)(struct wlr_renderer *renderer, + struct wlr_texture *texture, const float matrix[static 9], float alpha); void (*render_quad)(struct wlr_renderer *renderer, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); void (*render_ellipse)(struct wlr_renderer *renderer, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); const enum wl_shm_format *(*formats)( struct wlr_renderer *renderer, size_t *len); bool (*buffer_is_drm)(struct wlr_renderer *renderer, @@ -59,8 +59,8 @@ struct wlr_texture_impl { struct wl_resource *drm_buf); bool (*upload_eglimage)(struct wlr_texture *texture, EGLImageKHR image, uint32_t width, uint32_t height); - void (*get_matrix)(struct wlr_texture *state, float mat[static 16], - const float projection[static 16], int x, int y); + void (*get_matrix)(struct wlr_texture *state, float mat[static 9], + const float projection[static 9], int x, int y); void (*get_buffer_size)(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height); void (*bind)(struct wlr_texture *texture); diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h index cf5ad20d..5255980a 100644 --- a/include/wlr/types/wlr_matrix.h +++ b/include/wlr/types/wlr_matrix.h @@ -2,22 +2,22 @@ #define WLR_TYPES_WLR_MATRIX_H #include +#include #include -void wlr_matrix_identity(float mat[static 16]); -void wlr_matrix_translate(float mat[static 16], float x, float y, float z); -void wlr_matrix_scale(float mat[static 16], float x, float y, float z); -void wlr_matrix_rotate(float mat[static 16], float radians); -void wlr_matrix_mul(float mat[static 16], const float x[static 16], - const float y[static 16]); - -enum wl_output_transform; -void wlr_matrix_transform(float mat[static 16], +void wlr_matrix_identity(float mat[static 9]); +void wlr_matrix_translate(float mat[static 9], float x, float y); +void wlr_matrix_scale(float mat[static 9], float x, float y); +void wlr_matrix_rotate(float mat[static 9], float rad); +void wlr_matrix_multiply(float mat[static 9], const float a[static 9], + const float b[static 9]); +void wlr_matrix_transform(float mat[static 9], enum wl_output_transform transform); -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, + +void wlr_matrix_texture(float mat[static 9], int32_t width, int32_t height, enum wl_output_transform transform); -void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, +void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box, enum wl_output_transform transform, float rotation, - const float projection[static 16]); + const float projection[static 9]); #endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index a8138a80..b838a737 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -76,7 +76,7 @@ struct wlr_output { // damage for cursors and fullscreen surface, in output-local coordinates pixman_region32_t damage; bool frame_pending; - float transform_matrix[16]; + float transform_matrix[9]; struct { struct wl_signal frame; diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 1d4c1f01..2bfd1bc9 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -70,8 +70,8 @@ struct wlr_surface { struct wlr_surface_state *current, *pending; const char *role; // the lifetime-bound role or null - float buffer_to_surface_matrix[16]; - float surface_to_buffer_matrix[16]; + float buffer_to_surface_matrix[9]; + float surface_to_buffer_matrix[9]; struct { struct wl_signal commit; @@ -109,9 +109,9 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, * from 0 to 1 in both dimensions. */ void wlr_surface_get_matrix(struct wlr_surface *surface, - float mat[static 16], - const float projection[static 16], - const float transform[static 16]); + float mat[static 9], + const float projection[static 9], + const float transform[static 9]); /** diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 9134a2fd..e0a98d29 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -85,11 +85,13 @@ static void init_default_shaders() { if (!compile_program(quad_vertex_src, quad_fragment_src, &shaders.quad)) { goto error; } - if (!compile_program(quad_vertex_src, ellipse_fragment_src, &shaders.ellipse)) { + if (!compile_program(quad_vertex_src, ellipse_fragment_src, + &shaders.ellipse)) { goto error; } if (glEGLImageTargetTexture2DOES) { - if (!compile_program(quad_vertex_src, fragment_src_external, &shaders.external)) { + if (!compile_program(quad_vertex_src, fragment_src_external, + &shaders.external)) { goto error; } } @@ -170,16 +172,16 @@ static void draw_quad() { GL_CALL(glDisableVertexAttribArray(1)); } -static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, - struct wlr_texture *texture, const float matrix[static 16], - float alpha) { +static bool wlr_gles2_render_texture_with_matrix( + struct wlr_renderer *wlr_renderer, struct wlr_texture *texture, + const float matrix[static 9], float alpha) { if (!texture || !texture->valid) { wlr_log(L_ERROR, "attempt to render invalid texture"); return false; } wlr_texture_bind(texture); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); + GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, matrix)); GL_CALL(glUniform1f(2, alpha)); draw_quad(); return true; @@ -187,17 +189,17 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { GL_CALL(glUseProgram(shaders.quad)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); + GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, matrix)); GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { GL_CALL(glUseProgram(shaders.ellipse)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, matrix)); + GL_CALL(glUniformMatrix3fv(0, 1, GL_TRUE, matrix)); GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } @@ -258,7 +260,7 @@ static struct wlr_renderer_impl wlr_renderer_impl = { .clear = wlr_gles2_clear, .scissor = wlr_gles2_scissor, .texture_create = wlr_gles2_texture_create, - .render_with_matrix = wlr_gles2_render_texture, + .render_texture_with_matrix = wlr_gles2_render_texture_with_matrix, .render_quad = wlr_gles2_render_quad, .render_ellipse = wlr_gles2_render_ellipse, .formats = wlr_gles2_formats, diff --git a/render/gles2/shaders.c b/render/gles2/shaders.c index 46a10248..9d3a67c2 100644 --- a/render/gles2/shaders.c +++ b/render/gles2/shaders.c @@ -3,29 +3,29 @@ // Colored quads const GLchar quad_vertex_src[] = -"uniform mat4 proj;" +"uniform mat3 proj;" "uniform vec4 color;" "attribute vec2 pos;" "attribute vec2 texcoord;" "varying vec4 v_color;" "varying vec2 v_texcoord;" -"mat4 transpose(in mat4 inMatrix) {" -" vec4 i0 = inMatrix[0];" -" vec4 i1 = inMatrix[1];" -" vec4 i2 = inMatrix[2];" -" vec4 i3 = inMatrix[3];" -" mat4 outMatrix = mat4(" -" vec4(i0.x, i1.x, i2.x, i3.x)," -" vec4(i0.y, i1.y, i2.y, i3.y)," -" vec4(i0.z, i1.z, i2.z, i3.z)," -" vec4(i0.w, i1.w, i2.w, i3.w)" -" );" -" return outMatrix;" +"" +"mat3 transpose(in mat3 inMatrix) {" +" vec3 i0 = inMatrix[0];" +" vec3 i1 = inMatrix[1];" +" vec3 i2 = inMatrix[2];" +" mat3 outMatrix = mat3(" +" vec3(i0.x, i1.x, i2.x)," +" vec3(i0.y, i1.y, i2.y)," +" vec3(i0.z, i1.z, i2.z)" +" );" +" return outMatrix;" "}" +"" "void main() {" -" gl_Position = transpose(proj) * vec4(pos, 0.0, 1.0);" -" v_color = color;" -" v_texcoord = texcoord;" +" gl_Position = vec4(transpose(proj) * vec3(pos, 1.0), 1.0);" +" v_color = color;" +" v_texcoord = texcoord;" "}"; const GLchar quad_fragment_src[] = @@ -49,26 +49,25 @@ const GLchar ellipse_fragment_src[] = // Textured quads const GLchar vertex_src[] = -"uniform mat4 proj;" +"uniform mat3 proj;" "attribute vec2 pos;" "attribute vec2 texcoord;" "varying vec2 v_texcoord;" -"mat4 transpose(in mat4 inMatrix) {" -" vec4 i0 = inMatrix[0];" -" vec4 i1 = inMatrix[1];" -" vec4 i2 = inMatrix[2];" -" vec4 i3 = inMatrix[3];" -" mat4 outMatrix = mat4(" -" vec4(i0.x, i1.x, i2.x, i3.x)," -" vec4(i0.y, i1.y, i2.y, i3.y)," -" vec4(i0.z, i1.z, i2.z, i3.z)," -" vec4(i0.w, i1.w, i2.w, i3.w)" -" );" "" -" return outMatrix;" +"mat3 transpose(in mat3 inMatrix) {" +" vec3 i0 = inMatrix[0];" +" vec3 i1 = inMatrix[1];" +" vec3 i2 = inMatrix[2];" +" mat3 outMatrix = mat3(" +" vec3(i0.x, i1.x, i2.x)," +" vec3(i0.y, i1.y, i2.y)," +" vec3(i0.z, i1.z, i2.z)" +" );" +" return outMatrix;" "}" +"" "void main() {" -" gl_Position = transpose(proj) * vec4(pos, 0.0, 1.0);" +" gl_Position = vec4(transpose(proj) * vec3(pos, 1.0), 1.0);" " v_texcoord = texcoord;" "}"; @@ -87,8 +86,8 @@ const GLchar fragment_src_rgbx[] = "uniform sampler2D tex;" "uniform float alpha;" "void main() {" -" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;" -" gl_FragColor.a = alpha;" +" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;" +" gl_FragColor.a = alpha;" "}"; const GLchar fragment_src_external[] = @@ -97,6 +96,6 @@ const GLchar fragment_src_external[] = "varying vec2 v_texcoord;" "uniform samplerExternalOES texture0;" "void main() {" -" vec4 col = texture2D(texture0, v_texcoord);" -" gl_FragColor = vec4(col.rgb, col.a);" +" vec4 col = texture2D(texture0, v_texcoord);" +" gl_FragColor = vec4(col.rgb, col.a);" "}"; diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 0dfebc48..9ee2a3e3 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -227,16 +227,13 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex, } static void gles2_texture_get_matrix(struct wlr_texture *_texture, - float mat[static 16], const float projection[static 16], int x, int y) { + float mat[static 9], const float projection[static 9], int x, int y) { struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture; - float world[16]; wlr_matrix_identity(mat); - wlr_matrix_translate(world, x, y, 0); - wlr_matrix_mul(mat, mat, world); - wlr_matrix_scale(world, - texture->wlr_texture.width, texture->wlr_texture.height, 1); - wlr_matrix_mul(mat, mat, world); - wlr_matrix_mul(mat, projection, mat); + wlr_matrix_translate(mat, x, y); + wlr_matrix_scale(mat, texture->wlr_texture.width, + texture->wlr_texture.height); + wlr_matrix_multiply(mat, projection, mat); } static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 372e4caf..e847fcc2 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -35,19 +35,19 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { return r->impl->texture_create(r); } -bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float matrix[static 16], +bool wlr_render_texture_with_matrix(struct wlr_renderer *r, + struct wlr_texture *texture, const float matrix[static 9], float alpha) { - return r->impl->render_with_matrix(r, texture, matrix, alpha); + return r->impl->render_texture_with_matrix(r, texture, matrix, alpha); } void wlr_render_colored_quad(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { r->impl->render_quad(r, color, matrix); } void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { r->impl->render_ellipse(r, color, matrix); } diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 0bfac32c..1ec9beb9 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -54,7 +54,7 @@ bool wlr_texture_upload_eglimage(struct wlr_texture *texture, } void wlr_texture_get_matrix(struct wlr_texture *texture, - float mat[static 16], const float projection[static 16], int x, int y) { + float mat[static 9], const float projection[static 9], int x, int y) { texture->impl->get_matrix(texture, mat, projection, x, y); } diff --git a/rootston/output.c b/rootston/output.c index 47236720..29fb1202 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -287,7 +287,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, goto damage_finish; } - float matrix[16]; + float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); wlr_matrix_project_box(matrix, &box, transform, rotation, @@ -297,7 +297,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_with_matrix(renderer, surface->texture, matrix, data->alpha); + wlr_render_texture_with_matrix(renderer, surface->texture, matrix, data->alpha); } damage_finish: @@ -353,7 +353,7 @@ static void render_decorations(struct roots_view *view, goto damage_finish; } - float matrix[16]; + float matrix[9]; wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, view->rotation, output->wlr_output->transform_matrix); float color[] = { 0.2, 0.2, 0.2, view->alpha }; diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index a6be9908..85a294d9 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -5,143 +5,113 @@ #include #include -/* Obtains the index for the given row/column */ -static inline int mind(int row, int col) { - return (row - 1) * 4 + col - 1; -} - -void wlr_matrix_identity(float mat[static 16]) { - static const float identity[16] = { - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f, +void wlr_matrix_identity(float mat[static 9]) { + static const float identity[9] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }; memcpy(mat, identity, sizeof(identity)); } -void wlr_matrix_translate(float mat[static 16], float x, float y, float z) { - wlr_matrix_identity(mat); - mat[mind(1, 4)] = x; - mat[mind(2, 4)] = y; - mat[mind(3, 4)] = z; +void wlr_matrix_multiply(float mat[static 9], const float a[static 9], + const float b[static 9]) { + float product[9]; + + product[0] = a[0]*b[0] + a[1]*b[3] + a[2]*b[6]; + product[1] = a[0]*b[1] + a[1]*b[4] + a[2]*b[7]; + product[2] = a[0]*b[2] + a[1]*b[5] + a[2]*b[8]; + + product[3] = a[3]*b[0] + a[4]*b[3] + a[5]*b[6]; + product[4] = a[3]*b[1] + a[4]*b[4] + a[5]*b[7]; + product[5] = a[3]*b[2] + a[4]*b[5] + a[5]*b[8]; + + product[6] = a[6]*b[0] + a[7]*b[3] + a[8]*b[6]; + product[7] = a[6]*b[1] + a[7]*b[4] + a[8]*b[7]; + product[8] = a[6]*b[2] + a[7]*b[5] + a[8]*b[8]; + + memcpy(mat, product, sizeof(product)); } -void wlr_matrix_scale(float mat[static 16], float x, float y, float z) { - wlr_matrix_identity(mat); - mat[mind(1, 1)] = x; - mat[mind(2, 2)] = y; - mat[mind(3, 3)] = z; +void wlr_matrix_translate(float mat[static 9], float x, float y) { + float translate[9] = { + 1.0f, 0.0f, x, + 0.0f, 1.0f, y, + 0.0f, 0.0f, 1.0f, + }; + wlr_matrix_multiply(mat, mat, translate); } -void wlr_matrix_rotate(float mat[static 16], float radians) { - wlr_matrix_identity(mat); - float _cos = cosf(radians); - float _sin = sinf(radians); - mat[mind(1, 1)] = _cos; - mat[mind(1, 2)] = _sin; - mat[mind(2, 1)] = -_sin; - mat[mind(2, 2)] = _cos; +void wlr_matrix_scale(float mat[static 9], float x, float y) { + float scale[9] = { + x, 0.0f, 0.0f, + 0.0f, y, 0.0f, + 0.0f, 0.0f, 1.0f, + }; + wlr_matrix_multiply(mat, mat, scale); } -void wlr_matrix_mul(float mat[static 16], const float x[static 16], - const float y[static 16]) { - float product[16] = { - x[mind(1, 1)] * y[mind(1, 1)] + x[mind(1, 2)] * y[mind(2, 1)] + - x[mind(1, 3)] * y[mind(3, 1)] + x[mind(1, 4)] * y[mind(4, 1)], - x[mind(1, 1)] * y[mind(1, 2)] + x[mind(1, 2)] * y[mind(2, 2)] + - x[mind(1, 3)] * y[mind(3, 2)] + x[mind(1, 4)] * y[mind(4, 2)], - x[mind(1, 1)] * y[mind(1, 3)] + x[mind(1, 2)] * y[mind(2, 3)] + - x[mind(1, 3)] * y[mind(3, 3)] + x[mind(1, 4)] * y[mind(4, 3)], - x[mind(1, 1)] * y[mind(1, 4)] + x[mind(1, 2)] * y[mind(2, 4)] + - x[mind(1, 4)] * y[mind(3, 4)] + x[mind(1, 4)] * y[mind(4, 4)], - - x[mind(2, 1)] * y[mind(1, 1)] + x[mind(2, 2)] * y[mind(2, 1)] + - x[mind(2, 3)] * y[mind(3, 1)] + x[mind(2, 4)] * y[mind(4, 1)], - x[mind(2, 1)] * y[mind(1, 2)] + x[mind(2, 2)] * y[mind(2, 2)] + - x[mind(2, 3)] * y[mind(3, 2)] + x[mind(2, 4)] * y[mind(4, 2)], - x[mind(2, 1)] * y[mind(1, 3)] + x[mind(2, 2)] * y[mind(2, 3)] + - x[mind(2, 3)] * y[mind(3, 3)] + x[mind(2, 4)] * y[mind(4, 3)], - x[mind(2, 1)] * y[mind(1, 4)] + x[mind(2, 2)] * y[mind(2, 4)] + - x[mind(2, 4)] * y[mind(3, 4)] + x[mind(2, 4)] * y[mind(4, 4)], - - x[mind(3, 1)] * y[mind(1, 1)] + x[mind(3, 2)] * y[mind(2, 1)] + - x[mind(3, 3)] * y[mind(3, 1)] + x[mind(3, 4)] * y[mind(4, 1)], - x[mind(3, 1)] * y[mind(1, 2)] + x[mind(3, 2)] * y[mind(2, 2)] + - x[mind(3, 3)] * y[mind(3, 2)] + x[mind(3, 4)] * y[mind(4, 2)], - x[mind(3, 1)] * y[mind(1, 3)] + x[mind(3, 2)] * y[mind(2, 3)] + - x[mind(3, 3)] * y[mind(3, 3)] + x[mind(3, 4)] * y[mind(4, 3)], - x[mind(3, 1)] * y[mind(1, 4)] + x[mind(3, 2)] * y[mind(2, 4)] + - x[mind(3, 4)] * y[mind(3, 4)] + x[mind(3, 4)] * y[mind(4, 4)], - - x[mind(4, 1)] * y[mind(1, 1)] + x[mind(4, 2)] * y[mind(2, 1)] + - x[mind(4, 3)] * y[mind(3, 1)] + x[mind(4, 4)] * y[mind(4, 1)], - x[mind(4, 1)] * y[mind(1, 2)] + x[mind(4, 2)] * y[mind(2, 2)] + - x[mind(4, 3)] * y[mind(3, 2)] + x[mind(4, 4)] * y[mind(4, 2)], - x[mind(4, 1)] * y[mind(1, 3)] + x[mind(4, 2)] * y[mind(2, 3)] + - x[mind(4, 3)] * y[mind(3, 3)] + x[mind(4, 4)] * y[mind(4, 3)], - x[mind(4, 1)] * y[mind(1, 4)] + x[mind(4, 2)] * y[mind(2, 4)] + - x[mind(4, 4)] * y[mind(3, 4)] + x[mind(4, 4)] * y[mind(4, 4)], +void wlr_matrix_rotate(float mat[static 9], float rad) { + float rotate[9] = { + cos(rad), -sin(rad), 0.0f, + sin(rad), cos(rad), 0.0f, + 0.0f, 0.0f, 1.0f, }; - memcpy(mat, product, sizeof(product)); + wlr_matrix_multiply(mat, mat, rotate); } -static const float transforms[][4] = { +static const float transforms[][9] = { [WL_OUTPUT_TRANSFORM_NORMAL] = { - 1.0f, 0.0f, - 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_90] = { - 0.0f, -1.0f, - 1.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_180] = { - -1.0f, 0.0f, - 0.0f, -1.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_270] = { - 0.0f, 1.0f, - -1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED] = { - -1.0f, 0.0f, - 0.0f, 1.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { - 0.0f, -1.0f, - -1.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { - 1.0f, 0.0f, - 0.0f, -1.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { - 0.0f, 1.0f, - 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, }; -void wlr_matrix_transform(float mat[static 16], +void wlr_matrix_transform(float mat[static 9], enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); - - const float *t = transforms[transform]; - - // Rotation + reflection - mat[0] = t[0]; - mat[1] = t[1]; - mat[4] = t[2]; - mat[5] = t[3]; - - // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; + wlr_matrix_multiply(mat, mat, transforms[transform]); } // Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, +void wlr_matrix_texture(float mat[static 9], int32_t width, int32_t height, enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); + memset(mat, 0, sizeof(*mat) * 9); const float *t = transforms[transform]; float x = 2.0f / width; @@ -150,62 +120,41 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, // Rotation + reflection mat[0] = x * t[0]; mat[1] = x * t[1]; - mat[4] = y * -t[2]; - mat[5] = y * -t[3]; + mat[3] = y * -t[3]; + mat[4] = y * -t[4]; // Translation - mat[3] = -copysign(1.0f, mat[0] + mat[1]); - mat[7] = -copysign(1.0f, mat[4] + mat[5]); + mat[2] = -copysign(1.0f, mat[0] + mat[1]); + mat[5] = -copysign(1.0f, mat[3] + mat[4]); // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; + mat[8] = 1.0f; } -void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, +void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box, enum wl_output_transform transform, float rotation, - const float projection[static 16]) { + const float projection[static 9]) { int x = box->x; int y = box->y; int width = box->width; int height = box->height; - wlr_matrix_translate(mat, x, y, 0); + wlr_matrix_identity(mat); + wlr_matrix_translate(mat, x, y); if (rotation != 0) { - float translate_center[16]; - wlr_matrix_translate(translate_center, width/2, height/2, 0); - - float rotate[16]; - wlr_matrix_rotate(rotate, rotation); - - float translate_origin[16]; - wlr_matrix_translate(translate_origin, -width/2, -height/2, 0); - - wlr_matrix_mul(mat, mat, translate_center); - wlr_matrix_mul(mat, mat, rotate); - wlr_matrix_mul(mat, mat, translate_origin); + wlr_matrix_translate(mat, width/2, height/2); + wlr_matrix_rotate(mat, rotation); + wlr_matrix_translate(mat, -width/2, -height/2); } - float scale[16]; - wlr_matrix_scale(scale, width, height, 1); - - wlr_matrix_mul(mat, mat, scale); + wlr_matrix_scale(mat, width, height); if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { - float surface_translate_center[16]; - wlr_matrix_translate(surface_translate_center, 0.5, 0.5, 0); - - float surface_transform[16]; - wlr_matrix_transform(surface_transform, transform); - - float surface_translate_origin[16]; - wlr_matrix_translate(surface_translate_origin, -0.5, -0.5, 0); - - wlr_matrix_mul(mat, mat, surface_translate_center); - wlr_matrix_mul(mat, mat, surface_transform); - wlr_matrix_mul(mat, mat, surface_translate_origin); + wlr_matrix_translate(mat, 0.5, 0.5); + wlr_matrix_transform(mat, transform); + wlr_matrix_translate(mat, -0.5, -0.5); } - wlr_matrix_mul(mat, projection, mat); + wlr_matrix_multiply(mat, projection, mat); } diff --git a/types/wlr_output.c b/types/wlr_output.c index a9fb01c5..9a0edd44 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -375,7 +375,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output, struct wlr_box box; output_fullscreen_surface_get_box(output, surface, &box); - float matrix[16]; + float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); wlr_matrix_project_box(matrix, &box, transform, 0, @@ -386,7 +386,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output, for (int i = 0; i < nrects; ++i) { output_scissor(output, &rects[i]); wlr_renderer_clear(renderer, (float[]){0, 0, 0, 0}); - wlr_render_with_matrix(surface->renderer, surface->texture, matrix, 1.0f); + wlr_render_texture_with_matrix(surface->renderer, surface->texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); @@ -435,7 +435,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, goto surface_damage_finish; } - float matrix[16]; + float matrix[9]; wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, cursor->output->transform_matrix); @@ -443,7 +443,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects); for (int i = 0; i < nrects; ++i) { output_scissor(cursor->output, &rects[i]); - wlr_render_with_matrix(renderer, texture, matrix, 1.0f); + wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 04dcb141..ecab4842 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -624,20 +624,16 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, return surface; } -void wlr_surface_get_matrix(struct wlr_surface *surface, - float mat[static 16], - const float projection[static 16], - const float transform[static 16]) { +void wlr_surface_get_matrix(struct wlr_surface *surface, float mat[static 9], + const float projection[static 9], const float transform[static 9]) { int width = surface->texture->width; int height = surface->texture->height; - float scale[16]; wlr_matrix_identity(mat); - if (transform) { - wlr_matrix_mul(mat, mat, transform); + if (transform != NULL) { + wlr_matrix_multiply(mat, mat, transform); } - wlr_matrix_scale(scale, width, height, 1); - wlr_matrix_mul(mat, mat, scale); - wlr_matrix_mul(mat, projection, mat); + wlr_matrix_scale(mat, width, height); + wlr_matrix_multiply(mat, projection, mat); } bool wlr_surface_has_buffer(struct wlr_surface *surface) { -- cgit v1.2.3 From e607d0f7ee00c59354c996fc98e738c26adbca58 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 20:15:09 +0100 Subject: xdg-shell: add map/unmap support --- include/rootston/view.h | 2 + include/wlr/types/wlr_xdg_shell.h | 33 +-- rootston/xdg_shell.c | 58 ++++- types/wlr_xdg_shell.c | 518 ++++++++++++++++++++++---------------- 4 files changed, 355 insertions(+), 256 deletions(-) (limited to 'rootston') diff --git a/include/rootston/view.h b/include/rootston/view.h index 92d1feb5..775f3d11 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -44,6 +44,8 @@ struct roots_xdg_surface { struct wl_listener destroy; struct wl_listener new_popup; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 8422863c..ad0a626f 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -62,19 +62,10 @@ enum wlr_xdg_surface_role { }; struct wlr_xdg_toplevel_state { - bool maximized; - bool fullscreen; - bool resizing; - bool activated; - - uint32_t width; - uint32_t height; - - uint32_t max_width; - uint32_t max_height; - - uint32_t min_width; - uint32_t min_height; + bool maximized, fullscreen, resizing, activated; + uint32_t width, height; + uint32_t max_width, max_height; + uint32_t min_width, min_height; }; struct wlr_xdg_toplevel { @@ -90,7 +81,8 @@ struct wlr_xdg_toplevel { struct wlr_xdg_surface_configure { struct wl_list link; // wlr_xdg_surface::configure_list uint32_t serial; - struct wlr_xdg_toplevel_state state; + + struct wlr_xdg_toplevel_state *toplevel_state; }; struct wlr_xdg_surface { @@ -101,14 +93,13 @@ struct wlr_xdg_surface { enum wlr_xdg_surface_role role; union { - struct wlr_xdg_toplevel *toplevel_state; - struct wlr_xdg_popup *popup_state; + struct wlr_xdg_toplevel *toplevel; + struct wlr_xdg_popup *popup; }; struct wl_list popups; // wlr_xdg_popup::link - bool configured; - bool added; + bool added, configured, mapped; uint32_t configure_serial; struct wl_event_source *configure_idle; uint32_t configure_next_serial; @@ -118,8 +109,8 @@ struct wlr_xdg_surface { char *app_id; bool has_next_geometry; - struct wlr_box *next_geometry; - struct wlr_box *geometry; + struct wlr_box next_geometry; + struct wlr_box geometry; struct wl_listener surface_destroy_listener; @@ -127,6 +118,8 @@ struct wlr_xdg_surface { struct wl_signal destroy; struct wl_signal ping_timeout; struct wl_signal new_popup; + struct wl_signal map; + struct wl_signal unmap; struct wl_signal request_maximize; struct wl_signal request_fullscreen; diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 24c57bd5..851c0045 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -60,12 +60,14 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_VIEW); struct wlr_xdg_surface *surface = view->xdg_surface; - if (surface->geometry->width > 0 && surface->geometry->height > 0) { - box->width = surface->geometry->width; - box->height = surface->geometry->height; - } else { + if (surface->geometry.width > 0 && surface->geometry.height > 0) { + box->width = surface->geometry.width; + box->height = surface->geometry.height; + } else if (view->wlr_surface != NULL) { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; + } else { + box->width = box->height = 0; } } @@ -83,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface *surface, *dest_width = width; *dest_height = height; - struct wlr_xdg_toplevel_state *state = &surface->toplevel_state->current; + struct wlr_xdg_toplevel_state *state = &surface->toplevel->current; if (width < state->min_width) { *dest_width = state->min_width; } else if (state->max_width > 0 && @@ -181,10 +183,13 @@ static void close(struct roots_view *view) { } static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_XDG_SHELL_VIEW); struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface; wl_list_remove(&roots_xdg_surface->surface_commit.link); wl_list_remove(&roots_xdg_surface->destroy.link); wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->map.link); + wl_list_remove(&roots_xdg_surface->unmap.link); wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); @@ -231,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { return; } - view_maximize(view, surface->toplevel_state->next.maximized); + view_maximize(view, surface->toplevel->next.maximized); } static void handle_request_fullscreen(struct wl_listener *listener, @@ -255,6 +260,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface *surface = view->xdg_surface; + if (!surface->mapped) { + return; + } + view_apply_damage(view); struct wlr_box size; @@ -289,6 +298,26 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { popup_create(roots_xdg_surface->view, wlr_popup); } +static void handle_map(struct wl_listener *listener, void *data) { + struct roots_xdg_surface *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, map); + struct roots_view *view = roots_xdg_surface->view; + + struct wlr_box box; + get_size(view, &box); + view->width = box.width; + view->height = box.height; + + view_map(view, view->xdg_surface->surface); + view_setup(view); +} + +static void handle_unmap(struct wl_listener *listener, void *data) { + struct roots_xdg_surface *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, unmap); + view_unmap(roots_xdg_surface->view); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); @@ -321,6 +350,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { &roots_surface->surface_commit); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + roots_surface->map.notify = handle_map; + wl_signal_add(&surface->events.map, &roots_surface->map); + roots_surface->unmap.notify = handle_unmap; + wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; @@ -353,11 +386,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->destroy = destroy; roots_surface->view = view; - struct wlr_box box; - get_size(view, &box); - view->width = box.width; - view->height = box.height; - - view_map(view, surface->surface); - view_setup(view); + if (surface->toplevel->next.maximized) { + view_maximize(view, true); + } + if (surface->toplevel->next.fullscreen) { + view_set_fullscreen(view, true, NULL); + } } diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c index 990926cf..5b02088d 100644 --- a/types/wlr_xdg_shell.c +++ b/types/wlr_xdg_shell.c @@ -34,7 +34,7 @@ struct wlr_xdg_positioner { }; -static void resource_destroy(struct wl_client *client, +static void resource_handle_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } @@ -159,43 +159,37 @@ static struct wlr_xdg_popup_grab *xdg_shell_popup_grab_from_seat( } -static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { - // TODO: probably need to ungrab before this event - wlr_signal_emit_safe(&surface->events.destroy, surface); - - if (surface->configure_idle) { - wl_event_source_remove(surface->configure_idle); +static void xdg_surface_configure_destroy( + struct wlr_xdg_surface_configure *configure) { + if (configure == NULL) { + return; } + wl_list_remove(&configure->link); + free(configure->toplevel_state); + free(configure); +} - struct wlr_xdg_surface_configure *configure, *tmp; - wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { - free(configure); - } +static void xdg_surface_unmap(struct wlr_xdg_surface *surface) { + assert(surface->role != WLR_XDG_SURFACE_ROLE_NONE); + + // TODO: probably need to ungrab before this event + wlr_signal_emit_safe(&surface->events.unmap, surface); if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { - wl_resource_set_user_data(surface->toplevel_state->resource, NULL); - free(surface->toplevel_state); + wl_resource_set_user_data(surface->toplevel->resource, NULL); + free(surface->toplevel); + surface->toplevel = NULL; } if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - wl_resource_set_user_data(surface->popup_state->resource, NULL); + wl_resource_set_user_data(surface->popup->resource, NULL); - if (surface->popup_state->seat) { + if (surface->popup->seat) { struct wlr_xdg_popup_grab *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup_state->seat); + surface->popup->seat); - struct wlr_xdg_surface *topmost = - xdg_popup_grab_get_topmost(grab); - - if (topmost != surface) { - wl_resource_post_error(surface->client->resource, - XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP, - "xdg_popup was destroyed while it was not the topmost " - "popup."); - } - - wl_list_remove(&surface->popup_state->grab_link); + wl_list_remove(&surface->popup->grab_link); if (wl_list_empty(&grab->popups)) { if (grab->seat->pointer_state.grab == &grab->pointer_grab) { @@ -207,18 +201,46 @@ static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { } } - wl_list_remove(&surface->popup_state->link); - free(surface->popup_state); + wl_list_remove(&surface->popup->link); + free(surface->popup); + surface->popup = NULL; } + struct wlr_xdg_surface_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + xdg_surface_configure_destroy(configure); + } + + surface->role = WLR_XDG_SURFACE_ROLE_NONE; + free(surface->title); + surface->title = NULL; + free(surface->app_id); + surface->app_id = NULL; + + surface->added = surface->configured = surface->mapped = false; + surface->configure_serial = 0; + if (surface->configure_idle) { + wl_event_source_remove(surface->configure_idle); + surface->configure_idle = NULL; + } + surface->configure_next_serial = 0; + + surface->has_next_geometry = false; + memset(&surface->geometry, 0, sizeof(struct wlr_box)); + memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); +} + +static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { + if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) { + xdg_surface_unmap(surface); + } + + wlr_signal_emit_safe(&surface->events.destroy, surface); + wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); - free(surface->geometry); - free(surface->next_geometry); - free(surface->title); - free(surface->app_id); free(surface); } @@ -238,7 +260,7 @@ static void xdg_positioner_destroy(struct wl_resource *resource) { free(positioner); } -static void xdg_positioner_protocol_set_size(struct wl_client *client, +static void xdg_positioner_handle_set_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -254,7 +276,7 @@ static void xdg_positioner_protocol_set_size(struct wl_client *client, positioner->size.height = height; } -static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client, +static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_positioner *positioner = @@ -273,7 +295,7 @@ static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client, positioner->anchor_rect.height = height; } -static void xdg_positioner_protocol_set_anchor(struct wl_client *client, +static void xdg_positioner_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -288,7 +310,7 @@ static void xdg_positioner_protocol_set_anchor(struct wl_client *client, positioner->anchor = anchor; } -static void xdg_positioner_protocol_set_gravity(struct wl_client *client, +static void xdg_positioner_handle_set_gravity(struct wl_client *client, struct wl_resource *resource, uint32_t gravity) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -303,7 +325,7 @@ static void xdg_positioner_protocol_set_gravity(struct wl_client *client, positioner->gravity = gravity; } -static void xdg_positioner_protocol_set_constraint_adjustment( +static void xdg_positioner_handle_set_constraint_adjustment( struct wl_client *client, struct wl_resource *resource, uint32_t constraint_adjustment) { struct wlr_xdg_positioner *positioner = @@ -312,7 +334,7 @@ static void xdg_positioner_protocol_set_constraint_adjustment( positioner->constraint_adjustment = constraint_adjustment; } -static void xdg_positioner_protocol_set_offset(struct wl_client *client, +static void xdg_positioner_handle_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -323,17 +345,17 @@ static void xdg_positioner_protocol_set_offset(struct wl_client *client, static const struct xdg_positioner_interface xdg_positioner_implementation = { - .destroy = resource_destroy, - .set_size = xdg_positioner_protocol_set_size, - .set_anchor_rect = xdg_positioner_protocol_set_anchor_rect, - .set_anchor = xdg_positioner_protocol_set_anchor, - .set_gravity = xdg_positioner_protocol_set_gravity, + .destroy = resource_handle_destroy, + .set_size = xdg_positioner_handle_set_size, + .set_anchor_rect = xdg_positioner_handle_set_anchor_rect, + .set_anchor = xdg_positioner_handle_set_anchor, + .set_gravity = xdg_positioner_handle_set_gravity, .set_constraint_adjustment = - xdg_positioner_protocol_set_constraint_adjustment, - .set_offset = xdg_positioner_protocol_set_offset, + xdg_positioner_handle_set_constraint_adjustment, + .set_offset = xdg_positioner_handle_set_offset, }; -static void xdg_shell_create_positioner(struct wl_client *wl_client, +static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_positioner *positioner = calloc(1, sizeof(struct wlr_xdg_positioner)); @@ -458,7 +480,7 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_popup_resource( return wl_resource_get_user_data(resource); } -static void xdg_popup_protocol_grab(struct wl_client *client, +static void xdg_popup_handle_grab(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface *surface = @@ -466,8 +488,8 @@ static void xdg_popup_protocol_grab(struct wl_client *client, struct wlr_seat_client *seat_client = wlr_seat_client_from_resource(seat_resource); - if (surface->popup_state->committed) { - wl_resource_post_error(surface->popup_state->resource, + if (surface->popup->committed) { + wl_resource_post_error(surface->popup->resource, XDG_POPUP_ERROR_INVALID_GRAB, "xdg_popup is already mapped"); return; @@ -479,10 +501,10 @@ static void xdg_popup_protocol_grab(struct wl_client *client, struct wlr_xdg_surface *topmost = xdg_popup_grab_get_topmost(popup_grab); bool parent_is_toplevel = - surface->popup_state->parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL; + surface->popup->parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL; if ((topmost == NULL && !parent_is_toplevel) || - (topmost != NULL && topmost != surface->popup_state->parent)) { + (topmost != NULL && topmost != surface->popup->parent)) { wl_resource_post_error(surface->client->resource, XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP, "xdg_popup was not created on the topmost popup"); @@ -490,9 +512,9 @@ static void xdg_popup_protocol_grab(struct wl_client *client, } popup_grab->client = surface->client->client; - surface->popup_state->seat = seat_client->seat; + surface->popup->seat = seat_client->seat; - wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link); + wl_list_insert(&popup_grab->popups, &surface->popup->grab_link); wlr_seat_pointer_start_grab(seat_client->seat, &popup_grab->pointer_grab); @@ -500,16 +522,36 @@ static void xdg_popup_protocol_grab(struct wl_client *client, &popup_grab->keyboard_grab); } +static void xdg_popup_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_surface *surface = + xdg_surface_from_xdg_popup_resource(resource); + struct wlr_xdg_popup_grab *grab = + xdg_shell_popup_grab_from_seat(surface->client->shell, + surface->popup->seat); + struct wlr_xdg_surface *topmost = + xdg_popup_grab_get_topmost(grab); + + if (topmost != surface) { + wl_resource_post_error(surface->client->resource, + XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP, + "xdg_popup was destroyed while it was not the topmost popup"); + return; + } + + wl_resource_destroy(resource); +} + static const struct xdg_popup_interface xdg_popup_implementation = { - .destroy = resource_destroy, - .grab = xdg_popup_protocol_grab, + .destroy = xdg_popup_handle_destroy, + .grab = xdg_popup_handle_grab, }; static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { - xdg_surface_destroy(surface); + xdg_surface_unmap(surface); } } @@ -522,7 +564,7 @@ static struct wlr_xdg_surface *xdg_surface_from_resource( return wl_resource_get_user_data(resource); } -static void xdg_surface_get_popup(struct wl_client *client, +static void xdg_surface_handle_get_popup(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *parent_resource, struct wl_resource *positioner_resource) { @@ -545,33 +587,33 @@ static void xdg_surface_get_popup(struct wl_client *client, return; } - surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup)); - if (!surface->popup_state) { + surface->popup = calloc(1, sizeof(struct wlr_xdg_popup)); + if (!surface->popup) { wl_resource_post_no_memory(resource); return; } - surface->popup_state->resource = + surface->popup->resource = wl_resource_create(client, &xdg_popup_interface, wl_resource_get_version(resource), id); - if (surface->popup_state->resource == NULL) { - free(surface->popup_state); + if (surface->popup->resource == NULL) { + free(surface->popup); wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_ROLE_POPUP; - surface->popup_state->base = surface; - surface->popup_state->parent = parent; - surface->popup_state->geometry = + surface->popup->base = surface; + surface->popup->parent = parent; + surface->popup->geometry = xdg_positioner_get_geometry(positioner, surface, parent); - wl_list_insert(&parent->popups, &surface->popup_state->link); + wl_list_insert(&parent->popups, &surface->popup->link); - wl_resource_set_implementation(surface->popup_state->resource, + wl_resource_set_implementation(surface->popup->resource, &xdg_popup_implementation, surface, xdg_popup_resource_destroy); - wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state); + wlr_signal_emit_safe(&parent->events.new_popup, surface->popup); } @@ -584,7 +626,7 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource( return wl_resource_get_user_data(resource); } -static void xdg_toplevel_protocol_set_parent(struct wl_client *client, +static void xdg_toplevel_handle_set_parent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent_resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -594,10 +636,10 @@ static void xdg_toplevel_protocol_set_parent(struct wl_client *client, parent = xdg_surface_from_xdg_toplevel_resource(parent_resource); } - surface->toplevel_state->parent = parent; + surface->toplevel->parent = parent; } -static void xdg_toplevel_protocol_set_title(struct wl_client *client, +static void xdg_toplevel_handle_set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -612,7 +654,7 @@ static void xdg_toplevel_protocol_set_title(struct wl_client *client, surface->title = tmp; } -static void xdg_toplevel_protocol_set_app_id(struct wl_client *client, +static void xdg_toplevel_handle_set_app_id(struct wl_client *client, struct wl_resource *resource, const char *app_id) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -627,7 +669,7 @@ static void xdg_toplevel_protocol_set_app_id(struct wl_client *client, surface->app_id = tmp; } -static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, +static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct wlr_xdg_surface *surface = @@ -636,7 +678,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -658,7 +700,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event); } -static void xdg_toplevel_protocol_move(struct wl_client *client, +static void xdg_toplevel_handle_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface *surface = @@ -667,7 +709,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -687,7 +729,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_move, &event); } -static void xdg_toplevel_protocol_resize(struct wl_client *client, +static void xdg_toplevel_handle_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct wlr_xdg_surface *surface = @@ -696,7 +738,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -717,39 +759,39 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_resize, &event); } -static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, +static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.max_width = width; - surface->toplevel_state->next.max_height = height; + surface->toplevel->next.max_width = width; + surface->toplevel->next.max_height = height; } -static void xdg_toplevel_protocol_set_min_size(struct wl_client *client, +static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.min_width = width; - surface->toplevel_state->next.min_height = height; + surface->toplevel->next.min_width = width; + surface->toplevel->next.min_height = height; } -static void xdg_toplevel_protocol_set_maximized(struct wl_client *client, +static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = true; + surface->toplevel->next.maximized = true; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } -static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, +static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = false; + surface->toplevel->next.maximized = false; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } -static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, +static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -759,7 +801,7 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, output = wlr_output_from_resource(output_resource); } - surface->toplevel_state->next.fullscreen = true; + surface->toplevel->next.fullscreen = true; struct wlr_xdg_toplevel_set_fullscreen_event event = { .surface = surface, @@ -770,12 +812,12 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } -static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, +static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.fullscreen = false; + surface->toplevel->next.fullscreen = false; struct wlr_xdg_toplevel_set_fullscreen_event event = { .surface = surface, @@ -786,7 +828,7 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } -static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, +static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -794,20 +836,20 @@ static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, } static const struct xdg_toplevel_interface xdg_toplevel_implementation = { - .destroy = resource_destroy, - .set_parent = xdg_toplevel_protocol_set_parent, - .set_title = xdg_toplevel_protocol_set_title, - .set_app_id = xdg_toplevel_protocol_set_app_id, - .show_window_menu = xdg_toplevel_protocol_show_window_menu, - .move = xdg_toplevel_protocol_move, - .resize = xdg_toplevel_protocol_resize, - .set_max_size = xdg_toplevel_protocol_set_max_size, - .set_min_size = xdg_toplevel_protocol_set_min_size, - .set_maximized = xdg_toplevel_protocol_set_maximized, - .unset_maximized = xdg_toplevel_protocol_unset_maximized, - .set_fullscreen = xdg_toplevel_protocol_set_fullscreen, - .unset_fullscreen = xdg_toplevel_protocol_unset_fullscreen, - .set_minimized = xdg_toplevel_protocol_set_minimized + .destroy = resource_handle_destroy, + .set_parent = xdg_toplevel_handle_set_parent, + .set_title = xdg_toplevel_handle_set_title, + .set_app_id = xdg_toplevel_handle_set_app_id, + .show_window_menu = xdg_toplevel_handle_show_window_menu, + .move = xdg_toplevel_handle_move, + .resize = xdg_toplevel_handle_resize, + .set_max_size = xdg_toplevel_handle_set_max_size, + .set_min_size = xdg_toplevel_handle_set_min_size, + .set_maximized = xdg_toplevel_handle_set_maximized, + .unset_maximized = xdg_toplevel_handle_unset_maximized, + .set_fullscreen = xdg_toplevel_handle_set_fullscreen, + .unset_fullscreen = xdg_toplevel_handle_unset_fullscreen, + .set_minimized = xdg_toplevel_handle_set_minimized, }; static void xdg_surface_resource_destroy(struct wl_resource *resource) { @@ -822,11 +864,11 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { - xdg_surface_destroy(surface); + xdg_surface_unmap(surface); } } -static void xdg_surface_get_toplevel(struct wl_client *client, +static void xdg_surface_handle_get_toplevel(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); @@ -835,24 +877,24 @@ static void xdg_surface_get_toplevel(struct wl_client *client, return; } - surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel)); - if (surface->toplevel_state == NULL) { + surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel)); + if (surface->toplevel == NULL) { wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL; - surface->toplevel_state->base = surface; + surface->toplevel->base = surface; struct wl_resource *toplevel_resource = wl_resource_create(client, &xdg_toplevel_interface, wl_resource_get_version(resource), id); if (toplevel_resource == NULL) { - free(surface->toplevel_state); + free(surface->toplevel); wl_resource_post_no_memory(resource); return; } - surface->toplevel_state->resource = toplevel_resource; + surface->toplevel->resource = toplevel_resource; wl_resource_set_implementation(toplevel_resource, &xdg_toplevel_implementation, surface, @@ -863,12 +905,19 @@ static void wlr_xdg_toplevel_ack_configure( struct wlr_xdg_surface *surface, struct wlr_xdg_surface_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->next = configure->state; - surface->toplevel_state->pending.width = 0; - surface->toplevel_state->pending.height = 0; + assert(configure->toplevel_state != NULL); + + surface->toplevel->current.maximized = + configure->toplevel_state->maximized; + surface->toplevel->current.fullscreen = + configure->toplevel_state->fullscreen; + surface->toplevel->current.resizing = + configure->toplevel_state->resizing; + surface->toplevel->current.activated = + configure->toplevel_state->activated; } -static void xdg_surface_ack_configure(struct wl_client *client, +static void xdg_surface_handle_ack_configure(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); @@ -883,10 +932,8 @@ static void xdg_surface_ack_configure(struct wl_client *client, struct wlr_xdg_surface_configure *configure, *tmp; wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { if (configure->serial < serial) { - wl_list_remove(&configure->link); - free(configure); + xdg_surface_configure_destroy(configure); } else if (configure->serial == serial) { - wl_list_remove(&configure->link); found = true; break; } else { @@ -914,10 +961,10 @@ static void xdg_surface_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; - free(configure); + xdg_surface_configure_destroy(configure); } -static void xdg_surface_set_window_geometry(struct wl_client *client, +static void xdg_surface_handle_set_window_geometry(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); @@ -930,19 +977,31 @@ static void xdg_surface_set_window_geometry(struct wl_client *client, } surface->has_next_geometry = true; - surface->next_geometry->height = height; - surface->next_geometry->width = width; - surface->next_geometry->x = x; - surface->next_geometry->y = y; + surface->next_geometry.height = height; + surface->next_geometry.width = width; + surface->next_geometry.x = x; + surface->next_geometry.y = y; +} + +static void xdg_surface_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); + if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) { + wlr_log(L_ERROR, "Tried to destroy an xdg_surface before its role " + "object"); + return; + } + + wl_resource_destroy(resource); } static const struct xdg_surface_interface xdg_surface_implementation = { - .destroy = resource_destroy, - .get_toplevel = xdg_surface_get_toplevel, - .get_popup = xdg_surface_get_popup, - .ack_configure = xdg_surface_ack_configure, - .set_window_geometry = xdg_surface_set_window_geometry, + .destroy = xdg_surface_handle_destroy, + .get_toplevel = xdg_surface_handle_get_toplevel, + .get_popup = xdg_surface_handle_get_popup, + .ack_configure = xdg_surface_handle_ack_configure, + .set_window_geometry = xdg_surface_handle_set_window_geometry, }; static bool wlr_xdg_surface_toplevel_state_compare( @@ -965,9 +1024,9 @@ static bool wlr_xdg_surface_toplevel_state_compare( } else { struct wlr_xdg_surface_configure *configure = wl_container_of(state->base->configure_list.prev, configure, link); - configured.state = configure->state; - configured.width = configure->state.width; - configured.height = configure->state.height; + configured.state = *configure->toplevel_state; + configured.width = configure->toplevel_state->width; + configured.height = configure->toplevel_state->height; } if (state->pending.activated != configured.state.activated) { @@ -999,13 +1058,19 @@ static void wlr_xdg_toplevel_send_configure( struct wlr_xdg_surface *surface, struct wlr_xdg_surface_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - uint32_t *s; - struct wl_array states; - configure->state = surface->toplevel_state->pending; + configure->toplevel_state = malloc(sizeof(*configure->toplevel_state)); + if (configure->toplevel_state == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + wl_resource_post_no_memory(surface->toplevel->resource); + return; + } + *configure->toplevel_state = surface->toplevel->pending; + uint32_t *s; + struct wl_array states; wl_array_init(&states); - if (surface->toplevel_state->pending.maximized) { + if (surface->toplevel->pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -1013,7 +1078,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_MAXIMIZED; } - if (surface->toplevel_state->pending.fullscreen) { + if (surface->toplevel->pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -1021,7 +1086,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_FULLSCREEN; } - if (surface->toplevel_state->pending.resizing) { + if (surface->toplevel->pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -1029,7 +1094,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_RESIZING; } - if (surface->toplevel_state->pending.activated) { + if (surface->toplevel->pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -1038,23 +1103,17 @@ static void wlr_xdg_toplevel_send_configure( *s = XDG_TOPLEVEL_STATE_ACTIVATED; } - uint32_t width = surface->toplevel_state->pending.width; - uint32_t height = surface->toplevel_state->pending.height; - - if (width == 0 || height == 0) { - width = surface->geometry->width; - height = surface->geometry->height; - } - - xdg_toplevel_send_configure(surface->toplevel_state->resource, width, - height, &states); + uint32_t width = surface->toplevel->pending.width; + uint32_t height = surface->toplevel->pending.height; + xdg_toplevel_send_configure(surface->toplevel->resource, width, height, + &states); wl_array_release(&states); return; error_out: wl_array_release(&states); - wl_resource_post_no_memory(surface->toplevel_state->resource); + wl_resource_post_no_memory(surface->toplevel->resource); } static void wlr_xdg_surface_send_configure(void *user_data) { @@ -1080,11 +1139,11 @@ static void wlr_xdg_surface_send_configure(void *user_data) { wlr_xdg_toplevel_send_configure(surface, configure); break; case WLR_XDG_SURFACE_ROLE_POPUP: - xdg_popup_send_configure(surface->popup_state->resource, - surface->popup_state->geometry.x, - surface->popup_state->geometry.y, - surface->popup_state->geometry.width, - surface->popup_state->geometry.height); + xdg_popup_send_configure(surface->popup->resource, + surface->popup->geometry.x, + surface->popup->geometry.y, + surface->popup->geometry.width, + surface->popup->geometry.height); break; } @@ -1103,7 +1162,7 @@ static uint32_t wlr_xdg_surface_schedule_configure( break; case WLR_XDG_SURFACE_ROLE_TOPLEVEL: pending_same = - wlr_xdg_surface_toplevel_state_compare(surface->toplevel_state); + wlr_xdg_surface_toplevel_state_compare(surface->toplevel); break; case WLR_XDG_SURFACE_ROLE_POPUP: break; @@ -1143,29 +1202,32 @@ static void wlr_xdg_surface_toplevel_committed( struct wlr_xdg_surface *surface) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - if (!wlr_surface_has_buffer(surface->surface) - && !surface->toplevel_state->added) { + if (!surface->toplevel->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_schedule_configure(surface); - surface->toplevel_state->added = true; - return; - } - - if (!wlr_surface_has_buffer(surface->surface)) { + surface->toplevel->added = true; return; } - surface->toplevel_state->current = surface->toplevel_state->next; + // update state that doesn't need compositor approval + surface->toplevel->current.max_width = + surface->toplevel->next.max_width; + surface->toplevel->current.min_width = + surface->toplevel->next.min_width; + surface->toplevel->current.max_height = + surface->toplevel->next.max_height; + surface->toplevel->current.min_height = + surface->toplevel->next.min_height; } static void wlr_xdg_surface_popup_committed( struct wlr_xdg_surface *surface) { assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP); - if (!surface->popup_state->committed) { + if (!surface->popup->committed) { wlr_xdg_surface_schedule_configure(surface); - surface->popup_state->committed = true; + surface->popup->committed = true; } } @@ -1182,10 +1244,10 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (surface->has_next_geometry) { surface->has_next_geometry = false; - surface->geometry->x = surface->next_geometry->x; - surface->geometry->y = surface->next_geometry->y; - surface->geometry->width = surface->next_geometry->width; - surface->geometry->height = surface->next_geometry->height; + surface->geometry.x = surface->next_geometry.x; + surface->geometry.y = surface->next_geometry.y; + surface->geometry.width = surface->next_geometry.width; + surface->geometry.height = surface->next_geometry.height; } switch (surface->role) { @@ -1202,9 +1264,19 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, break; } - if (surface->configured && !surface->added) { + if (!surface->added) { surface->added = true; - wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + surface); + } + if (surface->configured && wlr_surface_has_buffer(surface->surface) && + !surface->mapped) { + surface->mapped = true; + wlr_signal_emit_safe(&surface->events.map, surface); + } + if (surface->configured && !wlr_surface_has_buffer(surface->surface) && + surface->mapped) { + xdg_surface_unmap(surface); } } @@ -1217,27 +1289,15 @@ static struct wlr_xdg_client *xdg_client_from_resource( return wl_resource_get_user_data(resource); } -static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, +static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, struct wl_resource *client_resource, uint32_t id, struct wl_resource *surface_resource) { struct wlr_xdg_client *client = xdg_client_from_resource(client_resource); - struct wlr_xdg_surface *surface; - if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface)))) { - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface); - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface->geometry); - free(surface); + struct wlr_xdg_surface *surface = + calloc(1, sizeof(struct wlr_xdg_surface)); + if (surface == NULL) { wl_client_post_no_memory(wl_client); return; } @@ -1249,8 +1309,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, &xdg_surface_interface, wl_resource_get_version(client_resource), id); if (surface->resource == NULL) { - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_client_post_no_memory(wl_client); return; @@ -1258,8 +1316,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, if (wlr_surface_has_buffer(surface->surface)) { wl_resource_destroy(surface->resource); - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_resource_post_error(surface_resource, XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER, @@ -1279,6 +1335,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.new_popup); + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); wl_signal_add(&surface->surface->events.destroy, &surface->surface_destroy_listener); @@ -1293,7 +1351,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_list_insert(&client->surfaces, &surface->link); } -static void xdg_shell_pong(struct wl_client *wl_client, +static void xdg_shell_handle_pong(struct wl_client *wl_client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_client *client = xdg_client_from_resource(resource); @@ -1305,11 +1363,25 @@ static void xdg_shell_pong(struct wl_client *wl_client, client->ping_serial = 0; } +static void xdg_shell_handle_destroy(struct wl_client *wl_client, + struct wl_resource *resource) { + struct wlr_xdg_client *client = xdg_client_from_resource(resource); + + if (!wl_list_empty(&client->surfaces)) { + wl_resource_post_error(client->resource, + XDG_WM_BASE_ERROR_DEFUNCT_SURFACES, + "xdg_wm_base was destroyed before children"); + return; + } + + wl_resource_destroy(resource); +} + static const struct xdg_wm_base_interface xdg_shell_impl = { - .destroy = resource_destroy, - .create_positioner = xdg_shell_create_positioner, - .get_xdg_surface = xdg_shell_get_xdg_surface, - .pong = xdg_shell_pong, + .destroy = xdg_shell_handle_destroy, + .create_positioner = xdg_shell_handle_create_positioner, + .get_xdg_surface = xdg_shell_handle_get_xdg_surface, + .pong = xdg_shell_handle_pong, }; static void wlr_xdg_client_destroy(struct wl_resource *resource) { @@ -1437,8 +1509,8 @@ void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface) { uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.width = width; - surface->toplevel_state->pending.height = height; + surface->toplevel->pending.width = width; + surface->toplevel->pending.height = height; return wlr_xdg_surface_schedule_configure(surface); } @@ -1446,7 +1518,7 @@ uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.activated = activated; + surface->toplevel->pending.activated = activated; return wlr_xdg_surface_schedule_configure(surface); } @@ -1454,7 +1526,7 @@ uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.maximized = maximized; + surface->toplevel->pending.maximized = maximized; return wlr_xdg_surface_schedule_configure(surface); } @@ -1462,7 +1534,7 @@ uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.fullscreen = fullscreen; + surface->toplevel->pending.fullscreen = fullscreen; return wlr_xdg_surface_schedule_configure(surface); } @@ -1470,24 +1542,24 @@ uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.resizing = resizing; + surface->toplevel->pending.resizing = resizing; return wlr_xdg_surface_schedule_configure(surface); } void wlr_xdg_toplevel_send_close(struct wlr_xdg_surface *surface) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - xdg_toplevel_send_close(surface->toplevel_state->resource); + xdg_toplevel_send_close(surface->toplevel->resource); } void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface, double *popup_sx, double *popup_sy) { assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP); - struct wlr_xdg_surface *parent = surface->popup_state->parent; - *popup_sx = parent->geometry->x + surface->popup_state->geometry.x - - surface->geometry->x; - *popup_sy = parent->geometry->y + surface->popup_state->geometry.y - - surface->geometry->y; + struct wlr_xdg_surface *parent = surface->popup->parent; + *popup_sx = parent->geometry.x + surface->popup->geometry.x - + surface->geometry.x; + *popup_sy = parent->geometry.y + surface->popup->geometry.y - + surface->geometry.y; } struct wlr_xdg_surface *wlr_xdg_surface_popup_at( @@ -1501,30 +1573,30 @@ struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_xdg_surface *popup = popup_state->base; double _popup_sx = - surface->geometry->x + popup_state->geometry.x; + surface->geometry.x + popup_state->geometry.x; double _popup_sy = - surface->geometry->y + popup_state->geometry.y; + surface->geometry.y + popup_state->geometry.y; int popup_width = popup_state->geometry.width; int popup_height = popup_state->geometry.height; struct wlr_xdg_surface *_popup = wlr_xdg_surface_popup_at(popup, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, popup_sx, popup_sy); if (_popup) { - *popup_sx = *popup_sx + _popup_sx - popup->geometry->x; - *popup_sy = *popup_sy + _popup_sy - popup->geometry->y; + *popup_sx = *popup_sx + _popup_sx - popup->geometry.x; + *popup_sy = *popup_sy + _popup_sy - popup->geometry.y; return _popup; } if ((sx > _popup_sx && sx < _popup_sx + popup_width) && (sy > _popup_sy && sy < _popup_sy + popup_height)) { if (pixman_region32_contains_point(&popup->surface->current->input, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, NULL)) { - *popup_sx = _popup_sx - popup->geometry->x; - *popup_sy = _popup_sy - popup->geometry->y; + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, NULL)) { + *popup_sx = _popup_sx - popup->geometry.x; + *popup_sy = _popup_sy - popup->geometry.y; return popup; } } -- cgit v1.2.3 From 303883ce49b81438c8653991f40e72b0481e27cf Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 21:47:20 +0100 Subject: rootston: properly emit view unmap event --- rootston/desktop.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rootston') diff --git a/rootston/desktop.c b/rootston/desktop.c index e9a9425c..78076e75 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -459,6 +459,8 @@ void view_map(struct roots_view *view, struct wlr_surface *surface) { void view_unmap(struct roots_view *view) { assert(view->wlr_surface != NULL); + wl_signal_emit(&view->events.unmap, view); + view_damage_whole(view); wl_list_remove(&view->link); -- cgit v1.2.3 From a491f780b892b60aa65e17dc5dcb1752a2b78ee7 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 18 Mar 2018 08:59:56 +0100 Subject: rootston rotation: change view->rotation sign The convetion with wlr_matrix changed and it's a good time to remove all these pesky minus signs --- rootston/cursor.c | 2 +- rootston/desktop.c | 4 ++-- rootston/output.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'rootston') diff --git a/rootston/cursor.c b/rootston/cursor.c index aa94daeb..52439dff 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -200,7 +200,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uy = cursor->offs_y - oy; int vx = cursor->cursor->x - ox, vy = cursor->cursor->y - oy; - float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy); + float angle = atan2(ux*vy - uy*vx, vx*ux + vy*uy); int steps = 12; angle = round(angle/M_PI*steps) / (steps/M_PI); view_rotate(view, cursor->view_rotation + angle); diff --git a/rootston/desktop.c b/rootston/desktop.c index 9730ca57..65d9a280 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -557,8 +557,8 @@ static bool view_at(struct roots_view *view, double lx, double ly, double ox = view_sx - (double)box.width/2, oy = view_sy - (double)box.height/2; // Rotated coordinates - double rx = cos(view->rotation)*ox - sin(view->rotation)*oy, - ry = cos(view->rotation)*oy + sin(view->rotation)*ox; + double rx = cos(view->rotation)*ox + sin(view->rotation)*oy, + ry = cos(view->rotation)*oy - sin(view->rotation)*ox; view_sx = rx + (double)box.width/2; view_sy = ry + (double)box.height/2; } diff --git a/rootston/output.c b/rootston/output.c index b8c73290..4146e3e2 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -29,8 +29,8 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh, double ox = *sx - pw/2 + sw/2, oy = *sy - ph/2 + sh/2; // Rotated coordinates - double rx = cos(-rotation)*ox - sin(-rotation)*oy, - ry = cos(-rotation)*oy + sin(-rotation)*ox; + double rx = cos(rotation)*ox - sin(rotation)*oy, + ry = cos(rotation)*oy + sin(rotation)*ox; *sx = rx + pw/2 - sw/2; *sy = ry + ph/2 - sh/2; } @@ -227,7 +227,7 @@ static bool surface_intersect_output(struct wlr_surface *surface, .x = lx, .y = ly, .width = surface->current->width, .height = surface->current->height, }; - wlr_box_rotated_bounds(&layout_box, -rotation, &layout_box); + wlr_box_rotated_bounds(&layout_box, rotation, &layout_box); return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box); } @@ -275,7 +275,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, } struct wlr_box rotated; - wlr_box_rotated_bounds(&box, -rotation, &rotated); + wlr_box_rotated_bounds(&box, rotation, &rotated); pixman_region32_t damage; pixman_region32_init(&damage); @@ -341,7 +341,7 @@ static void render_decorations(struct roots_view *view, get_decoration_box(view, output, &box); struct wlr_box rotated; - wlr_box_rotated_bounds(&box, -view->rotation, &rotated); + wlr_box_rotated_bounds(&box, view->rotation, &rotated); pixman_region32_t damage; pixman_region32_init(&damage); @@ -616,7 +616,7 @@ static void damage_whole_surface(struct wlr_surface *surface, return; } - wlr_box_rotated_bounds(&box, -rotation, &box); + wlr_box_rotated_bounds(&box, rotation, &box); wlr_output_damage_add_box(output->damage, &box); } @@ -630,7 +630,7 @@ static void damage_whole_decoration(struct roots_view *view, struct wlr_box box; get_decoration_box(view, output, &box); - wlr_box_rotated_bounds(&box, -view->rotation, &box); + wlr_box_rotated_bounds(&box, view->rotation, &box); wlr_output_damage_add_box(output->damage, &box); } @@ -689,7 +689,7 @@ static void damage_from_surface(struct wlr_surface *surface, .width = (extents->x2 - extents->x1) * wlr_output->scale, .height = (extents->y2 - extents->y1) * wlr_output->scale, }; - wlr_box_rotated_bounds(&damage_box, -rotation, &damage_box); + wlr_box_rotated_bounds(&damage_box, rotation, &damage_box); wlr_output_damage_add_box(output->damage, &damage_box); } } -- cgit v1.2.3 From c41de2d1be5c8e814e99e3a1859cdaa885b6042d Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 19 Mar 2018 23:16:29 +0100 Subject: render: split render.h into wlr_renderer.h and wlr_texture.h --- backend/drm/drm.c | 2 +- backend/drm/renderer.c | 2 +- examples/idle-inhibit.c | 2 +- examples/idle.c | 6 +- examples/multi-pointer.c | 28 ++++---- examples/output-layout.c | 26 +++---- examples/pointer.c | 28 ++++---- examples/rotation.c | 16 ++--- examples/simple.c | 6 +- examples/tablet.c | 20 +++--- examples/touch.c | 20 +++--- include/backend/drm/renderer.h | 2 +- include/backend/wayland.h | 2 +- include/render/gles2.h | 3 +- include/rootston/server.h | 2 +- include/wlr/render.h | 135 ------------------------------------- include/wlr/render/gles2.h | 2 +- include/wlr/render/interface.h | 5 +- include/wlr/render/wlr_renderer.h | 75 +++++++++++++++++++++ include/wlr/render/wlr_texture.h | 69 +++++++++++++++++++ include/wlr/types/wlr_compositor.h | 2 +- render/gles2/renderer.c | 2 +- render/gles2/texture.c | 2 +- render/wlr_renderer.c | 1 + render/wlr_texture.c | 1 + rootston/main.c | 2 +- types/wlr_linux_dmabuf.c | 1 - types/wlr_output.c | 2 +- types/wlr_screenshooter.c | 2 +- 29 files changed, 239 insertions(+), 227 deletions(-) delete mode 100644 include/wlr/render.h create mode 100644 include/wlr/render/wlr_renderer.h create mode 100644 include/wlr/render/wlr_texture.h (limited to 'rootston') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index fd436659..344756f8 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -15,8 +15,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 97fba95a..7e330990 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -7,9 +7,9 @@ #include #include #include -#include #include #include +#include #include #include #include "backend/drm/drm.h" diff --git a/examples/idle-inhibit.c b/examples/idle-inhibit.c index b7b9c21c..c09e6507 100644 --- a/examples/idle-inhibit.c +++ b/examples/idle-inhibit.c @@ -5,8 +5,8 @@ #include #include #include -#include "xdg-shell-client-protocol.h" #include "idle-inhibit-unstable-v1-client-protocol.h" +#include "xdg-shell-client-protocol.h" #include diff --git a/examples/idle.c b/examples/idle.c index 2b155c68..b65a81cf 100644 --- a/examples/idle.c +++ b/examples/idle.c @@ -1,11 +1,11 @@ +#include +#include #include #include #include #include -#include -#include -#include #include +#include #include #include "idle-client-protocol.h" diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index 6e56bfdc..43ccdb66 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -1,30 +1,30 @@ #define _POSIX_C_SOURCE 199309L #define _XOPEN_SOURCE 500 +#include +#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include #include #include +#include +#include +#include #include +#include +#include #include -#include -#include #include -#include -#include "support/shared.h" -#include "support/config.h" +#include +#include #include "support/cat.h" +#include "support/config.h" +#include "support/shared.h" struct sample_state; diff --git a/examples/output-layout.c b/examples/output-layout.c index 8f506208..de134a71 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -1,29 +1,29 @@ #define _POSIX_C_SOURCE 199309L #define _XOPEN_SOURCE 700 +#include +#include +#include #include #include -#include #include #include +#include #include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include #include #include +#include +#include +#include +#include #include #include -#include -#include -#include "support/shared.h" -#include "support/config.h" +#include +#include #include "support/cat.h" +#include "support/config.h" +#include "support/shared.h" struct sample_state { struct example_config *config; diff --git a/examples/pointer.c b/examples/pointer.c index e80b346a..e8a0e892 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -1,30 +1,30 @@ #define _POSIX_C_SOURCE 199309L #define _XOPEN_SOURCE 500 +#include +#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include #include #include +#include +#include +#include #include +#include +#include #include -#include -#include #include -#include -#include "support/shared.h" -#include "support/config.h" +#include +#include #include "support/cat.h" +#include "support/config.h" +#include "support/shared.h" struct sample_state { struct compositor_state *compositor; diff --git a/examples/rotation.c b/examples/rotation.c index aaf006cf..7f50b620 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -1,23 +1,23 @@ #define _POSIX_C_SOURCE 199309L #define _XOPEN_SOURCE 500 +#include +#include #include #include -#include #include #include +#include #include -#include #include -#include -#include -#include -#include -#include +#include #include #include +#include +#include #include +#include #include -#include +#include #include "support/shared.h" #include "support/config.h" #include "support/cat.h" diff --git a/examples/simple.c b/examples/simple.c index 90808b0f..79db4a0c 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -1,11 +1,11 @@ #define _POSIX_C_SOURCE 199309L -#include +#include +#include #include #include +#include #include -#include #include -#include #include #include #include diff --git a/examples/tablet.c b/examples/tablet.c index 521447b9..1b995003 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -1,27 +1,27 @@ #define _POSIX_C_SOURCE 199309L #define _XOPEN_SOURCE 500 +#include +#include #include #include -#include #include +#include #include -#include #include -#include -#include -#include -#include -#include +#include #include #include +#include +#include #include +#include #include -#include #include +#include #include -#include -#include "support/shared.h" +#include #include "support/cat.h" +#include "support/shared.h" struct sample_state { struct wlr_renderer *renderer; diff --git a/examples/touch.c b/examples/touch.c index 0af8bc4a..0968e82a 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -1,25 +1,25 @@ #define _POSIX_C_SOURCE 199309L #define _XOPEN_SOURCE 500 +#include +#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include #include #include +#include +#include #include +#include #include -#include "support/shared.h" +#include #include "support/cat.h" +#include "support/shared.h" struct sample_state { struct wlr_renderer *renderer; diff --git a/include/backend/drm/renderer.h b/include/backend/drm/renderer.h index a56a8673..73adfc27 100644 --- a/include/backend/drm/renderer.h +++ b/include/backend/drm/renderer.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include struct wlr_drm_backend; struct wlr_drm_plane; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 16c8e13b..b68208af 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include struct wlr_wl_backend { diff --git a/include/render/gles2.h b/include/render/gles2.h index e015160d..e8124050 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -9,9 +9,10 @@ #include #include #include -#include #include #include +#include +#include #include extern PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; diff --git a/include/rootston/server.h b/include/rootston/server.h index 5f35dd90..7ab15682 100644 --- a/include/rootston/server.h +++ b/include/rootston/server.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #ifdef WLR_HAS_XWAYLAND #include diff --git a/include/wlr/render.h b/include/wlr/render.h deleted file mode 100644 index 01d05fb1..00000000 --- a/include/wlr/render.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef WLR_RENDER_H -#define WLR_RENDER_H - -#include -#include -#include -#include -#include -#include - -struct wlr_texture; -struct wlr_renderer; - -void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); -void wlr_renderer_end(struct wlr_renderer *r); -void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); -/** - * Defines a scissor box. Only pixels that lie within the scissor box can be - * modified by drawing functions. Providing a NULL `box` disables the scissor - * box. - */ -void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box); -/** - * Requests a texture handle from this renderer. - */ -struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); -/** - * Renders the requested texture. - */ -bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, - const float projection[static 9], int x, int y, float alpha); -/** - * Renders the requested texture using the provided matrix. - */ -bool wlr_render_texture_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float matrix[static 9], float alpha); -/** - * Renders a solid quad in the specified color. - */ -void wlr_render_colored_quad(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 9]); -/** - * Renders a solid ellipse in the specified color. - */ -void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 9]); -/** - * Returns a list of pixel formats supported by this renderer. - */ -const enum wl_shm_format *wlr_renderer_get_formats( - struct wlr_renderer *r, size_t *len); -/** - * Returns true if this wl_buffer is a DRM buffer. - */ -bool wlr_renderer_buffer_is_drm(struct wlr_renderer *renderer, - struct wl_resource *buffer); -/** - * Reads out of pixels of the currently bound surface into data. `stride` is in - * bytes. - */ -bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt, - uint32_t stride, uint32_t width, uint32_t height, - uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data); -/** - * Checks if a format is supported. - */ -bool wlr_renderer_format_supported(struct wlr_renderer *r, - enum wl_shm_format fmt); -/** - * Destroys this wlr_renderer. Textures must be destroyed separately. - */ -void wlr_renderer_destroy(struct wlr_renderer *renderer); - -struct wlr_texture_impl; - -struct wlr_texture { - struct wlr_texture_impl *impl; - - bool valid; - uint32_t format; - int width, height; - bool inverted_y; - struct wl_signal destroy_signal; - struct wl_resource *resource; -}; - -/** - * Copies pixels to this texture. The buffer is not accessed after this function - * returns. - */ -bool wlr_texture_upload_pixels(struct wlr_texture *tex, - enum wl_shm_format format, int stride, int width, int height, - const unsigned char *pixels); -/** - * Copies pixels to this texture. The buffer is not accessed after this function - * returns. Under some circumstances, this function may re-upload the entire - * buffer - therefore, the entire buffer must be valid. - */ -bool wlr_texture_update_pixels(struct wlr_texture *surf, - enum wl_shm_format format, int stride, int x, int y, - int width, int height, const unsigned char *pixels); -/** - * Copies pixels from a wl_shm_buffer into this texture. The buffer is not - * accessed after this function returns. - */ -bool wlr_texture_upload_shm(struct wlr_texture *tex, uint32_t format, - struct wl_shm_buffer *shm); - -/** - * Attaches the contents from the given wl_drm wl_buffer resource onto the - * texture. The wl_resource is not used after this call. - * Will fail (return false) if the given resource is no drm buffer. - */ -bool wlr_texture_upload_drm(struct wlr_texture *tex, - struct wl_resource *drm_buffer); - -bool wlr_texture_upload_eglimage(struct wlr_texture *tex, - EGLImageKHR image, uint32_t width, uint32_t height); - -bool wlr_texture_upload_dmabuf(struct wlr_texture *tex, - struct wl_resource *dmabuf_resource); -/** - * Copies a rectangle of pixels from a wl_shm_buffer onto the texture. The - * buffer is not accessed after this function returns. Under some circumstances, - * this function may re-upload the entire buffer - therefore, the entire buffer - * must be valid. - */ -bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, - int x, int y, int width, int height, struct wl_shm_buffer *shm); -/** - * Destroys this wlr_texture. - */ -void wlr_texture_destroy(struct wlr_texture *texture); - -#endif diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index a924a065..b3b43ab2 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -2,7 +2,7 @@ #define WLR_RENDER_GLES2_H #include -#include +#include struct wlr_egl; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend); diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 1b8b7946..f0307230 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -5,10 +5,11 @@ #include #include #include -#include +#include +#include #include -#include #include +#include struct wlr_renderer_impl; diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h new file mode 100644 index 00000000..d5f3cf70 --- /dev/null +++ b/include/wlr/render/wlr_renderer.h @@ -0,0 +1,75 @@ +#ifndef WLR_RENDER_WLR_RENDERER_H +#define WLR_RENDER_WLR_RENDERER_H + +#include +#include +#include +#include +#include +#include + +struct wlr_output; + +struct wlr_renderer; + +void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); +void wlr_renderer_end(struct wlr_renderer *r); +void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); +/** + * Defines a scissor box. Only pixels that lie within the scissor box can be + * modified by drawing functions. Providing a NULL `box` disables the scissor + * box. + */ +void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box); +/** + * Requests a texture handle from this renderer. + */ +struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); +/** + * Renders the requested texture. + */ +bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, + const float projection[static 9], int x, int y, float alpha); +/** + * Renders the requested texture using the provided matrix. + */ +bool wlr_render_texture_with_matrix(struct wlr_renderer *r, + struct wlr_texture *texture, const float matrix[static 9], float alpha); +/** + * Renders a solid quad in the specified color. + */ +void wlr_render_colored_quad(struct wlr_renderer *r, + const float color[static 4], const float matrix[static 9]); +/** + * Renders a solid ellipse in the specified color. + */ +void wlr_render_colored_ellipse(struct wlr_renderer *r, + const float color[static 4], const float matrix[static 9]); +/** + * Returns a list of pixel formats supported by this renderer. + */ +const enum wl_shm_format *wlr_renderer_get_formats(struct wlr_renderer *r, + size_t *len); +/** + * Returns true if this wl_buffer is a DRM buffer. + */ +bool wlr_renderer_buffer_is_drm(struct wlr_renderer *renderer, + struct wl_resource *buffer); +/** + * Reads out of pixels of the currently bound surface into data. `stride` is in + * bytes. + */ +bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt, + uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data); +/** + * Checks if a format is supported. + */ +bool wlr_renderer_format_supported(struct wlr_renderer *r, + enum wl_shm_format fmt); +/** + * Destroys this wlr_renderer. Textures must be destroyed separately. + */ +void wlr_renderer_destroy(struct wlr_renderer *renderer); + +#endif diff --git a/include/wlr/render/wlr_texture.h b/include/wlr/render/wlr_texture.h new file mode 100644 index 00000000..49aa93d7 --- /dev/null +++ b/include/wlr/render/wlr_texture.h @@ -0,0 +1,69 @@ +#ifndef WLR_RENDER_WLR_TEXTURE_H +#define WLR_RENDER_WLR_TEXTURE_H + +#include +#include +#include +#include + +struct wlr_texture_impl; + +struct wlr_texture { + struct wlr_texture_impl *impl; + + bool valid; + uint32_t format; + int width, height; + bool inverted_y; + struct wl_signal destroy_signal; + struct wl_resource *resource; +}; + +/** + * Copies pixels to this texture. The buffer is not accessed after this function + * returns. + */ +bool wlr_texture_upload_pixels(struct wlr_texture *tex, + enum wl_shm_format format, int stride, int width, int height, + const unsigned char *pixels); +/** + * Copies pixels to this texture. The buffer is not accessed after this function + * returns. Under some circumstances, this function may re-upload the entire + * buffer - therefore, the entire buffer must be valid. + */ +bool wlr_texture_update_pixels(struct wlr_texture *surf, + enum wl_shm_format format, int stride, int x, int y, + int width, int height, const unsigned char *pixels); +/** + * Copies pixels from a wl_shm_buffer into this texture. The buffer is not + * accessed after this function returns. + */ +bool wlr_texture_upload_shm(struct wlr_texture *tex, uint32_t format, + struct wl_shm_buffer *shm); +/** + * Attaches the contents from the given wl_drm wl_buffer resource onto the + * texture. The wl_resource is not used after this call. + * Will fail (return false) if the given resource is no drm buffer. + */ +bool wlr_texture_upload_drm(struct wlr_texture *tex, + struct wl_resource *drm_buffer); + +bool wlr_texture_upload_eglimage(struct wlr_texture *tex, + EGLImageKHR image, uint32_t width, uint32_t height); + +bool wlr_texture_upload_dmabuf(struct wlr_texture *tex, + struct wl_resource *dmabuf_resource); +/** + * Copies a rectangle of pixels from a wl_shm_buffer onto the texture. The + * buffer is not accessed after this function returns. Under some circumstances, + * this function may re-upload the entire buffer - therefore, the entire buffer + * must be valid. + */ +bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, + int x, int y, int width, int height, struct wl_shm_buffer *shm); +/** + * Destroys this wlr_texture. + */ +void wlr_texture_destroy(struct wlr_texture *texture); + +#endif diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h index 5919b934..11bfac71 100644 --- a/include/wlr/types/wlr_compositor.h +++ b/include/wlr/types/wlr_compositor.h @@ -2,7 +2,7 @@ #define WLR_TYPES_WLR_COMPOSITOR_H #include -#include +#include struct wlr_compositor { struct wl_global *wl_global; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 8d8dd17f..55797805 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/render/gles2/texture.c b/render/gles2/texture.c index fc94ead5..c5f79ba8 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index c4f91d5e..21a7901a 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -1,6 +1,7 @@ #include #include #include +#include #include void wlr_renderer_init(struct wlr_renderer *renderer, diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 48f76c8e..a5d0abde 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -1,6 +1,7 @@ #include #include #include +#include void wlr_texture_init(struct wlr_texture *texture, struct wlr_texture_impl *impl) { diff --git a/rootston/main.c b/rootston/main.c index 5450ade2..d85701ca 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "rootston/config.h" #include "rootston/server.h" diff --git a/types/wlr_linux_dmabuf.c b/types/wlr_linux_dmabuf.c index 3b86166e..1883bc49 100644 --- a/types/wlr_linux_dmabuf.c +++ b/types/wlr_linux_dmabuf.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/types/wlr_output.c b/types/wlr_output.c index 9575f071..e30c3b78 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index e756b6aa..e1386be6 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3 From 3581573bdcbe3c905eae83af53cccbcdd52edad2 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 20 Mar 2018 23:10:42 +0100 Subject: render/gles2: make wlr_renderer_begin take viewport size This allows raw GL calls outside wlr_renderer to be removed. --- backend/drm/drm.c | 13 ++++++------- backend/drm/renderer.c | 23 +++++++++++------------ backend/headless/output.c | 14 ++++++-------- backend/wayland/output.c | 21 ++++++++++----------- examples/output-layout.c | 2 +- examples/rotation.c | 2 +- examples/tablet.c | 2 +- examples/touch.c | 2 +- include/wlr/render/interface.h | 3 ++- include/wlr/render/wlr_renderer.h | 2 +- render/gles2/renderer.c | 6 +++--- render/wlr_renderer.c | 4 ++-- rootston/output.c | 2 +- wlroots.syms | 2 +- 14 files changed, 47 insertions(+), 51 deletions(-) (limited to 'rootston') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 344756f8..345c0dd8 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -643,14 +643,13 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, wlr_texture_upload_pixels(plane->wlr_tex, WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); - glViewport(0, 0, plane->surf.width, plane->surf.height); - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT); + struct wlr_renderer *rend = plane->surf.renderer->wlr_rend; + wlr_renderer_begin(rend, plane->surf.width, plane->surf.height); + wlr_renderer_clear(rend, (float[]){ 0.0, 0.0, 0.0, 0.0 }); + wlr_render_texture(rend, plane->wlr_tex, plane->matrix, 0, 0, 1.0f); + wlr_renderer_end(rend); - wlr_render_texture(plane->surf.renderer->wlr_rend, plane->wlr_tex, - plane->matrix, 0, 0, 1.0f); - - glFinish(); + // TODO: remove these raw GL calls glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); glReadPixels(0, 0, plane->surf.width, plane->surf.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bo_data); diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 7e330990..3b9aaded 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -107,9 +106,6 @@ void wlr_drm_surface_finish(struct wlr_drm_surface *surf) { return; } - eglMakeCurrent(surf->renderer->egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); - if (surf->front) { gbm_surface_release_buffer(surf->gbm, surf->front); } @@ -151,9 +147,10 @@ struct gbm_bo *wlr_drm_surface_get_front(struct wlr_drm_surface *surf) { } wlr_drm_surface_make_current(surf, NULL); - glViewport(0, 0, surf->width, surf->height); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); + struct wlr_renderer *renderer = surf->renderer->wlr_rend; + wlr_renderer_begin(renderer, surf->width, surf->height); + wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 1.0 }); + wlr_renderer_end(renderer); return wlr_drm_surface_swap_buffers(surf, NULL); } @@ -185,6 +182,8 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, return tex->tex; } + // TODO: use wlr_texture_upload_dmabuf instead + tex = malloc(sizeof(*tex)); if (!tex) { wlr_log_errno(L_ERROR, "Allocation failed"); @@ -230,14 +229,14 @@ struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, struct wlr_texture *tex = get_tex_for_bo(dest->renderer, src); assert(tex); - static const float color[] = {0.0, 0.0, 0.0, 1.0}; - float mat[9]; wlr_matrix_projection(mat, 1, 1, WL_OUTPUT_TRANSFORM_FLIPPED_180); - glViewport(0, 0, dest->width, dest->height); - wlr_renderer_clear(dest->renderer->wlr_rend, color); - wlr_render_texture_with_matrix(dest->renderer->wlr_rend, tex, mat, 1.0f); + struct wlr_renderer *renderer = dest->renderer->wlr_rend; + wlr_renderer_begin(renderer, dest->width, dest->height); + wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 1.0 }); + wlr_render_texture_with_matrix(renderer, tex, mat, 1.0f); + wlr_renderer_end(renderer); return wlr_drm_surface_swap_buffers(dest, NULL); } diff --git a/backend/headless/output.c b/backend/headless/output.c index 6ce8fc35..4746d2f2 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -1,8 +1,8 @@ #include #include -#include #include #include +#include #include #include "backend/headless.h" #include "util/signal.h" @@ -120,16 +120,14 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, snprintf(wlr_output->name, sizeof(wlr_output->name), "HEADLESS-%d", wl_list_length(&backend->outputs) + 1); - if (!eglMakeCurrent(output->backend->egl.display, - output->egl_surface, output->egl_surface, - output->backend->egl.context)) { - wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); + if (!wlr_egl_make_current(&output->backend->egl, output->egl_surface, + NULL)) { goto error; } - glViewport(0, 0, wlr_output->width, wlr_output->height); - glClearColor(1.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); + wlr_renderer_begin(backend->renderer, wlr_output->width, wlr_output->height); + wlr_renderer_clear(backend->renderer, (float[]){ 1.0, 1.0, 1.0, 1.0 }); + wlr_renderer_end(backend->renderer); struct wl_event_loop *ev = wl_display_get_event_loop(backend->display); output->frame_timer = wl_event_loop_add_timer(ev, signal_frame, output); diff --git a/backend/wayland/output.c b/backend/wayland/output.c index fc40dea0..d528c888 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -9,6 +8,7 @@ #include #include #include +#include #include #include "backend/wayland.h" #include "util/signal.h" @@ -313,27 +313,26 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { output->egl_window = wl_egl_window_create(output->surface, wlr_output->width, wlr_output->height); - output->egl_surface = wlr_egl_create_surface(&backend->egl, output->egl_window); + output->egl_surface = wlr_egl_create_surface(&backend->egl, + output->egl_window); wl_display_roundtrip(output->backend->remote_display); // start rendering loop per callbacks by rendering first frame - if (!eglMakeCurrent(output->backend->egl.display, - output->egl_surface, output->egl_surface, - output->backend->egl.context)) { - wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); + if (!wlr_egl_make_current(&output->backend->egl, output->egl_surface, + NULL)) { goto error; } - glViewport(0, 0, wlr_output->width, wlr_output->height); - glClearColor(1.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); + wlr_renderer_begin(backend->renderer, wlr_output->width, wlr_output->height); + wlr_renderer_clear(backend->renderer, (float[]){ 1.0, 1.0, 1.0, 1.0 }); + wlr_renderer_end(backend->renderer); output->frame_callback = wl_surface_frame(output->surface); wl_callback_add_listener(output->frame_callback, &frame_listener, output); - if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) { - wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); + if (!wlr_egl_swap_buffers(&output->backend->egl, output->egl_surface, + NULL)) { goto error; } diff --git a/examples/output-layout.c b/examples/output-layout.c index de134a71..45d896b0 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -101,7 +101,7 @@ static void handle_output_frame(struct output_state *output, struct wlr_output *wlr_output = output->output; wlr_output_make_current(wlr_output, NULL); - wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); animate_cat(sample, output->output); diff --git a/examples/rotation.c b/examples/rotation.c index 7f50b620..cbff09a1 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -43,7 +43,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_effective_resolution(wlr_output, &width, &height); wlr_output_make_current(wlr_output, NULL); - wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { diff --git a/examples/tablet.c b/examples/tablet.c index 1b995003..65c559cb 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -46,7 +46,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_effective_resolution(wlr_output, &width, &height); wlr_output_make_current(wlr_output, NULL); - wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[9]; diff --git a/examples/touch.c b/examples/touch.c index 0968e82a..f9c496cf 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -42,7 +42,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_effective_resolution(wlr_output, &width, &height); wlr_output_make_current(wlr_output, NULL); - wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); struct touch_point *p; diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index da0aaec9..7f25c0ff 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -18,7 +18,8 @@ struct wlr_renderer { }; struct wlr_renderer_impl { - void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output); + void (*begin)(struct wlr_renderer *renderer, uint32_t width, + uint32_t height); void (*end)(struct wlr_renderer *renderer); void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h index d5f3cf70..6f0d2ecc 100644 --- a/include/wlr/render/wlr_renderer.h +++ b/include/wlr/render/wlr_renderer.h @@ -12,7 +12,7 @@ struct wlr_output; struct wlr_renderer; -void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); +void wlr_renderer_begin(struct wlr_renderer *r, int width, int height); void wlr_renderer_end(struct wlr_renderer *r); void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); /** diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 14eea666..6b046bc4 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -26,13 +26,13 @@ static struct wlr_gles2_renderer *gles2_get_renderer( return renderer; } -static void gles2_begin(struct wlr_renderer *wlr_renderer, - struct wlr_output *output) { +static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width, + uint32_t height) { gles2_get_renderer(wlr_renderer); GLES2_DEBUG_PUSH; - glViewport(0, 0, output->width, output->height); + glViewport(0, 0, width, height); // enable transparency glEnable(GL_BLEND); diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 79e0b5d5..622aa1dd 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -17,8 +17,8 @@ void wlr_renderer_destroy(struct wlr_renderer *r) { } } -void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *o) { - r->impl->begin(r, o); +void wlr_renderer_begin(struct wlr_renderer *r, int width, int height) { + r->impl->begin(r, width, height); } void wlr_renderer_end(struct wlr_renderer *r) { diff --git a/rootston/output.c b/rootston/output.c index 4146e3e2..1de27bad 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -479,7 +479,7 @@ static void render_output(struct roots_output *output) { goto damage_finish; } - wlr_renderer_begin(renderer, wlr_output); + wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height); if (!pixman_region32_not_empty(&damage)) { // Output isn't damaged but needs buffer swap diff --git a/wlroots.syms b/wlroots.syms index 3f45e045..cb030a6d 100644 --- a/wlroots.syms +++ b/wlroots.syms @@ -15,8 +15,8 @@ WLROOTS_0_0_0 { wlr_drm_get_connector_props; wlr_drm_get_crtc_props; wlr_drm_get_plane_props; - wlr_drm_get_prop; wlr_drm_get_prop_blob; + wlr_drm_get_prop; wlr_drm_plane_surfaces_init; wlr_drm_renderer_finish; wlr_drm_renderer_init; -- cgit v1.2.3 From d9a3c6694281fae6f720f91230e8ec27df8fd82b Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 17 Mar 2018 17:04:51 +0100 Subject: rootston/output: fix leak in damage_from_surface --- rootston/output.c | 1 + 1 file changed, 1 insertion(+) (limited to 'rootston') diff --git a/rootston/output.c b/rootston/output.c index 4146e3e2..22c0d7ed 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -680,6 +680,7 @@ static void damage_from_surface(struct wlr_surface *surface, } pixman_region32_translate(&damage, box.x, box.y); wlr_output_damage_add(output->damage, &damage); + pixman_region32_fini(&damage); } else { pixman_box32_t *extents = pixman_region32_extents(&surface->current->surface_damage); -- cgit v1.2.3