mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-18 06:47:31 -04:00
wlr_output: Introduce struct wlr_output_commit
This commit is contained in:
parent
1b0694b794
commit
c299c13d13
12 changed files with 145 additions and 49 deletions
|
|
@ -699,12 +699,12 @@ bool drm_connector_supports_vrr(struct wlr_drm_connector *conn) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool drm_connector_commit_state(struct wlr_drm_connector *conn,
|
||||
struct wlr_output_commit *drm_connector_commit_state(struct wlr_drm_connector *conn,
|
||||
const struct wlr_output_state *base) {
|
||||
struct wlr_drm_backend *drm = conn->backend;
|
||||
|
||||
if (!drm->session->active) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
|
|
@ -780,15 +780,21 @@ bool drm_connector_commit_state(struct wlr_drm_connector *conn,
|
|||
|
||||
out:
|
||||
drm_connector_state_finish(&pending);
|
||||
return ok;
|
||||
|
||||
if (!ok) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wlr_output_commit_init(&conn->commit, &conn->output);
|
||||
return &conn->commit;
|
||||
}
|
||||
|
||||
static bool drm_connector_commit(struct wlr_output *output,
|
||||
static struct wlr_output_commit *drm_connector_commit(struct wlr_output *output,
|
||||
const struct wlr_output_state *state) {
|
||||
struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
|
||||
|
||||
if (!drm_connector_test(output, state)) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return drm_connector_commit_state(conn, state);
|
||||
|
|
@ -1711,6 +1717,7 @@ static void handle_page_flip(int fd, unsigned seq,
|
|||
struct wlr_output_event_present present_event = {
|
||||
/* The DRM backend guarantees that the presentation event will be for
|
||||
* the last submitted frame. */
|
||||
.output = &conn->output,
|
||||
.commit_seq = conn->output.commit_seq,
|
||||
.presented = drm->session->active,
|
||||
.when = &present_time,
|
||||
|
|
@ -1719,6 +1726,7 @@ static void handle_page_flip(int fd, unsigned seq,
|
|||
.flags = present_flags,
|
||||
};
|
||||
wlr_output_send_present(&conn->output, &present_event);
|
||||
wl_signal_emit_mutable(&conn->commit.events.present, &present_event);
|
||||
|
||||
if (drm->session->active) {
|
||||
wlr_output_send_frame(&conn->output);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
#include <wlr/types/wlr_output_layer.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
|
@ -53,7 +55,7 @@ static bool output_test(struct wlr_output *wlr_output,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool output_commit(struct wlr_output *wlr_output,
|
||||
static struct wlr_output_commit *output_commit(struct wlr_output *wlr_output,
|
||||
const struct wlr_output_state *state) {
|
||||
struct wlr_headless_output *output =
|
||||
headless_output_from_output(wlr_output);
|
||||
|
|
@ -62,21 +64,20 @@ static bool output_commit(struct wlr_output *wlr_output,
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (state->committed & WLR_OUTPUT_STATE_MODE) {
|
||||
output_update_refresh(output, state->custom_mode.refresh);
|
||||
}
|
||||
|
||||
wlr_output_commit_init(&output->commit, wlr_output);
|
||||
|
||||
if (output_pending_enabled(wlr_output, state)) {
|
||||
struct wlr_output_event_present present_event = {
|
||||
.commit_seq = wlr_output->commit_seq + 1,
|
||||
.presented = true,
|
||||
};
|
||||
output_defer_present(wlr_output, present_event);
|
||||
output_commit_defer_present(&output->commit);
|
||||
|
||||
wl_event_source_timer_update(output->frame_timer, output->frame_delay);
|
||||
}
|
||||
|
||||
return true;
|
||||
return &output->commit;
|
||||
}
|
||||
|
||||
static void output_destroy(struct wlr_output *wlr_output) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -6,6 +7,7 @@
|
|||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include <wayland-client.h>
|
||||
|
|
@ -103,12 +105,14 @@ static void presentation_feedback_handle_presented(void *data,
|
|||
struct wlr_output_event_present event = {
|
||||
.commit_seq = feedback->commit_seq,
|
||||
.presented = true,
|
||||
.output = &feedback->output->wlr_output,
|
||||
.when = &t,
|
||||
.seq = ((uint64_t)seq_hi << 32) | seq_lo,
|
||||
.refresh = refresh_ns,
|
||||
.flags = flags,
|
||||
};
|
||||
wlr_output_send_present(&feedback->output->wlr_output, &event);
|
||||
wl_signal_emit_mutable(&feedback->commit.events.present, &event);
|
||||
|
||||
presentation_feedback_destroy(feedback);
|
||||
}
|
||||
|
|
@ -120,8 +124,10 @@ static void presentation_feedback_handle_discarded(void *data,
|
|||
struct wlr_output_event_present event = {
|
||||
.commit_seq = feedback->commit_seq,
|
||||
.presented = false,
|
||||
.output = &feedback->output->wlr_output,
|
||||
};
|
||||
wlr_output_send_present(&feedback->output->wlr_output, &event);
|
||||
wl_signal_emit_mutable(&feedback->commit.events.present, &event);
|
||||
|
||||
presentation_feedback_destroy(feedback);
|
||||
}
|
||||
|
|
@ -520,13 +526,13 @@ static bool commit_layers(struct wlr_wl_output *output,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool output_commit(struct wlr_output *wlr_output,
|
||||
static struct wlr_output_commit *output_commit(struct wlr_output *wlr_output,
|
||||
const struct wlr_output_state *state) {
|
||||
struct wlr_wl_output *output =
|
||||
get_wl_output_from_output(wlr_output);
|
||||
|
||||
if (!output_test(wlr_output, state)) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && !state->enabled) {
|
||||
|
|
@ -544,7 +550,7 @@ static bool output_commit(struct wlr_output *wlr_output,
|
|||
struct wlr_wl_buffer *buffer =
|
||||
get_or_create_wl_buffer(output->backend, wlr_buffer);
|
||||
if (buffer == NULL) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_surface_attach(output->surface, buffer->wl_buffer, 0, 0);
|
||||
|
|
@ -553,9 +559,11 @@ static bool output_commit(struct wlr_output *wlr_output,
|
|||
|
||||
if ((state->committed & WLR_OUTPUT_STATE_LAYERS) &&
|
||||
!commit_layers(output, state->layers, state->layers_len)) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_output_commit *commit = NULL;
|
||||
|
||||
if (output_pending_enabled(wlr_output, state)) {
|
||||
if (output->frame_callback != NULL) {
|
||||
wl_callback_destroy(output->frame_callback);
|
||||
|
|
@ -576,7 +584,7 @@ static bool output_commit(struct wlr_output *wlr_output,
|
|||
calloc(1, sizeof(*feedback));
|
||||
if (feedback == NULL) {
|
||||
wp_presentation_feedback_destroy(wp_feedback);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
feedback->output = output;
|
||||
feedback->feedback = wp_feedback;
|
||||
|
|
@ -585,18 +593,21 @@ static bool output_commit(struct wlr_output *wlr_output,
|
|||
|
||||
wp_presentation_feedback_add_listener(wp_feedback,
|
||||
&presentation_feedback_listener, feedback);
|
||||
|
||||
commit = &feedback->commit;
|
||||
wlr_output_commit_init(commit, wlr_output);
|
||||
} else {
|
||||
struct wlr_output_event_present present_event = {
|
||||
.commit_seq = wlr_output->commit_seq + 1,
|
||||
.presented = true,
|
||||
};
|
||||
output_defer_present(wlr_output, present_event);
|
||||
wlr_output_commit_init(commit, wlr_output);
|
||||
output_commit_defer_present(commit);
|
||||
}
|
||||
} else {
|
||||
commit = &output->commit;
|
||||
wlr_output_commit_init(commit, wlr_output);
|
||||
}
|
||||
|
||||
wl_display_flush(output->backend->remote_display);
|
||||
|
||||
return true;
|
||||
return commit;
|
||||
}
|
||||
|
||||
static bool output_set_cursor(struct wlr_output *wlr_output,
|
||||
|
|
|
|||
|
|
@ -105,6 +105,12 @@ static void output_destroy(struct wlr_output *wlr_output) {
|
|||
xcb_render_free_picture(x11->xcb, output->cursor.pic);
|
||||
}
|
||||
|
||||
struct wlr_x11_output_commit *commit, *tmp_commit;
|
||||
wl_list_for_each_safe(commit, tmp_commit, &output->commits, link) {
|
||||
wl_list_remove(&commit->link);
|
||||
free(commit);
|
||||
}
|
||||
|
||||
// A zero event mask deletes the event context
|
||||
xcb_present_select_input(x11->xcb, output->present_event_id, output->win, 0);
|
||||
xcb_destroy_window(x11->xcb, output->win);
|
||||
|
|
@ -288,7 +294,7 @@ static struct wlr_x11_buffer *get_or_create_x11_buffer(
|
|||
}
|
||||
|
||||
static bool output_commit_buffer(struct wlr_x11_output *output,
|
||||
const struct wlr_output_state *state) {
|
||||
const struct wlr_output_state *state, uint32_t serial) {
|
||||
struct wlr_x11_backend *x11 = output->x11;
|
||||
|
||||
struct wlr_buffer *buffer = state->buffer;
|
||||
|
|
@ -328,7 +334,6 @@ static bool output_commit_buffer(struct wlr_x11_output *output,
|
|||
|
||||
pixman_region32_clear(&output->exposed);
|
||||
|
||||
uint32_t serial = output->wlr_output.commit_seq;
|
||||
uint32_t options = 0;
|
||||
uint64_t target_msc = output->last_msc ? output->last_msc + 1 : 0;
|
||||
xcb_present_pixmap(x11->xcb, output->win, x11_buffer->pixmap, serial,
|
||||
|
|
@ -346,13 +351,18 @@ error:
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool output_commit(struct wlr_output *wlr_output,
|
||||
static struct wlr_output_commit *output_commit(struct wlr_output *wlr_output,
|
||||
const struct wlr_output_state *state) {
|
||||
struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
|
||||
struct wlr_x11_backend *x11 = output->x11;
|
||||
|
||||
if (!output_test(wlr_output, state)) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_x11_output_commit *commit = calloc(1, sizeof(*commit));
|
||||
if (!commit){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (state->committed & WLR_OUTPUT_STATE_ENABLED) {
|
||||
|
|
@ -368,23 +378,29 @@ static bool output_commit(struct wlr_output *wlr_output,
|
|||
state->custom_mode.width,
|
||||
state->custom_mode.height,
|
||||
state->custom_mode.refresh)) {
|
||||
return false;
|
||||
free(commit);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t serial = output->wlr_output.commit_seq;
|
||||
|
||||
wlr_output_commit_init(&commit->commit, wlr_output);
|
||||
wl_list_insert(&output->commits, &commit->link);
|
||||
commit->serial = serial;
|
||||
|
||||
if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
|
||||
if (!output_commit_buffer(output, state)) {
|
||||
return false;
|
||||
if (!output_commit_buffer(output, state, serial)) {
|
||||
return NULL;
|
||||
}
|
||||
} else if (output_pending_enabled(wlr_output, state)) {
|
||||
uint32_t serial = output->wlr_output.commit_seq;
|
||||
uint64_t target_msc = output->last_msc ? output->last_msc + 1 : 0;
|
||||
xcb_present_notify_msc(x11->xcb, output->win, serial, target_msc, 0, 0);
|
||||
}
|
||||
|
||||
xcb_flush(x11->xcb);
|
||||
|
||||
return true;
|
||||
return &commit->commit;
|
||||
}
|
||||
|
||||
static void update_x11_output_cursor(struct wlr_x11_output *output,
|
||||
|
|
@ -541,6 +557,7 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
|
|||
}
|
||||
output->x11 = x11;
|
||||
wl_list_init(&output->buffers);
|
||||
wl_list_init(&output->commits);
|
||||
pixman_region32_init(&output->exposed);
|
||||
|
||||
struct wlr_output *wlr_output = &output->wlr_output;
|
||||
|
|
@ -724,6 +741,16 @@ void handle_x11_present_event(struct wlr_x11_backend *x11,
|
|||
flags |= WLR_OUTPUT_PRESENT_ZERO_COPY;
|
||||
}
|
||||
|
||||
uint32_t serial = complete_notify->serial;
|
||||
struct wlr_x11_output_commit *commit = NULL;
|
||||
wl_list_for_each(commit, &output->commits, link) {
|
||||
if (commit->serial == serial) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(commit && commit->serial == serial);
|
||||
|
||||
bool presented = complete_notify->mode != XCB_PRESENT_COMPLETE_MODE_SKIP;
|
||||
struct wlr_output_event_present present_event = {
|
||||
.output = &output->wlr_output,
|
||||
|
|
@ -734,6 +761,10 @@ void handle_x11_present_event(struct wlr_x11_backend *x11,
|
|||
.flags = flags,
|
||||
};
|
||||
wlr_output_send_present(&output->wlr_output, &present_event);
|
||||
wl_signal_emit_mutable(&commit->commit.events.present, &present_event);
|
||||
|
||||
wl_list_remove(&commit->link);
|
||||
free(commit);
|
||||
|
||||
wlr_output_send_frame(&output->wlr_output);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue