Pick up new display mode information after a mode change (Windows only right now).

Sam Lantinga 2016-03-11 08:33:47 -08:00
parent 5333deab1c
commit a29a925d7e
1 changed files with 47 additions and 34 deletions

View File

@ -70,40 +70,16 @@ WIN_GetMonitorDPI(HMONITOR hMonitor,
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 @@ WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mod
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 @@ WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mod
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 @@ WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mod
} 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 @@ WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mod
}
}
}
}
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 @@ WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
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;
}