Skip to content
Myr

render: only do a full background fill on fresh buffers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Before this patch, each and every frame would do the following: * Fill the entire buffer with the background buffer, including the rounded corners. * Render the contents (match list, prompt etc) We note the following: * Rounded corners is expensive to render on the CPU * The contents will actually replace much of the buffer Since we track buffer age, we can do a fairly simple optimization: * Skip the full background fill (and the rounded corners) if we're re-using the last frame's buffer (buffer age is 0). * Have each component (match entries, prompt etc) render its own background. This improves performance in two ways: * We only do the expensive rounded corners once * The background fill is now threaded (since the match list is rendered by multiple threads). Also fix an issue where a large border.radius value combined with small margins caused rendering glitches, where the corners were "overwritten" by e.g. the selected item box. The fix is to reduce the amount of roundness as the margins grow smaller.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 738f898 · Browse files · 2 files+54 added−25 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+54 added−25 removed

  • other:+54 added−25 removed

2 files+54 added−25 removed

modified:render.c+51 added-25 removed
146 unmodified lines
147render_background(const struct render *render, struct buffer *buf)148{149 unsigned bw = render->conf->border.size;150151 pixman_color_t bg = rgba2pixman(render->conf->colors.background);152 pixman_color_t border_color = rgba2pixman(render->conf->colors.border);151 pixman_color_t bg = render->pix_background_color;152 pixman_color_t border_color = render->pix_border_color;153154 if (render->conf->border.radius == 0) {154 if (buf->age == 0) {155 /* Each sub-part of the window erases itself */156 return;157 }158159 /* Limit radius if the margins are very small, to prevent e.g. the160 selection "box" from overlapping the corners */161 const unsigned int radius =162 min(render->conf->border.radius,163 min(render->x_margin,164 render->y_margin));165166 if (radius == 0) {167 pixman_image_fill_rectangles(168 PIXMAN_OP_SRC, buf->pix[0], &bg,169 1, &(pixman_rectangle16_t){170 bw, bw, buf->width - 2 * bw, buf->height - 2 * bw});
8 unmodified lines
179 });180 } else {181 const int msaa_scale = 2;182 const double brd_sz_scaled = bw * msaa_scale;171 const double brd_rad_scaled = render->conf->border.radius * msaa_scale;183 const double brd_rad_scaled = radius * msaa_scale;184 int w = buf->width * msaa_scale;185 int h = buf->height * msaa_scale;186187 pixman_image_t *bg_img;
185 unmodified lines
373 int x = render->border_size + render->x_margin;374 int y = render->border_size + render->y_margin +375 (render->row_height + font->height) / 2 - font->descent;376377 /* Erase background */378 pixman_color_t bg = render->pix_background_color;379 pixman_image_fill_rectangles(380 PIXMAN_OP_SRC, buf->pix[0], &bg, 1,381 &(pixman_rectangle16_t){382 render->border_size + render->x_margin,383 render->border_size + render->y_margin,384 buf->width - 2 * (render->border_size + render->x_margin),385 render->row_height});386387 int stats_width = conf->match_counter388 ? render_match_count(render, buf, prompt, matches)389 : 0;390
426 unmodified lines
817 render->inner_pad);818}819820static void821render_match_entry_background(const struct render *render,822 int idx, int row_count, bool is_selected,823 pixman_image_t *pix, int width)824{825 pixman_color_t bg = is_selected826 ? render->pix_selection_color : render->pix_background_color;827828 const int sel_margin = render->x_margin / 3;829830 const int x = render->border_size + render->x_margin - sel_margin;831 const int y = first_row_y(render) + idx * render->row_height;832 const int w = width - 2 * (render->border_size + render->x_margin - sel_margin);833 const int h = row_count * render->row_height;834835 pixman_image_fill_rectangles(836 PIXMAN_OP_SRC, pix, &bg, 1, &(pixman_rectangle16_t){x, y, w, h});837}838839static void840render_one_match_entry(const struct render *render, const struct matches *matches,841 const struct match *match, bool render_icons,842 int idx, bool is_selected, int width, int height,843 pixman_image_t *pix, cairo_t *cairo)
11 unmodified lines
855 const int first_row = first_row_y(render);856 double cur_x = render->border_size + render->x_margin;857 double max_x = width - render->border_size - render->x_margin;858818#if 0 /* Render the icon+text bounding box */819 pixman_color_t sc = rgba2pixman(render->conf->colors.match);820 pixman_image_fill_rectangles(821 PIXMAN_OP_SRC, buf->pix[0], &sc, 1,822 &(pixman_rectangle16_t){823 cur_x, first_row + idx * render->row_height,824 max_x - cur_x, render->row_height}825 );826#endif859 render_match_entry_background(render, idx, 1, is_selected, pix, width);860861 if (is_selected) {862 /* If currently selected item has a scalable icon, and if863 * there's "enough" free space, render a large representation
14 unmodified lines
878 img_y > list_end + render->row_height)879 {880 render_svg(&match->application->icon, img_x, img_y, size, pix, cairo);881 }849850 const int sel_margin = render->x_margin / 3;851852 pixman_color_t sc = rgba2pixman(render->conf->colors.selection);853 pixman_image_fill_rectangles(854 PIXMAN_OP_OVER, pix, &sc, 1,855 &(pixman_rectangle16_t){856 render->x_margin - sel_margin,857 first_row + idx * render->row_height,858 width - 2 * (render->x_margin - sel_margin),859 render->row_height}860 );882 }883884 if (render_icons) {885 struct icon *icon = &match->application->icon;
88 unmodified lines
974975 assert(tll_length(render->workers.queue) == 0);976 }977978 /* Erase background of the "empty" area, after the last match */979 render_match_entry_background(980 render, match_count, render->conf->lines - match_count, false,981 buf->pix[0], buf->width);982983 for (size_t i = 0; i < match_count; i++) {984 if (render->workers.count == 0) {985 const struct match *match = matches_get(matches, i);986 render_one_match_entry(
333 unmodified lines
modified:wayland.c+3 added
2045 unmodified lines
2046 wayl->frame_cb = wl_surface_frame(wayl->surface);2047 wl_callback_add_listener(wayl->frame_cb, &frame_listener, wayl);20482049 wl_surface_commit(wayl->surface);20502051 if (!wayl->render_first_frame_transparent)2052 buf->age = 0;2053}20542055static void2056frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data)
507 unmodified lines