backend/drm: remove conn_enable from interface

Use crtc_commit instead.
This commit is contained in:
Simon Ser 2020-05-07 21:11:43 +02:00
parent c608fc89d8
commit f8e02db4bc
5 changed files with 91 additions and 75 deletions

View File

@ -69,6 +69,22 @@ static void atomic_add(struct atomic *atom, uint32_t id, uint32_t prop, uint64_t
} }
} }
static bool create_mode_blob(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, uint32_t *blob_id) {
if (!crtc->active) {
*blob_id = 0;
return true;
}
if (drmModeCreatePropertyBlob(drm->fd, &crtc->mode,
sizeof(drmModeModeInfo), blob_id)) {
wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
return false;
}
return true;
}
static bool create_gamma_lut_blob(struct wlr_drm_backend *drm, static bool create_gamma_lut_blob(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, uint32_t *blob_id) { struct wlr_drm_crtc *crtc, uint32_t *blob_id) {
if (crtc->gamma_table_size == 0) { if (crtc->gamma_table_size == 0) {
@ -148,15 +164,12 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, uint32_t flags) { struct wlr_drm_connector *conn, uint32_t flags) {
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
bool modeset = crtc->pending & WLR_DRM_CRTC_MODE; if (crtc->pending & WLR_DRM_CRTC_MODE) {
if (modeset) {
if (crtc->mode_id != 0) { if (crtc->mode_id != 0) {
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id); drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
} }
if (drmModeCreatePropertyBlob(drm->fd, &crtc->mode, if (!create_mode_blob(drm, crtc, &crtc->mode_id)) {
sizeof(drmModeModeInfo), &crtc->mode_id)) {
wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
return false; return false;
} }
} }
@ -179,6 +192,7 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
} }
} }
bool modeset = crtc->pending & WLR_DRM_CRTC_MODE;
if (modeset) { if (modeset) {
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
} else { } else {
@ -187,20 +201,28 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct atomic atom; struct atomic atom;
atomic_begin(crtc, &atom); atomic_begin(crtc, &atom);
atomic_add(&atom, conn->id, conn->props.crtc_id, crtc->id); atomic_add(&atom, conn->id, conn->props.crtc_id,
if (modeset && conn->props.link_status != 0) { crtc->active ? crtc->id : 0);
if (modeset && crtc->active && conn->props.link_status != 0) {
atomic_add(&atom, conn->id, conn->props.link_status, atomic_add(&atom, conn->id, conn->props.link_status,
DRM_MODE_LINK_STATUS_GOOD); DRM_MODE_LINK_STATUS_GOOD);
} }
atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id); atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id);
atomic_add(&atom, crtc->id, crtc->props.active, 1); atomic_add(&atom, crtc->id, crtc->props.active, crtc->active);
atomic_add(&atom, crtc->id, crtc->props.gamma_lut, crtc->gamma_lut); if (crtc->active) {
set_plane_props(&atom, drm, crtc->primary, crtc->id, 0, 0); atomic_add(&atom, crtc->id, crtc->props.gamma_lut, crtc->gamma_lut);
if (crtc->cursor) { set_plane_props(&atom, drm, crtc->primary, crtc->id, 0, 0);
if (crtc->cursor->cursor_enabled) { if (crtc->cursor) {
set_plane_props(&atom, drm, crtc->cursor, crtc->id, if (crtc->cursor->cursor_enabled) {
conn->cursor_x, conn->cursor_y); set_plane_props(&atom, drm, crtc->cursor, crtc->id,
} else { conn->cursor_x, conn->cursor_y);
} else {
plane_disable(&atom, crtc->cursor);
}
}
} else {
plane_disable(&atom, crtc->primary);
if (crtc->cursor) {
plane_disable(&atom, crtc->cursor); plane_disable(&atom, crtc->cursor);
} }
} }
@ -215,33 +237,12 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
return false; return false;
} }
if (crtc->cursor) { if (crtc->active && crtc->cursor) {
drm_fb_move(&crtc->cursor->queued_fb, &crtc->cursor->pending_fb); drm_fb_move(&crtc->cursor->queued_fb, &crtc->cursor->pending_fb);
} }
return true; return true;
} }
static bool atomic_conn_enable(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, bool enable) {
struct wlr_drm_crtc *crtc = conn->crtc;
if (crtc == NULL) {
return !enable;
}
struct atomic atom;
atomic_begin(crtc, &atom);
atomic_add(&atom, crtc->id, crtc->props.active, enable);
if (enable) {
atomic_add(&atom, conn->id, conn->props.crtc_id, crtc->id);
atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id);
} else {
atomic_add(&atom, conn->id, conn->props.crtc_id, 0);
atomic_add(&atom, crtc->id, crtc->props.mode_id, 0);
}
return atomic_commit(drm->fd, &atom, conn, DRM_MODE_ATOMIC_ALLOW_MODESET,
true);
}
static bool atomic_crtc_set_cursor(struct wlr_drm_backend *drm, static bool atomic_crtc_set_cursor(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, struct gbm_bo *bo) { struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
/* Cursor updates happen when we pageflip */ /* Cursor updates happen when we pageflip */
@ -265,7 +266,6 @@ static size_t atomic_crtc_get_gamma_size(struct wlr_drm_backend *drm,
} }
const struct wlr_drm_interface atomic_iface = { const struct wlr_drm_interface atomic_iface = {
.conn_enable = atomic_conn_enable,
.crtc_commit = atomic_crtc_commit, .crtc_commit = atomic_crtc_commit,
.crtc_set_cursor = atomic_crtc_set_cursor, .crtc_set_cursor = atomic_crtc_set_cursor,
.crtc_get_gamma_size = atomic_crtc_get_gamma_size, .crtc_get_gamma_size = atomic_crtc_get_gamma_size,

View File

@ -334,10 +334,17 @@ static bool drm_connector_attach_render(struct wlr_output *output,
return drm_surface_make_current(&conn->crtc->primary->surf, buffer_age); return drm_surface_make_current(&conn->crtc->primary->surf, buffer_age);
} }
static bool drm_crtc_page_flip(struct wlr_drm_connector *conn) { static bool drm_crtc_commit(struct wlr_drm_connector *conn, uint32_t flags) {
struct wlr_drm_backend *drm = struct wlr_drm_backend *drm =
get_drm_backend_from_backend(conn->output.backend); get_drm_backend_from_backend(conn->output.backend);
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
bool ok = drm->iface->crtc_commit(drm, conn, flags);
crtc->pending = 0;
return ok;
}
static bool drm_crtc_page_flip(struct wlr_drm_connector *conn) {
struct wlr_drm_crtc *crtc = conn->crtc;
if (conn->pageflip_pending) { if (conn->pageflip_pending) {
wlr_log(WLR_ERROR, "Failed to page-flip output '%s': " wlr_log(WLR_ERROR, "Failed to page-flip output '%s': "
@ -345,11 +352,9 @@ static bool drm_crtc_page_flip(struct wlr_drm_connector *conn) {
return false; return false;
} }
bool ok = drm->iface->crtc_commit(drm, conn, DRM_MODE_PAGE_FLIP_EVENT); assert(crtc->active);
assert(plane_get_next_fb(crtc->primary)->type != WLR_DRM_FB_TYPE_NONE);
crtc->pending = 0; if (!drm_crtc_commit(conn, DRM_MODE_PAGE_FLIP_EVENT)) {
if (!ok) {
return false; return false;
} }
@ -690,6 +695,7 @@ static void drm_connector_start_renderer(struct wlr_drm_connector *conn) {
struct wlr_drm_mode *mode = (struct wlr_drm_mode *)conn->output.current_mode; struct wlr_drm_mode *mode = (struct wlr_drm_mode *)conn->output.current_mode;
memcpy(&crtc->mode, &mode->drm_mode, sizeof(drmModeModeInfo)); memcpy(&crtc->mode, &mode->drm_mode, sizeof(drmModeModeInfo));
crtc->active = true;
crtc->pending |= WLR_DRM_CRTC_MODE; crtc->pending |= WLR_DRM_CRTC_MODE;
if (!drm_connector_pageflip_renderer(conn)) { if (!drm_connector_pageflip_renderer(conn)) {
@ -721,6 +727,7 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
crtc->pending |= WLR_DRM_CRTC_MODE; crtc->pending |= WLR_DRM_CRTC_MODE;
memcpy(&crtc->mode, &mode->drm_mode, sizeof(drmModeModeInfo)); memcpy(&crtc->mode, &mode->drm_mode, sizeof(drmModeModeInfo));
crtc->active = true;
int width = mode->wlr_mode.width; int width = mode->wlr_mode.width;
int height = mode->wlr_mode.height; int height = mode->wlr_mode.height;
@ -796,8 +803,14 @@ bool enable_drm_connector(struct wlr_output *output, bool enable) {
realloc_crtcs(drm); realloc_crtcs(drm);
} }
bool ok = drm->iface->conn_enable(drm, conn, enable); if (conn->crtc == NULL) {
if (!ok) { wlr_output_update_enabled(&conn->output, false);
return !enable;
}
conn->crtc->active = enable;
conn->crtc->pending |= WLR_DRM_CRTC_MODE;
if (!drm_crtc_commit(conn, 0)) {
return false; return false;
} }
@ -1112,11 +1125,10 @@ static void dealloc_crtc(struct wlr_drm_connector *conn) {
conn->crtc - drm->crtcs, conn->output.name); conn->crtc - drm->crtcs, conn->output.name);
set_drm_connector_gamma(&conn->output, 0, NULL, NULL, NULL); set_drm_connector_gamma(&conn->output, 0, NULL, NULL, NULL);
enable_drm_connector(&conn->output, false);
drm_plane_finish_surface(conn->crtc->primary); drm_plane_finish_surface(conn->crtc->primary);
drm_plane_finish_surface(conn->crtc->cursor); drm_plane_finish_surface(conn->crtc->cursor);
drm->iface->conn_enable(drm, conn, false);
conn->crtc = NULL; conn->crtc = NULL;
} }

View File

@ -11,21 +11,41 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *cursor = crtc->cursor; struct wlr_drm_plane *cursor = crtc->cursor;
struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary); uint32_t fb_id = 0;
struct gbm_bo *bo = drm_fb_acquire(fb, drm, &crtc->primary->mgpu_surf); if (crtc->active) {
if (!bo) { struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
return false; struct gbm_bo *bo = drm_fb_acquire(fb, drm, &crtc->primary->mgpu_surf);
} if (!bo) {
return false;
}
uint32_t fb_id = get_fb_for_bo(bo, drm->addfb2_modifiers); fb_id = get_fb_for_bo(bo, drm->addfb2_modifiers);
if (!fb_id) { if (!fb_id) {
return false; return false;
}
} }
if (crtc->pending & WLR_DRM_CRTC_MODE) { if (crtc->pending & WLR_DRM_CRTC_MODE) {
uint32_t *conns = NULL;
size_t conns_len = 0;
drmModeModeInfo *mode = NULL;
if (crtc->active) {
conns = &conn->id;
conns_len = 1;
mode = &crtc->mode;
}
if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
crtc->active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF) != 0) {
wlr_log_errno(WLR_ERROR, "%s: failed to set DPMS property",
conn->output.name);
return false;
}
if (drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0, if (drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0,
&conn->id, 1, &crtc->mode)) { conns, conns_len, mode)) {
wlr_log_errno(WLR_ERROR, "%s: Failed to set CRTC", conn->output.name); wlr_log_errno(WLR_ERROR, "%s: failed to set CRTC",
conn->output.name);
return false; return false;
} }
} }
@ -53,19 +73,6 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
return true; return true;
} }
static bool legacy_conn_enable(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, bool enable) {
int ret = drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF);
if (!enable) {
drmModeSetCrtc(drm->fd, conn->crtc->id, 0, 0, 0, NULL, 0,
NULL);
}
return ret >= 0;
}
bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm, bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, struct gbm_bo *bo) { struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
if (!crtc || !crtc->cursor) { if (!crtc || !crtc->cursor) {
@ -116,7 +123,6 @@ static size_t legacy_crtc_get_gamma_size(struct wlr_drm_backend *drm,
} }
const struct wlr_drm_interface legacy_iface = { const struct wlr_drm_interface legacy_iface = {
.conn_enable = legacy_conn_enable,
.crtc_commit = legacy_crtc_commit, .crtc_commit = legacy_crtc_commit,
.crtc_set_cursor = legacy_crtc_set_cursor, .crtc_set_cursor = legacy_crtc_set_cursor,
.crtc_get_gamma_size = legacy_crtc_get_gamma_size, .crtc_get_gamma_size = legacy_crtc_get_gamma_size,

View File

@ -51,6 +51,7 @@ struct wlr_drm_crtc {
uint32_t id; uint32_t id;
uint32_t pending; // bitfield of enum wlr_drm_crtc_field uint32_t pending; // bitfield of enum wlr_drm_crtc_field
bool active;
drmModeModeInfo mode; drmModeModeInfo mode;
// Atomic modesetting only // Atomic modesetting only

View File

@ -13,9 +13,6 @@ struct wlr_drm_crtc;
// Used to provide atomic or legacy DRM functions // Used to provide atomic or legacy DRM functions
struct wlr_drm_interface { struct wlr_drm_interface {
// Enable or disable DPMS for connector
bool (*conn_enable)(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, bool enable);
// Commit al pending changes on a CRTC. // Commit al pending changes on a CRTC.
bool (*crtc_commit)(struct wlr_drm_backend *drm, bool (*crtc_commit)(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, uint32_t flags); struct wlr_drm_connector *conn, uint32_t flags);