diff --git a/cage.c b/cage.c index a90639f..ccf3b11 100644 --- a/cage.c +++ b/cage.c @@ -187,9 +187,6 @@ usage(FILE *file, const char *cage) "Usage: %s [OPTIONS] [--] APPLICATION\n" "\n" " -d\t Don't draw client side decorations, when possible\n" -#ifdef DEBUG - " -D\t Turn on damage tracking debugging\n" -#endif " -h\t Display this help message\n" " -m extend Extend the display across all connected outputs (default)\n" " -m last Use only the last connected output\n" @@ -205,20 +202,11 @@ static bool parse_args(struct cg_server *server, int argc, char *argv[]) { int c; -#ifdef DEBUG - while ((c = getopt(argc, argv, "dDhm:rsv")) != -1) { -#else while ((c = getopt(argc, argv, "dhm:rsv")) != -1) { -#endif switch (c) { case 'd': server->xdg_decoration = true; break; -#ifdef DEBUG - case 'D': - server->debug_damage_tracking = true; - break; -#endif case 'h': usage(stdout, argv[0]); return false; diff --git a/meson.build b/meson.build index 7c57967..550cd6c 100644 --- a/meson.build +++ b/meson.build @@ -123,7 +123,6 @@ cage_sources = [ 'cage.c', 'idle_inhibit_v1.c', 'output.c', - 'render.c', 'seat.c', 'util.c', 'view.c', diff --git a/output.c b/output.c index 42e3c9b..5ab1ea3 100644 --- a/output.c +++ b/output.c @@ -225,50 +225,9 @@ output_disable(struct cg_output *output) } static void -damage_surface_iterator(struct cg_output *output, struct wlr_surface *surface, struct wlr_box *box, void *user_data) +handle_output_frame(struct wl_listener *listener, void *data) { - struct wlr_output *wlr_output = output->wlr_output; - bool whole = *(bool *) user_data; - - scale_box(box, output->wlr_output->scale); - - if (whole) { - wlr_output_damage_add_box(output->damage, box); - } else if (pixman_region32_not_empty(&surface->buffer_damage)) { - pixman_region32_t damage; - pixman_region32_init(&damage); - wlr_surface_get_effective_damage(surface, &damage); - - wlr_region_scale(&damage, &damage, wlr_output->scale); - if (ceil(wlr_output->scale) > surface->current.scale) { - /* When scaling up a surface it'll become - blurry, so we need to expand the damage - region. */ - wlr_region_expand(&damage, &damage, ceil(wlr_output->scale) - surface->current.scale); - } - pixman_region32_translate(&damage, box->x, box->y); - wlr_output_damage_add(output->damage, &damage); - pixman_region32_fini(&damage); - } -} - -void -output_damage_surface(struct cg_output *output, struct wlr_surface *surface, double lx, double ly, bool whole) -{ - if (!output->wlr_output->enabled) { - wlr_log(WLR_DEBUG, "Not adding damage for disabled output %s", output->wlr_output->name); - return; - } - - double ox = lx, oy = ly; - wlr_output_layout_output_coords(output->server->output_layout, output->wlr_output, &ox, &oy); - output_surface_for_each_surface(output, surface, ox, oy, damage_surface_iterator, &whole); -} - -static void -handle_output_damage_frame(struct wl_listener *listener, void *data) -{ - struct cg_output *output = wl_container_of(listener, output, damage_frame); + struct cg_output *output = wl_container_of(listener, output, frame); struct send_frame_done_data frame_data = {0}; if (!output->wlr_output->enabled) { @@ -287,33 +246,12 @@ handle_output_damage_frame(struct wl_listener *listener, void *data) } last_scanned_out = scanned_out; - if (scanned_out) { - goto frame_done; + if (!scanned_out) { + wlr_scene_output_commit(output->scene_output); } - bool needs_frame; - pixman_region32_t damage; - pixman_region32_init(&damage); - if (!wlr_output_damage_attach_render(output->damage, &needs_frame, &damage)) { - wlr_log(WLR_ERROR, "Cannot make damage output current"); - goto damage_finish; - } - - if (!needs_frame) { - wlr_output_rollback(output->wlr_output); - goto damage_finish; - } - - output_render(output, &damage); - -damage_finish: - pixman_region32_fini(&damage); - -frame_done: clock_gettime(CLOCK_MONOTONIC, &frame_data.when); send_frame_done(output, &frame_data); - - wlr_output_damage_add_whole(output->damage); } static void @@ -357,8 +295,7 @@ output_destroy(struct cg_output *output) wl_list_remove(&output->destroy.link); wl_list_remove(&output->commit.link); wl_list_remove(&output->mode.link); - wl_list_remove(&output->damage_frame.link); - wl_list_remove(&output->damage_destroy.link); + wl_list_remove(&output->frame.link); wl_list_remove(&output->link); wlr_output_layout_remove(server->output_layout, output->wlr_output); @@ -380,18 +317,10 @@ output_destroy(struct cg_output *output) } } -static void -handle_output_damage_destroy(struct wl_listener *listener, void *data) -{ - struct cg_output *output = wl_container_of(listener, output, damage_destroy); - output_destroy(output); -} - static void handle_output_destroy(struct wl_listener *listener, void *data) { struct cg_output *output = wl_container_of(listener, output, destroy); - wlr_output_damage_destroy(output->damage); output_destroy(output); } @@ -414,7 +343,8 @@ handle_new_output(struct wl_listener *listener, void *data) output->wlr_output = wlr_output; output->server = server; - output->damage = wlr_output_damage_create(wlr_output); + output->scene_output = wlr_scene_output_create(server->scene, wlr_output); + wl_list_insert(&server->outputs, &output->link); output->commit.notify = handle_output_commit; @@ -423,10 +353,8 @@ handle_new_output(struct wl_listener *listener, void *data) wl_signal_add(&wlr_output->events.mode, &output->mode); output->destroy.notify = handle_output_destroy; wl_signal_add(&wlr_output->events.destroy, &output->destroy); - output->damage_frame.notify = handle_output_damage_frame; - wl_signal_add(&output->damage->events.frame, &output->damage_frame); - output->damage_destroy.notify = handle_output_damage_destroy; - wl_signal_add(&output->damage->events.destroy, &output->damage_destroy); + output->frame.notify = handle_output_frame; + wl_signal_add(&wlr_output->events.frame, &output->frame); struct wlr_output_mode *preferred_mode = wlr_output_preferred_mode(wlr_output); if (preferred_mode) { diff --git a/output.h b/output.h index 8c5799f..41a4a55 100644 --- a/output.h +++ b/output.h @@ -11,13 +11,12 @@ struct cg_output { struct cg_server *server; struct wlr_output *wlr_output; - struct wlr_output_damage *damage; + struct wlr_scene_output *scene_output; struct wl_listener commit; struct wl_listener mode; struct wl_listener destroy; - struct wl_listener damage_frame; - struct wl_listener damage_destroy; + struct wl_listener frame; struct wl_list link; // cg_server::outputs }; @@ -26,9 +25,6 @@ typedef void (*cg_surface_iterator_func_t)(struct cg_output *output, struct wlr_ void *user_data); void handle_new_output(struct wl_listener *listener, void *data); -void output_surface_for_each_surface(struct cg_output *output, struct wlr_surface *surface, double ox, double oy, - cg_surface_iterator_func_t iterator, void *user_data); -void output_damage_surface(struct cg_output *output, struct wlr_surface *surface, double lx, double ly, bool whole); void output_set_window_title(struct cg_output *output, const char *title); #endif diff --git a/render.c b/render.c deleted file mode 100644 index 9eb4d30..0000000 --- a/render.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Cage: A Wayland kiosk. - * - * Copyright (C) 2018-2020 Jente Hidskes - * Copyright (C) 2019 The Sway authors - * - * See the LICENSE file accompanying this file. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "output.h" -#include "seat.h" -#include "server.h" -#include "util.h" -#include "view.h" - -static void -scissor_output(struct wlr_output *output, pixman_box32_t *rect) -{ - struct wlr_box box = { - .x = rect->x1, - .y = rect->y1, - .width = rect->x2 - rect->x1, - .height = rect->y2 - rect->y1, - }; - - int output_width, output_height; - wlr_output_transformed_resolution(output, &output_width, &output_height); - enum wl_output_transform transform = wlr_output_transform_invert(output->transform); - wlr_box_transform(&box, &box, transform, output_width, output_height); - - wlr_renderer_scissor(output->renderer, &box); -} - -struct render_data { - pixman_region32_t *damage; -}; - -void -output_render(struct cg_output *output, pixman_region32_t *damage) -{ - struct cg_server *server = output->server; - struct wlr_output *wlr_output = output->wlr_output; - - wlr_renderer_begin(server->renderer, wlr_output->width, wlr_output->height); - - if (!pixman_region32_not_empty(damage)) { - wlr_log(WLR_DEBUG, "Output isn't damaged but needs a buffer swap"); - goto renderer_end; - } - -#ifdef DEBUG - if (server->debug_damage_tracking) { - wlr_renderer_clear(server->renderer, (float[]){1.0f, 0.0f, 0.0f, 1.0f}); - } -#endif - - float color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - int nrects; - pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); - for (int i = 0; i < nrects; i++) { - scissor_output(wlr_output, &rects[i]); - wlr_renderer_clear(server->renderer, color); - } - - double lx = 0, ly = 0; - wlr_output_layout_output_coords(output->server->output_layout, output->wlr_output, &lx, &ly); - wlr_scene_render_output(server->scene, wlr_output, lx, ly, damage); - -renderer_end: - /* Draw software cursor in case hardware cursors aren't - available. This is a no-op when they are. */ - wlr_output_render_software_cursors(wlr_output, damage); - wlr_renderer_scissor(server->renderer, NULL); - wlr_renderer_end(server->renderer); - - int output_width, output_height; - wlr_output_transformed_resolution(wlr_output, &output_width, &output_height); - - pixman_region32_t frame_damage; - pixman_region32_init(&frame_damage); - - enum wl_output_transform transform = wlr_output_transform_invert(wlr_output->transform); - wlr_region_transform(&frame_damage, &output->damage->current, transform, output_width, output_height); - -#ifdef DEBUG - if (server->debug_damage_tracking) { - pixman_region32_union_rect(&frame_damage, &frame_damage, 0, 0, output_width, output_height); - } -#endif - - wlr_output_set_damage(wlr_output, &frame_damage); - pixman_region32_fini(&frame_damage); - - if (!wlr_output_commit(wlr_output)) { - wlr_log(WLR_ERROR, "Could not commit output"); - } -} diff --git a/seat.c b/seat.c index 2736a6b..2bf1614 100644 --- a/seat.c +++ b/seat.c @@ -587,15 +587,6 @@ handle_cursor_motion(struct wl_listener *listener, void *data) wlr_idle_notify_activity(seat->server->idle, seat->seat); } -static void -drag_icon_damage(struct cg_drag_icon *drag_icon) -{ - struct cg_output *output; - wl_list_for_each (output, &drag_icon->seat->server->outputs, link) { - output_damage_surface(output, drag_icon->wlr_drag_icon->surface, drag_icon->lx, drag_icon->ly, true); - } -} - static void drag_icon_update_position(struct cg_drag_icon *drag_icon) { @@ -603,8 +594,6 @@ drag_icon_update_position(struct cg_drag_icon *drag_icon) struct cg_seat *seat = drag_icon->seat; struct wlr_touch_point *point; - drag_icon_damage(drag_icon); - switch (wlr_icon->drag->grab_type) { case WLR_DRAG_GRAB_KEYBOARD: return; @@ -622,8 +611,6 @@ drag_icon_update_position(struct cg_drag_icon *drag_icon) break; } - drag_icon_damage(drag_icon); - wlr_scene_node_set_position(drag_icon->scene_node, drag_icon->lx, drag_icon->ly); } @@ -632,7 +619,6 @@ handle_drag_icon_destroy(struct wl_listener *listener, void *data) { struct cg_drag_icon *drag_icon = wl_container_of(listener, drag_icon, destroy); - drag_icon_damage(drag_icon); wl_list_remove(&drag_icon->link); wl_list_remove(&drag_icon->destroy.link); wlr_scene_node_destroy(drag_icon->scene_node); diff --git a/server.h b/server.h index 0712708..bb7f3c1 100644 --- a/server.h +++ b/server.h @@ -51,9 +51,6 @@ struct cg_server { bool xdg_decoration; bool allow_vt_switch; enum wl_output_transform output_transform; -#ifdef DEBUG - bool debug_damage_tracking; -#endif }; #endif diff --git a/view.c b/view.c index 8e47445..26c3b7b 100644 --- a/view.c +++ b/view.c @@ -24,13 +24,6 @@ #include "xwayland.h" #endif -static void -view_child_handle_commit(struct wl_listener *listener, void *data) -{ - struct cg_view_child *child = wl_container_of(listener, child, commit); - view_damage_part(child->view); -} - void view_child_finish(struct cg_view_child *child) { @@ -38,10 +31,7 @@ view_child_finish(struct cg_view_child *child) return; } - view_damage_whole(child->view); - wl_list_remove(&child->link); - wl_list_remove(&child->commit.link); } void @@ -50,9 +40,6 @@ view_child_init(struct cg_view_child *child, struct cg_view *view, struct wlr_su child->view = view; child->wlr_surface = wlr_surface; - child->commit.notify = view_child_handle_commit; - wl_signal_add(&wlr_surface->events.commit, &child->commit); - wl_list_insert(&view->children, &child->link); } @@ -78,24 +65,6 @@ view_is_transient_for(struct cg_view *child, struct cg_view *parent) return child->impl->is_transient_for(child, parent); } -void -view_damage_part(struct cg_view *view) -{ - struct cg_output *output; - wl_list_for_each (output, &view->server->outputs, link) { - output_damage_surface(output, view->wlr_surface, view->lx, view->ly, false); - } -} - -void -view_damage_whole(struct cg_view *view) -{ - struct cg_output *output; - wl_list_for_each (output, &view->server->outputs, link) { - output_damage_surface(output, view->wlr_surface, view->lx, view->ly, true); - } -} - void view_activate(struct cg_view *view, bool activate) { diff --git a/view.h b/view.h index 49468c1..67f2280 100644 --- a/view.h +++ b/view.h @@ -50,16 +50,12 @@ struct cg_view_child { struct wlr_surface *wlr_surface; struct wl_list link; - struct wl_listener commit; - void (*destroy)(struct cg_view_child *child); }; char *view_get_title(struct cg_view *view); bool view_is_primary(struct cg_view *view); bool view_is_transient_for(struct cg_view *child, struct cg_view *parent); -void view_damage_part(struct cg_view *view); -void view_damage_whole(struct cg_view *view); void view_activate(struct cg_view *view, bool activate); void view_position(struct cg_view *view); void view_unmap(struct cg_view *view); diff --git a/xdg_shell.c b/xdg_shell.c index 3fb47db..271b05e 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -69,7 +69,6 @@ handle_xdg_popup_map(struct wl_listener *listener, void *data) double sx, sy; wlr_xdg_popup_get_position(popup->wlr_popup, &sx, &sy); wlr_scene_node_set_position(&popup->scene_surface->node, sx, sy); - view_damage_whole(popup->view_child.view); } static void @@ -77,7 +76,6 @@ handle_xdg_popup_unmap(struct wl_listener *listener, void *data) { struct cg_xdg_popup *popup = wl_container_of(listener, popup, unmap); wlr_scene_node_destroy(&popup->scene_surface->node); - view_damage_whole(popup->view_child.view); } static void @@ -235,24 +233,12 @@ handle_xdg_shell_surface_request_fullscreen(struct wl_listener *listener, void * wlr_xdg_toplevel_set_fullscreen(xdg_shell_view->xdg_surface, event->fullscreen); } -static void -handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data) -{ - struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); - struct cg_view *view = &xdg_shell_view->view; - view_damage_part(view); -} - static void handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, unmap); struct cg_view *view = &xdg_shell_view->view; - view_damage_whole(view); - - wl_list_remove(&xdg_shell_view->commit.link); - view_unmap(view); } @@ -262,12 +248,7 @@ handle_xdg_shell_surface_map(struct wl_listener *listener, void *data) struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, map); struct cg_view *view = &xdg_shell_view->view; - xdg_shell_view->commit.notify = handle_xdg_shell_surface_commit; - wl_signal_add(&xdg_shell_view->xdg_surface->surface->events.commit, &xdg_shell_view->commit); - view_map(view, xdg_shell_view->xdg_surface->surface); - - view_damage_whole(view); } static void diff --git a/xdg_shell.h b/xdg_shell.h index 5ee0bba..a5539b9 100644 --- a/xdg_shell.h +++ b/xdg_shell.h @@ -14,7 +14,6 @@ struct cg_xdg_shell_view { struct wl_listener destroy; struct wl_listener unmap; struct wl_listener map; - struct wl_listener commit; struct wl_listener request_fullscreen; struct wl_listener new_popup; }; diff --git a/xwayland.c b/xwayland.c index 47e1a2b..ef37a49 100644 --- a/xwayland.c +++ b/xwayland.c @@ -103,24 +103,12 @@ handle_xwayland_surface_request_fullscreen(struct wl_listener *listener, void *d wlr_xwayland_surface_set_fullscreen(xwayland_view->xwayland_surface, xwayland_surface->fullscreen); } -static void -handle_xwayland_surface_commit(struct wl_listener *listener, void *data) -{ - struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, commit); - struct cg_view *view = &xwayland_view->view; - view_damage_part(view); -} - static void handle_xwayland_surface_unmap(struct wl_listener *listener, void *data) { struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, unmap); struct cg_view *view = &xwayland_view->view; - view_damage_whole(view); - - wl_list_remove(&xwayland_view->commit.link); - view_unmap(view); } @@ -135,12 +123,7 @@ handle_xwayland_surface_map(struct wl_listener *listener, void *data) view->ly = xwayland_view->xwayland_surface->y; } - xwayland_view->commit.notify = handle_xwayland_surface_commit; - wl_signal_add(&xwayland_view->xwayland_surface->surface->events.commit, &xwayland_view->commit); - view_map(view, xwayland_view->xwayland_surface->surface); - - view_damage_whole(view); } static void diff --git a/xwayland.h b/xwayland.h index d257f57..31edb8f 100644 --- a/xwayland.h +++ b/xwayland.h @@ -12,7 +12,6 @@ struct cg_xwayland_view { struct wl_listener destroy; struct wl_listener unmap; struct wl_listener map; - struct wl_listener commit; struct wl_listener request_fullscreen; };