From f8a50e4fe75ac01a86c94bfedf6cfbaf07c391b2 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 10 Sep 2018 23:35:22 +0200 Subject: backend/drm: steal CRTCs from disabled outputs This commit allows outputs that need a CRTC to steal it from user-disabled outputs. Note that in the case there are enough CRTCs, disabled outputs don't loose it (so there's no modeset and plane initialization needed after DPMS). CRTC allocation still prefers to keep the old configuration, even if that means allocating an extra CRTC to a disabled output. CRTC reallocation now happen when enabling/disabling an output as well as when trying to modeset. When enabling an output without a CRTC, we realloc to try to steal a CRTC from a disabled output (that doesn't really need the CRTC). When disabling an output, we try to give our CRTC to an output that needs one. Modesetting is similar to enabling. A new DRM connector field has been added: `desired_enabled`. Outputs without CRTCs get automatically disabled. This field keeps track of the state desired by the user, allowing to automatically re-enable outputs when a CRTC becomes free. This required some changes to the allocation algorithm. Previously, the algorithm tried to keep the previous configuration even if a new configuration with a better score was possible (it only changed configuration when the old one didn't work anymore). This is now changed and the old configuration (still preferred) is only retained without considering new possibilities when it's perfect (all outputs have CRTCs). User-disabled outputs now have `possible_crtcs` set to 0, meaning they can only retain a previous CRTC (not acquire a new one). The allocation algorithm has been updated to do not bump the score when assigning a CRTC to a disabled output. --- backend/drm/util.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'backend/drm/util.c') diff --git a/backend/drm/util.c b/backend/drm/util.c index 050da2a6..f9637c33 100644 --- a/backend/drm/util.c +++ b/backend/drm/util.c @@ -223,7 +223,8 @@ struct match_state { static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_t replaced, size_t i) { // Finished if (i >= st->num_res) { - if (score > st->score || (score == st->score && replaced < st->replaced)) { + if (score > st->score || + (score == st->score && replaced < st->replaced)) { st->score = score; st->replaced = replaced; memcpy(st->best, st->res, sizeof(st->best[0]) * st->num_res); @@ -243,29 +244,33 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ return match_obj_(st, skips + 1, score, replaced, i + 1); } + bool has_best = false; + /* * Attempt to use the current solution first, to try and avoid * recalculating everything */ if (st->orig[i] != UNMATCHED && !is_taken(i, st->res, st->orig[i])) { st->res[i] = st->orig[i]; - if (match_obj_(st, skips, score + 1, replaced, i + 1)) { - return true; + size_t obj_score = st->objs[st->res[i]] != 0 ? 1 : 0; + if (match_obj_(st, skips, score + obj_score, replaced, i + 1)) { + has_best = true; } } if (st->orig[i] == UNMATCHED) { st->res[i] = UNMATCHED; - match_obj_(st, skips, score, replaced, i + 1); - if (st->exit_early) { - return true; + if (match_obj_(st, skips, score, replaced, i + 1)) { + has_best = true; } } + if (st->exit_early) { + return true; + } if (st->orig[i] != UNMATCHED) { ++replaced; } - bool has_best = false; for (size_t candidate = 0; candidate < st->num_objs; ++candidate) { // We tried this earlier if (candidate == st->orig[i]) { @@ -283,7 +288,8 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ } st->res[i] = candidate; - if (match_obj_(st, skips, score + 1, replaced, i + 1)) { + size_t obj_score = st->objs[candidate] != 0 ? 1 : 0; + if (match_obj_(st, skips, score + obj_score, replaced, i + 1)) { has_best = true; } -- cgit v1.2.3