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.
master
Simon Ser 6 years ago committed by Drew DeVault
parent 31dcecbfa9
commit 5e6766a165

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

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

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

@ -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.frame);
wl_signal_init(&output->events.needs_commit); wl_signal_init(&output->events.needs_commit);
wl_signal_init(&output->events.precommit); wl_signal_init(&output->events.precommit);
wl_signal_init(&output->events.commit);
wl_signal_init(&output->events.present); wl_signal_init(&output->events.present);
wl_signal_init(&output->events.enable); wl_signal_init(&output->events.enable);
wl_signal_init(&output->events.mode); 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_surface_send_frame_done(cursor->surface, &now);
} }
wlr_signal_emit_safe(&output->events.commit, output);
output->frame_pending = true; output->frame_pending = true;
output->needs_commit = false; output->needs_commit = false;
output_state_clear(&output->pending); output_state_clear(&output->pending);

@ -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); 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 *wlr_output_damage_create(struct wlr_output *output) {
struct wlr_output_damage *output_damage = struct wlr_output_damage *output_damage =
calloc(1, sizeof(struct wlr_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; output_damage->output_needs_commit.notify = output_handle_needs_commit;
wl_signal_add(&output->events.frame, &output_damage->output_frame); wl_signal_add(&output->events.frame, &output_damage->output_frame);
output_damage->output_frame.notify = output_handle_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; return output_damage;
} }
@ -102,7 +121,7 @@ void wlr_output_damage_destroy(struct wlr_output_damage *output_damage) {
free(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) { bool *needs_commit, pixman_region32_t *damage) {
struct wlr_output *output = output_damage->output; 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; 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, void wlr_output_damage_add(struct wlr_output_damage *output_damage,
pixman_region32_t *damage) { pixman_region32_t *damage) {
int width, height; int width, height;

Loading…
Cancel
Save