shm: scroll: keep shm pool around, and fix its size at max allowed

This lessens the burden on (primarily) the compositor, since we no
longer tear down and re-create the SHM pool when scrolling.

The SHM pool is setup once, and its size is fixed at the maximum
allowed (512MB for now, 2GB would be possible).

This also allows us to mmap() the memfd once. The exposed raw pointer
is simply an offset from the memfd mmapping.

Note that this means e.g. rouge rendering code will be able to write
outside the buffer.

Finally, only do this if the caller explicitly wants to enable
scrolling. The memfd of other buffers are sized to the requested size.
This commit is contained in:
Daniel Eklöf 2020-03-25 18:26:58 +01:00
parent 1891489cd6
commit 03319560f5
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 149 additions and 138 deletions

View file

@ -588,9 +588,10 @@ grid_render_scroll(struct terminal *term, struct buffer *buf,
* SHM. Otherwise use memmove.
*/
bool try_shm_scroll =
shm_can_scroll() && (dmg->scroll.lines +
dmg->scroll.region.start +
(term->rows - dmg->scroll.region.end)) < term->rows / 2;
shm_can_scroll(buf) && (
dmg->scroll.lines +
dmg->scroll.region.start +
(term->rows - dmg->scroll.region.end)) < term->rows / 2;
bool did_shm_scroll = false;
@ -657,9 +658,10 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
int dst_y = term->margins.top + (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
bool try_shm_scroll =
shm_can_scroll() && (dmg->scroll.lines +
dmg->scroll.region.start +
(term->rows - dmg->scroll.region.end)) < term->rows / 2;
shm_can_scroll(buf) && (
dmg->scroll.lines +
dmg->scroll.region.start +
(term->rows - dmg->scroll.region.end)) < term->rows / 2;
bool did_shm_scroll = false;
@ -912,7 +914,7 @@ render_csd_title(struct terminal *term)
unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE);
struct buffer *buf = shm_get_buffer(
term->wl->shm, info.width, info.height, cookie);
term->wl->shm, info.width, info.height, cookie, false);
uint32_t _color = term->colors.default_fg;
uint16_t alpha = 0xffff;
@ -943,7 +945,7 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx)
unsigned long cookie = shm_cookie_csd(term, surf_idx);
struct buffer *buf = shm_get_buffer(
term->wl->shm, info.width, info.height, cookie);
term->wl->shm, info.width, info.height, cookie, false);
pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0);
render_csd_part(term, surf, buf, info.width, info.height, &color);
@ -1112,7 +1114,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
unsigned long cookie = shm_cookie_csd(term, surf_idx);
struct buffer *buf = shm_get_buffer(
term->wl->shm, info.width, info.height, cookie);
term->wl->shm, info.width, info.height, cookie, false);
uint32_t _color;
uint16_t alpha = 0xffff;
@ -1239,7 +1241,7 @@ grid_render(struct terminal *term)
unsigned long cookie = shm_cookie_grid(term);
struct buffer *buf = shm_get_buffer(
term->wl->shm, term->width, term->height, cookie);
term->wl->shm, term->width, term->height, cookie, true);
pixman_image_set_clip_region(buf->pix, NULL);
@ -1526,7 +1528,7 @@ render_search_box(struct terminal *term)
size_t glyph_offset = term->render.search_glyph_offset;
unsigned long cookie = shm_cookie_search(term);
struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie);
struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie, false);
/* Background - yellow on empty/match, red on mismatch */
pixman_color_t color = color_hex_to_pixman(