mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-20 06:47:19 -04:00
Merge branch 'output-auto-buffer' into 'master'
output: Remove output_ensure_buffer See merge request wlroots/wlroots!4484
This commit is contained in:
commit
c289b8e462
21 changed files with 215 additions and 268 deletions
|
|
@ -89,8 +89,9 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor,
|
|||
|
||||
void wlr_output_add_software_cursors_to_render_pass(struct wlr_output *output,
|
||||
struct wlr_render_pass *render_pass, const pixman_region32_t *damage) {
|
||||
// TODO: pass output state from caller
|
||||
int width, height;
|
||||
wlr_output_transformed_resolution(output, &width, &height);
|
||||
wlr_output_transformed_resolution(output, NULL, &width, &height);
|
||||
|
||||
struct wlr_output_cursor *cursor;
|
||||
wl_list_for_each(cursor, &output->cursors, link) {
|
||||
|
|
@ -152,7 +153,7 @@ static void output_cursor_damage_whole(struct wlr_output_cursor *cursor) {
|
|||
static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
|
||||
struct wlr_box output_box;
|
||||
output_box.x = output_box.y = 0;
|
||||
wlr_output_transformed_resolution(cursor->output, &output_box.width,
|
||||
wlr_output_transformed_resolution(cursor->output, NULL, &output_box.width,
|
||||
&output_box.height);
|
||||
|
||||
struct wlr_box cursor_box;
|
||||
|
|
|
|||
|
|
@ -441,21 +441,32 @@ void wlr_output_destroy(struct wlr_output *output) {
|
|||
}
|
||||
|
||||
void wlr_output_transformed_resolution(struct wlr_output *output,
|
||||
int *width, int *height) {
|
||||
if (output->transform % 2 == 0) {
|
||||
*width = output->width;
|
||||
*height = output->height;
|
||||
} else {
|
||||
*width = output->height;
|
||||
*height = output->width;
|
||||
const struct wlr_output_state *state, int *width, int *height) {
|
||||
output_pending_resolution(output, state, width, height);
|
||||
|
||||
enum wl_output_transform transform = output->transform;
|
||||
if (state && state->committed & WLR_OUTPUT_STATE_TRANSFORM) {
|
||||
transform = state->transform;
|
||||
}
|
||||
|
||||
if (transform % 2 != 0) {
|
||||
int tmp = *width;
|
||||
*width = *height;
|
||||
*height = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_output_effective_resolution(struct wlr_output *output,
|
||||
int *width, int *height) {
|
||||
wlr_output_transformed_resolution(output, width, height);
|
||||
*width /= output->scale;
|
||||
*height /= output->scale;
|
||||
const struct wlr_output_state *state, int *width, int *height) {
|
||||
wlr_output_transformed_resolution(output, state, width, height);
|
||||
|
||||
float scale = output->scale;
|
||||
if (state && state->committed & WLR_OUTPUT_STATE_SCALE) {
|
||||
scale = state->scale;
|
||||
}
|
||||
|
||||
*width /= scale;
|
||||
*height /= scale;
|
||||
}
|
||||
|
||||
struct wlr_output_mode *wlr_output_preferred_mode(struct wlr_output *output) {
|
||||
|
|
@ -476,7 +487,7 @@ struct wlr_output_mode *wlr_output_preferred_mode(struct wlr_output *output) {
|
|||
|
||||
void output_pending_resolution(struct wlr_output *output,
|
||||
const struct wlr_output_state *state, int *width, int *height) {
|
||||
if (state->committed & WLR_OUTPUT_STATE_MODE) {
|
||||
if (state && state->committed & WLR_OUTPUT_STATE_MODE) {
|
||||
switch (state->mode_type) {
|
||||
case WLR_OUTPUT_STATE_MODE_FIXED:
|
||||
*width = state->mode->width;
|
||||
|
|
@ -610,6 +621,12 @@ static bool output_basic_test(struct wlr_output *output,
|
|||
}
|
||||
}
|
||||
|
||||
if ((state->committed & WLR_OUTPUT_STATE_RENDER_FORMAT) &&
|
||||
(state->committed & WLR_OUTPUT_STATE_BUFFER) == 0) {
|
||||
wlr_log(WLR_DEBUG, "Tried to change the render format without a buffer.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state->committed & WLR_OUTPUT_STATE_RENDER_FORMAT) {
|
||||
struct wlr_allocator *allocator = output->allocator;
|
||||
assert(allocator != NULL);
|
||||
|
|
@ -625,8 +642,13 @@ static bool output_basic_test(struct wlr_output *output,
|
|||
wlr_drm_format_finish(&format);
|
||||
}
|
||||
|
||||
bool enabled = output_pending_enabled(output, state);
|
||||
if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && state->enabled &&
|
||||
(state->committed & WLR_OUTPUT_STATE_BUFFER) == 0) {
|
||||
wlr_log(WLR_DEBUG, "Tried to enable an output without a buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enabled = output_pending_enabled(output, state);
|
||||
if (enabled && (state->committed & (WLR_OUTPUT_STATE_ENABLED |
|
||||
WLR_OUTPUT_STATE_MODE))) {
|
||||
int pending_width, pending_height;
|
||||
|
|
@ -699,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) {
|
||||
|
|
@ -770,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue