output: Remove output_ensure_buffer

Compositors are now required to commit a buffer themselves when they
modeset.
This commit is contained in:
Alexander Orzechowski 2023-12-05 20:06:52 -05:00
parent 3ae9c80ddf
commit b3ccec6148
3 changed files with 1 additions and 118 deletions

View file

@ -12,8 +12,6 @@ bool output_pending_enabled(struct wlr_output *output,
bool output_pick_format(struct wlr_output *output, bool output_pick_format(struct wlr_output *output,
const struct wlr_drm_format_set *display_formats, const struct wlr_drm_format_set *display_formats,
struct wlr_drm_format *format, uint32_t fmt); struct wlr_drm_format *format, uint32_t fmt);
bool output_ensure_buffer(struct wlr_output *output,
struct wlr_output_state *state, bool *new_back_buffer);
bool output_cursor_set_texture(struct wlr_output_cursor *cursor, bool output_cursor_set_texture(struct wlr_output_cursor *cursor,
struct wlr_texture *texture, bool own_texture, const struct wlr_fbox *src_box, struct wlr_texture *texture, bool own_texture, const struct wlr_fbox *src_box,

View file

@ -721,16 +721,7 @@ bool wlr_output_test_state(struct wlr_output *output,
return true; return true;
} }
bool new_back_buffer = false; return output->impl->test(output, &copy);
if (!output_ensure_buffer(output, &copy, &new_back_buffer)) {
return false;
}
bool success = output->impl->test(output, &copy);
if (new_back_buffer) {
wlr_buffer_unlock(copy.buffer);
}
return success;
} }
bool output_prepare_commit(struct wlr_output *output, const struct wlr_output_state *state) { bool output_prepare_commit(struct wlr_output *output, const struct wlr_output_state *state) {
@ -792,28 +783,16 @@ bool wlr_output_commit_state(struct wlr_output *output,
return false; return false;
} }
bool new_back_buffer = false;
if (!output_ensure_buffer(output, &pending, &new_back_buffer)) {
return false;
}
if (!output_prepare_commit(output, &pending)) { if (!output_prepare_commit(output, &pending)) {
return false; return false;
} }
if (!output->impl->commit(output, &pending)) { if (!output->impl->commit(output, &pending)) {
if (new_back_buffer) {
wlr_buffer_unlock(pending.buffer);
}
return false; return false;
} }
output_apply_commit(output, &pending); output_apply_commit(output, &pending);
if (new_back_buffer) {
wlr_buffer_unlock(pending.buffer);
}
return true; return true;
} }

View file

@ -38,100 +38,6 @@ bool wlr_output_init_render(struct wlr_output *output,
return true; return true;
} }
static struct wlr_buffer *output_acquire_empty_buffer(struct wlr_output *output,
const struct wlr_output_state *state) {
assert(!(state->committed & WLR_OUTPUT_STATE_BUFFER));
// wlr_output_configure_primary_swapchain() function will call
// wlr_output_test_state(), which can call us again. This is dangerous: we
// risk infinite recursion. However, a buffer will always be supplied in
// wlr_output_test_state(), which will prevent us from being called.
if (!wlr_output_configure_primary_swapchain(output, state,
&output->swapchain)) {
return NULL;
}
struct wlr_buffer *buffer = wlr_swapchain_acquire(output->swapchain);
if (buffer == NULL) {
return NULL;
}
struct wlr_render_pass *pass =
wlr_renderer_begin_buffer_pass(output->renderer, buffer, NULL);
if (pass == NULL) {
wlr_buffer_unlock(buffer);
return NULL;
}
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
.color = { 0, 0, 0, 0 },
.blend_mode = WLR_RENDER_BLEND_MODE_NONE,
});
if (!wlr_render_pass_submit(pass)) {
wlr_buffer_unlock(buffer);
return NULL;
}
return buffer;
}
// This function may attach a new, empty buffer if necessary.
// If so, the new_back_buffer out parameter will be set to true.
bool output_ensure_buffer(struct wlr_output *output,
struct wlr_output_state *state, bool *new_buffer) {
assert(*new_buffer == false);
// If we already have a buffer, we don't need to allocate a new one
if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
return true;
}
// If the compositor hasn't called wlr_output_init_render(), they will use
// their own logic to attach buffers
if (output->renderer == NULL) {
return true;
}
bool enabled = output->enabled;
if (state->committed & WLR_OUTPUT_STATE_ENABLED) {
enabled = state->enabled;
}
// If we're lighting up an output or changing its mode, make sure to
// provide a new buffer
bool needs_new_buffer = false;
if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && state->enabled) {
needs_new_buffer = true;
}
if (state->committed & WLR_OUTPUT_STATE_MODE) {
needs_new_buffer = true;
}
if (state->committed & WLR_OUTPUT_STATE_RENDER_FORMAT) {
needs_new_buffer = true;
}
if (state->allow_reconfiguration && output->commit_seq == 0 && 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.
needs_new_buffer = true;
}
if (!needs_new_buffer) {
return true;
}
wlr_log(WLR_DEBUG, "Attaching empty buffer to output for modeset");
struct wlr_buffer *buffer = output_acquire_empty_buffer(output, state);
if (buffer == NULL) {
return false;
}
*new_buffer = true;
wlr_output_state_set_buffer(state, buffer);
wlr_buffer_unlock(buffer);
return true;
}
void wlr_output_lock_attach_render(struct wlr_output *output, bool lock) { void wlr_output_lock_attach_render(struct wlr_output *output, bool lock) {
if (lock) { if (lock) {
++output->attach_render_locks; ++output->attach_render_locks;