kmsdrm: check SDL_HINT_KMSDRM_DEVICE_INDEX hint in dri_getindex().

Otherwise, it would work for Init but not Available.
This commit is contained in:
Ryan C. Gordon 2022-07-26 15:11:19 -04:00
parent 218c3dbb34
commit 542a4da3d6
No known key found for this signature in database
GPG key ID: FA148B892AB48044

View file

@ -77,6 +77,15 @@ get_driindex(void)
int i; int i;
int devindex = -1; int devindex = -1;
DIR *folder; DIR *folder;
const char *hint;
hint = SDL_GetHint(SDL_HINT_KMSDRM_DEVICE_INDEX);
if (hint) {
const int idx = SDL_atoi(hint);
if ((idx >= 0) && (idx < 99)) {
return idx; /* we'll take the user's request here. */
}
}
SDL_strlcpy(device, kmsdrm_dri_path, sizeof(device)); SDL_strlcpy(device, kmsdrm_dri_path, sizeof(device));
folder = opendir(device); folder = opendir(device);
@ -193,8 +202,9 @@ KMSDRM_Available(void)
kmsdrm_dri_path, kmsdrm_dri_devname); kmsdrm_dri_path, kmsdrm_dri_devname);
ret = get_driindex(); ret = get_driindex();
if (ret >= 0) if (ret >= 0) {
return 1; return 1;
}
return ret; return ret;
} }
@ -217,24 +227,15 @@ KMSDRM_CreateDevice(void)
{ {
SDL_VideoDevice *device; SDL_VideoDevice *device;
SDL_VideoData *viddata; SDL_VideoData *viddata;
int devindex = 0; /* !!! FIXME: let app/user specify this. */ int devindex;
const char *hint;
if (!KMSDRM_Available()) { if (!KMSDRM_Available()) {
return NULL; return NULL;
} }
hint = SDL_GetHint(SDL_HINT_KMSDRM_DEVICE_INDEX); devindex = get_driindex();
if (hint) {
devindex = SDL_atoi(hint);
}
if (!devindex || (devindex > 99)) {
devindex = get_driindex();
}
if (devindex < 0) { if (devindex < 0) {
SDL_SetError("devindex (%d) must be between 0 and 99.\n", devindex); SDL_SetError("devindex (%d) must be between 0 and 99.", devindex);
return NULL; return NULL;
} }