backend/drm: add test_only arg to wlr_drm_interface.crtc_commit

Right now callers of drm_crtc_commit need to check whether the
interface is legacy or atomic before passing the TEST_ONLY flag.
Additionally, the fallbacks for legacy are in-place in the common
code.

Add a test_only arg to the crtc_commit hook. This way, there's no
risk to pass atomic-only flags to the legacy function (add an assert
to ensure this) and all of the legacy-specific logic can be put back
into legacy.c (done in next commit).
This commit is contained in:
Simon Ser 2021-07-08 15:56:01 +02:00 committed by Simon Zeni
parent a362d21d6b
commit 017555651b
4 changed files with 24 additions and 14 deletions

View File

@ -168,7 +168,7 @@ error:
static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t flags) {
uint32_t flags, bool test_only) {
struct wlr_output *output = &conn->output;
struct wlr_drm_crtc *crtc = conn->crtc;
@ -209,9 +209,12 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
vrr_enabled = state->adaptive_sync_enabled;
}
if (test_only) {
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
}
if (modeset) {
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
} else if (!(flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
} else if (!test_only) {
flags |= DRM_MODE_ATOMIC_NONBLOCK;
}
@ -250,7 +253,7 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
bool ok = atomic_commit(&atom, conn, flags);
atomic_finish(&atom);
if (ok && !(flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
if (ok && !test_only) {
commit_blob(drm, &crtc->mode_id, mode_id);
commit_blob(drm, &crtc->gamma_lut, gamma_lut);

View File

@ -345,11 +345,14 @@ static void drm_plane_set_committed(struct wlr_drm_plane *plane) {
}
static bool drm_crtc_commit(struct wlr_drm_connector *conn,
const struct wlr_output_state *state, uint32_t flags) {
const struct wlr_output_state *state, uint32_t flags, bool test_only) {
// Disallow atomic-only flags
assert((flags & ~DRM_MODE_PAGE_FLIP_FLAGS) == 0);
struct wlr_drm_backend *drm = conn->backend;
struct wlr_drm_crtc *crtc = conn->crtc;
bool ok = drm->iface->crtc_commit(drm, conn, state, flags);
if (ok && !(flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
bool ok = drm->iface->crtc_commit(drm, conn, state, flags, test_only);
if (ok && !test_only) {
drm_plane_set_committed(crtc->primary);
if (crtc->cursor != NULL) {
drm_plane_set_committed(crtc->cursor);
@ -383,7 +386,7 @@ static bool drm_crtc_page_flip(struct wlr_drm_connector *conn,
assert(drm_connector_state_active(conn, state));
assert(plane_get_next_fb(crtc->primary));
if (!drm_crtc_commit(conn, state, DRM_MODE_PAGE_FLIP_EVENT)) {
if (!drm_crtc_commit(conn, state, DRM_MODE_PAGE_FLIP_EVENT, false)) {
return false;
}
@ -475,7 +478,7 @@ static bool drm_connector_test(struct wlr_output *output) {
if (!drm_connector_set_pending_fb(conn, &output->pending)) {
return false;
}
if (!drm_crtc_commit(conn, &output->pending, DRM_MODE_ATOMIC_TEST_ONLY)) {
if (!drm_crtc_commit(conn, &output->pending, 0, true)) {
return false;
}
}
@ -559,7 +562,7 @@ bool drm_connector_commit_state(struct wlr_drm_connector *conn,
WLR_OUTPUT_STATE_GAMMA_LUT)) {
assert(conn->crtc != NULL);
// TODO: maybe request a page-flip event here?
if (!drm_crtc_commit(conn, &state, 0)) {
if (!drm_crtc_commit(conn, &state, 0, false)) {
return false;
}
}
@ -677,7 +680,7 @@ static bool drm_connector_test_renderer(struct wlr_drm_connector *conn,
goto out;
}
ok = drm_crtc_commit(conn, state, DRM_MODE_ATOMIC_TEST_ONLY);
ok = drm_crtc_commit(conn, state, 0, true);
out:
drm_fb_move(&plane->pending_fb, &prev_fb);
@ -783,7 +786,7 @@ static bool drm_connector_set_mode(struct wlr_drm_connector *conn,
if (wlr_mode == NULL) {
if (conn->crtc != NULL) {
if (!drm_crtc_commit(conn, state, 0)) {
if (!drm_crtc_commit(conn, state, 0, false)) {
return false;
}
realloc_crtcs(drm);
@ -1128,7 +1131,7 @@ static void dealloc_crtc(struct wlr_drm_connector *conn) {
.committed = WLR_OUTPUT_STATE_ENABLED,
.enabled = false,
};
if (!drm_crtc_commit(conn, &state, 0)) {
if (!drm_crtc_commit(conn, &state, 0, false)) {
// On GPU unplug, disabling the CRTC can fail with EPERM
wlr_drm_conn_log(conn, WLR_ERROR, "Failed to disable CRTC %"PRIu32,
conn->crtc->id);

View File

@ -10,7 +10,11 @@
static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t flags) {
uint32_t flags, bool test_only) {
if (test_only) {
return true;
}
struct wlr_output *output = &conn->output;
struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *cursor = crtc->cursor;

View File

@ -16,7 +16,7 @@ struct wlr_drm_interface {
// Commit al pending changes on a CRTC.
bool (*crtc_commit)(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t flags);
uint32_t flags, bool test_only);
};
extern const struct wlr_drm_interface atomic_iface;