Skip to content

Commit a37f4c0

Browse files
author
Anton Kindestam
committed
drm_common: Be smarter when deciding on which CRTC and Encoder to use
Inspired by kmscube, first try to pick the Encoder and CRTC already associated with the selected Connector, if any. Otherwise try to find the first matching encoder & CRTC like before. The previous behavior had problems when using atomic modesetting (crtc_setup_atomic) when we picked an Encoder & CRTC that was currently being used by the fbcon together with another Encoder. drmModeSetCrtc was able to "steal" the CRTC in this case, but using atomic modesetting we do not seem to get this behavior automatically. This should also improve behavior somewhat when run on a multi screen setup with regards to deinit and VT switching (still sometimes you end up with a blank screen where you previously had a cloned display of your fbcon)
1 parent 6322297 commit a37f4c0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

video/out/drm_common.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ static bool setup_connector(struct kms *kms, const drmModeRes *res,
173173

174174
static bool setup_crtc(struct kms *kms, const drmModeRes *res)
175175
{
176+
// First try to find currently connected encoder and its current CRTC
177+
for (unsigned int i = 0; i < res->count_encoders; i++) {
178+
drmModeEncoder *encoder = drmModeGetEncoder(kms->fd, res->encoders[i]);
179+
if (!encoder) {
180+
MP_WARN(kms, "Cannot retrieve encoder %u:%u: %s\n",
181+
i, res->encoders[i], mp_strerror(errno));
182+
continue;
183+
}
184+
185+
if (encoder->encoder_id == kms->connector->encoder_id && encoder->crtc_id != 0) {
186+
MP_VERBOSE(kms, "Connector %u currently connected to encoder %u\n",
187+
kms->connector->connector_id, kms->connector->encoder_id);
188+
kms->encoder = encoder;
189+
kms->crtc_id = encoder->crtc_id;
190+
goto success;
191+
}
192+
193+
drmModeFreeEncoder(encoder);
194+
}
195+
196+
// Otherwise pick first legal encoder and CRTC combo for the connector
176197
for (unsigned int i = 0; i < kms->connector->count_encoders; ++i) {
177198
drmModeEncoder *encoder
178199
= drmModeGetEncoder(kms->fd, kms->connector->encoders[i]);
@@ -190,7 +211,7 @@ static bool setup_crtc(struct kms *kms, const drmModeRes *res)
190211

191212
kms->encoder = encoder;
192213
kms->crtc_id = res->crtcs[j];
193-
return true;
214+
goto success;
194215
}
195216

196217
drmModeFreeEncoder(encoder);
@@ -199,6 +220,11 @@ static bool setup_crtc(struct kms *kms, const drmModeRes *res)
199220
MP_ERR(kms, "Connector %u has no suitable CRTC\n",
200221
kms->connector->connector_id);
201222
return false;
223+
224+
success:
225+
MP_VERBOSE(kms, "Selected Encoder %u with CRTC %u\n",
226+
kms->encoder->encoder_id, kms->crtc_id);
227+
return true;
202228
}
203229

204230
static bool setup_mode(struct kms *kms, int mode_id)

0 commit comments

Comments
 (0)