Implement double buffering

Until this point we was using one single buffer. This cause tearing when
they are scanned while we are drawing.

This refactorize our buffer and damage tracking to use two buffers. One
buffer, the back_buffer, is our dirty area. The other one, the
display_buffer, is left untouched.

Now we only flip buffers on adequate moments, indicated by the
compositor sending the frame callback event. We can draw multiple
time between those events, and we store all damaged areas. We only
schedule frame callbacks when needed, after storing a new damaged area.

Once flipped, we backport the damaged area from the new display_buffer
to the new back_buffer. Which generally means, for wvkbd, one rectangle
for each one of the surf and popup_surf.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
Willow Barraco
2025-04-17 08:23:03 +02:00
committed by Maarten van Gompel
parent 646d47d072
commit 686b27a72d
4 changed files with 150 additions and 54 deletions

View File

@@ -337,10 +337,7 @@ kbd_release_key(struct kbd *kb, uint32_t time)
kb->last_swipe = NULL;
}
drwsurf_flip(kb->surf);
kbd_clear_last_popup(kb);
drwsurf_flip(kb->popup_surf);
}
void
@@ -366,10 +363,7 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y)
kbd_unpress_key(kb, time);
}
drwsurf_flip(kb->surf);
kbd_clear_last_popup(kb);
drwsurf_flip(kb->popup_surf);
}
void
@@ -501,9 +495,6 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time)
default:
break;
}
drwsurf_flip(kb->surf);
drwsurf_flip(kb->popup_surf);
}
void
@@ -553,8 +544,13 @@ kbd_clear_last_popup(struct kbd *kb)
if (kb->last_popup_w && kb->last_popup_h) {
drw_do_clear(kb->popup_surf, kb->last_popup_x, kb->last_popup_y,
kb->last_popup_w, kb->last_popup_h);
wl_surface_damage(kb->popup_surf->surf, kb->last_popup_x,
kb->last_popup_y, kb->last_popup_w, kb->last_popup_h);
drwsurf_damage(
kb->popup_surf,
kb->last_popup_x,
kb->last_popup_y,
kb->last_popup_w,
kb->last_popup_h
);
kb->last_popup_w = kb->last_popup_h = 0;
}
@@ -588,7 +584,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label, scheme->font_description);
wl_surface_damage(kb->surf->surf, k->x, k->y, k->w, k->h);
drwsurf_damage(kb->surf, k->x, k->y, k->w, k->h);
if (type == Press || type == Unpress) {
kbd_clear_last_popup(kb);
@@ -605,8 +601,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
k->w, k->h, KBD_KEY_BORDER, label,
scheme->font_description);
wl_surface_damage(kb->popup_surf->surf, k->x, kb->last_popup_y, k->w,
k->h);
drwsurf_damage(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h);
}
}
@@ -633,7 +628,7 @@ kbd_draw_layout(struct kbd *kb)
}
next_key++;
}
wl_surface_damage(d->surf, 0, 0, kb->w, kb->h);
drwsurf_damage(d, 0, 0, kb->w, kb->h);
}
void