[Commits] SDL: Pick up new display mode information after a mode change (W...

libsdl.org revision control commits-owner at libsdl.org
Fri Mar 11 16:34:25 PST 2016


details:   https://hg.libsdl.org/SDL/rev/7552aa4c1c6d
changeset: 10117:7552aa4c1c6d
user:      Sam Lantinga <slouken at libsdl.org>
date:      Fri Mar 11 08:33:47 2016 -0800
description:
Pick up new display mode information after a mode change (Windows only right now).

diffstat:

 src/video/windows/SDL_windowsmodes.c |  81 ++++++++++++++++++++---------------
 1 files changed, 47 insertions(+), 34 deletions(-)

diffs (134 lines):

diff -r 418691d83f6a -r 7552aa4c1c6d src/video/windows/SDL_windowsmodes.c
--- a/src/video/windows/SDL_windowsmodes.c	Fri Mar 11 08:30:18 2016 -0800
+++ b/src/video/windows/SDL_windowsmodes.c	Fri Mar 11 08:33:47 2016 -0800
@@ -70,40 +70,16 @@
     return TRUE;
 }
 
-static SDL_bool
-WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
+static void
+WIN_UpdateDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
 {
     SDL_VideoData *vid_data = (SDL_VideoData *) _this->driverdata;
-    SDL_DisplayModeData *data;
-    DEVMODE devmode;
+    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
     HDC hdc;
 
-    devmode.dmSize = sizeof(devmode);
-    devmode.dmDriverExtra = 0;
-    if (!EnumDisplaySettings(deviceName, index, &devmode)) {
-        return SDL_FALSE;
-    }
-
-    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
-    if (!data) {
-        return SDL_FALSE;
-    }
-    data->DeviceMode = devmode;
     data->DeviceMode.dmFields =
         (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
          DM_DISPLAYFLAGS);
-    data->ScaleX = 1.0f;
-    data->ScaleY = 1.0f;
-    data->DiagDPI = 0.0f;
-    data->HorzDPI = 0.0f;
-    data->VertDPI = 0.0f;
-
-    /* Fill in the mode information */
-    mode->format = SDL_PIXELFORMAT_UNKNOWN;
-    mode->w = devmode.dmPelsWidth;
-    mode->h = devmode.dmPelsHeight;
-    mode->refresh_rate = devmode.dmDisplayFrequency;
-    mode->driverdata = data;
 
     if (index == ENUM_CURRENT_SETTINGS
         && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
@@ -113,8 +89,8 @@
         int logical_width = GetDeviceCaps( hdc, HORZRES );
         int logical_height = GetDeviceCaps( hdc, VERTRES );
 
-        data->ScaleX = (float)logical_width / devmode.dmPelsWidth;
-        data->ScaleY = (float)logical_height / devmode.dmPelsHeight;
+        data->ScaleX = (float)logical_width / data->DeviceMode.dmPelsWidth;
+        data->ScaleY = (float)logical_height / data->DeviceMode.dmPelsHeight;
         mode->w = logical_width;
         mode->h = logical_height;
 
@@ -127,8 +103,8 @@
             dpi_data.vid_data = vid_data;
             dpi_data.mode = mode;
             dpi_data.mode_data = data;
-            monitor_rect.left = devmode.dmPosition.x;
-            monitor_rect.top = devmode.dmPosition.y;
+            monitor_rect.left = data->DeviceMode.dmPosition.x;
+            monitor_rect.top = data->DeviceMode.dmPosition.y;
             monitor_rect.right = monitor_rect.left + 1;
             monitor_rect.bottom = monitor_rect.top + 1;
             EnumDisplayMonitors(NULL, &monitor_rect, WIN_GetMonitorDPI, (LPARAM)&dpi_data);
@@ -176,10 +152,10 @@
         } else if (bmi->bmiHeader.biBitCount == 4) {
             mode->format = SDL_PIXELFORMAT_INDEX4LSB;
         }
-    } else {
+    } else if (mode->format == SDL_PIXELFORMAT_UNKNOWN) {
         /* FIXME: Can we tell what this will be? */
-        if ((devmode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
-            switch (devmode.dmBitsPerPel) {
+        if ((data->DeviceMode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
+            switch (data->DeviceMode.dmBitsPerPel) {
             case 32:
                 mode->format = SDL_PIXELFORMAT_RGB888;
                 break;
@@ -201,6 +177,42 @@
             }
         }
     }
+}
+
+static SDL_bool
+WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
+{
+    SDL_DisplayModeData *data;
+    DEVMODE devmode;
+
+    devmode.dmSize = sizeof(devmode);
+    devmode.dmDriverExtra = 0;
+    if (!EnumDisplaySettings(deviceName, index, &devmode)) {
+        return SDL_FALSE;
+    }
+
+    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
+    if (!data) {
+        return SDL_FALSE;
+    }
+
+    mode->driverdata = data;
+    data->DeviceMode = devmode;
+
+    /* Default basic information */
+    data->ScaleX = 1.0f;
+    data->ScaleY = 1.0f;
+    data->DiagDPI = 0.0f;
+    data->HorzDPI = 0.0f;
+    data->VertDPI = 0.0f;
+
+    mode->format = SDL_PIXELFORMAT_UNKNOWN;
+    mode->w = data->DeviceMode.dmPelsWidth;
+    mode->h = data->DeviceMode.dmPelsHeight;
+    mode->refresh_rate = data->DeviceMode.dmDisplayFrequency;
+
+    /* Fill in the mode information */
+    WIN_UpdateDisplayMode(_this, deviceName, index, mode);
     return SDL_TRUE;
 }
 
@@ -427,6 +439,7 @@
         return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
     }
     EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
+    WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode);
     return 0;
 }
 


More information about the commits mailing list