mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-17 06:46:39 -04:00
Merge branch 'vt-switch-enable-atomic' into 'master'
Draft: backend/drm: use a single commit to restore state after VT switch See merge request wlroots/wlroots!4554
This commit is contained in:
commit
d6cf4a2594
6 changed files with 487 additions and 354 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include <fcntl.h>
|
||||
#include <libliftoff.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
|
@ -126,27 +127,6 @@ static bool add_prop(drmModeAtomicReq *req, uint32_t obj,
|
|||
return true;
|
||||
}
|
||||
|
||||
static void commit_blob(struct wlr_drm_backend *drm,
|
||||
uint32_t *current, uint32_t next) {
|
||||
if (*current == next) {
|
||||
return;
|
||||
}
|
||||
if (*current != 0) {
|
||||
drmModeDestroyPropertyBlob(drm->fd, *current);
|
||||
}
|
||||
*current = next;
|
||||
}
|
||||
|
||||
static void rollback_blob(struct wlr_drm_backend *drm,
|
||||
uint32_t *current, uint32_t next) {
|
||||
if (*current == next) {
|
||||
return;
|
||||
}
|
||||
if (next != 0) {
|
||||
drmModeDestroyPropertyBlob(drm->fd, next);
|
||||
}
|
||||
}
|
||||
|
||||
static bool set_plane_props(struct wlr_drm_plane *plane,
|
||||
struct liftoff_layer *layer, struct wlr_drm_fb *fb, int32_t x, int32_t y, uint64_t zpos) {
|
||||
if (fb == NULL) {
|
||||
|
|
@ -300,86 +280,16 @@ static void update_layer_feedback(struct wlr_drm_backend *drm,
|
|||
wlr_drm_format_set_finish(&formats);
|
||||
}
|
||||
|
||||
static bool crtc_commit(struct wlr_drm_connector *conn,
|
||||
static bool add_connector(drmModeAtomicReq *req,
|
||||
const struct wlr_drm_connector_state *state,
|
||||
struct wlr_drm_page_flip *page_flip, uint32_t flags, bool test_only) {
|
||||
struct wlr_drm_backend *drm = conn->backend;
|
||||
struct wlr_output *output = &conn->output;
|
||||
bool modeset, struct wl_array *fb_damage_clips_arr) {
|
||||
struct wlr_drm_connector *conn = state->connector;
|
||||
struct wlr_drm_crtc *crtc = conn->crtc;
|
||||
|
||||
bool modeset = state->modeset;
|
||||
struct wlr_drm_backend *drm = conn->backend;
|
||||
bool active = state->active;
|
||||
bool ok = true;
|
||||
|
||||
if (modeset && !register_planes_for_crtc(drm, crtc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t mode_id = crtc->mode_id;
|
||||
if (modeset) {
|
||||
if (!create_mode_blob(conn, state, &mode_id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t gamma_lut = crtc->gamma_lut;
|
||||
if (state->base->committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
|
||||
// Fallback to legacy gamma interface when gamma properties are not
|
||||
// available (can happen on older Intel GPUs that support gamma but not
|
||||
// degamma).
|
||||
if (crtc->props.gamma_lut == 0) {
|
||||
if (!drm_legacy_crtc_set_gamma(drm, crtc,
|
||||
state->base->gamma_lut_size,
|
||||
state->base->gamma_lut)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!create_gamma_lut_blob(drm, state->base->gamma_lut_size,
|
||||
state->base->gamma_lut, &gamma_lut)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct wl_array fb_damage_clips_arr = {0};
|
||||
|
||||
uint32_t primary_fb_damage_clips = 0;
|
||||
if ((state->base->committed & WLR_OUTPUT_STATE_DAMAGE) &&
|
||||
crtc->primary->props.fb_damage_clips != 0) {
|
||||
uint32_t *ptr = wl_array_add(&fb_damage_clips_arr, sizeof(primary_fb_damage_clips));
|
||||
if (ptr == NULL) {
|
||||
return false;
|
||||
}
|
||||
create_fb_damage_clips_blob(drm, state->primary_fb->wlr_buf->width,
|
||||
state->primary_fb->wlr_buf->height, &state->base->damage,
|
||||
&primary_fb_damage_clips);
|
||||
*ptr = primary_fb_damage_clips;
|
||||
}
|
||||
|
||||
bool prev_vrr_enabled =
|
||||
output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED;
|
||||
bool vrr_enabled = prev_vrr_enabled;
|
||||
if ((state->base->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED) &&
|
||||
drm_connector_supports_vrr(conn)) {
|
||||
vrr_enabled = state->base->adaptive_sync_enabled;
|
||||
}
|
||||
|
||||
if (test_only) {
|
||||
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
|
||||
}
|
||||
if (modeset) {
|
||||
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
|
||||
}
|
||||
if (!test_only && state->nonblock) {
|
||||
flags |= DRM_MODE_ATOMIC_NONBLOCK;
|
||||
}
|
||||
|
||||
drmModeAtomicReq *req = drmModeAtomicAlloc();
|
||||
if (req == NULL) {
|
||||
wlr_log(WLR_ERROR, "drmModeAtomicAlloc failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = add_prop(req, conn->id, conn->props.crtc_id,
|
||||
ok = ok && add_prop(req, conn->id, conn->props.crtc_id,
|
||||
active ? crtc->id : 0);
|
||||
if (modeset && active && conn->props.link_status != 0) {
|
||||
ok = ok && add_prop(req, conn->id, conn->props.link_status,
|
||||
|
|
@ -391,28 +301,28 @@ static bool crtc_commit(struct wlr_drm_connector *conn,
|
|||
}
|
||||
// TODO: set "max bpc"
|
||||
ok = ok &&
|
||||
add_prop(req, crtc->id, crtc->props.mode_id, mode_id) &&
|
||||
add_prop(req, crtc->id, crtc->props.mode_id, state->mode_id) &&
|
||||
add_prop(req, crtc->id, crtc->props.active, active);
|
||||
if (active) {
|
||||
if (crtc->props.gamma_lut != 0) {
|
||||
ok = ok && add_prop(req, crtc->id, crtc->props.gamma_lut, gamma_lut);
|
||||
ok = ok && add_prop(req, crtc->id, crtc->props.gamma_lut, state->gamma_lut);
|
||||
}
|
||||
if (crtc->props.vrr_enabled != 0) {
|
||||
ok = ok && add_prop(req, crtc->id, crtc->props.vrr_enabled, vrr_enabled);
|
||||
ok = ok && add_prop(req, crtc->id, crtc->props.vrr_enabled, state->vrr_enabled);
|
||||
}
|
||||
ok = ok &&
|
||||
set_plane_props(crtc->primary, crtc->primary->liftoff_layer, state->primary_fb, 0, 0, 0) &&
|
||||
set_plane_props(crtc->primary, crtc->liftoff_composition_layer, state->primary_fb, 0, 0, 0);
|
||||
liftoff_layer_set_property(crtc->primary->liftoff_layer,
|
||||
"FB_DAMAGE_CLIPS", primary_fb_damage_clips);
|
||||
"FB_DAMAGE_CLIPS", state->fb_damage_clips);
|
||||
liftoff_layer_set_property(crtc->liftoff_composition_layer,
|
||||
"FB_DAMAGE_CLIPS", primary_fb_damage_clips);
|
||||
"FB_DAMAGE_CLIPS", state->fb_damage_clips);
|
||||
|
||||
if (state->base->committed & WLR_OUTPUT_STATE_LAYERS) {
|
||||
for (size_t i = 0; i < state->base->layers_len; i++) {
|
||||
const struct wlr_output_layer_state *layer_state = &state->base->layers[i];
|
||||
ok = ok && set_layer_props(drm, layer_state, i + 1,
|
||||
&fb_damage_clips_arr);
|
||||
fb_damage_clips_arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -432,62 +342,101 @@ static bool crtc_commit(struct wlr_drm_connector *conn,
|
|||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
goto out;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void connector_update_layers_feedback(const struct wlr_drm_connector_state *state) {
|
||||
struct wlr_drm_backend *drm = state->connector->backend;
|
||||
|
||||
if (!(state->base->committed & WLR_OUTPUT_STATE_LAYERS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = liftoff_output_apply(crtc->liftoff, req, flags);
|
||||
if (ret != 0) {
|
||||
wlr_drm_conn_log(conn, test_only ? WLR_DEBUG : WLR_ERROR,
|
||||
"liftoff_output_apply failed: %s", strerror(-ret));
|
||||
ok = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (crtc->cursor &&
|
||||
liftoff_layer_needs_composition(crtc->cursor->liftoff_layer)) {
|
||||
wlr_drm_conn_log(conn, WLR_DEBUG, "Failed to scan-out cursor plane");
|
||||
ok = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = drmModeAtomicCommit(drm->fd, req, flags, page_flip);
|
||||
if (ret != 0) {
|
||||
wlr_drm_conn_log_errno(conn, test_only ? WLR_DEBUG : WLR_ERROR,
|
||||
"Atomic commit failed");
|
||||
ok = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (state->base->committed & WLR_OUTPUT_STATE_LAYERS) {
|
||||
for (size_t i = 0; i < state->base->layers_len; i++) {
|
||||
struct wlr_output_layer_state *layer_state = &state->base->layers[i];
|
||||
struct wlr_drm_layer *layer = get_drm_layer(drm, layer_state->layer);
|
||||
layer_state->accepted =
|
||||
!liftoff_layer_needs_composition(layer->liftoff);
|
||||
if (!test_only && !layer_state->accepted) {
|
||||
update_layer_feedback(drm, layer);
|
||||
}
|
||||
for (size_t i = 0; i < state->base->layers_len; i++) {
|
||||
struct wlr_output_layer_state *layer_state = &state->base->layers[i];
|
||||
struct wlr_drm_layer *layer = get_drm_layer(drm, layer_state->layer);
|
||||
layer_state->accepted =
|
||||
!liftoff_layer_needs_composition(layer->liftoff);
|
||||
if (!layer_state->accepted) {
|
||||
update_layer_feedback(drm, layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool commit(struct wlr_drm_backend *drm,
|
||||
const struct wlr_drm_device_state *state,
|
||||
struct wlr_drm_page_flip *page_flip, uint32_t flags, bool test_only) {
|
||||
bool ok = false;
|
||||
struct wl_array fb_damage_clips_arr = {0};
|
||||
drmModeAtomicReq *req = NULL;
|
||||
|
||||
if (test_only) {
|
||||
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
|
||||
}
|
||||
if (state->modeset) {
|
||||
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
|
||||
}
|
||||
if (!test_only && state->nonblock) {
|
||||
flags |= DRM_MODE_ATOMIC_NONBLOCK;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < state->connectors_len; i++) {
|
||||
struct wlr_drm_connector_state *conn_state = &state->connectors[i];
|
||||
struct wlr_drm_connector *conn = conn_state->connector;
|
||||
if (state->modeset && !register_planes_for_crtc(drm, conn->crtc)) {
|
||||
goto out;
|
||||
}
|
||||
if (!drm_atomic_connector_prepare(conn_state, state->modeset)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
req = drmModeAtomicAlloc();
|
||||
if (req == NULL) {
|
||||
wlr_log(WLR_ERROR, "drmModeAtomicAlloc failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < state->connectors_len; i++) {
|
||||
if (!add_connector(req, &state->connectors[i], state->modeset, &fb_damage_clips_arr)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < state->connectors_len; i++) {
|
||||
struct wlr_drm_connector *conn = state->connectors[i].connector;
|
||||
struct wlr_drm_crtc *crtc = conn->crtc;
|
||||
|
||||
int ret = liftoff_output_apply(crtc->liftoff, req, flags);
|
||||
if (ret != 0) {
|
||||
wlr_drm_conn_log(conn, test_only ? WLR_DEBUG : WLR_ERROR,
|
||||
"liftoff_output_apply failed: %s", strerror(-ret));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (crtc->cursor &&
|
||||
liftoff_layer_needs_composition(crtc->cursor->liftoff_layer)) {
|
||||
wlr_drm_conn_log(conn, WLR_DEBUG, "Failed to scan-out cursor plane");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ok = drmModeAtomicCommit(drm->fd, req, flags, page_flip) == 0;
|
||||
if (!ok) {
|
||||
wlr_log_errno(test_only ? WLR_DEBUG : WLR_ERROR,
|
||||
"Atomic commit failed");
|
||||
}
|
||||
|
||||
out:
|
||||
drmModeAtomicFree(req);
|
||||
|
||||
if (ok && !test_only) {
|
||||
commit_blob(drm, &crtc->mode_id, mode_id);
|
||||
commit_blob(drm, &crtc->gamma_lut, gamma_lut);
|
||||
|
||||
if (vrr_enabled != prev_vrr_enabled) {
|
||||
output->adaptive_sync_status = vrr_enabled ?
|
||||
WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED :
|
||||
WLR_OUTPUT_ADAPTIVE_SYNC_DISABLED;
|
||||
wlr_drm_conn_log(conn, WLR_DEBUG, "VRR %s",
|
||||
vrr_enabled ? "enabled" : "disabled");
|
||||
for (size_t i = 0; i < state->connectors_len; i++) {
|
||||
struct wlr_drm_connector_state *conn_state = &state->connectors[i];
|
||||
if (ok && !test_only) {
|
||||
drm_atomic_connector_apply_commit(conn_state);
|
||||
connector_update_layers_feedback(conn_state);
|
||||
} else {
|
||||
drm_atomic_connector_rollback_commit(conn_state);
|
||||
}
|
||||
} else {
|
||||
rollback_blob(drm, &crtc->mode_id, mode_id);
|
||||
rollback_blob(drm, &crtc->gamma_lut, gamma_lut);
|
||||
}
|
||||
|
||||
uint32_t *fb_damage_clips_ptr;
|
||||
|
|
@ -504,6 +453,6 @@ out:
|
|||
const struct wlr_drm_interface liftoff_iface = {
|
||||
.init = init,
|
||||
.finish = finish,
|
||||
.crtc_commit = crtc_commit,
|
||||
.commit = commit,
|
||||
.reset = drm_atomic_reset,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue