mirror of https://github.com/encounter/SDL.git
Pick up new display mode information after a mode change (Windows only right now).
This commit is contained in:
parent
5333deab1c
commit
a29a925d7e
|
@ -70,40 +70,16 @@ WIN_GetMonitorDPI(HMONITOR hMonitor,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static void
|
||||||
WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
|
WIN_UpdateDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
|
||||||
{
|
{
|
||||||
SDL_VideoData *vid_data = (SDL_VideoData *) _this->driverdata;
|
SDL_VideoData *vid_data = (SDL_VideoData *) _this->driverdata;
|
||||||
SDL_DisplayModeData *data;
|
SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
|
||||||
DEVMODE devmode;
|
|
||||||
HDC hdc;
|
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 =
|
data->DeviceMode.dmFields =
|
||||||
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
|
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
|
||||||
DM_DISPLAYFLAGS);
|
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
|
if (index == ENUM_CURRENT_SETTINGS
|
||||||
&& (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
|
&& (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_width = GetDeviceCaps( hdc, HORZRES );
|
||||||
int logical_height = GetDeviceCaps( hdc, VERTRES );
|
int logical_height = GetDeviceCaps( hdc, VERTRES );
|
||||||
|
|
||||||
data->ScaleX = (float)logical_width / devmode.dmPelsWidth;
|
data->ScaleX = (float)logical_width / data->DeviceMode.dmPelsWidth;
|
||||||
data->ScaleY = (float)logical_height / devmode.dmPelsHeight;
|
data->ScaleY = (float)logical_height / data->DeviceMode.dmPelsHeight;
|
||||||
mode->w = logical_width;
|
mode->w = logical_width;
|
||||||
mode->h = logical_height;
|
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.vid_data = vid_data;
|
||||||
dpi_data.mode = mode;
|
dpi_data.mode = mode;
|
||||||
dpi_data.mode_data = data;
|
dpi_data.mode_data = data;
|
||||||
monitor_rect.left = devmode.dmPosition.x;
|
monitor_rect.left = data->DeviceMode.dmPosition.x;
|
||||||
monitor_rect.top = devmode.dmPosition.y;
|
monitor_rect.top = data->DeviceMode.dmPosition.y;
|
||||||
monitor_rect.right = monitor_rect.left + 1;
|
monitor_rect.right = monitor_rect.left + 1;
|
||||||
monitor_rect.bottom = monitor_rect.top + 1;
|
monitor_rect.bottom = monitor_rect.top + 1;
|
||||||
EnumDisplayMonitors(NULL, &monitor_rect, WIN_GetMonitorDPI, (LPARAM)&dpi_data);
|
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) {
|
} else if (bmi->bmiHeader.biBitCount == 4) {
|
||||||
mode->format = SDL_PIXELFORMAT_INDEX4LSB;
|
mode->format = SDL_PIXELFORMAT_INDEX4LSB;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (mode->format == SDL_PIXELFORMAT_UNKNOWN) {
|
||||||
/* FIXME: Can we tell what this will be? */
|
/* FIXME: Can we tell what this will be? */
|
||||||
if ((devmode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
|
if ((data->DeviceMode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
|
||||||
switch (devmode.dmBitsPerPel) {
|
switch (data->DeviceMode.dmBitsPerPel) {
|
||||||
case 32:
|
case 32:
|
||||||
mode->format = SDL_PIXELFORMAT_RGB888;
|
mode->format = SDL_PIXELFORMAT_RGB888;
|
||||||
break;
|
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;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,6 +439,7 @@ WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
||||||
return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
|
return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
|
||||||
}
|
}
|
||||||
EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
|
EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
|
||||||
|
WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue