Skip to content

Commit

Permalink
output: use backend commits
Browse files Browse the repository at this point in the history
Pass the whole new desired state to the backend, so that the
backend can leverage KMS atomic commits.
  • Loading branch information
emersion committed Feb 16, 2024
1 parent 9ddb996 commit 60c3350
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#if WLR_HAS_X11_BACKEND
#include <wlr/backend/x11.h>
#endif
#include <wlr/render/swapchain.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
Expand Down Expand Up @@ -131,31 +132,6 @@ output_disable(struct cg_output *output)
output_layout_remove(output);
}

static bool
output_apply_config(struct cg_output *output, struct wlr_output_configuration_head_v1 *head, bool test_only)
{
struct wlr_output_state state = {0};
wlr_output_head_v1_state_apply(&head->state, &state);

if (test_only) {
bool ret = wlr_output_test_state(output->wlr_output, &state);
return ret;
}

/* Apply output configuration */
if (!wlr_output_commit_state(output->wlr_output, &state)) {
return false;
}

if (head->state.enabled) {
output_layout_add(output, head->state.x, head->state.y);
} else {
output_layout_remove(output);
}

return true;
}

static void
handle_output_frame(struct wl_listener *listener, void *data)
{
Expand Down Expand Up @@ -356,17 +332,59 @@ output_set_window_title(struct cg_output *output, const char *title)
static bool
output_config_apply(struct cg_server *server, struct wlr_output_configuration_v1 *config, bool test_only)
{
struct wlr_output_configuration_head_v1 *head;
size_t states_len;
struct wlr_output_state *states = wlr_output_configuration_v1_build_state(config, &states_len);
if (states == NULL) {
return false;
}

for (size_t i = 0; i < states_len; i++) {
struct wlr_output_state *state = &states[i];

bool enabled = state->output->enabled;
if (state->committed & WLR_OUTPUT_STATE_ENABLED) {
enabled = state->enabled;
}
if (!enabled) {
continue;
}

if (!wlr_output_configure_primary_swapchain(state->output, state, &state->output->swapchain)) {
goto out;
}

struct wlr_buffer *buffer = wlr_swapchain_acquire(state->output->swapchain, NULL);
if (buffer == NULL) {
goto out;
}

wlr_output_state_set_buffer(state, buffer);
}

bool ok = wlr_backend_test(server->backend, states, states_len);
if (!ok || test_only) {
goto out;
}

ok = wlr_backend_commit(server->backend, states, states_len);
if (!ok) {
goto out;
}

struct wlr_output_configuration_head_v1 *head;
wl_list_for_each (head, &config->heads, link) {
struct cg_output *output = head->state.output->data;

if (!output_apply_config(output, head, test_only)) {
return false;
if (head->state.enabled) {
output_layout_add(output, head->state.x, head->state.y);
} else {
output_layout_remove(output);
}
}

return true;
out:
free(states);
return ok;
}

void
Expand Down

0 comments on commit 60c3350

Please sign in to comment.