mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-18 06:47:31 -04:00
Merge branch 'wlr-output-commit' into 'master'
Introduce struct wlr_output_commit Closes #3717 See merge request wlroots/wlroots!4330
This commit is contained in:
commit
8eb0a8580f
15 changed files with 183 additions and 130 deletions
|
|
@ -411,7 +411,6 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
|||
.render_format = DRM_FORMAT_XRGB8888,
|
||||
.transform = WL_OUTPUT_TRANSFORM_NORMAL,
|
||||
.scale = 1,
|
||||
.commit_seq = 0,
|
||||
};
|
||||
|
||||
wl_list_init(&output->modes);
|
||||
|
|
@ -423,7 +422,6 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
|||
wl_signal_init(&output->events.needs_frame);
|
||||
wl_signal_init(&output->events.precommit);
|
||||
wl_signal_init(&output->events.commit);
|
||||
wl_signal_init(&output->events.present);
|
||||
wl_signal_init(&output->events.bind);
|
||||
wl_signal_init(&output->events.description);
|
||||
wl_signal_init(&output->events.request_state);
|
||||
|
|
@ -440,6 +438,8 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
|||
output->display_destroy.notify = handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &output->display_destroy);
|
||||
|
||||
output->not_committed = true;
|
||||
|
||||
if (state) {
|
||||
output_apply_state(output, state);
|
||||
}
|
||||
|
|
@ -780,7 +780,13 @@ bool wlr_output_test(struct wlr_output *output) {
|
|||
return wlr_output_test_state(output, &state);
|
||||
}
|
||||
|
||||
bool wlr_output_commit_state(struct wlr_output *output,
|
||||
void wlr_output_commit_init(struct wlr_output_commit *commit,
|
||||
struct wlr_output *output) {
|
||||
wl_signal_init(&commit->events.present);
|
||||
commit->output = output;
|
||||
}
|
||||
|
||||
struct wlr_output_commit *wlr_output_commit_state(struct wlr_output *output,
|
||||
const struct wlr_output_state *state) {
|
||||
uint32_t unchanged = output_compare_state(output, state);
|
||||
|
||||
|
|
@ -791,12 +797,12 @@ bool wlr_output_commit_state(struct wlr_output *output,
|
|||
|
||||
if (!output_basic_test(output, &pending)) {
|
||||
wlr_log(WLR_ERROR, "Basic output test failed for %s", output->name);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool new_back_buffer = false;
|
||||
if (!output_ensure_buffer(output, &pending, &new_back_buffer)) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((pending.committed & WLR_OUTPUT_STATE_BUFFER) &&
|
||||
|
|
@ -815,15 +821,14 @@ bool wlr_output_commit_state(struct wlr_output *output,
|
|||
};
|
||||
wl_signal_emit_mutable(&output->events.precommit, &pre_event);
|
||||
|
||||
if (!output->impl->commit(output, &pending)) {
|
||||
struct wlr_output_commit *commit = output->impl->commit(output, &pending);
|
||||
if (!commit) {
|
||||
if (new_back_buffer) {
|
||||
wlr_buffer_unlock(pending.buffer);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
output->commit_seq++;
|
||||
|
||||
if (output_pending_enabled(output, state)) {
|
||||
output->frame_pending = true;
|
||||
output->needs_frame = false;
|
||||
|
|
@ -836,6 +841,7 @@ bool wlr_output_commit_state(struct wlr_output *output,
|
|||
.committed = pending.committed,
|
||||
.when = &now,
|
||||
.buffer = (pending.committed & WLR_OUTPUT_STATE_BUFFER) ? pending.buffer : NULL,
|
||||
.commit = commit,
|
||||
};
|
||||
wl_signal_emit_mutable(&output->events.commit, &event);
|
||||
|
||||
|
|
@ -843,10 +849,12 @@ bool wlr_output_commit_state(struct wlr_output *output,
|
|||
wlr_buffer_unlock(pending.buffer);
|
||||
}
|
||||
|
||||
return true;
|
||||
output->not_committed = false;
|
||||
|
||||
return commit;
|
||||
}
|
||||
|
||||
bool wlr_output_commit(struct wlr_output *output) {
|
||||
struct wlr_output_commit *wlr_output_commit(struct wlr_output *output) {
|
||||
// Make sure the pending state is cleared before the output is committed
|
||||
struct wlr_output_state state = {0};
|
||||
output_state_move(&state, &output->pending);
|
||||
|
|
@ -860,9 +868,9 @@ bool wlr_output_commit(struct wlr_output *output) {
|
|||
output_clear_back_buffer(output);
|
||||
}
|
||||
|
||||
bool ok = wlr_output_commit_state(output, &state);
|
||||
struct wlr_output_commit *commit = wlr_output_commit_state(output, &state);
|
||||
wlr_output_state_finish(&state);
|
||||
return ok;
|
||||
return commit;
|
||||
}
|
||||
|
||||
void wlr_output_rollback(struct wlr_output *output) {
|
||||
|
|
@ -907,30 +915,9 @@ void wlr_output_schedule_frame(struct wlr_output *output) {
|
|||
wl_event_loop_add_idle(ev, schedule_frame_handle_idle_timer, output);
|
||||
}
|
||||
|
||||
void wlr_output_send_present(struct wlr_output *output,
|
||||
struct wlr_output_event_present *event) {
|
||||
assert(event);
|
||||
event->output = output;
|
||||
|
||||
struct timespec now;
|
||||
if (event->presented && event->when == NULL) {
|
||||
clockid_t clock = wlr_backend_get_presentation_clock(output->backend);
|
||||
errno = 0;
|
||||
if (clock_gettime(clock, &now) != 0) {
|
||||
wlr_log_errno(WLR_ERROR, "failed to send output present event: "
|
||||
"failed to read clock");
|
||||
return;
|
||||
}
|
||||
event->when = &now;
|
||||
}
|
||||
|
||||
wl_signal_emit_mutable(&output->events.present, event);
|
||||
}
|
||||
|
||||
struct deferred_present_event {
|
||||
struct wlr_output *output;
|
||||
struct wlr_output_commit *commit;
|
||||
struct wl_event_source *idle_source;
|
||||
struct wlr_output_event_present event;
|
||||
struct wl_listener output_destroy;
|
||||
};
|
||||
|
||||
|
|
@ -941,7 +928,19 @@ static void deferred_present_event_destroy(struct deferred_present_event *deferr
|
|||
|
||||
static void deferred_present_event_handle_idle(void *data) {
|
||||
struct deferred_present_event *deferred = data;
|
||||
wlr_output_send_present(deferred->output, &deferred->event);
|
||||
|
||||
clockid_t clock = wlr_backend_get_presentation_clock(deferred->commit->output->backend);
|
||||
struct timespec now;
|
||||
clock_gettime(clock, &now);
|
||||
|
||||
struct wlr_output_event_present present_event = {
|
||||
.presented = true,
|
||||
.output = deferred->commit->output,
|
||||
.when = &now,
|
||||
};
|
||||
|
||||
wl_signal_emit_mutable(&deferred->commit->events.present, &present_event);
|
||||
|
||||
deferred_present_event_destroy(deferred);
|
||||
}
|
||||
|
||||
|
|
@ -951,19 +950,16 @@ static void deferred_present_event_handle_output_destroy(struct wl_listener *lis
|
|||
deferred_present_event_destroy(deferred);
|
||||
}
|
||||
|
||||
void output_defer_present(struct wlr_output *output, struct wlr_output_event_present event) {
|
||||
void output_commit_defer_present(struct wlr_output_commit *commit) {
|
||||
struct deferred_present_event *deferred = calloc(1, sizeof(*deferred));
|
||||
if (!deferred) {
|
||||
return;
|
||||
}
|
||||
*deferred = (struct deferred_present_event){
|
||||
.output = output,
|
||||
.event = event,
|
||||
};
|
||||
deferred->commit = commit;
|
||||
deferred->output_destroy.notify = deferred_present_event_handle_output_destroy;
|
||||
wl_signal_add(&output->events.destroy, &deferred->output_destroy);
|
||||
wl_signal_add(&commit->output->events.destroy, &deferred->output_destroy);
|
||||
|
||||
struct wl_event_loop *ev = wl_display_get_event_loop(output->display);
|
||||
struct wl_event_loop *ev = wl_display_get_event_loop(commit->output->display);
|
||||
deferred->idle_source = wl_event_loop_add_idle(ev, deferred_present_event_handle_idle, deferred);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ bool output_ensure_buffer(struct wlr_output *output,
|
|||
if (state->committed & WLR_OUTPUT_STATE_RENDER_FORMAT) {
|
||||
needs_new_buffer = true;
|
||||
}
|
||||
if (state->allow_artifacts && output->commit_seq == 0 && enabled) {
|
||||
if (state->allow_artifacts && output->not_committed && enabled) {
|
||||
// On first commit, require a new buffer if the compositor called a
|
||||
// mode-setting function, even if the mode won't change. This makes it
|
||||
// so the swapchain is created now.
|
||||
|
|
|
|||
|
|
@ -269,28 +269,12 @@ static void feedback_unset_output(struct wlr_presentation_feedback *feedback) {
|
|||
wl_list_remove(&feedback->output_destroy.link);
|
||||
}
|
||||
|
||||
static void feedback_handle_output_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_presentation_feedback *feedback =
|
||||
wl_container_of(listener, feedback, output_commit);
|
||||
if (feedback->output_committed) {
|
||||
return;
|
||||
}
|
||||
feedback->output_committed = true;
|
||||
feedback->output_commit_seq = feedback->output->commit_seq;
|
||||
}
|
||||
|
||||
static void feedback_handle_output_present(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_presentation_feedback *feedback =
|
||||
wl_container_of(listener, feedback, output_present);
|
||||
struct wlr_output_event_present *output_event = data;
|
||||
|
||||
if (!feedback->output_committed ||
|
||||
output_event->commit_seq != feedback->output_commit_seq) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (output_event->presented) {
|
||||
struct wlr_presentation_event event = {0};
|
||||
wlr_presentation_event_from_output(&event, output_event);
|
||||
|
|
@ -302,6 +286,20 @@ static void feedback_handle_output_present(struct wl_listener *listener,
|
|||
wlr_presentation_feedback_destroy(feedback);
|
||||
}
|
||||
|
||||
static void feedback_handle_output_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_event_commit *event = data;
|
||||
struct wlr_presentation_feedback *feedback =
|
||||
wl_container_of(listener, feedback, output_commit);
|
||||
|
||||
// we only care about the first commit
|
||||
wl_list_remove(&feedback->output_commit.link);
|
||||
wl_list_init(&feedback->output_commit.link);
|
||||
|
||||
feedback->output_present.notify = feedback_handle_output_present;
|
||||
wl_signal_add(&event->commit->events.present, &feedback->output_present);
|
||||
}
|
||||
|
||||
static void feedback_handle_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_presentation_feedback *feedback =
|
||||
|
|
@ -324,10 +322,10 @@ static void presentation_surface_queued_on_output(
|
|||
|
||||
feedback->output_commit.notify = feedback_handle_output_commit;
|
||||
wl_signal_add(&output->events.commit, &feedback->output_commit);
|
||||
feedback->output_present.notify = feedback_handle_output_present;
|
||||
wl_signal_add(&output->events.present, &feedback->output_present);
|
||||
feedback->output_destroy.notify = feedback_handle_output_destroy;
|
||||
wl_signal_add(&output->events.destroy, &feedback->output_destroy);
|
||||
|
||||
wl_list_init(&feedback->output_present.link);
|
||||
}
|
||||
|
||||
void wlr_presentation_surface_textured_on_output(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue