kmsdrm: check SDL_HINT_KMSDRM_DEVICE_INDEX hint in dri_getindex(). Otherwise, it would work for Init but not Available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index fb3f1a3..79039ba 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -77,6 +77,15 @@ get_driindex(void)
int i;
int devindex = -1;
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));
folder = opendir(device);
@@ -193,8 +202,9 @@ KMSDRM_Available(void)
kmsdrm_dri_path, kmsdrm_dri_devname);
ret = get_driindex();
- if (ret >= 0)
+ if (ret >= 0) {
return 1;
+ }
return ret;
}
@@ -217,24 +227,15 @@ KMSDRM_CreateDevice(void)
{
SDL_VideoDevice *device;
SDL_VideoData *viddata;
- int devindex = 0; /* !!! FIXME: let app/user specify this. */
- const char *hint;
+ int devindex;
if (!KMSDRM_Available()) {
return NULL;
}
- hint = SDL_GetHint(SDL_HINT_KMSDRM_DEVICE_INDEX);
- if (hint) {
- devindex = SDL_atoi(hint);
- }
-
- if (!devindex || (devindex > 99)) {
- devindex = get_driindex();
- }
-
+ devindex = get_driindex();
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;
}