From 25dd3cc0cd89d3220f603e2fcb530ec80c29ff5f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 24 May 2022 19:16:50 +0200 Subject: [PATCH] output: pass wlr_output_state to backend Groundwork for the following commits. The goal is to allow users to specify their own wlr_output_state instead of wlr_output.pending. --- backend/drm/drm.c | 25 +++++++++--------- backend/headless/output.c | 25 +++++++++--------- backend/wayland/output.c | 35 ++++++++++++------------ backend/x11/output.c | 41 ++++++++++++++++------------- include/wlr/interfaces/wlr_output.h | 8 +++--- types/output/output.c | 4 +-- types/output/render.c | 6 ++--- 7 files changed, 75 insertions(+), 69 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index af7e7836..2caa0ef0 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -459,24 +459,24 @@ static bool drm_connector_set_pending_fb(struct wlr_drm_connector *conn, static bool drm_connector_alloc_crtc(struct wlr_drm_connector *conn); -static bool drm_connector_test(struct wlr_output *output) { +static bool drm_connector_test(struct wlr_output *output, + const struct wlr_output_state *state) { struct wlr_drm_connector *conn = get_drm_connector_from_output(output); if (!conn->backend->session->active) { return false; } - uint32_t unsupported = output->pending.committed & ~SUPPORTED_OUTPUT_STATE; + uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE; if (unsupported != 0) { wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, unsupported); return false; } - if ((output->pending.committed & WLR_OUTPUT_STATE_ENABLED) && - output->pending.enabled) { + if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && state->enabled) { if (output->current_mode == NULL && - !(output->pending.committed & WLR_OUTPUT_STATE_MODE)) { + !(state->committed & WLR_OUTPUT_STATE_MODE)) { wlr_drm_conn_log(conn, WLR_DEBUG, "Can't enable an output without a mode"); return false; @@ -484,12 +484,12 @@ static bool drm_connector_test(struct wlr_output *output) { } struct wlr_drm_connector_state pending = {0}; - drm_connector_state_init(&pending, conn, &output->pending); + drm_connector_state_init(&pending, conn, state); if (pending.active) { - if ((output->pending.committed & + if ((state->committed & (WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE)) && - !(output->pending.committed & WLR_OUTPUT_STATE_BUFFER)) { + !(state->committed & WLR_OUTPUT_STATE_BUFFER)) { wlr_drm_conn_log(conn, WLR_DEBUG, "Can't enable an output without a buffer"); return false; @@ -514,7 +514,7 @@ static bool drm_connector_test(struct wlr_output *output) { return true; } - if (output->pending.committed & WLR_OUTPUT_STATE_BUFFER) { + if (state->committed & WLR_OUTPUT_STATE_BUFFER) { if (!drm_connector_set_pending_fb(conn, pending.base)) { return false; } @@ -597,14 +597,15 @@ bool drm_connector_commit_state(struct wlr_drm_connector *conn, return true; } -static bool drm_connector_commit(struct wlr_output *output) { +static bool drm_connector_commit(struct wlr_output *output, + const struct wlr_output_state *state) { struct wlr_drm_connector *conn = get_drm_connector_from_output(output); - if (!drm_connector_test(output)) { + if (!drm_connector_test(output, state)) { return false; } - return drm_connector_commit_state(conn, &output->pending); + return drm_connector_commit_state(conn, state); } size_t drm_crtc_get_gamma_lut_size(struct wlr_drm_backend *drm, diff --git a/backend/headless/output.c b/backend/headless/output.c index 824a265e..2ce15a16 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -29,40 +29,41 @@ static bool output_set_custom_mode(struct wlr_headless_output *output, return true; } -static bool output_test(struct wlr_output *wlr_output) { - uint32_t unsupported = - wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE; +static bool output_test(struct wlr_output *wlr_output, + const struct wlr_output_state *state) { + uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE; if (unsupported != 0) { wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, unsupported); return false; } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { - assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); + if (state->committed & WLR_OUTPUT_STATE_MODE) { + assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); } return true; } -static bool output_commit(struct wlr_output *wlr_output) { +static bool output_commit(struct wlr_output *wlr_output, + const struct wlr_output_state *state) { struct wlr_headless_output *output = headless_output_from_output(wlr_output); - if (!output_test(wlr_output)) { + if (!output_test(wlr_output, state)) { return false; } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { + if (state->committed & WLR_OUTPUT_STATE_MODE) { if (!output_set_custom_mode(output, - wlr_output->pending.custom_mode.width, - wlr_output->pending.custom_mode.height, - wlr_output->pending.custom_mode.refresh)) { + state->custom_mode.width, + state->custom_mode.height, + state->custom_mode.refresh)) { return false; } } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) { + if (state->committed & WLR_OUTPUT_STATE_BUFFER) { struct wlr_output_event_present present_event = { .commit_seq = wlr_output->commit_seq + 1, .presented = true, diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 87b8ca1f..baa25bc3 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -240,48 +240,49 @@ static struct wlr_wl_buffer *get_or_create_wl_buffer(struct wlr_wl_backend *wl, return create_wl_buffer(wl, wlr_buffer); } -static bool output_test(struct wlr_output *wlr_output) { +static bool output_test(struct wlr_output *wlr_output, + const struct wlr_output_state *state) { struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); - uint32_t unsupported = - wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE; + uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE; if (unsupported != 0) { wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, unsupported); return false; } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { - assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); + if (state->committed & WLR_OUTPUT_STATE_MODE) { + assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); } - if ((wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) && - !test_buffer(output->backend, wlr_output->pending.buffer)) { + if ((state->committed & WLR_OUTPUT_STATE_BUFFER) && + !test_buffer(output->backend, state->buffer)) { return false; } return true; } -static bool output_commit(struct wlr_output *wlr_output) { +static bool output_commit(struct wlr_output *wlr_output, + const struct wlr_output_state *state) { struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); - if (!output_test(wlr_output)) { + if (!output_test(wlr_output, state)) { return false; } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { + if (state->committed & WLR_OUTPUT_STATE_MODE) { if (!output_set_custom_mode(wlr_output, - wlr_output->pending.custom_mode.width, - wlr_output->pending.custom_mode.height, - wlr_output->pending.custom_mode.refresh)) { + state->custom_mode.width, + state->custom_mode.height, + state->custom_mode.refresh)) { return false; } } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) { + if (state->committed & WLR_OUTPUT_STATE_BUFFER) { struct wp_presentation_feedback *wp_feedback = NULL; if (output->backend->presentation != NULL) { wp_feedback = wp_presentation_feedback(output->backend->presentation, @@ -289,8 +290,8 @@ static bool output_commit(struct wlr_output *wlr_output) { } pixman_region32_t *damage = NULL; - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) { - damage = &wlr_output->pending.damage; + if (state->committed & WLR_OUTPUT_STATE_DAMAGE) { + damage = (pixman_region32_t *) &state->damage; } if (output->frame_callback != NULL) { @@ -301,7 +302,7 @@ static bool output_commit(struct wlr_output *wlr_output) { output->frame_callback = wl_surface_frame(output->surface); wl_callback_add_listener(output->frame_callback, &frame_listener, output); - struct wlr_buffer *wlr_buffer = wlr_output->pending.buffer; + struct wlr_buffer *wlr_buffer = state->buffer; struct wlr_wl_buffer *buffer = get_or_create_wl_buffer(output->backend, wlr_buffer); if (buffer == NULL) { diff --git a/backend/x11/output.c b/backend/x11/output.c index ba34fef7..3a599023 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -104,17 +104,17 @@ static void output_destroy(struct wlr_output *wlr_output) { free(output); } -static bool output_test(struct wlr_output *wlr_output) { - uint32_t unsupported = - wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE; +static bool output_test(struct wlr_output *wlr_output, + const struct wlr_output_state *state) { + uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE; if (unsupported != 0) { wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, unsupported); return false; } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { - assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); + if (state->committed & WLR_OUTPUT_STATE_MODE) { + assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); } return true; @@ -257,10 +257,11 @@ static struct wlr_x11_buffer *get_or_create_x11_buffer( return create_x11_buffer(output, wlr_buffer); } -static bool output_commit_buffer(struct wlr_x11_output *output) { +static bool output_commit_buffer(struct wlr_x11_output *output, + const struct wlr_output_state *state) { struct wlr_x11_backend *x11 = output->x11; - struct wlr_buffer *buffer = output->wlr_output.pending.buffer; + struct wlr_buffer *buffer = state->buffer; struct wlr_x11_buffer *x11_buffer = get_or_create_x11_buffer(output, buffer); if (!x11_buffer) { @@ -268,8 +269,9 @@ static bool output_commit_buffer(struct wlr_x11_output *output) { } xcb_xfixes_region_t region = XCB_NONE; - if (output->wlr_output.pending.committed & WLR_OUTPUT_STATE_DAMAGE) { - pixman_region32_union(&output->exposed, &output->exposed, &output->wlr_output.pending.damage); + if (state->committed & WLR_OUTPUT_STATE_DAMAGE) { + pixman_region32_union(&output->exposed, &output->exposed, + (pixman_region32_t *) &state->damage); int rects_len = 0; pixman_box32_t *rects = pixman_region32_rectangles(&output->exposed, &rects_len); @@ -315,26 +317,27 @@ error: return false; } -static bool output_commit(struct wlr_output *wlr_output) { +static bool output_commit(struct wlr_output *wlr_output, + const struct wlr_output_state *state) { struct wlr_x11_output *output = get_x11_output_from_output(wlr_output); struct wlr_x11_backend *x11 = output->x11; - if (!output_test(wlr_output)) { + if (!output_test(wlr_output, state)) { return false; } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { + if (state->committed & WLR_OUTPUT_STATE_MODE) { if (!output_set_custom_mode(wlr_output, - wlr_output->pending.custom_mode.width, - wlr_output->pending.custom_mode.height, - wlr_output->pending.custom_mode.refresh)) { + state->custom_mode.width, + state->custom_mode.height, + state->custom_mode.refresh)) { return false; } } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED && + if (state->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED && x11->atoms.variable_refresh != XCB_ATOM_NONE) { - if (wlr_output->pending.adaptive_sync_enabled) { + if (state->adaptive_sync_enabled) { uint32_t enabled = 1; xcb_change_property(x11->xcb, XCB_PROP_MODE_REPLACE, output->win, x11->atoms.variable_refresh, XCB_ATOM_CARDINAL, 32, 1, @@ -347,8 +350,8 @@ static bool output_commit(struct wlr_output *wlr_output) { } } - if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) { - if (!output_commit_buffer(output)) { + if (state->committed & WLR_OUTPUT_STATE_BUFFER) { + if (!output_commit_buffer(output, state)) { return false; } } diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 4de02c0b..7a1252db 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -54,18 +54,18 @@ struct wlr_output_impl { */ void (*destroy)(struct wlr_output *output); /** - * Check that the pending output state is a valid configuration. + * Check that the supplied output state is a valid configuration. * * If this function returns true, commit can only fail due to a runtime * error. */ - bool (*test)(struct wlr_output *output); + bool (*test)(struct wlr_output *output, const struct wlr_output_state *state); /** - * Commit the pending output state. + * Commit the supplied output state. * * If a buffer has been attached, a frame event is scheduled. */ - bool (*commit)(struct wlr_output *output); + bool (*commit)(struct wlr_output *output, const struct wlr_output_state *state); /** * Get the maximum number of gamma LUT elements for each channel. * diff --git a/types/output/output.c b/types/output/output.c index 4f725915..d5cc0c64 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -665,7 +665,7 @@ bool wlr_output_test(struct wlr_output *output) { return true; } - success = output->impl->test(output); + success = output->impl->test(output, &output->pending); if (!had_buffer) { output_clear_back_buffer(output); @@ -709,7 +709,7 @@ bool wlr_output_commit(struct wlr_output *output) { output_clear_back_buffer(output); } - if (!output->impl->commit(output)) { + if (!output->impl->commit(output, &output->pending)) { wlr_buffer_unlock(back_buffer); output_state_clear(&output->pending); return false; diff --git a/types/output/render.c b/types/output/render.c index 985b93a9..5427b439 100644 --- a/types/output/render.c +++ b/types/output/render.c @@ -185,7 +185,7 @@ bool output_ensure_buffer(struct wlr_output *output) { // If the backend doesn't necessarily need a new buffer on modeset, don't // bother allocating one. - if (!output->impl->test || output->impl->test(output)) { + if (!output->impl->test || output->impl->test(output, &output->pending)) { return true; } @@ -194,7 +194,7 @@ bool output_ensure_buffer(struct wlr_output *output) { if (!output_attach_empty_buffer(output)) { goto error; } - if (!output->impl->test || output->impl->test(output)) { + if (!output->impl->test || output->impl->test(output, &output->pending)) { return true; } @@ -215,7 +215,7 @@ bool output_ensure_buffer(struct wlr_output *output) { if (!output_attach_empty_buffer(output)) { goto error; } - if (!output->impl->test(output)) { + if (!output->impl->test(output, &output->pending)) { goto error; } return true;