Merge pull request #286 from versusvoid/update-connector-crtc-bindings

Update Connector-CRTC bindings after resume in DRM backend
This commit is contained in:
Scott Anderson 2017-10-23 20:25:40 +13:00 committed by GitHub
commit 75f0a6c998
2 changed files with 65 additions and 28 deletions

View file

@ -62,10 +62,13 @@ static void session_signal(struct wl_listener *listener, void *data) {
if (session->active) { if (session->active) {
wlr_log(L_INFO, "DRM fd resumed"); wlr_log(L_INFO, "DRM fd resumed");
wlr_drm_scan_connectors(drm);
struct wlr_drm_connector *conn; struct wlr_drm_connector *conn;
wl_list_for_each(conn, &drm->outputs, link){ wl_list_for_each(conn, &drm->outputs, link){
wlr_drm_connector_start_renderer(conn); if (conn->output.current_mode) {
wlr_output_set_mode(&conn->output, conn->output.current_mode);
}
if (!conn->crtc) { if (!conn->crtc) {
continue; continue;

View file

@ -259,7 +259,8 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) {
} }
} }
static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in) { static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in,
bool *changed_outputs) {
// overlay, primary, cursor // overlay, primary, cursor
for (int type = 0; type < 3; ++type) { for (int type = 0; type < 3; ++type) {
if (drm->num_type_planes[type] == 0) { if (drm->num_type_planes[type] == 0) {
@ -298,6 +299,7 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in)
struct wlr_drm_plane *new = &drm->type_planes[type][crtc_res[i]]; struct wlr_drm_plane *new = &drm->type_planes[type][crtc_res[i]];
if (*old != new) { if (*old != new) {
changed_outputs[crtc_res[i]] = true;
if (*old) { if (*old) {
wlr_drm_surface_finish(&(*old)->surf); wlr_drm_surface_finish(&(*old)->surf);
} }
@ -308,10 +310,12 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in)
} }
} }
static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn) { static void realloc_crtcs(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, bool *changed_outputs) {
uint32_t crtc[drm->num_crtcs]; uint32_t crtc[drm->num_crtcs];
uint32_t crtc_res[drm->num_crtcs]; uint32_t crtc_res[drm->num_crtcs];
uint32_t possible_crtc[wl_list_length(&drm->outputs)]; ssize_t num_outputs = wl_list_length(&drm->outputs);
uint32_t possible_crtc[num_outputs];
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
crtc[i] = UNMATCHED; crtc[i] = UNMATCHED;
@ -327,41 +331,50 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
index = i; index = i;
} }
if (c->state != WLR_DRM_CONN_CONNECTED) { if (c->crtc) {
continue; crtc[c->crtc - drm->crtcs] = i;
}
if (c->state == WLR_DRM_CONN_CONNECTED) {
possible_crtc[i] = c->possible_crtc;
} }
possible_crtc[i] = c->possible_crtc;
crtc[c->crtc - drm->crtcs] = i;
} }
assert(index != -1); assert(index != -1);
possible_crtc[index] = conn->possible_crtc; possible_crtc[index] = conn->possible_crtc;
match_obj(wl_list_length(&drm->outputs), possible_crtc, drm->num_crtcs, match_obj(wl_list_length(&drm->outputs), possible_crtc,
crtc, crtc_res); drm->num_crtcs, crtc, crtc_res);
bool matched = false; bool matched[num_outputs];
memset(matched, false, sizeof(matched));
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
// We don't want any of the current monitors to be deactivated. if (crtc_res[i] != UNMATCHED) {
if (crtc[i] != UNMATCHED && crtc_res[i] == UNMATCHED) { matched[crtc_res[i]] = true;
return;
}
if (crtc_res[i] == index) {
matched = true;
} }
} }
// There is no point doing anything if this monitor doesn't get activated // There is no point doing anything if this monitor doesn't get activated
if (!matched) { if (!matched[index]) {
return; return;
} }
for (size_t i = 0; i < drm->num_crtcs; ++i) {
// We don't want any of the current monitors to be deactivated.
if (crtc[i] != UNMATCHED && !matched[crtc[i]]) {
return;
}
}
changed_outputs[index] = true;
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
if (crtc_res[i] == UNMATCHED) { if (crtc_res[i] == UNMATCHED) {
continue; continue;
} }
if (crtc_res[i] != crtc[i]) { if (crtc_res[i] != crtc[i]) {
changed_outputs[crtc_res[i]] = true;
struct wlr_drm_connector *c; struct wlr_drm_connector *c;
size_t pos = 0; size_t pos = 0;
wl_list_for_each(c, &drm->outputs, link) { wl_list_for_each(c, &drm->outputs, link) {
@ -374,7 +387,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
} }
} }
realloc_planes(drm, crtc_res); realloc_planes(drm, crtc_res, changed_outputs);
} }
static uint32_t get_possible_crtcs(int fd, uint32_t conn_id) { static uint32_t get_possible_crtcs(int fd, uint32_t conn_id) {
@ -413,6 +426,7 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output,
struct wlr_output_mode *mode) { struct wlr_output_mode *mode) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
bool changed_outputs[wl_list_length(&drm->outputs)];
wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", conn->output.name, wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", conn->output.name,
mode->width, mode->height, mode->refresh); mode->width, mode->height, mode->refresh);
@ -422,7 +436,8 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output,
goto error_conn; goto error_conn;
} }
realloc_crtcs(drm, conn); memset(changed_outputs, false, sizeof(changed_outputs));
realloc_crtcs(drm, conn, changed_outputs);
if (!conn->crtc) { if (!conn->crtc) {
wlr_log(L_ERROR, "Unable to match %s with a CRTC", conn->output.name); wlr_log(L_ERROR, "Unable to match %s with a CRTC", conn->output.name);
@ -437,18 +452,23 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output,
crtc->cursor ? crtc->cursor - drm->cursor_planes : -1); crtc->cursor ? crtc->cursor - drm->cursor_planes : -1);
conn->state = WLR_DRM_CONN_CONNECTED; conn->state = WLR_DRM_CONN_CONNECTED;
conn->output.width = mode->width;
conn->output.height = mode->height;
conn->output.current_mode = mode; conn->output.current_mode = mode;
wl_signal_emit(&conn->output.events.resolution, &conn->output); if (conn->output.width != mode->width || conn->output.height != mode->height) {
conn->output.width = mode->width;
conn->output.height = mode->height;
wl_signal_emit(&conn->output.events.resolution, &conn->output);
}
// Since realloc_crtcs can deallocate planes on OTHER outputs, // Since realloc_crtcs can deallocate planes on OTHER outputs,
// we actually need to reinitalise all of them // we actually need to reinitalise any than has changed
ssize_t output_index = -1;
wl_list_for_each(conn, &drm->outputs, link) { wl_list_for_each(conn, &drm->outputs, link) {
output_index += 1;
struct wlr_output_mode *mode = conn->output.current_mode; struct wlr_output_mode *mode = conn->output.current_mode;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
if (conn->state != WLR_DRM_CONN_CONNECTED) { if (conn->state != WLR_DRM_CONN_CONNECTED ||
!changed_outputs[output_index]) {
continue; continue;
} }
@ -698,6 +718,9 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wlr_log_errno(L_ERROR, "Failed to get DRM connector"); wlr_log_errno(L_ERROR, "Failed to get DRM connector");
continue; continue;
} }
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);
int index = -1; int index = -1;
struct wlr_drm_connector *c, *wlr_conn = NULL; struct wlr_drm_connector *c, *wlr_conn = NULL;
wl_list_for_each(c, &drm->outputs, link) { wl_list_for_each(c, &drm->outputs, link) {
@ -707,10 +730,12 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
break; break;
} }
} }
if (!wlr_conn) { if (!wlr_conn) {
wlr_conn = calloc(1, sizeof(*wlr_conn)); wlr_conn = calloc(1, sizeof(*wlr_conn));
if (!wlr_conn) { if (!wlr_conn) {
wlr_log_errno(L_ERROR, "Allocation failed"); wlr_log_errno(L_ERROR, "Allocation failed");
drmModeFreeEncoder(curr_enc);
drmModeFreeConnector(drm_conn); drmModeFreeConnector(drm_conn);
continue; continue;
} }
@ -724,11 +749,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wlr_conn->state = WLR_DRM_CONN_DISCONNECTED; wlr_conn->state = WLR_DRM_CONN_DISCONNECTED;
wlr_conn->id = drm_conn->connector_id; wlr_conn->id = drm_conn->connector_id;
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);
if (curr_enc) { if (curr_enc) {
wlr_conn->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id); wlr_conn->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id);
drmModeFreeEncoder(curr_enc);
} }
wlr_conn->output.phys_width = drm_conn->mmWidth; wlr_conn->output.phys_width = drm_conn->mmWidth;
@ -753,6 +775,17 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
seen[index] = true; seen[index] = true;
} }
if (curr_enc) {
for (size_t i = 0; i < drm->num_crtcs; ++i) {
if (drm->crtcs[i].id == curr_enc->crtc_id) {
wlr_conn->crtc = &drm->crtcs[i];
break;
}
}
} else {
wlr_conn->crtc = NULL;
}
if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED && if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED &&
drm_conn->connection == DRM_MODE_CONNECTED) { drm_conn->connection == DRM_MODE_CONNECTED) {
wlr_log(L_INFO, "'%s' connected", wlr_conn->output.name); wlr_log(L_INFO, "'%s' connected", wlr_conn->output.name);
@ -790,6 +823,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wlr_drm_connector_cleanup(wlr_conn); wlr_drm_connector_cleanup(wlr_conn);
} }
drmModeFreeEncoder(curr_enc);
drmModeFreeConnector(drm_conn); drmModeFreeConnector(drm_conn);
} }