kmsdrm: fix KMSDRM_SetDisplayMode being called for the default desktop mode doing nothing
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 60 61
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index b9947ea..84b74fe 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -538,8 +538,10 @@ void KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resource
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
SDL_DisplayData *dispdata = NULL;
SDL_VideoDisplay display = {0};
+ SDL_DisplayModeData *modedata = NULL;
drmModeEncoder *encoder = NULL;
drmModeCrtc *crtc = NULL;
+ int mode_index;
int i, j;
int ret = 0;
@@ -627,6 +629,23 @@ void KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resource
goto cleanup;
}
+ /* Find the index of the mode attached to this CRTC */
+ mode_index = -1;
+
+ for (i = 0; i < connector->count_modes; i++) {
+ drmModeModeInfo *mode = &connector->modes[i];
+
+ if (!memcmp(mode, &crtc->mode, sizeof(crtc->mode))) {
+ mode_index = i;
+ break;
+ }
+ }
+
+ if (mode_index == -1) {
+ ret = SDL_SetError("Failed to find index of mode attached to the CRTC.");
+ goto cleanup;
+ }
+
/*********************************************/
/* Create an SDL Display for this connector. */
/*********************************************/
@@ -657,11 +676,21 @@ void KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resource
/* Setup the display.
There's no problem with it being still incomplete. */
+ modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData));
+
+ if (!modedata) {
+ ret = SDL_OutOfMemory();
+ goto cleanup;
+ }
+
+ modedata->mode_index = mode_index;
+
display.driverdata = dispdata;
display.desktop_mode.w = dispdata->mode.hdisplay;
display.desktop_mode.h = dispdata->mode.vdisplay;
display.desktop_mode.refresh_rate = dispdata->mode.vrefresh;
display.desktop_mode.format = SDL_PIXELFORMAT_ARGB8888;
+ display.desktop_mode.driverdata = modedata;
display.current_mode = display.desktop_mode;
/* Add the display to the list of SDL displays. */