kmsdrm: settle with first card that has a connected connector

Previously the first card with non-empty connectors, encoders
and crtcs would be selected, however KMSDRM_VideoInit could still reject
it if the connector was not connected. This allow finding the first card
(in a multi GPU setup) that is actually connected to a display.
This commit is contained in:
RALOVICH, Kristof 2020-07-19 21:48:17 -04:00
parent b78b88f7fb
commit 155fdc7ac0
1 changed files with 15 additions and 1 deletions

View File

@ -56,6 +56,7 @@ check_modesetting(int devindex)
int drm_fd; int drm_fd;
SDL_snprintf(device, sizeof (device), "%scard%d", KMSDRM_DRI_PATH, devindex); SDL_snprintf(device, sizeof (device), "%scard%d", KMSDRM_DRI_PATH, devindex);
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "check_modesetting: probing \"%s\"", device);
drm_fd = open(device, O_RDWR | O_CLOEXEC); drm_fd = open(device, O_RDWR | O_CLOEXEC);
if (drm_fd >= 0) { if (drm_fd >= 0) {
@ -67,7 +68,20 @@ check_modesetting(int devindex)
resources->count_connectors, resources->count_encoders, resources->count_crtcs); resources->count_connectors, resources->count_encoders, resources->count_crtcs);
if (resources->count_connectors > 0 && resources->count_encoders > 0 && resources->count_crtcs > 0) { if (resources->count_connectors > 0 && resources->count_encoders > 0 && resources->count_crtcs > 0) {
for (int i = 0; i < resources->count_connectors; i++) {
drmModeConnector *conn = KMSDRM_drmModeGetConnector(drm_fd, resources->connectors[i]);
if (!conn) {
continue;
}
if (conn->connection == DRM_MODE_CONNECTED && conn->count_modes) {
available = SDL_TRUE; available = SDL_TRUE;
break;
}
KMSDRM_drmModeFreeConnector(conn);
}
} }
KMSDRM_drmModeFreeResources(resources); KMSDRM_drmModeFreeResources(resources);
} }