From b3ccec61486934aa1fa04bebb192752bf0df2f5a Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Tue, 5 Dec 2023 20:06:52 -0500 Subject: [PATCH] output: Remove output_ensure_buffer Compositors are now required to commit a buffer themselves when they modeset. --- include/types/wlr_output.h | 2 - types/output/output.c | 23 +--------- types/output/render.c | 94 -------------------------------------- 3 files changed, 1 insertion(+), 118 deletions(-) diff --git a/include/types/wlr_output.h b/include/types/wlr_output.h index 2dc979c66..5784efdec 100644 --- a/include/types/wlr_output.h +++ b/include/types/wlr_output.h @@ -12,8 +12,6 @@ bool output_pending_enabled(struct wlr_output *output, bool output_pick_format(struct wlr_output *output, const struct wlr_drm_format_set *display_formats, 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, struct wlr_texture *texture, bool own_texture, const struct wlr_fbox *src_box, diff --git a/types/output/output.c b/types/output/output.c index 83e9653cc..9407895bb 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -721,16 +721,7 @@ bool wlr_output_test_state(struct wlr_output *output, return true; } - bool new_back_buffer = false; - if (!output_ensure_buffer(output, ©, &new_back_buffer)) { - return false; - } - - bool success = output->impl->test(output, ©); - if (new_back_buffer) { - wlr_buffer_unlock(copy.buffer); - } - return success; + return output->impl->test(output, ©); } 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; } - bool new_back_buffer = false; - if (!output_ensure_buffer(output, &pending, &new_back_buffer)) { - return false; - } - if (!output_prepare_commit(output, &pending)) { return false; } if (!output->impl->commit(output, &pending)) { - if (new_back_buffer) { - wlr_buffer_unlock(pending.buffer); - } return false; } output_apply_commit(output, &pending); - if (new_back_buffer) { - wlr_buffer_unlock(pending.buffer); - } - return true; } diff --git a/types/output/render.c b/types/output/render.c index 155da5cf8..f841fe87c 100644 --- a/types/output/render.c +++ b/types/output/render.c @@ -38,100 +38,6 @@ bool wlr_output_init_render(struct wlr_output *output, 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) { if (lock) { ++output->attach_render_locks;