From d2d530bd092cbd754dff182f59fc1defa4a6e9cb Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 1 Jul 2018 12:50:54 +1000 Subject: [PATCH] Introduce render_context and reduce number of function arguments This adds a struct render_context which contains the commonly accessed output-specific properties and saves us from having to pass them through several functions as arguments. --- sway/desktop/render.c | 330 +++++++++++++++++++----------------------- 1 file changed, 152 insertions(+), 178 deletions(-) diff --git a/sway/desktop/render.c b/sway/desktop/render.c index bb1b26a93..0de8bdd97 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -27,6 +27,15 @@ #include "sway/tree/view.h" #include "sway/tree/workspace.h" +struct render_context { + struct sway_output *output; + int output_lx; + int output_ly; + pixman_region32_t *damage; + float scale; +}; +struct render_context context; + /** * Rotate a child's position relative to a parent. The parent size is (pw, ph), * the child position is (*sx, *sy) and its size is (sw, sh). @@ -66,7 +75,7 @@ struct render_data { }; static bool get_surface_box(struct root_geometry *geo, - struct sway_output *output, struct wlr_surface *surface, int sx, int sy, + struct wlr_surface *surface, int sx, int sy, struct wlr_box *surface_box) { if (!wlr_surface_has_buffer(surface)) { return false; @@ -93,8 +102,8 @@ static bool get_surface_box(struct root_geometry *geo, wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box); struct wlr_box output_box = { - .width = output->swayc->current.swayc_width, - .height = output->swayc->current.swayc_height, + .width = context.output->swayc->current.swayc_width, + .height = context.output->swayc->current.swayc_height, }; struct wlr_box intersection; @@ -116,9 +125,10 @@ static void surface_for_each_surface(struct wlr_surface *surface, static void output_view_for_each_surface(struct sway_view *view, struct root_geometry *geo, wlr_surface_iterator_func_t iterator, void *user_data) { - struct render_data *data = user_data; - geo->x = view->swayc->current.view_x - data->output->swayc->current.swayc_x; - geo->y = view->swayc->current.view_y - data->output->swayc->current.swayc_y; + geo->x = + view->swayc->current.view_x - context.output->swayc->current.swayc_x; + geo->y = + view->swayc->current.view_y - context.output->swayc->current.swayc_y; geo->width = view->swayc->current.view_width; geo->height = view->swayc->current.view_height; geo->rotation = 0; // TODO @@ -140,14 +150,14 @@ static void layer_for_each_surface(struct wl_list *layer_surfaces, } static void unmanaged_for_each_surface(struct wl_list *unmanaged, - struct sway_output *output, struct root_geometry *geo, - wlr_surface_iterator_func_t iterator, void *user_data) { + struct root_geometry *geo, wlr_surface_iterator_func_t iterator, + void *user_data) { struct sway_xwayland_unmanaged *unmanaged_surface; wl_list_for_each(unmanaged_surface, unmanaged, link) { struct wlr_xwayland_surface *xsurface = unmanaged_surface->wlr_xwayland_surface; - double ox = unmanaged_surface->lx - output->swayc->current.swayc_x; - double oy = unmanaged_surface->ly - output->swayc->current.swayc_y; + double ox = unmanaged_surface->lx - context.output_lx; + double oy = unmanaged_surface->ly - context.output_ly; surface_for_each_surface(xsurface->surface, ox, oy, geo, iterator, user_data); @@ -155,12 +165,12 @@ static void unmanaged_for_each_surface(struct wl_list *unmanaged, } static void drag_icons_for_each_surface(struct wl_list *drag_icons, - struct sway_output *output, struct root_geometry *geo, - wlr_surface_iterator_func_t iterator, void *user_data) { + struct root_geometry *geo, wlr_surface_iterator_func_t iterator, + void *user_data) { struct sway_drag_icon *drag_icon; wl_list_for_each(drag_icon, drag_icons, link) { - double ox = drag_icon->x - output->swayc->x; - double oy = drag_icon->y - output->swayc->y; + double ox = drag_icon->x - context.output_lx; + double oy = drag_icon->y - context.output_ly; if (drag_icon->wlr_drag_icon->mapped) { surface_for_each_surface(drag_icon->wlr_drag_icon->surface, @@ -198,9 +208,9 @@ static void scissor_output(struct wlr_output *wlr_output, wlr_renderer_scissor(renderer, &box); } -static void render_texture(struct wlr_output *wlr_output, - pixman_region32_t *output_damage, struct wlr_texture *texture, +static void render_texture(struct wlr_texture *texture, const struct wlr_box *box, const float matrix[static 9], float alpha) { + struct wlr_output *wlr_output = context.output->wlr_output; struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); @@ -208,7 +218,7 @@ static void render_texture(struct wlr_output *wlr_output, pixman_region32_init(&damage); pixman_region32_union_rect(&damage, &damage, box->x, box->y, box->width, box->height); - pixman_region32_intersect(&damage, &damage, output_damage); + pixman_region32_intersect(&damage, &damage, context.damage); bool damaged = pixman_region32_not_empty(&damage); if (!damaged) { goto damage_finish; @@ -228,9 +238,8 @@ damage_finish: static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, void *_data) { struct render_data *data = _data; - struct wlr_output *wlr_output = data->output->wlr_output; + struct wlr_output *wlr_output = context.output->wlr_output; float rotation = data->root_geo.rotation; - pixman_region32_t *output_damage = data->damage; float alpha = data->alpha; struct wlr_texture *texture = wlr_surface_get_texture(surface); @@ -239,13 +248,12 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, } struct wlr_box box; - bool intersects = get_surface_box(&data->root_geo, data->output, surface, - sx, sy, &box); + bool intersects = get_surface_box(&data->root_geo, surface, sx, sy, &box); if (!intersects) { return; } - scale_box(&box, wlr_output->scale); + scale_box(&box, context.scale); float matrix[9]; enum wl_output_transform transform = @@ -253,58 +261,48 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, wlr_matrix_project_box(matrix, &box, transform, rotation, wlr_output->transform_matrix); - render_texture(wlr_output, output_damage, texture, &box, matrix, alpha); + render_texture(texture, &box, matrix, alpha); } -static void render_layer(struct sway_output *output, - pixman_region32_t *damage, struct wl_list *layer_surfaces) { +static void render_layer(struct wl_list *layer_surfaces) { struct render_data data = { - .output = output, - .damage = damage, .alpha = 1.0f, }; layer_for_each_surface(layer_surfaces, &data.root_geo, render_surface_iterator, &data); } -static void render_unmanaged(struct sway_output *output, - pixman_region32_t *damage, struct wl_list *unmanaged) { +static void render_unmanaged(struct wl_list *unmanaged) { struct render_data data = { - .output = output, - .damage = damage, .alpha = 1.0f, }; - unmanaged_for_each_surface(unmanaged, output, &data.root_geo, + unmanaged_for_each_surface(unmanaged, &data.root_geo, render_surface_iterator, &data); } -static void render_drag_icons(struct sway_output *output, - pixman_region32_t *damage, struct wl_list *drag_icons) { +static void render_drag_icons(struct wl_list *drag_icons) { struct render_data data = { - .output = output, - .damage = damage, .alpha = 1.0f, }; - drag_icons_for_each_surface(drag_icons, output, &data.root_geo, + drag_icons_for_each_surface(drag_icons, &data.root_geo, render_surface_iterator, &data); } -static void render_rect(struct wlr_output *wlr_output, - pixman_region32_t *output_damage, const struct wlr_box *_box, - float color[static 4]) { +static void render_rect(const struct wlr_box *_box, float color[static 4]) { + struct wlr_output *wlr_output = context.output->wlr_output; struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); struct wlr_box box; memcpy(&box, _box, sizeof(struct wlr_box)); - box.x -= wlr_output->lx * wlr_output->scale; - box.y -= wlr_output->ly * wlr_output->scale; + box.x -= context.output_lx * context.scale; + box.y -= context.output_ly * context.scale; 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, output_damage); + pixman_region32_intersect(&damage, &damage, context.damage); bool damaged = pixman_region32_not_empty(&damage); if (!damaged) { goto damage_finish; @@ -314,8 +312,7 @@ static void render_rect(struct wlr_output *wlr_output, pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(wlr_output, &rects[i]); - wlr_render_rect(renderer, &box, color, - wlr_output->transform_matrix); + wlr_render_rect(renderer, &box, color, wlr_output->transform_matrix); } damage_finish: @@ -329,11 +326,8 @@ static void premultiply_alpha(float color[4], float opacity) { color[2] *= color[3]; } -static void render_view_surfaces(struct sway_view *view, - struct sway_output *output, pixman_region32_t *damage, float alpha) { +static void render_view_surfaces(struct sway_view *view, float alpha) { struct render_data data = { - .output = output, - .damage = damage, .view = view, .alpha = alpha, }; @@ -341,10 +335,7 @@ static void render_view_surfaces(struct sway_view *view, view, &data.root_geo, render_surface_iterator, &data); } -static void render_saved_view(struct sway_view *view, - struct sway_output *output, pixman_region32_t *damage, float alpha) { - struct wlr_output *wlr_output = output->wlr_output; - +static void render_saved_view(struct sway_view *view, float alpha) { int width, height; struct wlr_texture *texture = transaction_get_saved_texture(view, &width, &height); @@ -352,15 +343,15 @@ static void render_saved_view(struct sway_view *view, return; } struct wlr_box box = { - .x = view->swayc->current.view_x - output->swayc->current.swayc_x, - .y = view->swayc->current.view_y - output->swayc->current.swayc_y, + .x = view->swayc->current.view_x - context.output_lx, + .y = view->swayc->current.view_y - context.output_ly, .width = width, .height = height, }; struct wlr_box output_box = { - .width = output->swayc->current.swayc_width, - .height = output->swayc->current.swayc_height, + .width = context.output->swayc->current.swayc_width, + .height = context.output->swayc->current.swayc_height, }; struct wlr_box intersection; @@ -369,29 +360,28 @@ static void render_saved_view(struct sway_view *view, return; } - scale_box(&box, wlr_output->scale); + scale_box(&box, context.scale); float matrix[9]; wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, - wlr_output->transform_matrix); + context.output->wlr_output->transform_matrix); - render_texture(wlr_output, damage, texture, &box, matrix, alpha); + render_texture(texture, &box, matrix, alpha); } /** * Render a view's surface and left/bottom/right borders. */ -static void render_view(struct sway_output *output, pixman_region32_t *damage, - struct sway_container *con, struct border_colors *colors) { +static void render_view(struct sway_container *con, + struct border_colors *colors) { struct sway_view *view = con->sway_view; if (view->swayc->instructions->length) { - render_saved_view(view, output, damage, view->swayc->alpha); + render_saved_view(view, view->swayc->alpha); } else { - render_view_surfaces(view, output, damage, view->swayc->alpha); + render_view_surfaces(view, view->swayc->alpha); } struct wlr_box box; - float output_scale = output->wlr_output->scale; float color[4]; struct sway_container_state *state = &con->current; @@ -403,8 +393,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage, box.y = state->view_y; box.width = state->border_thickness; box.height = state->view_height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); } if (state->border_right) { @@ -419,8 +409,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage, box.y = state->view_y; box.width = state->border_thickness; box.height = state->view_height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); } if (state->border_bottom) { @@ -435,8 +425,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage, box.y = state->view_y + state->view_height; box.width = state->swayc_width; box.height = state->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); } } } @@ -451,20 +441,15 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage, * The left side for L_TABBED is: 1px border, 2px padding, title * The left side for other layouts is: 3px padding, title */ -static void render_titlebar(struct sway_output *output, - pixman_region32_t *output_damage, struct sway_container *con, - int x, int y, int width, +static void render_titlebar(struct sway_container *con, int x, int y, int width, struct border_colors *colors, struct wlr_texture *title_texture, struct wlr_texture *marks_texture) { struct wlr_box box; float color[4]; struct sway_container_state *state = &con->current; - float output_scale = output->wlr_output->scale; enum sway_container_layout layout = state->parent->current.layout; list_t *children = state->parent->current.children; bool is_last_child = children->items[children->length - 1] == con; - double output_x = output->swayc->current.swayc_x; - double output_y = output->swayc->current.swayc_y; // Single pixel bar above title memcpy(&color, colors->border, sizeof(float) * 4); @@ -473,8 +458,8 @@ static void render_titlebar(struct sway_output *output, box.y = y; box.width = width; box.height = TITLEBAR_BORDER_THICKNESS; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); // Single pixel bar below title size_t left_offset = 0, right_offset = 0; @@ -491,8 +476,8 @@ static void render_titlebar(struct sway_output *output, box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.width = width - left_offset - right_offset; box.height = TITLEBAR_BORDER_THICKNESS; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); if (layout == L_TABBED) { // Single pixel left edge @@ -501,12 +486,12 @@ static void render_titlebar(struct sway_output *output, box.width = TITLEBAR_BORDER_THICKNESS; box.height = container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); // Single pixel right edge - box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * output_scale; - render_rect(output->wlr_output, output_damage, &box, color); + box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * context.scale; + render_rect(&box, color); } size_t inner_width = width - TITLEBAR_H_PADDING * 2; @@ -517,20 +502,20 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); - texture_box.x = (x - output_x + width - TITLEBAR_H_PADDING) - * output_scale - texture_box.width; - texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale; + texture_box.x = (x - context.output_lx + width - TITLEBAR_H_PADDING) + * context.scale - texture_box.width; + texture_box.y = (y - context.output_ly + TITLEBAR_V_PADDING) + * context.scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, - 0.0, output->wlr_output->transform_matrix); + 0.0, context.output->wlr_output->transform_matrix); - if (inner_width * output_scale < texture_box.width) { - texture_box.width = inner_width * output_scale; + if (inner_width * context.scale < texture_box.width) { + texture_box.width = inner_width * context.scale; } - render_texture(output->wlr_output, output_damage, marks_texture, - &texture_box, matrix, con->alpha); + render_texture(marks_texture, &texture_box, matrix, con->alpha); marks_width = texture_box.width; } @@ -540,19 +525,20 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = (x - output_x + TITLEBAR_H_PADDING) * output_scale; - texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale; + texture_box.x = + (x - context.output_lx + TITLEBAR_H_PADDING) * context.scale; + texture_box.y = + (y - context.output_ly + TITLEBAR_V_PADDING) * context.scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, - 0.0, output->wlr_output->transform_matrix); + 0.0, context.output->wlr_output->transform_matrix); - if (inner_width * output_scale - marks_width < texture_box.width) { - texture_box.width = inner_width * output_scale - marks_width; + if (inner_width * context.scale - marks_width < texture_box.width) { + texture_box.width = inner_width * context.scale - marks_width; } - render_texture(output->wlr_output, output_damage, title_texture, - &texture_box, matrix, con->alpha); + render_texture(title_texture, &texture_box, matrix, con->alpha); title_width = texture_box.width; } @@ -563,20 +549,20 @@ static void render_titlebar(struct sway_output *output, box.y = y + TITLEBAR_BORDER_THICKNESS; box.width = width - (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS * 2; box.height = TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); // Padding below title - box.y = (y + TITLEBAR_V_PADDING + config->font_height) * output_scale; - render_rect(output->wlr_output, output_damage, &box, color); + box.y = (y + TITLEBAR_V_PADDING + config->font_height) * context.scale; + render_rect(&box, color); // Filler between title and marks - box.width = inner_width * output_scale - title_width - marks_width; + box.width = inner_width * context.scale - title_width - marks_width; if (box.width > 0) { - box.x = (x + TITLEBAR_H_PADDING) * output_scale + title_width; - box.y = (y + TITLEBAR_V_PADDING) * output_scale; - box.height = config->font_height * output_scale; - render_rect(output->wlr_output, output_damage, &box, color); + box.x = (x + TITLEBAR_H_PADDING) * context.scale + title_width; + box.y = (y + TITLEBAR_V_PADDING) * context.scale; + box.height = config->font_height * context.scale; + render_rect(&box, color); } // Padding left of title @@ -585,8 +571,8 @@ static void render_titlebar(struct sway_output *output, box.y = y + TITLEBAR_V_PADDING; box.width = TITLEBAR_H_PADDING - left_offset; box.height = config->font_height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); // Padding right of marks right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; @@ -594,8 +580,8 @@ static void render_titlebar(struct sway_output *output, box.y = y + TITLEBAR_V_PADDING; box.width = TITLEBAR_H_PADDING - right_offset; box.height = config->font_height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); if (connects_sides) { // Left pixel in line with bottom bar @@ -603,24 +589,23 @@ static void render_titlebar(struct sway_output *output, box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.width = state->border_thickness * state->border_left; box.height = TITLEBAR_BORDER_THICKNESS; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); // Right pixel in line with bottom bar box.x = x + width - state->border_thickness * state->border_right; box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.width = state->border_thickness * state->border_right; box.height = TITLEBAR_BORDER_THICKNESS; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); } } /** * Render the top border line for a view using "border pixel". */ -static void render_top_border(struct sway_output *output, - pixman_region32_t *output_damage, struct sway_container *con, +static void render_top_border(struct sway_container *con, struct border_colors *colors) { struct sway_container_state *state = &con->current; if (!state->border_top) { @@ -628,7 +613,6 @@ static void render_top_border(struct sway_output *output, } struct wlr_box box; float color[4]; - float output_scale = output->wlr_output->scale; // Child border - top edge memcpy(&color, colors->child_border, sizeof(float) * 4); @@ -637,12 +621,11 @@ static void render_top_border(struct sway_output *output, box.y = state->swayc_y; box.width = state->swayc_width; box.height = state->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); + scale_box(&box, context.scale); + render_rect(&box, color); } -static void render_container(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con, bool parent_focused); +static void render_container(struct sway_container *con, bool parent_focused); /** * Render a container's children using a L_HORIZ or L_VERT layout. @@ -650,8 +633,7 @@ static void render_container(struct sway_output *output, * Wrap child views in borders and leave child containers borderless because * they'll apply their own borders to their children. */ -static void render_container_simple(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con, +static void render_container_simple(struct sway_container *con, bool parent_focused) { struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = seat_get_focus(seat); @@ -681,16 +663,15 @@ static void render_container_simple(struct sway_output *output, } if (state->border == B_NORMAL) { - render_titlebar(output, damage, child, state->swayc_x, - state->swayc_y, state->swayc_width, colors, + render_titlebar(child, state->swayc_x, state->swayc_y, + state->swayc_width, colors, title_texture, marks_texture); } else { - render_top_border(output, damage, child, colors); + render_top_border(child, colors); } - render_view(output, damage, child, colors); + render_view(child, colors); } else { - render_container(output, damage, child, - parent_focused || focus == child); + render_container(child, parent_focused || focus == child); } } } @@ -698,8 +679,7 @@ static void render_container_simple(struct sway_output *output, /** * Render a container's children using the L_TABBED layout. */ -static void render_container_tabbed(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con, +static void render_container_tabbed(struct sway_container *con, bool parent_focused) { if (!con->current.children->length) { return; @@ -740,8 +720,8 @@ static void render_container_tabbed(struct sway_output *output, tab_width = pstate->swayc_width - tab_width * i; } - render_titlebar(output, damage, child, x, cstate->swayc_y, tab_width, - colors, title_texture, marks_texture); + render_titlebar(child, x, cstate->swayc_y, tab_width, colors, + title_texture, marks_texture); if (child == current) { current_colors = colors; @@ -751,10 +731,9 @@ static void render_container_tabbed(struct sway_output *output, // Render surface and left/right/bottom borders if (current) { if (current->type == C_VIEW) { - render_view(output, damage, current, current_colors); + render_view(current, current_colors); } else { - render_container(output, damage, current, - parent_focused || current == focus); + render_container(current, parent_focused || current == focus); } } } @@ -762,8 +741,7 @@ static void render_container_tabbed(struct sway_output *output, /** * Render a container's children using the L_STACKED layout. */ -static void render_container_stacked(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con, +static void render_container_stacked(struct sway_container *con, bool parent_focused) { if (!con->current.children->length) { return; @@ -798,8 +776,8 @@ static void render_container_stacked(struct sway_output *output, } int y = pstate->swayc_y + container_titlebar_height() * i; - render_titlebar(output, damage, child, cstate->swayc_x, y, - cstate->swayc_width, colors, title_texture, marks_texture); + render_titlebar(child, cstate->swayc_x, y, cstate->swayc_width, colors, + title_texture, marks_texture); if (child == current) { current_colors = colors; @@ -809,36 +787,32 @@ static void render_container_stacked(struct sway_output *output, // Render surface and left/right/bottom borders if (current) { if (current->type == C_VIEW) { - render_view(output, damage, current, current_colors); + render_view(current, current_colors); } else { - render_container(output, damage, current, - parent_focused || current == focus); + render_container(current, parent_focused || current == focus); } } } -static void render_container(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con, - bool parent_focused) { +static void render_container(struct sway_container *con, bool parent_focused) { switch (con->current.layout) { case L_NONE: case L_HORIZ: case L_VERT: - render_container_simple(output, damage, con, parent_focused); + render_container_simple(con, parent_focused); break; case L_STACKED: - render_container_stacked(output, damage, con, parent_focused); + render_container_stacked(con, parent_focused); break; case L_TABBED: - render_container_tabbed(output, damage, con, parent_focused); + render_container_tabbed(con, parent_focused); break; case L_FLOATING: sway_assert(false, "Didn't expect to see floating here"); } } -static void render_floating_container(struct sway_output *soutput, - pixman_region32_t *damage, struct sway_container *con) { +static void render_floating_container(struct sway_container *con) { if (con->type == C_VIEW) { struct sway_view *view = con->sway_view; struct sway_seat *seat = input_manager_current_seat(input_manager); @@ -858,20 +832,19 @@ static void render_floating_container(struct sway_output *soutput, } if (con->current.border == B_NORMAL) { - render_titlebar(soutput, damage, con, con->current.swayc_x, - con->current.swayc_y, con->current.swayc_width, colors, + render_titlebar(con, con->current.swayc_x, con->current.swayc_y, + con->current.swayc_width, colors, title_texture, marks_texture); } else if (con->current.border != B_NONE) { - render_top_border(soutput, damage, con, colors); + render_top_border(con, colors); } - render_view(soutput, damage, con, colors); + render_view(con, colors); } else { - render_container(soutput, damage, con, false); + render_container(con, false); } } -static void render_floating(struct sway_output *soutput, - pixman_region32_t *damage) { +static void render_floating() { for (int i = 0; i < root_container.current.children->length; ++i) { struct sway_container *output = root_container.current.children->items[i]; @@ -884,7 +857,7 @@ static void render_floating(struct sway_output *soutput, ws->current.ws_floating->current.children; for (int k = 0; k < floating->length; ++k) { struct sway_container *floater = floating->items[k]; - render_floating_container(soutput, damage, floater); + render_floating_container(floater); } } } @@ -910,6 +883,13 @@ void render_output(struct sway_output *output, struct timespec *when, pixman_region32_t *damage) { struct wlr_output *wlr_output = output->wlr_output; + memset(&context, 0, sizeof(struct render_context)); + context.output = output; + context.output_lx = output->swayc->current.swayc_x; + context.output_ly = output->swayc->current.swayc_y; + context.damage = damage; + context.scale = output->wlr_output->scale; + struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); if (!sway_assert(renderer != NULL, @@ -951,11 +931,10 @@ void render_output(struct sway_output *output, struct timespec *when, } // TODO: handle views smaller than the output - render_view_surfaces(fullscreen_view, output, damage, 1.0f); + render_view_surfaces(fullscreen_view, 1.0f); if (fullscreen_view->type == SWAY_VIEW_XWAYLAND) { - render_unmanaged(output, damage, - &root_container.sway_root->xwayland_unmanaged); + render_unmanaged(&root_container.sway_root->xwayland_unmanaged); } } else { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; @@ -967,24 +946,19 @@ void render_output(struct sway_output *output, struct timespec *when, wlr_renderer_clear(renderer, clear_color); } - render_layer(output, damage, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]); - render_layer(output, damage, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); + render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]); + render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = seat_get_focus(seat); - render_container(output, damage, workspace, focus == workspace); - render_floating(output, damage); + render_container(workspace, focus == workspace); + render_floating(); - render_unmanaged(output, damage, - &root_container.sway_root->xwayland_unmanaged); - render_layer(output, damage, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); + render_unmanaged(&root_container.sway_root->xwayland_unmanaged); + render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); } - render_layer(output, damage, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); - render_drag_icons(output, damage, &root_container.sway_root->drag_icons); + render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); + render_drag_icons(&root_container.sway_root->drag_icons); renderer_end: if (root_container.sway_root->debug_tree) {