output-damage: refactor API

wlr_output_damage_make_current has been renamed to
wlr_output_damage_attach_render, since it's just a wrapper for
wlr_output_attach_render.

wlr_output_damage_swap_buffers has been removed completely. Instead,
wlr_output_damage now listens to successful wlr_output commits and updates its
internal state accordingly.
This commit is contained in:
Simon Ser 2019-04-23 20:16:08 +03:00 committed by Drew DeVault
parent 31dcecbfa9
commit 5e6766a165
5 changed files with 46 additions and 42 deletions

View File

@ -111,8 +111,10 @@ struct wlr_output {
// Emitted when buffers need to be swapped (because software cursors or
// fullscreen damage or because of backend-specific logic)
struct wl_signal needs_commit;
// Emitted right before buffer commit
// Emitted right before commit
struct wl_signal precommit; // wlr_output_event_precommit
// Emitted right after commit
struct wl_signal commit;
// Emitted right after the buffer has been presented to the user
struct wl_signal present; // wlr_output_event_present
struct wl_signal enable;

View File

@ -24,10 +24,13 @@
/**
* Tracks damage for an output.
*
* When a `frame` event is emitted, `wlr_output_damage_make_current` should be
* called. If necessary, the output should be repainted and
* `wlr_output_damage_swap_buffers` should be called. No rendering should happen
* outside a `frame` event handler.
* The `frame` event will be emitted when it is a good time for the compositor
* to submit a new frame.
*
* To render a new frame, compositors should call
* `wlr_output_damage_attach_render`, render and call `wlr_output_commit`. No
* rendering should happen outside a `frame` event handler or before
* `wlr_output_damage_attach_render`.
*/
struct wlr_output_damage {
struct wlr_output *output;
@ -50,25 +53,22 @@ struct wlr_output_damage {
struct wl_listener output_scale;
struct wl_listener output_needs_commit;
struct wl_listener output_frame;
struct wl_listener output_commit;
};
struct wlr_output_damage *wlr_output_damage_create(struct wlr_output *output);
void wlr_output_damage_destroy(struct wlr_output_damage *output_damage);
/**
* Makes the output rendering context current. `needs_swap` is set to true if
* `wlr_output_damage_swap_buffers` needs to be called. The region of the output
* that needs to be repainted is added to `damage`.
*/
bool wlr_output_damage_make_current(struct wlr_output_damage *output_damage,
bool *needs_swap, pixman_region32_t *damage);
/**
* Swaps the output buffers. If the time of the frame isn't known, set `when` to
* NULL.
* Attach the renderer's buffer to the output. Compositors must call this
* function before rendering. After they are done rendering, they should call
* `wlr_output_set_damage` and `wlr_output_commit` to submit the new frame.
*
* Swapping buffers schedules a `frame` event.
* `needs_commit` will be set to true if a frame should be submitted. `damage`
* will be set to the region of the output that needs to be repainted, in
* output-buffer-local coordinates.
*/
bool wlr_output_damage_swap_buffers(struct wlr_output_damage *output_damage,
struct timespec *when, pixman_region32_t *damage);
bool wlr_output_damage_attach_render(struct wlr_output_damage *output_damage,
bool *needs_commit, pixman_region32_t *damage);
/**
* Accumulates damage and schedules a `frame` event.
*/

View File

@ -223,7 +223,7 @@ void output_render(struct roots_output *output) {
bool needs_swap;
pixman_region32_t damage;
pixman_region32_init(&damage);
if (!wlr_output_damage_make_current(output->damage, &needs_swap, &damage)) {
if (!wlr_output_damage_attach_render(output->damage, &needs_swap, &damage)) {
return;
}
@ -310,7 +310,8 @@ renderer_end:
wlr_output_transform_invert(wlr_output->transform);
wlr_region_transform(&damage, &damage, transform, width, height);
if (!wlr_output_damage_swap_buffers(output->damage, &now, &damage)) {
wlr_output_set_damage(wlr_output, &damage);
if (!wlr_output_commit(wlr_output)) {
goto damage_finish;
}
output->last_frame = desktop->last_frame = now;
@ -319,6 +320,5 @@ damage_finish:
pixman_region32_fini(&damage);
// Send frame done events to all surfaces
output_for_each_surface(output, surface_send_frame_done_iterator,
&now);
output_for_each_surface(output, surface_send_frame_done_iterator, &now);
}

View File

@ -275,6 +275,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
wl_signal_init(&output->events.frame);
wl_signal_init(&output->events.needs_commit);
wl_signal_init(&output->events.precommit);
wl_signal_init(&output->events.commit);
wl_signal_init(&output->events.present);
wl_signal_init(&output->events.enable);
wl_signal_init(&output->events.mode);
@ -433,6 +434,8 @@ bool wlr_output_commit(struct wlr_output *output) {
wlr_surface_send_frame_done(cursor->surface, &now);
}
wlr_signal_emit_safe(&output->events.commit, output);
output->frame_pending = true;
output->needs_commit = false;
output_state_clear(&output->pending);

View File

@ -51,6 +51,23 @@ static void output_handle_frame(struct wl_listener *listener, void *data) {
wlr_signal_emit_safe(&output_damage->events.frame, output_damage);
}
static void output_handle_commit(struct wl_listener *listener, void *data) {
struct wlr_output_damage *output_damage =
wl_container_of(listener, output_damage, output_commit);
if (!(output_damage->output->pending.committed & WLR_OUTPUT_STATE_BUFFER)) {
return;
}
// same as decrementing, but works on unsigned integers
output_damage->previous_idx += WLR_OUTPUT_DAMAGE_PREVIOUS_LEN - 1;
output_damage->previous_idx %= WLR_OUTPUT_DAMAGE_PREVIOUS_LEN;
pixman_region32_copy(&output_damage->previous[output_damage->previous_idx],
&output_damage->current);
pixman_region32_clear(&output_damage->current);
}
struct wlr_output_damage *wlr_output_damage_create(struct wlr_output *output) {
struct wlr_output_damage *output_damage =
calloc(1, sizeof(struct wlr_output_damage));
@ -80,6 +97,8 @@ struct wlr_output_damage *wlr_output_damage_create(struct wlr_output *output) {
output_damage->output_needs_commit.notify = output_handle_needs_commit;
wl_signal_add(&output->events.frame, &output_damage->output_frame);
output_damage->output_frame.notify = output_handle_frame;
wl_signal_add(&output->events.commit, &output_damage->output_commit);
output_damage->output_commit.notify = output_handle_commit;
return output_damage;
}
@ -102,7 +121,7 @@ void wlr_output_damage_destroy(struct wlr_output_damage *output_damage) {
free(output_damage);
}
bool wlr_output_damage_make_current(struct wlr_output_damage *output_damage,
bool wlr_output_damage_attach_render(struct wlr_output_damage *output_damage,
bool *needs_commit, pixman_region32_t *damage) {
struct wlr_output *output = output_damage->output;
@ -141,26 +160,6 @@ bool wlr_output_damage_make_current(struct wlr_output_damage *output_damage,
return true;
}
bool wlr_output_damage_swap_buffers(struct wlr_output_damage *output_damage,
struct timespec *when, pixman_region32_t *damage) {
if (damage != NULL) {
wlr_output_set_damage(output_damage->output, damage);
}
if (!wlr_output_commit(output_damage->output)) {
return false;
}
// same as decrementing, but works on unsigned integers
output_damage->previous_idx += WLR_OUTPUT_DAMAGE_PREVIOUS_LEN - 1;
output_damage->previous_idx %= WLR_OUTPUT_DAMAGE_PREVIOUS_LEN;
pixman_region32_copy(&output_damage->previous[output_damage->previous_idx],
&output_damage->current);
pixman_region32_clear(&output_damage->current);
return true;
}
void wlr_output_damage_add(struct wlr_output_damage *output_damage,
pixman_region32_t *damage) {
int width, height;