mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-19 06:47:02 -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;
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ static void logical_to_buffer_coords(pixman_region32_t *region, const struct ren
|
|||
|
||||
static void output_to_buffer_coords(pixman_region32_t *damage, struct wlr_output *output) {
|
||||
int width, height;
|
||||
wlr_output_transformed_resolution(output, &width, &height);
|
||||
wlr_output_transformed_resolution(output, NULL, &width, &height);
|
||||
|
||||
wlr_region_transform(damage, damage,
|
||||
wlr_output_transform_invert(output->transform), width, height);
|
||||
|
|
@ -445,7 +445,7 @@ static void update_node_update_outputs(struct wlr_scene_node *node,
|
|||
.x = scene_output->x,
|
||||
.y = scene_output->y,
|
||||
};
|
||||
wlr_output_effective_resolution(scene_output->output,
|
||||
wlr_output_effective_resolution(scene_output->output, NULL,
|
||||
&output_box.width, &output_box.height);
|
||||
|
||||
pixman_region32_t intersection;
|
||||
|
|
@ -1579,7 +1579,7 @@ static void scene_output_handle_damage(struct wl_listener *listener, void *data)
|
|||
struct wlr_output_event_damage *event = data;
|
||||
|
||||
int width, height;
|
||||
wlr_output_transformed_resolution(output, &width, &height);
|
||||
wlr_output_transformed_resolution(output, NULL, &width, &height);
|
||||
|
||||
pixman_region32_t damage;
|
||||
pixman_region32_init(&damage);
|
||||
|
|
@ -2337,7 +2337,7 @@ static void scene_output_for_each_scene_buffer(const struct wlr_box *output_box,
|
|||
void wlr_scene_output_for_each_buffer(struct wlr_scene_output *scene_output,
|
||||
wlr_scene_buffer_iterator_func_t iterator, void *user_data) {
|
||||
struct wlr_box box = { .x = scene_output->x, .y = scene_output->y };
|
||||
wlr_output_effective_resolution(scene_output->output,
|
||||
wlr_output_effective_resolution(scene_output->output, NULL,
|
||||
&box.width, &box.height);
|
||||
scene_output_for_each_scene_buffer(&box, &scene_output->scene->tree.node, 0, 0,
|
||||
iterator, user_data);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ static void output_layout_output_get_box(
|
|||
struct wlr_box *box) {
|
||||
box->x = l_output->x;
|
||||
box->y = l_output->y;
|
||||
wlr_output_effective_resolution(l_output->output,
|
||||
wlr_output_effective_resolution(l_output->output, NULL,
|
||||
&box->width, &box->height);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -573,7 +573,7 @@ static void capture_output(struct wl_client *wl_client,
|
|||
buffer_box.height = output->height;
|
||||
} else {
|
||||
int ow, oh;
|
||||
wlr_output_effective_resolution(output, &ow, &oh);
|
||||
wlr_output_effective_resolution(output, NULL, &ow, &oh);
|
||||
|
||||
buffer_box = *box;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ static void output_update(struct wlr_xdg_output_v1 *xdg_output) {
|
|||
}
|
||||
|
||||
int width, height;
|
||||
wlr_output_effective_resolution(layout_output->output, &width, &height);
|
||||
wlr_output_effective_resolution(layout_output->output, NULL, &width, &height);
|
||||
if (xdg_output->width != width || xdg_output->height != height) {
|
||||
xdg_output->width = width;
|
||||
xdg_output->height = height;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue