diff options
Diffstat (limited to 'rootston/output.c')
-rw-r--r-- | rootston/output.c | 138 |
1 files changed, 93 insertions, 45 deletions
diff --git a/rootston/output.c b/rootston/output.c index 1b2a17d8..2283ad16 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -174,7 +174,6 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, struct render_data *data = _data; struct roots_output *output = data->output; struct timespec *when = data->when; - pixman_region32_t *damage = data->damage; if (!wlr_surface_has_buffer(surface)) { return; @@ -188,63 +187,95 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, } // 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, + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, box.width, box.height); - pixman_region32_intersect(&surface_damage, &surface_damage, damage); - bool damaged = pixman_region32_not_empty(&surface_damage); + pixman_region32_intersect(&damage, &damage, data->damage); + bool damaged = pixman_region32_not_empty(&damage); if (!damaged) { - goto surface_damage_finish; + goto damage_finish; } - 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.width/2, box.height/2, 0); + 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); - float rotate[16]; - wlr_matrix_rotate(&rotate, rotation); + int nrects; + pixman_box32_t *rects = + pixman_region32_rectangles(&damage, &nrects); + for (int i = 0; i < nrects; ++i) { + struct wlr_box scissor = { + .x = rects[i].x1, + .y = output->wlr_output->height - rects[i].y2, + .width = rects[i].x2 - rects[i].x1, + .height = rects[i].y2 - rects[i].y1, + }; + wlr_renderer_scissor(output->desktop->server->renderer, &scissor); + wlr_render_with_matrix(output->desktop->server->renderer, + surface->texture, &matrix); + } - float translate_origin[16]; - wlr_matrix_translate(&translate_origin, -box.width/2, -box.height/2, 0); + wlr_surface_send_frame_done(surface, when); - wlr_matrix_mul(&transform, &translate_center, &transform); - wlr_matrix_mul(&transform, &rotate, &transform); - wlr_matrix_mul(&transform, &translate_origin, &transform); - } +damage_finish: + pixman_region32_fini(&damage); +} - float scale[16]; - wlr_matrix_scale(&scale, box.width, box.height, 1); +static void get_decoration_box(struct roots_view *view, + struct roots_output *output, struct wlr_box *box) { + struct wlr_output *wlr_output = output->wlr_output; - wlr_matrix_mul(&transform, &scale, &transform); + struct wlr_box deco_box; + view_get_deco_box(view, &deco_box); + double sx = deco_box.x - view->x; + double sy = deco_box.y - view->y; + rotate_child_position(&sx, &sy, deco_box.width, deco_box.height, + view->wlr_surface->current->width, + view->wlr_surface->current->height, view->rotation); + double x = sx + view->x; + double y = sy + view->y; + + wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y); + + box->x = x * wlr_output->scale; + box->y = y * wlr_output->scale; + box->width = deco_box.width * wlr_output->scale; + box->height = deco_box.height * wlr_output->scale; +} - if (surface->current->transform != WL_OUTPUT_TRANSFORM_NORMAL) { - float surface_translate_center[16]; - wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); +static void render_decorations(struct roots_view *view, + struct render_data *data) { + if (!view->decorated || view->wlr_surface == NULL) { + return; + } - float surface_transform[16]; - wlr_matrix_transform(surface_transform, - wlr_output_transform_invert(surface->current->transform)); + struct roots_output *output = data->output; - float surface_translate_origin[16]; - wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); + struct wlr_box box; + get_decoration_box(view, output, &box); - wlr_matrix_mul(&transform, &surface_translate_center, - &transform); - wlr_matrix_mul(&transform, &surface_transform, &transform); - wlr_matrix_mul(&transform, &surface_translate_origin, - &transform); + // TODO: output scale, output transform support + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, + box.width, box.height); + pixman_region32_intersect(&damage, &damage, data->damage); + bool damaged = pixman_region32_not_empty(&damage); + if (!damaged) { + goto damage_finish; } float matrix[16]; - wlr_matrix_mul(&output->wlr_output->transform_matrix, &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, 1 }; int nrects; pixman_box32_t *rects = - pixman_region32_rectangles(&surface_damage, &nrects); + pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { struct wlr_box scissor = { .x = rects[i].x1, @@ -253,14 +284,17 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, .height = rects[i].y2 - rects[i].y1, }; wlr_renderer_scissor(output->desktop->server->renderer, &scissor); - wlr_render_with_matrix(output->desktop->server->renderer, - surface->texture, &matrix); + wlr_render_colored_quad(output->desktop->server->renderer, &color, + &matrix); } - wlr_surface_send_frame_done(surface, when); +damage_finish: + pixman_region32_fini(&damage); +} -surface_damage_finish: - pixman_region32_fini(&surface_damage); +static void render_view(struct roots_view *view, struct render_data *data) { + render_decorations(view, data); + view_for_each_surface(view, render_surface, data); } static bool has_standalone_surface(struct roots_view *view) { @@ -402,7 +436,7 @@ static void render_output(struct roots_output *output) { // Render all views struct roots_view *view; wl_list_for_each_reverse(view, &desktop->views, link) { - view_for_each_surface(view, render_surface, &data); + render_view(view, &data); } // Render drag icons @@ -505,12 +539,26 @@ static void damage_whole_surface(struct wlr_surface *surface, schedule_render(output); } +static void damage_whole_decoration(struct roots_view *view, + struct roots_output *output) { + if (!view->decorated || view->wlr_surface == NULL) { + return; + } + + struct wlr_box box; + get_decoration_box(view, output, &box); + + pixman_region32_union_rect(&output->damage, &output->damage, + box.x, box.y, box.width, box.height); +} + void output_damage_whole_view(struct roots_output *output, struct roots_view *view) { if (!view_accept_damage(output, view)) { return; } + damage_whole_decoration(view, output); view_for_each_surface(view, damage_whole_surface, output); } |