From 1a084807ce6ce1d8e4b8c35e3195240507ebffe8 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 03:31:46 +0100 Subject: rootston: do not redraw if output has no damage --- rootston/desktop.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index d7da1600..3b8e6602 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -513,12 +513,20 @@ void desktop_destroy(struct roots_desktop *desktop) { } struct roots_output *desktop_output_from_wlr_output( - struct roots_desktop *desktop, struct wlr_output *output) { - struct roots_output *roots_output; - wl_list_for_each(roots_output, &desktop->outputs, link) { - if (roots_output->wlr_output == output) { - return roots_output; + struct roots_desktop *desktop, struct wlr_output *wlr_output) { + struct roots_output *output; + wl_list_for_each(output, &desktop->outputs, link) { + if (output->wlr_output == wlr_output) { + return output; } } return NULL; } + +void desktop_damage_surface(struct roots_desktop *desktop, + struct wlr_surface *surface, double lx, double ly) { + struct roots_output *output; + wl_list_for_each(output, &desktop->outputs, link) { + output_damage_surface(output, surface, lx, ly); + } +} -- cgit v1.2.3 From 01bcc2ab01715df1f105ab972041134c878612e0 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 12:25:39 +0100 Subject: rootston: damage views when moved --- include/rootston/desktop.h | 4 ++-- include/rootston/output.h | 3 +-- rootston/desktop.c | 26 ++++++++++++++++---------- rootston/output.c | 8 +++++++- rootston/wl_shell.c | 9 ++++++--- rootston/xdg_shell_v6.c | 11 ++++++----- rootston/xwayland.c | 24 ++++++++++++++---------- 7 files changed, 52 insertions(+), 33 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 3d0e2a2b..c0790917 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -62,12 +62,12 @@ struct roots_output *desktop_output_from_wlr_output( struct roots_desktop *desktop, struct wlr_output *output); struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); -void desktop_damage_surface(struct roots_desktop *desktop, - struct wlr_surface *surface, double lx, double ly); void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_destroy(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); +void view_damage(struct roots_view *view); +void view_update_position(struct roots_view *view, double x, double y); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/output.h b/include/rootston/output.h index d44479ed..e8c64c3e 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -23,7 +23,6 @@ struct roots_output { void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); -void output_damage_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly); +void output_damage_view(struct roots_output *output, struct roots_view *view); #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 3b8e6602..94350359 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -61,8 +61,7 @@ void view_move(struct roots_view *view, double x, double y) { if (view->move) { view->move(view, x, y); } else { - view->x = x; - view->y = y; + view_update_position(view, x, y); } view_update_output(view, &before); } @@ -268,6 +267,7 @@ void view_destroy(struct roots_view *view) { void view_init(struct roots_view *view, struct roots_desktop *desktop) { view->desktop = desktop; wl_signal_init(&view->events.destroy); + view_damage(view); } void view_setup(struct roots_view *view) { @@ -282,6 +282,20 @@ void view_setup(struct roots_view *view) { view_update_output(view, NULL); } +void view_damage(struct roots_view *view) { + struct roots_output *output; + wl_list_for_each(output, &view->desktop->outputs, link) { + output_damage_view(output, view); + } +} + +void view_update_position(struct roots_view *view, double x, double y) { + view_damage(view); + view->x = x; + view->y = y; + view_damage(view); +} + static bool view_at(struct roots_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (view->type == ROOTS_WL_SHELL_VIEW && @@ -522,11 +536,3 @@ struct roots_output *desktop_output_from_wlr_output( } return NULL; } - -void desktop_damage_surface(struct roots_desktop *desktop, - struct wlr_surface *surface, double lx, double ly) { - struct roots_output *output; - wl_list_for_each(output, &desktop->outputs, link) { - output_damage_surface(output, surface, lx, ly); - } -} diff --git a/rootston/output.c b/rootston/output.c index a700ea07..5ccd9eb7 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -337,7 +337,7 @@ static int handle_repaint(void *data) { return 0; } -void output_damage_surface(struct roots_output *output, +static void output_damage_surface(struct roots_output *output, struct wlr_surface *surface, double lx, double ly) { if (!wlr_surface_has_buffer(surface)) { return; @@ -355,6 +355,12 @@ void output_damage_surface(struct roots_output *output, box.width, box.height); } +void output_damage_view(struct roots_output *output, struct roots_view *view) { + output_damage_surface(output, view->wlr_surface, view->x, view->y); + + // TODO: subsurfaces, popups, etc +} + static void set_mode(struct wlr_output *output, struct roots_output_config *oc) { int mhz = (int)(oc->mode.refresh_rate * 1000); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 65067920..e1dea82b 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -90,17 +90,20 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int width = wlr_surface->current->width; int height = wlr_surface->current->height; - if (view->pending_move_resize.update_x) { - view->x = view->pending_move_resize.x + + double x = view->pending_move_resize.x + view->pending_move_resize.width - width; + view_update_position(view, x, view->y); view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - view->y = view->pending_move_resize.y + + double y = view->pending_move_resize.y + view->pending_move_resize.height - height; + view_update_position(view, view->x, y); view->pending_move_resize.update_y = false; } + + view_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index e915d1a6..259b62a5 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -102,8 +102,7 @@ static void move_resize(struct roots_view *view, double x, double y, if (serial > 0) { roots_surface->pending_move_resize_configure_serial = serial; } else { - view->x = x; - view->y = y; + view_update_position(view, x, y); } } @@ -205,12 +204,14 @@ static void handle_commit(struct wl_listener *listener, void *data) { get_size(view, &size); if (view->pending_move_resize.update_x) { - view->x = view->pending_move_resize.x + + double x = view->pending_move_resize.x + view->pending_move_resize.width - size.width; + view_update_position(view, x, view->y); } if (view->pending_move_resize.update_y) { - view->y = view->pending_move_resize.y + + double y = view->pending_move_resize.y + view->pending_move_resize.height - size.height; + view_update_position(view, view->x, y); } if (pending_serial == surface->configure_serial) { @@ -218,7 +219,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { } } - desktop_damage_surface(view->desktop, view->wlr_surface, view->x, view->y); + view_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 3d84dc19..b3cf409c 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -18,8 +18,7 @@ static void activate(struct roots_view *view, bool active) { static void move(struct roots_view *view, double x, double y) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - view->x = x; - view->y = y; + view_update_position(view, x, y); wlr_xwayland_surface_configure(xwayland_surface, x, y, xwayland_surface->width, xwayland_surface->height); } @@ -133,8 +132,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { roots_surface->view->xwayland_surface; struct wlr_xwayland_surface_configure_event *event = data; - roots_surface->view->x = (double)event->x; - roots_surface->view->y = (double)event->y; + view_update_position(roots_surface->view, event->x, event->y); wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y, event->width, event->height); @@ -210,15 +208,19 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int height = wlr_surface->current->height; if (view->pending_move_resize.update_x) { - view->x = view->pending_move_resize.x + + double x = view->pending_move_resize.x + view->pending_move_resize.width - width; + view_update_position(view, x, view->y); view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - view->y = view->pending_move_resize.y + + double y = view->pending_move_resize.y + view->pending_move_resize.height - height; + view_update_position(view, view->x, y); view->pending_move_resize.update_y = false; } + + view_damage(view); } static void handle_map_notify(struct wl_listener *listener, void *data) { @@ -229,8 +231,9 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = view->desktop; view->wlr_surface = xsurface->surface; - view->x = (double)xsurface->x; - view->y = (double)xsurface->y; + view->x = xsurface->x; + view->y = xsurface->y; + view_damage(view); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, @@ -242,10 +245,11 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, unmap_notify); - roots_surface->view->wlr_surface = NULL; - wl_list_remove(&roots_surface->surface_commit.link); + view_damage(roots_surface->view); + roots_surface->view->wlr_surface = NULL; + wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->view->link); } -- cgit v1.2.3 From 5017d7f7625e4ca3369feb241a81ad8a570d0fd1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 14:36:42 +0100 Subject: rootston: only draw damaged regions --- render/gles2/renderer.c | 8 +-- rootston/desktop.c | 1 + rootston/output.c | 179 +++++++++++++++++++++++++++++------------------- 3 files changed, 114 insertions(+), 74 deletions(-) (limited to 'rootston/desktop.c') diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 89cc4ffb..2dd64176 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -108,11 +108,9 @@ static void init_globals() { static void wlr_gles2_begin(struct wlr_renderer *_renderer, struct wlr_output *output) { // TODO: let users customize the clear color? - GL_CALL(glClearColor(0.25f, 0.25f, 0.25f, 1)); - GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); - int32_t width = output->width; - int32_t height = output->height; - GL_CALL(glViewport(0, 0, width, height)); + //GL_CALL(glClearColor(0.25f, 0.25f, 0.25f, 1)); + //GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); + GL_CALL(glViewport(0, 0, output->width, output->height)); // enable transparency GL_CALL(glEnable(GL_BLEND)); diff --git a/rootston/desktop.c b/rootston/desktop.c index 94350359..b8c876cb 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -255,6 +255,7 @@ bool view_center(struct roots_view *view) { } void view_destroy(struct roots_view *view) { + view_damage(view); wl_signal_emit(&view->events.destroy, view); if (view->fullscreen_output) { diff --git a/rootston/output.c b/rootston/output.c index 5ccd9eb7..027d8275 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -41,71 +41,99 @@ static bool surface_intersect_output(struct wlr_surface *surface, box->width = surface->current->width * wlr_output->scale; box->height = surface->current->height * wlr_output->scale; - struct wlr_box render_box = { + struct wlr_box layout_box = { .x = lx, .y = ly, - .width = box->width, .height = box->height, + .width = surface->current->width, .height = surface->current->height, }; - return wlr_output_layout_intersects(output_layout, wlr_output, &render_box); + return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box); } static void render_surface(struct wlr_surface *surface, - struct roots_desktop *desktop, struct wlr_output *wlr_output, - struct timespec *when, double lx, double ly, float rotation) { + struct roots_output *output, struct timespec *when, + double lx, double ly, float rotation) { if (!wlr_surface_has_buffer(surface)) { return; } struct wlr_box box; - bool intersects = surface_intersect_output(surface, desktop->layout, - wlr_output, lx, ly, &box); - if (intersects) { - float matrix[16]; + bool intersects = surface_intersect_output(surface, output->desktop->layout, + output->wlr_output, lx, ly, &box); + if (!intersects) { + goto render_subsurfaces; + } + + // TODO: do not render regions of the surface that aren't damaged + // TODO: output scale, output transform support + pixman_region32_t surface_damage; + pixman_region32_init(&surface_damage); + pixman_region32_union_rect(&surface_damage, &surface_damage, box.x, box.y, + box.width, box.height); + pixman_region32_intersect(&surface_damage, &surface_damage, + &output->damage); + bool damaged = pixman_region32_not_empty(&surface_damage); + if (!damaged) { + goto render_subsurfaces; + } + float transform[16]; + wlr_matrix_translate(&transform, box.x, box.y, 0); + + if (rotation != 0) { float translate_center[16]; - wlr_matrix_translate(&translate_center, - box.x + box.width / 2, box.y + box.height / 2, 0); + wlr_matrix_translate(&translate_center, box.width/2, box.height/2, 0); float rotate[16]; wlr_matrix_rotate(&rotate, rotation); float translate_origin[16]; - wlr_matrix_translate(&translate_origin, -box.width / 2, - -box.height / 2, 0); - - float scale[16]; - wlr_matrix_scale(&scale, box.width, box.height, 1); + wlr_matrix_translate(&translate_origin, -box.width/2, -box.height/2, 0); - float transform[16]; - wlr_matrix_mul(&translate_center, &rotate, &transform); + wlr_matrix_mul(&transform, &translate_center, &transform); + wlr_matrix_mul(&transform, &rotate, &transform); wlr_matrix_mul(&transform, &translate_origin, &transform); - wlr_matrix_mul(&transform, &scale, &transform); + } - if (surface->current->transform != WL_OUTPUT_TRANSFORM_NORMAL) { - float surface_translate_center[16]; - wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); + float scale[16]; + wlr_matrix_scale(&scale, box.width, box.height, 1); - float surface_transform[16]; - wlr_matrix_transform(surface_transform, - wlr_output_transform_invert(surface->current->transform)); + wlr_matrix_mul(&transform, &scale, &transform); - float surface_translate_origin[16]; - wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); + if (surface->current->transform != WL_OUTPUT_TRANSFORM_NORMAL) { + float surface_translate_center[16]; + wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); - wlr_matrix_mul(&transform, &surface_translate_center, - &transform); - wlr_matrix_mul(&transform, &surface_transform, &transform); - wlr_matrix_mul(&transform, &surface_translate_origin, - &transform); - } + float surface_transform[16]; + wlr_matrix_transform(surface_transform, + wlr_output_transform_invert(surface->current->transform)); - wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix); + float surface_translate_origin[16]; + wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); - wlr_render_with_matrix(desktop->server->renderer, surface->texture, - &matrix); + wlr_matrix_mul(&transform, &surface_translate_center, + &transform); + wlr_matrix_mul(&transform, &surface_transform, &transform); + wlr_matrix_mul(&transform, &surface_translate_origin, + &transform); + } - wlr_surface_send_frame_done(surface, when); + float matrix[16]; + wlr_matrix_mul(&output->wlr_output->transform_matrix, &transform, &matrix); + + int nrects; + pixman_box32_t *rects = + pixman_region32_rectangles(&surface_damage, &nrects); + for (int i = 0; i < nrects; ++i) { + glScissor(rects[i].x1, output->wlr_output->height - rects[i].y2, + rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1); + wlr_render_with_matrix(output->desktop->server->renderer, + surface->texture, &matrix); } + wlr_surface_send_frame_done(surface, when); + +render_subsurfaces: + pixman_region32_fini(&surface_damage); + struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { struct wlr_surface_state *state = subsurface->surface->current; @@ -116,16 +144,14 @@ static void render_surface(struct wlr_surface *surface, rotate_child_position(&sx, &sy, sw, sh, surface->current->width, surface->current->height, rotation); - render_surface(subsurface->surface, desktop, wlr_output, when, - lx + sx, - ly + sy, + render_surface(subsurface->surface, output, when, lx + sx, ly + sy, rotation); } } static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, - struct roots_desktop *desktop, struct wlr_output *wlr_output, - struct timespec *when, double base_x, double base_y, float rotation) { + struct roots_output *output, struct timespec *when, + double base_x, double base_y, float rotation) { double width = surface->surface->current->width; double height = surface->surface->current->height; @@ -143,20 +169,18 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, width, height, rotation); - render_surface(popup->surface, desktop, wlr_output, when, + render_surface(popup->surface, output, when, base_x + popup_sx, base_y + popup_sy, rotation); - render_xdg_v6_popups(popup, desktop, wlr_output, when, + render_xdg_v6_popups(popup, output, when, base_x + popup_sx, base_y + popup_sy, rotation); } } static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, - struct roots_desktop *desktop, struct wlr_output *wlr_output, - struct timespec *when, double lx, double ly, float rotation, - bool is_child) { + struct roots_output *output, struct timespec *when, + double lx, double ly, float rotation, bool is_child) { if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { - render_surface(surface->surface, desktop, wlr_output, when, - lx, ly, rotation); + render_surface(surface->surface, output, when, lx, ly, rotation); double width = surface->surface->current->width; double height = surface->surface->current->height; @@ -171,41 +195,40 @@ static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, width, height, rotation); - render_wl_shell_surface(popup, desktop, wlr_output, when, + render_wl_shell_surface(popup, output, when, lx + popup_x, ly + popup_y, rotation, true); } } } static void render_xwayland_children(struct wlr_xwayland_surface *surface, - struct roots_desktop *desktop, struct wlr_output *wlr_output, - struct timespec *when) { + struct roots_output *output, struct timespec *when) { struct wlr_xwayland_surface *child; wl_list_for_each(child, &surface->children, parent_link) { if (child->surface != NULL && child->added) { - render_surface(child->surface, desktop, wlr_output, when, + render_surface(child->surface, output, when, child->x, child->y, 0); } - render_xwayland_children(child, desktop, wlr_output, when); + render_xwayland_children(child, output, when); } } -static void render_view(struct roots_view *view, struct roots_desktop *desktop, - struct wlr_output *wlr_output, struct timespec *when) { +static void render_view(struct roots_view *view, struct roots_output *output, + struct timespec *when) { switch (view->type) { case ROOTS_XDG_SHELL_V6_VIEW: - render_surface(view->wlr_surface, desktop, wlr_output, when, + render_surface(view->wlr_surface, output, when, view->x, view->y, + view->rotation); + render_xdg_v6_popups(view->xdg_surface_v6, output, when, view->x, view->y, view->rotation); - render_xdg_v6_popups(view->xdg_surface_v6, desktop, wlr_output, - when, view->x, view->y, view->rotation); break; case ROOTS_WL_SHELL_VIEW: - render_wl_shell_surface(view->wl_shell_surface, desktop, wlr_output, - when, view->x, view->y, view->rotation, false); + render_wl_shell_surface(view->wl_shell_surface, output, when, + view->x, view->y, view->rotation, false); break; case ROOTS_XWAYLAND_VIEW: - render_surface(view->wlr_surface, desktop, wlr_output, when, - view->x, view->y, view->rotation); + render_surface(view->wlr_surface, output, when, view->x, view->y, + view->rotation); break; } } @@ -239,6 +262,13 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); + // TODO: use real wlr_output damage + if (wlr_output->needs_swap) { + int width, height; + wlr_output_effective_resolution(wlr_output, &width, &height); + pixman_region32_union_rect(&output->damage, &output->damage, 0, 0, + width, height); + } // TODO: fullscreen if (!pixman_region32_not_empty(&output->damage) && !wlr_output->needs_swap) { @@ -252,6 +282,17 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { wlr_output_make_current(wlr_output); wlr_renderer_begin(server->renderer, wlr_output); + glEnable(GL_SCISSOR_TEST); + + int nrects; + pixman_box32_t *rects = + pixman_region32_rectangles(&output->damage, &nrects); + for (int i = 0; i < nrects; ++i) { + glScissor(rects[i].x1, wlr_output->height - rects[i].y2, + rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1); + glClearColor(0.25f, 0.25f, 0.25f, 1); + glClear(GL_COLOR_BUFFER_BIT); + } if (output->fullscreen_view != NULL) { struct roots_view *view = output->fullscreen_view; @@ -275,14 +316,13 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); - render_view(view, desktop, wlr_output, &now); + render_view(view, output, &now); // During normal rendering the xwayland window tree isn't traversed // because all windows are rendered. Here we only want to render // the fullscreen window's children so we have to traverse the tree. if (view->type == ROOTS_XWAYLAND_VIEW) { - render_xwayland_children(view->xwayland_surface, desktop, - wlr_output, &now); + render_xwayland_children(view->xwayland_surface, output, &now); } } @@ -293,7 +333,7 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { struct roots_view *view; wl_list_for_each_reverse(view, &desktop->views, link) { - render_view(view, desktop, wlr_output, &now); + render_view(view, output, &now); } struct wlr_drag_icon *drag_icon = NULL; @@ -309,20 +349,21 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { if (drag_icon->is_pointer) { icon_x = cursor->x + drag_icon->sx; icon_y = cursor->y + drag_icon->sy; - render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + render_surface(icon, output, &now, icon_x, icon_y, 0); } else { struct wlr_touch_point *point = wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id); if (point) { icon_x = seat->touch_x + drag_icon->sx; icon_y = seat->touch_y + drag_icon->sy; - render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + render_surface(icon, output, &now, icon_x, icon_y, 0); } } } } renderer_end: + glDisable(GL_SCISSOR_TEST); wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output); -- cgit v1.2.3 From 96d6f34eddbd0159e347d41e5c20c74a0600e878 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 16:30:56 +0100 Subject: rootston: replace view_damage with view_apply_damage and view_damage_whole --- include/rootston/desktop.h | 3 ++- include/rootston/output.h | 5 ++++- rootston/desktop.c | 19 +++++++++++++------ rootston/output.c | 15 +++++++++++---- rootston/wl_shell.c | 2 +- rootston/xdg_shell_v6.c | 2 +- rootston/xwayland.c | 6 +++--- 7 files changed, 35 insertions(+), 17 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index c0790917..812bb42a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -66,7 +66,8 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_destroy(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); -void view_damage(struct roots_view *view); +void view_apply_damage(struct roots_view *view); +void view_damage_whole(struct roots_view *view); void view_update_position(struct roots_view *view, double x, double y); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/output.h b/include/rootston/output.h index e8c64c3e..cf34496b 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -23,6 +23,9 @@ struct roots_output { void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); -void output_damage_view(struct roots_output *output, struct roots_view *view); +void output_damage_whole_view(struct roots_output *output, + struct roots_view *view); +void output_damage_from_view(struct roots_output *output, + struct roots_view *view); #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index b8c876cb..faaefd05 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -255,7 +255,7 @@ bool view_center(struct roots_view *view) { } void view_destroy(struct roots_view *view) { - view_damage(view); + view_damage_whole(view); wl_signal_emit(&view->events.destroy, view); if (view->fullscreen_output) { @@ -268,7 +268,7 @@ void view_destroy(struct roots_view *view) { void view_init(struct roots_view *view, struct roots_desktop *desktop) { view->desktop = desktop; wl_signal_init(&view->events.destroy); - view_damage(view); + view_damage_whole(view); } void view_setup(struct roots_view *view) { @@ -283,18 +283,25 @@ void view_setup(struct roots_view *view) { view_update_output(view, NULL); } -void view_damage(struct roots_view *view) { +void view_apply_damage(struct roots_view *view) { struct roots_output *output; wl_list_for_each(output, &view->desktop->outputs, link) { - output_damage_view(output, view); + output_damage_from_view(output, view); + } +} + +void view_damage_whole(struct roots_view *view) { + struct roots_output *output; + wl_list_for_each(output, &view->desktop->outputs, link) { + output_damage_whole_view(output, view); } } void view_update_position(struct roots_view *view, double x, double y) { - view_damage(view); + view_damage_whole(view); view->x = x; view->y = y; - view_damage(view); + view_damage_whole(view); } static bool view_at(struct roots_view *view, double lx, double ly, diff --git a/rootston/output.c b/rootston/output.c index 16a185af..846bb4e6 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -379,7 +379,7 @@ static int handle_repaint(void *data) { return 0; } -static void output_damage_surface(struct roots_output *output, +static void output_damage_whole_surface(struct roots_output *output, struct wlr_surface *surface, double lx, double ly) { if (!wlr_surface_has_buffer(surface)) { return; @@ -392,17 +392,24 @@ static void output_damage_surface(struct roots_output *output, return; } - // TODO: use surface damage + pixman_region32_union_rect(&output->damage, &output->damage, box.x, box.y, box.width, box.height); } -void output_damage_view(struct roots_output *output, struct roots_view *view) { - output_damage_surface(output, view->wlr_surface, view->x, view->y); +void output_damage_whole_view(struct roots_output *output, + struct roots_view *view) { + output_damage_whole_surface(output, view->wlr_surface, view->x, view->y); // TODO: subsurfaces, popups, etc } +void output_damage_from_view(struct roots_output *output, + struct roots_view *view) { + // TODO: use surface damage + output_damage_whole_view(output, view); +} + static void set_mode(struct wlr_output *output, struct roots_output_config *oc) { int mhz = (int)(oc->mode.refresh_rate * 1000); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index e1dea82b..25ef9a3c 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -103,7 +103,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view->pending_move_resize.update_y = false; } - view_damage(view); + view_apply_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 259b62a5..225886ad 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -219,7 +219,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { } } - view_damage(view); + view_apply_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index b3cf409c..856c3d70 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -220,7 +220,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view->pending_move_resize.update_y = false; } - view_damage(view); + view_apply_damage(view); } static void handle_map_notify(struct wl_listener *listener, void *data) { @@ -233,7 +233,7 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; - view_damage(view); + view_damage_whole(view); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, @@ -246,7 +246,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, unmap_notify); - view_damage(roots_surface->view); + view_damage_whole(roots_surface->view); roots_surface->view->wlr_surface = NULL; wl_list_remove(&roots_surface->surface_commit.link); -- cgit v1.2.3 From bc001e90e988c965776abbd078224c14ac296047 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 20 Jan 2018 01:04:35 +0100 Subject: rootston: fix artifacts when un-maximizing a view --- rootston/desktop.c | 4 ++++ rootston/wl_shell.c | 17 +++++++++-------- rootston/xdg_shell_v6.c | 17 +++++++++-------- rootston/xwayland.c | 18 +++++++++--------- 4 files changed, 31 insertions(+), 25 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index faaefd05..e36ae6a4 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -298,6 +298,10 @@ void view_damage_whole(struct roots_view *view) { } void view_update_position(struct roots_view *view, double x, double y) { + if (view->x == x && view->y == y) { + return; + } + view_damage_whole(view); view->x = x; view->y = y; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 25ef9a3c..f7b09db0 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -88,22 +88,23 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_surface *wlr_surface = view->wlr_surface; + view_apply_damage(view); + int width = wlr_surface->current->width; int height = wlr_surface->current->height; + double x = view->x; + double y = view->y; if (view->pending_move_resize.update_x) { - double x = view->pending_move_resize.x + - view->pending_move_resize.width - width; - view_update_position(view, x, view->y); + x = view->pending_move_resize.x + view->pending_move_resize.width - + width; view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - double y = view->pending_move_resize.y + - view->pending_move_resize.height - height; - view_update_position(view, view->x, y); + y = view->pending_move_resize.y + view->pending_move_resize.height - + height; view->pending_move_resize.update_y = false; } - - view_apply_damage(view); + view_update_position(view, x, y); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 225886ad..295be6a2 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -197,29 +197,30 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + view_apply_damage(view); + uint32_t pending_serial = roots_surface->pending_move_resize_configure_serial; if (pending_serial > 0 && pending_serial >= surface->configure_serial) { struct wlr_box size; get_size(view, &size); + double x = view->x; + double y = view->y; if (view->pending_move_resize.update_x) { - double x = view->pending_move_resize.x + - view->pending_move_resize.width - size.width; - view_update_position(view, x, view->y); + x = view->pending_move_resize.x + view->pending_move_resize.width - + size.width; } if (view->pending_move_resize.update_y) { - double y = view->pending_move_resize.y + - view->pending_move_resize.height - size.height; - view_update_position(view, view->x, y); + y = view->pending_move_resize.y + view->pending_move_resize.height - + size.height; } + view_update_position(view, x, y); if (pending_serial == surface->configure_serial) { roots_surface->pending_move_resize_configure_serial = 0; } } - - view_apply_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 856c3d70..81f91b4f 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -204,23 +204,23 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_surface *wlr_surface = view->wlr_surface; + view_apply_damage(view); + int width = wlr_surface->current->width; int height = wlr_surface->current->height; - + double x = view->x; + double y = view->y; if (view->pending_move_resize.update_x) { - double x = view->pending_move_resize.x + - view->pending_move_resize.width - width; - view_update_position(view, x, view->y); + x = view->pending_move_resize.x + view->pending_move_resize.width - + width; view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - double y = view->pending_move_resize.y + - view->pending_move_resize.height - height; - view_update_position(view, view->x, y); + y = view->pending_move_resize.y + view->pending_move_resize.height - + height; view->pending_move_resize.update_y = false; } - - view_apply_damage(view); + view_update_position(view, x, y); } static void handle_map_notify(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From a636d72fc77ebcaa986fd1b72e85664e2fe586a3 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 21 Jan 2018 14:50:37 +0100 Subject: rootston: track subsurface damage --- include/rootston/desktop.h | 2 +- include/rootston/view.h | 27 ++++++++++++++ rootston/desktop.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-- rootston/output.c | 38 ++++++++++++++++---- rootston/wl_shell.c | 3 +- rootston/xdg_shell_v6.c | 3 +- rootston/xwayland.c | 17 +++++---- 7 files changed, 162 insertions(+), 18 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 812bb42a..388fb55d 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -64,7 +64,7 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); void view_init(struct roots_view *view, struct roots_desktop *desktop); -void view_destroy(struct roots_view *view); +void view_finish(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); void view_apply_damage(struct roots_view *view); void view_damage_whole(struct roots_view *view); diff --git a/include/rootston/view.h b/include/rootston/view.h index 579b148a..6c5e0573 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -91,7 +91,11 @@ struct roots_view { struct roots_xwayland_surface *roots_xwayland_surface; #endif }; + struct wlr_surface *wlr_surface; + struct wl_list children; // roots_view_child::link + + struct wl_listener new_subsurface; struct { struct wl_signal destroy; @@ -112,6 +116,21 @@ struct roots_view { void (*close)(struct roots_view *view); }; +struct roots_view_child { + struct roots_view *view; + struct wlr_surface *wlr_surface; + struct wl_list link; + + struct wl_listener commit; + struct wl_listener new_subsurface; +}; + +struct roots_subsurface { + struct roots_view_child view_child; + struct wlr_subsurface *wlr_subsurface; + struct wl_listener destroy; +}; + void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_move(struct roots_view *view, double x, double y); @@ -126,4 +145,12 @@ bool view_center(struct roots_view *view); void view_setup(struct roots_view *view); void view_teardown(struct roots_view *view); +void view_child_init(struct roots_view_child *child, struct roots_view *view, + struct wlr_surface *wlr_surface); +void view_child_finish(struct roots_view_child *child); + +struct roots_subsurface *subsurface_create(struct roots_view *view, + struct wlr_subsurface *wlr_subsurface); +void subsurface_destroy(struct roots_subsurface *subsurface); + #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index e36ae6a4..191338a8 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -254,20 +254,106 @@ bool view_center(struct roots_view *view) { return true; } -void view_destroy(struct roots_view *view) { +void view_child_finish(struct roots_view_child *child) { + if (child == NULL) { + return; + } + view_damage_whole(child->view); + wl_list_remove(&child->link); + wl_list_remove(&child->commit.link); + wl_list_remove(&child->new_subsurface.link); +} + +static void view_child_handle_commit(struct wl_listener *listener, + void *data) { + struct roots_view_child *child = wl_container_of(listener, child, commit); + view_apply_damage(child->view); +} + +static void view_child_handle_new_subsurface(struct wl_listener *listener, + void *data) { + struct roots_view_child *child = + wl_container_of(listener, child, new_subsurface); + struct wlr_subsurface *wlr_subsurface = data; + subsurface_create(child->view, wlr_subsurface); +} + +void view_child_init(struct roots_view_child *child, struct roots_view *view, + struct wlr_surface *wlr_surface) { + child->view = view; + child->wlr_surface = wlr_surface; + child->commit.notify = view_child_handle_commit; + wl_signal_add(&wlr_surface->events.commit, &child->commit); + child->new_subsurface.notify = view_child_handle_new_subsurface; + wl_signal_add(&wlr_surface->events.new_subsurface, &child->new_subsurface); + wl_list_insert(&view->children, &child->link); +} + +static void subsurface_handle_destroy(struct wl_listener *listener, + void *data) { + struct roots_subsurface *subsurface = + wl_container_of(listener, subsurface, destroy); + subsurface_destroy(subsurface); +} + +struct roots_subsurface *subsurface_create(struct roots_view *view, + struct wlr_subsurface *wlr_subsurface) { + struct roots_subsurface *subsurface = + calloc(1, sizeof(struct roots_subsurface)); + if (subsurface == NULL) { + return NULL; + } + subsurface->wlr_subsurface = wlr_subsurface; + view_child_init(&subsurface->view_child, view, wlr_subsurface->surface); + subsurface->destroy.notify = subsurface_handle_destroy; + wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy); + return subsurface; +} + +void subsurface_destroy(struct roots_subsurface *subsurface) { + if (subsurface == NULL) { + return; + } + wl_list_remove(&subsurface->destroy.link); + view_child_finish(&subsurface->view_child); + free(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); + if (view->fullscreen_output) { view->fullscreen_output->fullscreen_view = NULL; } +} - free(view); +static void view_handle_new_subsurface(struct wl_listener *listener, + void *data) { + struct roots_view *view = wl_container_of(listener, view, new_subsurface); + struct wlr_subsurface *wlr_subsurface = data; + subsurface_create(view, wlr_subsurface); } void view_init(struct roots_view *view, struct roots_desktop *desktop) { + assert(view->wlr_surface); + view->desktop = desktop; wl_signal_init(&view->events.destroy); + wl_list_init(&view->children); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list, + parent_link) { + subsurface_create(view, subsurface); + } + + view->new_subsurface.notify = view_handle_new_subsurface; + wl_signal_add(&view->wlr_surface->events.new_subsurface, + &view->new_subsurface); + view_damage_whole(view); } diff --git a/rootston/output.c b/rootston/output.c index f8da9c77..1c966e08 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -444,7 +444,7 @@ static void output_damage_whole(struct roots_output *output) { } static void output_damage_whole_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly) { + struct wlr_surface *surface, double lx, double ly, float rotation) { if (!wlr_surface_has_buffer(surface)) { return; } @@ -460,6 +460,18 @@ static void output_damage_whole_surface(struct roots_output *output, box.x, box.y, box.width, box.height); schedule_render(output); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + struct wlr_surface_state *state = subsurface->surface->current; + double sx = state->subsurface_position.x; + double sy = state->subsurface_position.y; + rotate_child_position(&sx, &sy, state->width, state->height, + surface->current->width, surface->current->height, rotation); + + output_damage_whole_surface(output, subsurface->surface, + lx + sx, ly + sy, rotation); + } } void output_damage_whole_view(struct roots_output *output, @@ -469,14 +481,15 @@ void output_damage_whole_view(struct roots_output *output, } if (view->wlr_surface != NULL) { - output_damage_whole_surface(output, view->wlr_surface, view->x, view->y); + output_damage_whole_surface(output, view->wlr_surface, + view->x, view->y, view->rotation); } - // TODO: subsurfaces, popups, etc + // TODO: popups, etc } static void output_damage_from_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly) { + struct wlr_surface *surface, double lx, double ly, float rotation) { if (!wlr_surface_has_buffer(surface)) { return; } @@ -497,6 +510,18 @@ static void output_damage_from_surface(struct roots_output *output, pixman_region32_fini(&damage); schedule_render(output); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + struct wlr_surface_state *state = subsurface->surface->current; + double sx = state->subsurface_position.x; + double sy = state->subsurface_position.y; + rotate_child_position(&sx, &sy, state->width, state->height, + surface->current->width, surface->current->height, rotation); + + output_damage_from_surface(output, subsurface->surface, + lx + sx, ly + sy, rotation); + } } void output_damage_from_view(struct roots_output *output, @@ -506,10 +531,11 @@ void output_damage_from_view(struct roots_output *output, } if (view->wlr_surface != NULL) { - output_damage_from_surface(output, view->wlr_surface, view->x, view->y); + output_damage_from_surface(output, view->wlr_surface, + view->x, view->y, view->rotation); } - // TODO: subsurfaces, popups, etc + // TODO: popups, etc } static void output_handle_mode(struct wl_listener *listener, void *data) { diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index f7b09db0..be658f40 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -118,7 +118,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->view->link); - view_destroy(roots_surface->view); + view_finish(roots_surface->view); + free(roots_surface->view); free(roots_surface); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 295be6a2..7337fb1e 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -231,7 +231,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->view->link); - view_destroy(roots_xdg_surface->view); + view_finish(roots_xdg_surface->view); + free(roots_xdg_surface->view); free(roots_xdg_surface); } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 81f91b4f..6f9912e6 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -121,7 +121,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { if (xwayland_surface->mapped) { wl_list_remove(&roots_surface->view->link); } - view_destroy(roots_surface->view); + view_finish(roots_surface->view); + free(roots_surface->view); free(roots_surface); } @@ -233,24 +234,26 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; + wl_list_insert(&desktop->views, &view->link); + view_damage_whole(view); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, &roots_surface->surface_commit); - - wl_list_insert(&desktop->views, &view->link); } static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, unmap_notify); + struct roots_view *view = roots_surface->view; - view_damage_whole(roots_surface->view); - - roots_surface->view->wlr_surface = NULL; wl_list_remove(&roots_surface->surface_commit.link); - wl_list_remove(&roots_surface->view->link); + + view_damage_whole(view); + + view->wlr_surface = NULL; + wl_list_remove(&view->link); } void handle_xwayland_surface(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From d8b36357e4c8d9edef7df4ecb465b7f728795f90 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 21 Jan 2018 15:13:10 +0100 Subject: rootston: add roots_view_child::destroy --- include/rootston/view.h | 3 ++- rootston/desktop.c | 29 +++++++++++++++++++---------- rootston/xwayland.c | 11 +++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/view.h b/include/rootston/view.h index 6c5e0573..d07f9ca2 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -123,6 +123,8 @@ struct roots_view_child { struct wl_listener commit; struct wl_listener new_subsurface; + + void (*destroy)(struct roots_view_child *child); }; struct roots_subsurface { @@ -151,6 +153,5 @@ void view_child_finish(struct roots_view_child *child); struct roots_subsurface *subsurface_create(struct roots_view *view, struct wlr_subsurface *wlr_subsurface); -void subsurface_destroy(struct roots_subsurface *subsurface); #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 191338a8..4bb1de5f 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -280,6 +280,7 @@ static void view_child_handle_new_subsurface(struct wl_listener *listener, void view_child_init(struct roots_view_child *child, struct roots_view *view, struct wlr_surface *wlr_surface) { + assert(child->destroy); child->view = view; child->wlr_surface = wlr_surface; child->commit.notify = view_child_handle_commit; @@ -289,11 +290,22 @@ void view_child_init(struct roots_view_child *child, struct roots_view *view, wl_list_insert(&view->children, &child->link); } +static void subsurface_destroy(struct roots_view_child *child) { + assert(child->destroy == subsurface_destroy); + struct roots_subsurface *subsurface = (struct roots_subsurface *)child; + if (subsurface == NULL) { + return; + } + wl_list_remove(&subsurface->destroy.link); + view_child_finish(&subsurface->view_child); + free(subsurface); +} + static void subsurface_handle_destroy(struct wl_listener *listener, void *data) { struct roots_subsurface *subsurface = wl_container_of(listener, subsurface, destroy); - subsurface_destroy(subsurface); + subsurface_destroy((struct roots_view_child *)subsurface); } struct roots_subsurface *subsurface_create(struct roots_view *view, @@ -304,27 +316,24 @@ struct roots_subsurface *subsurface_create(struct roots_view *view, return NULL; } subsurface->wlr_subsurface = wlr_subsurface; + subsurface->view_child.destroy = subsurface_destroy; view_child_init(&subsurface->view_child, view, wlr_subsurface->surface); subsurface->destroy.notify = subsurface_handle_destroy; wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy); return subsurface; } -void subsurface_destroy(struct roots_subsurface *subsurface) { - if (subsurface == NULL) { - return; - } - wl_list_remove(&subsurface->destroy.link); - view_child_finish(&subsurface->view_child); - free(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); + } + if (view->fullscreen_output) { view->fullscreen_output->fullscreen_view = NULL; } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 6f9912e6..24315e1a 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -236,6 +236,12 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->y = xsurface->y; 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); roots_surface->surface_commit.notify = handle_surface_commit; @@ -252,6 +258,11 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { view_damage_whole(view); + struct roots_view_child *child, *tmp; + wl_list_for_each_safe(child, tmp, &view->children, link) { + child->destroy(child); + } + view->wlr_surface = NULL; wl_list_remove(&view->link); } -- cgit v1.2.3 From 7111dd79efb6cccf39866051a92090cfc9ea5c67 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 27 Jan 2018 10:43:17 +0100 Subject: rootston: damage tracking for rotated views --- include/rootston/view.h | 1 + include/wlr/types/wlr_box.h | 6 ++++++ rootston/cursor.c | 2 +- rootston/desktop.c | 18 ++++++++++++++---- rootston/output.c | 31 +++++++++++++++++++++++-------- types/wlr_box.c | 29 +++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 13 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/view.h b/include/rootston/view.h index 35660d64..c9d1deb2 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -164,6 +164,7 @@ void view_move_resize(struct roots_view *view, double x, double y, void view_maximize(struct roots_view *view, bool maximized); void view_set_fullscreen(struct roots_view *view, bool fullscreen, struct wlr_output *output); +void view_rotate(struct roots_view *view, float rotation); void view_close(struct roots_view *view); bool view_center(struct roots_view *view); void view_setup(struct roots_view *view); diff --git a/include/wlr/types/wlr_box.h b/include/wlr/types/wlr_box.h index d6cc3509..fc86f0ac 100644 --- a/include/wlr/types/wlr_box.h +++ b/include/wlr/types/wlr_box.h @@ -26,4 +26,10 @@ void wlr_box_transform(const struct wlr_box *box, enum wl_output_transform transform, int width, int height, struct wlr_box *dest); +/** + * Creates the smallest box that contains a rotated box. + */ +void wlr_box_rotated_bounds(const struct wlr_box *box, float rotation, + struct wlr_box *dest); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index a09211b7..158c4708 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -203,7 +203,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy); int steps = 12; angle = round(angle/M_PI*steps) / (steps/M_PI); - view->rotation = cursor->view_rotation + angle; + view_rotate(view, cursor->view_rotation + angle); } break; } diff --git a/rootston/desktop.c b/rootston/desktop.c index b2d586f4..25930d2a 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -200,7 +200,7 @@ void view_maximize(struct roots_view *view, bool maximized) { view_move_resize(view, output_box->x, output_box->y, output_box->width, output_box->height); - view->rotation = 0; + view_rotate(view, 0); } if (view->maximized && !maximized) { @@ -208,7 +208,7 @@ void view_maximize(struct roots_view *view, bool maximized) { view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, view->saved.height); - view->rotation = view->saved.rotation; + view_rotate(view, view->saved.rotation); } } @@ -249,7 +249,7 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, wlr_output_layout_get_box(view->desktop->layout, output); view_move_resize(view, output_box->x, output_box->y, output_box->width, output_box->height); - view->rotation = 0; + view_rotate(view, 0); roots_output->fullscreen_view = view; view->fullscreen_output = roots_output; @@ -258,13 +258,23 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, if (was_fullscreen && !fullscreen) { view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, view->saved.height); - view->rotation = view->saved.rotation; + view_rotate(view, view->saved.rotation); view->fullscreen_output->fullscreen_view = NULL; view->fullscreen_output = NULL; } } +void view_rotate(struct roots_view *view, float rotation) { + if (view->rotation == rotation) { + return; + } + + view_damage_whole(view); + view->rotation = rotation; + view_damage_whole(view); +} + void view_close(struct roots_view *view) { if (view->close) { view->close(view); diff --git a/rootston/output.c b/rootston/output.c index f928184b..d4cd1efd 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -155,7 +155,7 @@ struct render_data { */ static bool surface_intersect_output(struct wlr_surface *surface, struct wlr_output_layout *output_layout, struct wlr_output *wlr_output, - double lx, double ly, struct wlr_box *box) { + double lx, double ly, float rotation, struct wlr_box *box) { double ox = lx, oy = ly; wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy); box->x = ox * wlr_output->scale; @@ -167,6 +167,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); return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box); } @@ -215,15 +216,18 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, struct wlr_box box; bool intersects = surface_intersect_output(surface, output->desktop->layout, - output->wlr_output, lx, ly, &box); + output->wlr_output, lx, ly, rotation, &box); if (!intersects) { return; } + struct wlr_box rotated; + wlr_box_rotated_bounds(&box, -rotation, &rotated); + pixman_region32_t damage; pixman_region32_init(&damage); - pixman_region32_union_rect(&damage, &damage, box.x, box.y, - box.width, box.height); + pixman_region32_union_rect(&damage, &damage, rotated.x, rotated.y, + rotated.width, rotated.height); pixman_region32_intersect(&damage, &damage, data->damage); bool damaged = pixman_region32_not_empty(&damage); if (!damaged) { @@ -415,6 +419,8 @@ static void render_output(struct roots_output *output) { goto renderer_end; } + wlr_renderer_clear(output->desktop->server->renderer, 1, 1, 1, 1); + int nrects; pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { @@ -526,12 +532,14 @@ static void damage_whole_surface(struct wlr_surface *surface, } struct wlr_box box; - bool intersects = surface_intersect_output(surface, - output->desktop->layout, output->wlr_output, lx, ly, &box); + bool intersects = surface_intersect_output(surface, output->desktop->layout, + output->wlr_output, lx, ly, rotation, &box); if (!intersects) { return; } + wlr_box_rotated_bounds(&box, -rotation, &box); + pixman_region32_union_rect(&output->damage, &output->damage, box.x, box.y, box.width, box.height); @@ -547,6 +555,8 @@ 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); + pixman_region32_union_rect(&output->damage, &output->damage, box.x, box.y, box.width, box.height); } @@ -576,8 +586,8 @@ static void damage_from_surface(struct wlr_surface *surface, } struct wlr_box box; - bool intersects = surface_intersect_output(surface, - output->desktop->layout, output->wlr_output, lx, ly, &box); + bool intersects = surface_intersect_output(surface, output->desktop->layout, + output->wlr_output, lx, ly, rotation, &box); if (!intersects) { return; } @@ -599,6 +609,11 @@ void output_damage_from_view(struct roots_output *output, return; } + if (view->rotation != 0) { + output_damage_whole_view(output, view); + return; + } + view_for_each_surface(view, damage_from_surface, output); } diff --git a/types/wlr_box.c b/types/wlr_box.c index 3217a7d0..a7388209 100644 --- a/types/wlr_box.c +++ b/types/wlr_box.c @@ -114,3 +114,32 @@ void wlr_box_transform(const struct wlr_box *box, break; } } + +void wlr_box_rotated_bounds(const struct wlr_box *box, float rotation, + struct wlr_box *dest) { + if (rotation == 0) { + *dest = *box; + return; + } + + double ox = box->x + (double)box->width/2; + double oy = box->y + (double)box->height/2; + + double c = fabs(cos(rotation)); + double s = fabs(sin(rotation)); + + double x1 = ox + (box->x - ox) * c + (box->y - oy) * s; + double x2 = ox + + (box->x + box->width - ox) * c + + (box->y + box->height - oy) * s; + + double y1 = oy + (box->x - ox) * s + (box->y - oy) * c; + double y2 = oy + + (box->x + box->width - ox) * s + + (box->y + box->height - oy) * c; + + dest->x = fmin(x1, x2); + dest->width = fmax(x1, x2) - fmin(x1, x2); + dest->y = fmin(y1, y2); + dest->height = fmax(y1, y2) - fmin(y1, y2); +} -- cgit v1.2.3 From 63736be2143a1821fe0b378e56c7e70f1f3cafec Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 28 Jan 2018 10:11:31 +0100 Subject: rootston: fix damage tracking for SSD --- include/rootston/desktop.h | 1 + include/rootston/view.h | 7 ++----- rootston/desktop.c | 25 +++++++++++++------------ rootston/wl_shell.c | 4 ++++ rootston/xdg_shell_v6.c | 15 +++++++++++---- rootston/xwayland.c | 7 +++++++ 6 files changed, 38 insertions(+), 21 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 388fb55d..1232121a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -69,6 +69,7 @@ void view_activate(struct roots_view *view, bool activate); void view_apply_damage(struct roots_view *view); void view_damage_whole(struct roots_view *view); void view_update_position(struct roots_view *view, double x, double y); +void view_update_size(struct roots_view *view, uint32_t width, uint32_t height); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/view.h b/include/rootston/view.h index c9d1deb2..9312c8c3 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -62,6 +62,7 @@ struct roots_view { struct wl_list link; // roots_desktop::views double x, y; + uint32_t width, height; float rotation; bool decorated; @@ -108,11 +109,7 @@ struct roots_view { struct wl_signal destroy; } events; - // TODO: This would probably be better as a field that's updated on a - // configure event from the xdg_shell - // If not then this should follow the typical type/impl pattern we use - // elsewhere - void (*get_size)(const struct roots_view *view, struct wlr_box *box); + // TODO: this should follow the typical type/impl pattern we use elsewhere void (*activate)(struct roots_view *view, bool active); void (*move)(struct roots_view *view, double x, double y); void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); diff --git a/rootston/desktop.c b/rootston/desktop.c index 25930d2a..9abcfa33 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -24,18 +24,8 @@ void view_get_box(const struct roots_view *view, struct wlr_box *box) { box->x = view->x; box->y = view->y; - if (view->get_size) { - view->get_size(view, box); - } else { - if (view->wlr_surface == NULL) { - // View is unmapped - box->width = box->height = 0; - return; - } - - box->width = view->wlr_surface->current->width; - box->height = view->wlr_surface->current->height; - } + box->width = view->width; + box->height = view->height; } void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { @@ -469,6 +459,17 @@ void view_update_position(struct roots_view *view, double x, double y) { view_damage_whole(view); } +void view_update_size(struct roots_view *view, uint32_t width, uint32_t height) { + if (view->width == width && view->height == height) { + return; + } + + view_damage_whole(view); + view->width = width; + view->height = height; + view_damage_whole(view); +} + static bool view_at(struct roots_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (view->type == ROOTS_WL_SHELL_VIEW && diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 1fc48452..267e2cf5 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -147,6 +147,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int width = wlr_surface->current->width; int height = wlr_surface->current->height; + view_update_size(view, width, height); + double x = view->x; double y = view->y; if (view->pending_move_resize.update_x) { @@ -231,6 +233,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { return; } view->type = ROOTS_WL_SHELL_VIEW; + view->width = surface->surface->current->width; + view->height = surface->surface->current->height; view->wl_shell_surface = surface; view->roots_wl_shell_surface = roots_surface; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 0a3ca72c..b354b77b 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -245,12 +245,13 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view_apply_damage(view); + struct wlr_box size; + get_size(view, &size); + view_update_size(view, size.width, size.height); + uint32_t pending_serial = roots_surface->pending_move_resize_configure_serial; if (pending_serial > 0 && pending_serial >= surface->configure_serial) { - struct wlr_box size; - get_size(view, &size); - double x = view->x; double y = view->y; if (view->pending_move_resize.update_x) { @@ -338,10 +339,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { return; } view->type = ROOTS_XDG_SHELL_V6_VIEW; + view->xdg_surface_v6 = surface; view->roots_xdg_surface_v6 = roots_surface; view->wlr_surface = surface->surface; - view->get_size = get_size; view->activate = activate; view->resize = resize; view->move_resize = move_resize; @@ -349,6 +350,12 @@ 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_init(view, desktop); wl_list_insert(&desktop->views, &view->link); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index c0bc9ae7..a3e12d00 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -209,6 +209,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int width = wlr_surface->current->width; int height = wlr_surface->current->height; + view_update_size(view, width, height); + double x = view->x; double y = view->y; if (view->pending_move_resize.update_x) { @@ -234,6 +236,8 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { 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; @@ -264,6 +268,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { } view->wlr_surface = NULL; + view->width = view->height = 0; wl_list_remove(&view->link); } @@ -314,6 +319,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->type = ROOTS_XWAYLAND_VIEW; view->x = (double)surface->x; view->y = (double)surface->y; + view->width = surface->surface->current->width; + view->height = surface->surface->current->height; view->xwayland_surface = surface; view->roots_xwayland_surface = roots_surface; -- cgit v1.2.3 From a7cba7d83fc0c881af79792029f36cd46c6cab2c Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 30 Jan 2018 14:40:22 +0100 Subject: rootston: damage whole output when entering/leaving fullscreen --- include/rootston/output.h | 1 + rootston/desktop.c | 2 ++ rootston/output.c | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/output.h b/include/rootston/output.h index a9f9bc2b..3a6d3cc7 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -39,6 +39,7 @@ void output_remove_notify(struct wl_listener *listener, void *data); struct roots_view; struct roots_drag_icon; +void output_damage_whole(struct roots_output *output); void output_damage_whole_view(struct roots_output *output, struct roots_view *view); void output_damage_from_view(struct roots_output *output, diff --git a/rootston/desktop.c b/rootston/desktop.c index d3654661..91661c05 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -243,6 +243,7 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, roots_output->fullscreen_view = view; view->fullscreen_output = roots_output; + output_damage_whole(roots_output); } if (was_fullscreen && !fullscreen) { @@ -250,6 +251,7 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, view->saved.height); view_rotate(view, view->saved.rotation); + output_damage_whole(view->fullscreen_output); view->fullscreen_output->fullscreen_view = NULL; view->fullscreen_output = NULL; } diff --git a/rootston/output.c b/rootston/output.c index de4922ba..a7fca415 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -493,7 +493,7 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { render_output(output); } -static void output_damage_whole(struct roots_output *output) { +void output_damage_whole(struct roots_output *output) { int width, height; wlr_output_transformed_resolution(output->wlr_output, &width, &height); -- cgit v1.2.3