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.
This commit is contained in:
Simon Ser 2022-05-24 19:16:50 +02:00
parent 93ee4c7684
commit 25dd3cc0cd
7 changed files with 75 additions and 69 deletions

View file

@ -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_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); struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
if (!conn->backend->session->active) { if (!conn->backend->session->active) {
return false; return false;
} }
uint32_t unsupported = output->pending.committed & ~SUPPORTED_OUTPUT_STATE; uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE;
if (unsupported != 0) { if (unsupported != 0) {
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
unsupported); unsupported);
return false; return false;
} }
if ((output->pending.committed & WLR_OUTPUT_STATE_ENABLED) && if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && state->enabled) {
output->pending.enabled) {
if (output->current_mode == NULL && 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, wlr_drm_conn_log(conn, WLR_DEBUG,
"Can't enable an output without a mode"); "Can't enable an output without a mode");
return false; return false;
@ -484,12 +484,12 @@ static bool drm_connector_test(struct wlr_output *output) {
} }
struct wlr_drm_connector_state pending = {0}; 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 (pending.active) {
if ((output->pending.committed & if ((state->committed &
(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE)) && (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, wlr_drm_conn_log(conn, WLR_DEBUG,
"Can't enable an output without a buffer"); "Can't enable an output without a buffer");
return false; return false;
@ -514,7 +514,7 @@ static bool drm_connector_test(struct wlr_output *output) {
return true; 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)) { if (!drm_connector_set_pending_fb(conn, pending.base)) {
return false; return false;
} }
@ -597,14 +597,15 @@ bool drm_connector_commit_state(struct wlr_drm_connector *conn,
return true; 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); 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 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, size_t drm_crtc_get_gamma_lut_size(struct wlr_drm_backend *drm,

View file

@ -29,40 +29,41 @@ static bool output_set_custom_mode(struct wlr_headless_output *output,
return true; return true;
} }
static bool output_test(struct wlr_output *wlr_output) { static bool output_test(struct wlr_output *wlr_output,
uint32_t unsupported = const struct wlr_output_state *state) {
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE; uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE;
if (unsupported != 0) { if (unsupported != 0) {
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
unsupported); unsupported);
return false; return false;
} }
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { if (state->committed & WLR_OUTPUT_STATE_MODE) {
assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM);
} }
return true; 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 = struct wlr_headless_output *output =
headless_output_from_output(wlr_output); headless_output_from_output(wlr_output);
if (!output_test(wlr_output)) { if (!output_test(wlr_output, state)) {
return false; return false;
} }
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { if (state->committed & WLR_OUTPUT_STATE_MODE) {
if (!output_set_custom_mode(output, if (!output_set_custom_mode(output,
wlr_output->pending.custom_mode.width, state->custom_mode.width,
wlr_output->pending.custom_mode.height, state->custom_mode.height,
wlr_output->pending.custom_mode.refresh)) { state->custom_mode.refresh)) {
return false; 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 = { struct wlr_output_event_present present_event = {
.commit_seq = wlr_output->commit_seq + 1, .commit_seq = wlr_output->commit_seq + 1,
.presented = true, .presented = true,

View file

@ -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); 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 = struct wlr_wl_output *output =
get_wl_output_from_output(wlr_output); get_wl_output_from_output(wlr_output);
uint32_t unsupported = uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE;
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
if (unsupported != 0) { if (unsupported != 0) {
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
unsupported); unsupported);
return false; return false;
} }
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { if (state->committed & WLR_OUTPUT_STATE_MODE) {
assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM);
} }
if ((wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) && if ((state->committed & WLR_OUTPUT_STATE_BUFFER) &&
!test_buffer(output->backend, wlr_output->pending.buffer)) { !test_buffer(output->backend, state->buffer)) {
return false; return false;
} }
return true; 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 = struct wlr_wl_output *output =
get_wl_output_from_output(wlr_output); get_wl_output_from_output(wlr_output);
if (!output_test(wlr_output)) { if (!output_test(wlr_output, state)) {
return false; 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, if (!output_set_custom_mode(wlr_output,
wlr_output->pending.custom_mode.width, state->custom_mode.width,
wlr_output->pending.custom_mode.height, state->custom_mode.height,
wlr_output->pending.custom_mode.refresh)) { state->custom_mode.refresh)) {
return false; 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; struct wp_presentation_feedback *wp_feedback = NULL;
if (output->backend->presentation != NULL) { if (output->backend->presentation != NULL) {
wp_feedback = wp_presentation_feedback(output->backend->presentation, 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; pixman_region32_t *damage = NULL;
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) { if (state->committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &wlr_output->pending.damage; damage = (pixman_region32_t *) &state->damage;
} }
if (output->frame_callback != NULL) { 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); output->frame_callback = wl_surface_frame(output->surface);
wl_callback_add_listener(output->frame_callback, &frame_listener, output); 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 = struct wlr_wl_buffer *buffer =
get_or_create_wl_buffer(output->backend, wlr_buffer); get_or_create_wl_buffer(output->backend, wlr_buffer);
if (buffer == NULL) { if (buffer == NULL) {

View file

@ -104,17 +104,17 @@ static void output_destroy(struct wlr_output *wlr_output) {
free(output); free(output);
} }
static bool output_test(struct wlr_output *wlr_output) { static bool output_test(struct wlr_output *wlr_output,
uint32_t unsupported = const struct wlr_output_state *state) {
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE; uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE;
if (unsupported != 0) { if (unsupported != 0) {
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32, wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
unsupported); unsupported);
return false; return false;
} }
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { if (state->committed & WLR_OUTPUT_STATE_MODE) {
assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM);
} }
return true; return true;
@ -257,10 +257,11 @@ static struct wlr_x11_buffer *get_or_create_x11_buffer(
return create_x11_buffer(output, wlr_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_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 = struct wlr_x11_buffer *x11_buffer =
get_or_create_x11_buffer(output, buffer); get_or_create_x11_buffer(output, buffer);
if (!x11_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; xcb_xfixes_region_t region = XCB_NONE;
if (output->wlr_output.pending.committed & WLR_OUTPUT_STATE_DAMAGE) { if (state->committed & WLR_OUTPUT_STATE_DAMAGE) {
pixman_region32_union(&output->exposed, &output->exposed, &output->wlr_output.pending.damage); pixman_region32_union(&output->exposed, &output->exposed,
(pixman_region32_t *) &state->damage);
int rects_len = 0; int rects_len = 0;
pixman_box32_t *rects = pixman_region32_rectangles(&output->exposed, &rects_len); pixman_box32_t *rects = pixman_region32_rectangles(&output->exposed, &rects_len);
@ -315,26 +317,27 @@ error:
return false; 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_output *output = get_x11_output_from_output(wlr_output);
struct wlr_x11_backend *x11 = output->x11; struct wlr_x11_backend *x11 = output->x11;
if (!output_test(wlr_output)) { if (!output_test(wlr_output, state)) {
return false; 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, if (!output_set_custom_mode(wlr_output,
wlr_output->pending.custom_mode.width, state->custom_mode.width,
wlr_output->pending.custom_mode.height, state->custom_mode.height,
wlr_output->pending.custom_mode.refresh)) { state->custom_mode.refresh)) {
return false; 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) { x11->atoms.variable_refresh != XCB_ATOM_NONE) {
if (wlr_output->pending.adaptive_sync_enabled) { if (state->adaptive_sync_enabled) {
uint32_t enabled = 1; uint32_t enabled = 1;
xcb_change_property(x11->xcb, XCB_PROP_MODE_REPLACE, output->win, xcb_change_property(x11->xcb, XCB_PROP_MODE_REPLACE, output->win,
x11->atoms.variable_refresh, XCB_ATOM_CARDINAL, 32, 1, 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 (state->committed & WLR_OUTPUT_STATE_BUFFER) {
if (!output_commit_buffer(output)) { if (!output_commit_buffer(output, state)) {
return false; return false;
} }
} }

View file

@ -54,18 +54,18 @@ struct wlr_output_impl {
*/ */
void (*destroy)(struct wlr_output *output); 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 * If this function returns true, commit can only fail due to a runtime
* error. * 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. * 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. * Get the maximum number of gamma LUT elements for each channel.
* *

View file

@ -665,7 +665,7 @@ bool wlr_output_test(struct wlr_output *output) {
return true; return true;
} }
success = output->impl->test(output); success = output->impl->test(output, &output->pending);
if (!had_buffer) { if (!had_buffer) {
output_clear_back_buffer(output); output_clear_back_buffer(output);
@ -709,7 +709,7 @@ bool wlr_output_commit(struct wlr_output *output) {
output_clear_back_buffer(output); output_clear_back_buffer(output);
} }
if (!output->impl->commit(output)) { if (!output->impl->commit(output, &output->pending)) {
wlr_buffer_unlock(back_buffer); wlr_buffer_unlock(back_buffer);
output_state_clear(&output->pending); output_state_clear(&output->pending);
return false; return false;

View file

@ -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 // If the backend doesn't necessarily need a new buffer on modeset, don't
// bother allocating one. // bother allocating one.
if (!output->impl->test || output->impl->test(output)) { if (!output->impl->test || output->impl->test(output, &output->pending)) {
return true; return true;
} }
@ -194,7 +194,7 @@ bool output_ensure_buffer(struct wlr_output *output) {
if (!output_attach_empty_buffer(output)) { if (!output_attach_empty_buffer(output)) {
goto error; goto error;
} }
if (!output->impl->test || output->impl->test(output)) { if (!output->impl->test || output->impl->test(output, &output->pending)) {
return true; return true;
} }
@ -215,7 +215,7 @@ bool output_ensure_buffer(struct wlr_output *output) {
if (!output_attach_empty_buffer(output)) { if (!output_attach_empty_buffer(output)) {
goto error; goto error;
} }
if (!output->impl->test(output)) { if (!output->impl->test(output, &output->pending)) {
goto error; goto error;
} }
return true; return true;