Add full high DPI information to SDL_DisplayMode

SDL_DisplayMode now includes the pixel size, the screen size and the relationship between the two. For example, a 4K display at 200% scale could have a pixel size of 3840x2160, a screen size of 1920x1080, and a display scale of 2.0.
This commit is contained in:
Sam Lantinga 2023-01-27 10:46:51 -08:00
parent b23d20cd4d
commit 24fec13ac1
31 changed files with 370 additions and 345 deletions

View file

@ -954,6 +954,8 @@ The SDL_WINDOW_SHOWN flag has been removed. Windows are shown by default and can
The SDL_WINDOW_ALLOW_HIGHDPI flag has been removed. Windows are automatically high DPI aware and their coordinates are in screen space, which may differ from physical pixels on displays using display scaling.
SDL_DisplayMode now includes the pixel size, the screen size and the relationship between the two. For example, a 4K display at 200% scale could have a pixel size of 3840x2160, a screen size of 1920x1080, and a display scale of 2.0.
The refresh rate in SDL_DisplayMode is now a float.
SDL_SetWindowBrightness and SDL_SetWindowGammaRamp have been removed from the API, because they interact poorly with modern operating systems and aren't able to limit their effects to the SDL window.

View file

@ -56,9 +56,11 @@ typedef Uint32 SDL_WindowID;
typedef struct
{
Uint32 format; /**< pixel format */
int w; /**< width in pixels */
int h; /**< height in pixels */
float display_scale; /**< scale converting screen coordinates to pixels (e.g. a 3840x2160 mode with 1.5 scale would have a screen size of 2560x1440) */
int pixel_w; /**< width in pixels (used for creating back buffers) */
int pixel_h; /**< height in pixels (used for creating back buffers) */
int screen_w; /**< width in screen coordinates (used for creating windows) */
int screen_h; /**< height in screen coordinates (used for creating windows) */
float display_scale; /**< scale converting screen coordinates to pixels (e.g. a 2560x1440 screen size mode with 1.5 scale would have 3840x2160 pixels) */
float refresh_rate; /**< refresh rate (or zero for unspecified) */
void *driverdata; /**< driver-specific data, initialize to 0 */
} SDL_DisplayMode;

View file

@ -116,10 +116,10 @@ static void WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identify
SDL_Window *window = WINRT_GlobalSDLWindow;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
int x = (int)SDL_lroundf(data->coreWindow->Bounds.Left);
int y = (int)SDL_lroundf(data->coreWindow->Bounds.Top);
int w = (int)SDL_floorf(data->coreWindow->Bounds.Width);
int h = (int)SDL_floorf(data->coreWindow->Bounds.Height);
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
/* WinPhone 8.0 always keeps its native window size in portrait,
@ -235,8 +235,8 @@ void SDL_WinRTApp::OnOrientationChanged(Object ^ sender)
SDL_Window *window = WINRT_GlobalSDLWindow;
if (window) {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
int w = (int)SDL_floorf(data->coreWindow->Bounds.Width);
int h = (int)SDL_floorf(data->coreWindow->Bounds.Height);
SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_EVENT_WINDOW_SIZE_CHANGED, w, h);
}
#endif

View file

@ -1130,7 +1130,7 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_GetMasksForPixelFormatEnum(mode.format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
SDL_Log(" Current mode: %dx%d@%gHz, %d%% scale, %d bits-per-pixel (%s)\n",
mode.w, mode.h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), bpp,
mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n", Rmask);
@ -1152,7 +1152,7 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_GetMasksForPixelFormatEnum(mode.format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
SDL_Log(" Mode %d: %dx%d@%gHz, %d%% scale, %d bits-per-pixel (%s)\n",
j, mode.w, mode.h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), bpp,
j, mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n",
@ -2246,7 +2246,7 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
if (0 == SDL_GetWindowDisplayMode(window, &mode)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayMode: %dx%d@%gHz %d%% scale, (%s)",
mode.w, mode.h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format));
mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format));
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
}
@ -2276,14 +2276,14 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%gHz %d%% scale, (%s)",
mode.w, mode.h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format));
mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format));
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
}
if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%gHz %d%% scale, (%s)",
mode.w, mode.h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format));
mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format));
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
}

View file

@ -382,16 +382,16 @@ static int SDLCALL cmpmodes(const void *A, const void *B)
{
const SDL_DisplayMode *a = (const SDL_DisplayMode *)A;
const SDL_DisplayMode *b = (const SDL_DisplayMode *)B;
float a_display_scale = (a->display_scale == 0.0f) ? 1.0f : a->display_scale;
float b_display_scale = (b->display_scale == 0.0f) ? 1.0f : b->display_scale;
if (a == b) {
return 0;
} else if (a->w != b->w) {
return b->w - a->w;
} else if (a->h != b->h) {
return b->h - a->h;
} else if (a_display_scale != b_display_scale) {
return (int)(a_display_scale * 100) - (int)(b_display_scale * 100);
} else if (a->screen_w != b->screen_w) {
return b->screen_w - a->screen_w;
} else if (a->screen_h != b->screen_h) {
return b->screen_h - a->screen_h;
} else if (a->pixel_w != b->pixel_w) {
return b->pixel_w - a->pixel_w;
} else if (a->pixel_h != b->pixel_h) {
return b->pixel_h - a->pixel_h;
} else if (SDL_BITSPERPIXEL(a->format) != SDL_BITSPERPIXEL(b->format)) {
return SDL_BITSPERPIXEL(b->format) - SDL_BITSPERPIXEL(a->format);
} else if (SDL_PIXELLAYOUT(a->format) != SDL_PIXELLAYOUT(b->format)) {
@ -585,6 +585,40 @@ SDL_bool SDL_OnVideoThread()
return (_this && SDL_ThreadID() == _this->thread) ? SDL_TRUE : SDL_FALSE;
}
static void SDL_FinalizeDisplayMode(SDL_DisplayMode *mode)
{
/* Make sure all the fields are set up correctly */
if (mode->display_scale <= 0.0f) {
if (mode->screen_w == 0 && mode->screen_h == 0) {
mode->screen_w = mode->pixel_w;
mode->screen_h = mode->pixel_h;
}
if (mode->pixel_w == 0 && mode->pixel_h == 0) {
mode->pixel_w = mode->screen_w;
mode->pixel_h = mode->screen_h;
}
if (mode->screen_w > 0) {
mode->display_scale = (float)mode->pixel_w / mode->screen_w;
}
} else {
if (mode->screen_w == 0 && mode->screen_h == 0) {
mode->screen_w = (int)SDL_floorf(mode->pixel_w / mode->display_scale);
mode->screen_h = (int)SDL_floorf(mode->pixel_h / mode->display_scale);
}
if (mode->pixel_w == 0 && mode->pixel_h == 0) {
mode->pixel_w = (int)SDL_ceilf(mode->screen_w * mode->display_scale);
mode->pixel_h = (int)SDL_ceilf(mode->screen_h * mode->display_scale);
}
}
/* Make sure the screen width, pixel width, and display scale all match */
if (mode->display_scale != 0.0f) {
SDL_assert(mode->display_scale > 0.0f);
SDL_assert(SDL_fabsf(mode->screen_w - (mode->pixel_w / mode->display_scale)) < 1.0f);
SDL_assert(SDL_fabsf(mode->screen_h - (mode->pixel_h / mode->display_scale)) < 1.0f);
}
}
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
{
SDL_VideoDisplay display;
@ -592,9 +626,7 @@ int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
SDL_zero(display);
if (desktop_mode) {
display.desktop_mode = *desktop_mode;
if (display.desktop_mode.display_scale == 0.0f) {
display.desktop_mode.display_scale = 1.0f;
}
SDL_FinalizeDisplayMode(&display.desktop_mode);
}
display.current_mode = display.desktop_mode;
@ -624,12 +656,9 @@ int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event)
displays[index].name = SDL_strdup(name);
}
if (displays[index].desktop_mode.display_scale == 0.0f) {
displays[index].desktop_mode.display_scale = 1.0f;
}
if (displays[index].current_mode.display_scale == 0.0f) {
displays[index].current_mode.display_scale = 1.0f;
}
SDL_FinalizeDisplayMode(&displays[index].desktop_mode);
SDL_FinalizeDisplayMode(&displays[index].current_mode);
if (send_event) {
SDL_SendDisplayEvent(&_this->displays[index], SDL_EVENT_DISPLAY_CONNECTED, 0);
}
@ -722,8 +751,8 @@ int SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rect)
SDL_GetDisplayBounds(displayIndex - 1, rect);
rect->x += rect->w;
}
rect->w = (int)(display->current_mode.w / display->current_mode.display_scale);
rect->h = (int)(display->current_mode.h / display->current_mode.display_scale);
rect->w = display->current_mode.screen_w;
rect->h = display->current_mode.screen_h;
return 0;
}
@ -812,9 +841,7 @@ SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mo
display->max_display_modes += 32;
}
modes[nmodes] = *mode;
if (modes[nmodes].display_scale == 0.0f) {
modes[nmodes].display_scale = 1.0f;
}
SDL_FinalizeDisplayMode(&modes[nmodes]);
display->num_display_modes++;
/* Re-sort video modes */
@ -827,17 +854,13 @@ SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mo
void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
{
SDL_memcpy(&display->current_mode, mode, sizeof(*mode));
if (display->current_mode.display_scale == 0.0f) {
display->current_mode.display_scale = 1.0f;
}
SDL_FinalizeDisplayMode(&display->current_mode);
}
void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
{
SDL_memcpy(&display->desktop_mode, mode, sizeof(*mode));
if (display->desktop_mode.display_scale == 0.0f) {
display->desktop_mode.display_scale = 1.0f;
}
SDL_FinalizeDisplayMode(&display->desktop_mode);
}
static int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay *display)
@ -922,9 +945,9 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
SDL_DisplayMode *closest)
{
Uint32 target_format;
float target_display_scale;
float target_refresh_rate;
int i;
SDL_DisplayMode requested_mode;
SDL_DisplayMode *current, *match;
if (mode == NULL || closest == NULL) {
@ -932,6 +955,11 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
return NULL;
}
/* Make sure all the fields are filled out in the requested mode */
requested_mode = *mode;
SDL_FinalizeDisplayMode(&requested_mode);
mode = &requested_mode;
/* Default to the desktop format */
if (mode->format) {
target_format = mode->format;
@ -939,13 +967,6 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
target_format = display->desktop_mode.format;
}
/* Default to 1.0 scale */
if (mode->display_scale > 0.0f) {
target_display_scale = mode->display_scale;
} else {
target_display_scale = 1.0f;
}
/* Default to the desktop refresh rate */
if (mode->refresh_rate > 0.0f) {
target_refresh_rate = mode->refresh_rate;
@ -957,12 +978,12 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) {
current = &display->display_modes[i];
if (current->w && (current->w < mode->w)) {
if (current->pixel_w && (current->pixel_w < mode->pixel_w)) {
/* Out of sorted modes large enough here */
break;
}
if (current->h && (current->h < mode->h)) {
if (current->w && (current->w == mode->w)) {
if (current->pixel_h && (current->pixel_h < mode->pixel_h)) {
if (current->pixel_w && (current->pixel_w == mode->pixel_w)) {
/* Out of sorted modes large enough here */
break;
}
@ -971,7 +992,7 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
modes may still follow. */
continue;
}
if (match == NULL || current->w < match->w || current->h < match->h) {
if (match == NULL || current->pixel_w < match->pixel_w || current->pixel_h < match->pixel_h) {
match = current;
continue;
}
@ -993,35 +1014,29 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
continue;
}
}
if (current->display_scale != match->display_scale) {
/* Sorted lowest display scale to highest */
if (current->display_scale <= target_display_scale) {
match = current;
continue;
}
}
}
if (match) {
SDL_zerop(closest);
if (match->format) {
closest->format = match->format;
} else {
closest->format = mode->format;
}
if (match->w && match->h) {
closest->w = match->w;
closest->h = match->h;
if (match->screen_w && match->screen_h) {
closest->screen_w = match->screen_w;
closest->screen_h = match->screen_h;
} else {
closest->w = mode->w;
closest->h = mode->h;
closest->screen_w = mode->screen_w;
closest->screen_h = mode->screen_h;
}
if (match->display_scale > 0.0f) {
closest->display_scale = match->display_scale;
} else if (mode->display_scale > 0.0f) {
closest->display_scale = mode->display_scale;
if (match->pixel_w && match->pixel_h) {
closest->pixel_w = match->pixel_w;
closest->pixel_h = match->pixel_h;
} else {
closest->display_scale = 1.0f;
closest->pixel_w = mode->pixel_w;
closest->pixel_h = mode->pixel_h;
}
if (match->refresh_rate > 0.0f) {
closest->refresh_rate = match->refresh_rate;
} else {
@ -1029,19 +1044,17 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di
}
closest->driverdata = match->driverdata;
/*
* Pick some reasonable defaults if the app and driver don't
* care
*/
/* Pick some reasonable defaults if the app and driver don't care */
if (!closest->format) {
closest->format = SDL_PIXELFORMAT_RGB888;
}
if (!closest->w) {
closest->w = 640;
if (!closest->screen_w) {
closest->screen_w = 640;
}
if (!closest->h) {
closest->h = 480;
if (!closest->screen_h) {
closest->screen_h = 480;
}
SDL_FinalizeDisplayMode(closest);
return closest;
}
return NULL;
@ -1075,11 +1088,17 @@ static int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, const SDL_Dis
if (!display_mode.format) {
display_mode.format = display->current_mode.format;
}
if (!display_mode.w) {
display_mode.w = display->current_mode.w;
if (!display_mode.pixel_w) {
display_mode.pixel_w = display->current_mode.pixel_w;
}
if (!display_mode.h) {
display_mode.h = display->current_mode.h;
if (!display_mode.pixel_h) {
display_mode.pixel_h = display->current_mode.pixel_h;
}
if (!display_mode.screen_w) {
display_mode.screen_w = display->current_mode.screen_w;
}
if (!display_mode.screen_h) {
display_mode.screen_h = display->current_mode.screen_h;
}
if (display_mode.refresh_rate == 0.0f) {
display_mode.refresh_rate = display->current_mode.refresh_rate;
@ -1087,7 +1106,9 @@ static int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, const SDL_Dis
/* Get a good video mode, the closest one possible */
if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
return SDL_SetError("No video mode large enough for %dx%d", display_mode.w, display_mode.h);
return SDL_SetError("No video mode large enough for %dx%d (%dx%d)",
display_mode.pixel_w, display_mode.pixel_h,
display_mode.screen_w, display_mode.screen_h);
}
} else {
display_mode = display->desktop_mode;
@ -1284,11 +1305,11 @@ int SDL_SetWindowDisplayMode(SDL_Window *window, const SDL_DisplayMode *mode)
#ifndef __ANDROID__
/* Android may not resize the window to exactly what our fullscreen mode is, especially on
* windowed Android environments like the Chromebook or Samsung DeX. Given this, we shouldn't
* use fullscreen_mode.w and fullscreen_mode.h, but rather get our current native size. As such,
* use fullscreen_mode.screen_w and fullscreen_mode.screen_h, but rather get our current native size. As such,
* Android's SetWindowFullscreen will generate the window event for us with the proper final size.
*/
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, fullscreen_mode.w, fullscreen_mode.h);
#endif
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, fullscreen_mode.screen_w, fullscreen_mode.screen_h);
#endif /* !__ANDROID__ */
}
}
}
@ -1307,11 +1328,11 @@ int SDL_GetWindowDisplayMode(SDL_Window *window, SDL_DisplayMode *mode)
}
fullscreen_mode = window->fullscreen_mode;
if (!fullscreen_mode.w) {
fullscreen_mode.w = window->windowed.w;
if (!fullscreen_mode.screen_w) {
fullscreen_mode.screen_w = window->windowed.w;
}
if (!fullscreen_mode.h) {
fullscreen_mode.h = window->windowed.h;
if (!fullscreen_mode.screen_h) {
fullscreen_mode.screen_h = window->windowed.h;
}
display = SDL_GetDisplayForWindow(window);
@ -1469,7 +1490,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
SDL_bool resized = SDL_TRUE;
if (other->w == fullscreen_mode.w && other->h == fullscreen_mode.h) {
if (other->w == fullscreen_mode.screen_w && other->h == fullscreen_mode.screen_h) {
resized = SDL_FALSE;
}
@ -1501,11 +1522,8 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
/* This is also unnecessary on Win32 (WIN_SetWindowFullscreen calls SetWindowPos,
* WM_WINDOWPOSCHANGED will send SDL_EVENT_WINDOW_RESIZED).
*/
/* The new fullscreen window size must be sent in screen coordinates, not pixels. */
SDL_SendWindowEvent(other, SDL_EVENT_WINDOW_RESIZED,
(int)(fullscreen_mode.w / fullscreen_mode.display_scale),
(int)(fullscreen_mode.h / fullscreen_mode.display_scale));
fullscreen_mode.screen_w, fullscreen_mode.screen_h);
#endif
} else {
SDL_OnWindowResized(other);
@ -1745,15 +1763,15 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint
if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP && (bounds.w != w || bounds.h != h)) {
SDL_DisplayMode fullscreen_mode, closest_mode;
SDL_zero(fullscreen_mode);
fullscreen_mode.w = w;
fullscreen_mode.h = h;
fullscreen_mode.screen_w = w;
fullscreen_mode.screen_h = h;
if (SDL_GetClosestDisplayModeForDisplay(display, &fullscreen_mode, &closest_mode) != NULL) {
bounds.w = closest_mode.w;
bounds.h = closest_mode.h;
bounds.w = closest_mode.screen_w;
bounds.h = closest_mode.screen_h;
}
}
window->fullscreen_mode.w = bounds.w;
window->fullscreen_mode.h = bounds.h;
window->fullscreen_mode.screen_w = bounds.w;
window->fullscreen_mode.screen_h = bounds.h;
window->x = bounds.x;
window->y = bounds.y;
window->w = bounds.w;
@ -2409,8 +2427,16 @@ void SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h)
if (display)
{
*w = (int)SDL_ceilf(*w * display->current_mode.display_scale);
*h = (int)SDL_ceilf(*h * display->current_mode.display_scale);
if (*w == display->current_mode.screen_w) {
*w = display->current_mode.pixel_w;
} else {
*w = (int)SDL_ceilf(*w * display->current_mode.display_scale);
}
if (*h == display->current_mode.screen_h) {
*h = display->current_mode.pixel_h;
} else {
*h = (int)SDL_ceilf(*h * display->current_mode.display_scale);
}
}
}
}
@ -2999,8 +3025,8 @@ void SDL_OnWindowDisplayChanged(SDL_Window *window)
window->y = rect.y;
window->w = rect.w;
window->h = rect.h;
window->fullscreen_mode.w = rect.w;
window->fullscreen_mode.h = rect.h;
window->fullscreen_mode.screen_w = rect.w;
window->fullscreen_mode.screen_h = rect.h;
if (_this->SetWindowSize) {
_this->SetWindowSize(_this, window);
}

View file

@ -180,8 +180,8 @@ int Android_VideoInit(_THIS)
SDL_zero(mode);
mode.format = Android_ScreenFormat;
mode.w = Android_DeviceWidth;
mode.h = Android_DeviceHeight;
mode.pixel_w = Android_DeviceWidth;
mode.pixel_h = Android_DeviceHeight;
mode.display_scale = Android_ScreenDensity;
mode.refresh_rate = Android_ScreenRate;
mode.driverdata = NULL;
@ -276,11 +276,15 @@ void Android_SendResize(SDL_Window *window)
SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->num_displays > 0) {
SDL_VideoDisplay *display = &device->displays[0];
display->desktop_mode.format = Android_ScreenFormat;
display->desktop_mode.w = Android_DeviceWidth;
display->desktop_mode.h = Android_DeviceHeight;
display->desktop_mode.display_scale = Android_ScreenDensity;
display->desktop_mode.refresh_rate = Android_ScreenRate;
SDL_DisplayMode desktop_mode;
SDL_zero(desktop_mode);
desktop_mode.format = Android_ScreenFormat;
desktop_mode.pixel_w = Android_DeviceWidth;
desktop_mode.pixel_h = Android_DeviceHeight;
desktop_mode.display_scale = Android_ScreenDensity;
desktop_mode.refresh_rate = Android_ScreenRate;
SDL_SetDesktopDisplayMode(display, &desktop_mode);
}
if (window) {
@ -288,15 +292,17 @@ void Android_SendResize(SDL_Window *window)
* will fall back to the old mode */
int w, h;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
display->display_modes[0].format = Android_ScreenFormat;
display->display_modes[0].w = Android_DeviceWidth;
display->display_modes[0].h = Android_DeviceHeight;
display->display_modes[0].display_scale = Android_ScreenDensity;
display->display_modes[0].refresh_rate = Android_ScreenRate;
display->current_mode = display->display_modes[0];
SDL_DisplayMode current_mode;
w = (int)SDL_ceilf(Android_SurfaceWidth / Android_ScreenDensity);
h = (int)SDL_ceilf(Android_SurfaceHeight / Android_ScreenDensity);
current_mode.format = Android_ScreenFormat;
current_mode.pixel_w = Android_DeviceWidth;
current_mode.pixel_h = Android_DeviceHeight;
current_mode.display_scale = Android_ScreenDensity;
current_mode.refresh_rate = Android_ScreenRate;
SDL_SetCurrentDisplayMode(display, &current_mode);
w = (int)SDL_floorf(Android_SurfaceWidth / Android_ScreenDensity);
h = (int)SDL_floorf(Android_SurfaceHeight / Android_ScreenDensity);
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, w, h);
}
}

View file

@ -143,10 +143,10 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
{
SDL_DisplayModeData *data;
bool usableForGUI = CGDisplayModeIsUsableForDesktopGUI(vidmode);
int width = (int)CGDisplayModeGetWidth(vidmode);
int height = (int)CGDisplayModeGetHeight(vidmode);
int pixelW = width;
int pixelH = height;
size_t width = CGDisplayModeGetWidth(vidmode);
size_t height = CGDisplayModeGetHeight(vidmode);
size_t pixelW = width;
size_t pixelH = height;
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
float refreshrate = GetDisplayModeRefreshRate(vidmode, link);
Uint32 format = GetDisplayModePixelFormat(vidmode);
@ -173,15 +173,15 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
* modes to try (see comment below for why that's necessary).
* CGDisplayModeGetPixelWidth and friends are only available in 10.8+. */
#ifdef MAC_OS_X_VERSION_10_8
pixelW = (int)CGDisplayModeGetPixelWidth(vidmode);
pixelH = (int)CGDisplayModeGetPixelHeight(vidmode);
pixelW = CGDisplayModeGetPixelWidth(vidmode);
pixelH = CGDisplayModeGetPixelHeight(vidmode);
if (modelist != NULL && floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_7) {
CFIndex modescount = CFArrayGetCount(modelist);
int i;
for (i = 0; i < modescount; i++) {
int otherW, otherH, otherpixelW, otherpixelH;
size_t otherW, otherH, otherpixelW, otherpixelH;
float otherrefresh;
Uint32 otherformat;
bool otherGUI;
@ -196,10 +196,10 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
continue;
}
otherW = (int)CGDisplayModeGetWidth(othermode);
otherH = (int)CGDisplayModeGetHeight(othermode);
otherpixelW = (int)CGDisplayModeGetPixelWidth(othermode);
otherpixelH = (int)CGDisplayModeGetPixelHeight(othermode);
otherW = CGDisplayModeGetWidth(othermode);
otherH = CGDisplayModeGetHeight(othermode);
otherpixelW = CGDisplayModeGetPixelWidth(othermode);
otherpixelH = CGDisplayModeGetPixelHeight(othermode);
otherrefresh = GetDisplayModeRefreshRate(othermode, link);
otherformat = GetDisplayModePixelFormat(othermode);
otherGUI = CGDisplayModeIsUsableForDesktopGUI(othermode);
@ -264,9 +264,10 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
}
data->modes = modes;
mode->format = format;
mode->w = pixelW;
mode->h = pixelH;
mode->display_scale = (float)pixelW / width;
mode->pixel_w = (int)pixelW;
mode->pixel_h = (int)pixelH;
mode->screen_w = (int)width;
mode->screen_h = (int)height;
mode->refresh_rate = refreshrate;
mode->driverdata = data;
return SDL_TRUE;

View file

@ -144,8 +144,8 @@ int DUMMY_VideoInit(_THIS)
/* Use a fake 32-bpp desktop mode */
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 1024;
mode.h = 768;
mode.pixel_w = 1024;
mode.pixel_h = 768;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}

View file

@ -129,7 +129,8 @@ int Emscripten_VideoInit(_THIS)
/* Use a fake 32-bpp desktop mode */
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
emscripten_get_screen_size(&mode.w, &mode.h);
emscripten_get_screen_size(&mode.screen_w, &mode.screen_h);
mode.display_scale = emscripten_get_device_pixel_ratio();
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;

View file

@ -78,7 +78,7 @@ static float get_refresh_rate(display_mode &mode) {
void _SpoutModeData(display_mode *bmode) {
printf("BMode:\n");
printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
printf("\th,v = (%i,%i)\n", bmode->h_display_start,
printf("\th,v = (%i,%i)\n", bmode->h_display_start,
bmode->v_display_start);
if (bmode->flags) {
printf("\tFlags:\n");
@ -162,25 +162,23 @@ int32 HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace)
/* May never get here, but safer and needed to shut up compiler */
SDL_SetError("Invalid color space");
return 0;
return 0;
}
static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
SDL_DisplayMode *mode) {
static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) {
SDL_zerop(mode);
mode->w = bmode->virtual_width;
mode->h = bmode->virtual_height;
mode->pixel_w = bmode->virtual_width;
mode->pixel_h = bmode->virtual_height;
mode->refresh_rate = get_refresh_rate(*bmode);
#if WRAP_BMODE
SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1,
sizeof(SDL_DisplayModeData));
data->bmode = bmode;
mode->driverdata = data;
#else
mode->driverdata = bmode;
#endif
@ -190,19 +188,13 @@ static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
/* Later, there may be more than one monitor available */
static void _AddDisplay(BScreen *screen) {
SDL_VideoDisplay display;
SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1,
sizeof(SDL_DisplayMode));
display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode));
screen->GetMode(bmode);
SDL_DisplayMode mode;
display_mode bmode;
screen->GetMode(&bmode);
_BDisplayModeToSdlDisplayMode(bmode, mode);
SDL_zero(display);
display.desktop_mode = *mode;
display.current_mode = *mode;
SDL_AddVideoDisplay(&display, SDL_FALSE);
_BDisplayModeToSdlDisplayMode(&bmode, &mode);
SDL_AddBasicVideoDisplay(&mode);
}
/*
@ -243,11 +235,11 @@ void HAIKU_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
display_mode this_bmode;
display_mode *bmodes;
uint32 count, i;
/* Get graphics-hardware supported modes */
bscreen.GetModeList(&bmodes, &count);
bscreen.GetMode(&this_bmode);
for (i = 0; i < count; ++i) {
// FIXME: Apparently there are errors with colorspace changes
if (bmodes[i].space == this_bmode.space) {
@ -286,9 +278,9 @@ int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode
if (bscreen.SetMode(bmode) != B_OK) {
return SDL_SetError("Bad video mode");
}
free(bmode_list); /* This should not be SDL_free() */
#if SDL_VIDEO_OPENGL
/* FIXME: Is there some way to reboot the OpenGL context? This doesn't
help */

View file

@ -501,11 +501,10 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
SDL_DisplayMode target, closest;
drmModeModeInfo *drm_mode;
target.w = width;
target.h = height;
target.format = 0; /* Will use the default mode format. */
target.refresh_rate = refresh_rate;
target.driverdata = 0; /* Initialize to 0 */
SDL_zero(target);
target.pixel_w = (int)width;
target.pixel_h = (int)height;
target.refresh_rate = (int)refresh_rate;
if (!SDL_GetClosestDisplayMode(SDL_atoi(display->name), &target, &closest)) {
return NULL;
@ -871,8 +870,8 @@ static void KMSDRM_AddDisplay(_THIS, drmModeConnector *connector, drmModeRes *re
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.pixel_w = dispdata->mode.hdisplay;
display.desktop_mode.pixel_h = dispdata->mode.vdisplay;
display.desktop_mode.refresh_rate = CalculateRefreshRate(&dispdata->mode);
display.desktop_mode.format = SDL_PIXELFORMAT_ARGB8888;
display.desktop_mode.driverdata = modedata;
@ -1158,6 +1157,7 @@ int KMSDRM_CreateSurfaces(_THIS, SDL_Window *window)
SDL_WindowData *windata = (SDL_WindowData *)window->driverdata;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata;
SDL_DisplayMode current_mode;
uint32_t surface_fmt = GBM_FORMAT_ARGB8888;
uint32_t surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
@ -1182,10 +1182,12 @@ int KMSDRM_CreateSurfaces(_THIS, SDL_Window *window)
mode that's set in sync with what SDL_video.c thinks is set */
KMSDRM_GetModeToSet(window, &dispdata->mode);
display->current_mode.w = dispdata->mode.hdisplay;
display->current_mode.h = dispdata->mode.vdisplay;
display->current_mode.refresh_rate = CalculateRefreshRate(&dispdata->mode);
display->current_mode.format = SDL_PIXELFORMAT_ARGB8888;
SDL_zero(current_mode);
current_mode.pixel_w = dispdata->mode.hdisplay;
current_mode.pixel_h = dispdata->mode.vdisplay;
current_mode.refresh_rate = CalculateRefreshRate(&dispdata->mode);
current_mode.format = SDL_PIXELFORMAT_ARGB8888;
SDL_SetCurrentDisplayMode(display, &current_mode);
windata->gs = KMSDRM_gbm_surface_create(viddata->gbm_dev,
dispdata->mode.hdisplay, dispdata->mode.vdisplay,

View file

@ -118,8 +118,8 @@ AddN3DSDisplay(gfxScreen_t screen)
display_driver_data->screen = screen;
mode.w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM;
mode.h = GSP_SCREEN_WIDTH;
mode.pixel_w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM;
mode.pixel_h = GSP_SCREEN_WIDTH;
mode.refresh_rate = 60.0f;
mode.format = FRAMEBUFFER_FORMAT;
@ -154,8 +154,8 @@ static int N3DS_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
}
rect->x = 0;
rect->y = (driver_data->screen == GFX_TOP) ? 0 : GSP_SCREEN_WIDTH;
rect->w = display->current_mode.w;
rect->h = display->current_mode.h;
rect->w = display->current_mode.screen_w;
rect->h = display->current_mode.screen_h;
return 0;
}

View file

@ -150,8 +150,8 @@ int NGAGE_VideoInit(_THIS)
/* Use 12-bpp desktop mode */
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB444;
mode.w = 176;
mode.h = 208;
mode.pixel_w = 176;
mode.pixel_h = 208;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}

View file

@ -103,8 +103,8 @@ int OFFSCREEN_VideoInit(_THIS)
/* Use a fake 32-bpp desktop mode */
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 1024;
mode.h = 768;
mode.pixel_w = 1024;
mode.pixel_h = 768;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}

View file

@ -65,23 +65,17 @@ static int PS2_CreateWindow(_THIS, SDL_Window *window)
static int PS2_VideoInit(_THIS)
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayMode mode;
SDL_zero(current_mode);
current_mode.w = 640;
current_mode.h = 480;
current_mode.refresh_rate = 60.0f;
SDL_zero(mode);
mode.pixel_w = 640;
mode.pixel_h = 480;
mode.refresh_rate = 60.0f;
/* 32 bpp for default */
current_mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.format = SDL_PIXELFORMAT_ABGR8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
SDL_AddDisplayMode(&display, &current_mode);
SDL_AddVideoDisplay(&display, SDL_FALSE);
SDL_AddBasicVideoDisplay(&mode);
return 1;
}

View file

@ -137,29 +137,28 @@ VideoBootStrap PSP_bootstrap = {
int PSP_VideoInit(_THIS)
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayMode mode;
SDL_zero(current_mode);
current_mode.w = 480;
current_mode.h = 272;
current_mode.refresh_rate = 60.0f;
SDL_zero(mode);
mode.pixel_w = 480;
mode.pixel_h = 272;
mode.refresh_rate = 60.0f;
/* 32 bpp for default */
current_mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.format = SDL_PIXELFORMAT_ABGR8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
display.desktop_mode = mode;
display.current_mode = mode;
SDL_AddDisplayMode(&display, &current_mode);
SDL_AddDisplayMode(&display, &mode);
/* 16 bpp secondary mode */
current_mode.format = SDL_PIXELFORMAT_BGR565;
display.desktop_mode = current_mode;
display.current_mode = current_mode;
SDL_AddDisplayMode(&display, &current_mode);
mode.format = SDL_PIXELFORMAT_BGR565;
SDL_AddDisplayMode(&display, &mode);
SDL_AddVideoDisplay(&display, SDL_FALSE);
return 1;
}

View file

@ -148,7 +148,7 @@ static void AddDispManXDisplay(const int display_id)
DISPMANX_MODEINFO_T modeinfo;
DISPMANX_DISPLAY_HANDLE_T handle;
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayMode mode;
SDL_DisplayData *data;
handle = vc_dispmanx_display_open(display_id);
@ -162,17 +162,17 @@ static void AddDispManXDisplay(const int display_id)
}
/* RPI_GetRefreshRate() doesn't distinguish between displays. I'm not sure the hardware distinguishes either */
SDL_zero(current_mode);
current_mode.w = modeinfo.width;
current_mode.h = modeinfo.height;
current_mode.refresh_rate = RPI_GetRefreshRate();
SDL_zero(mode);
mode.pixel_w = modeinfo.width;
mode.pixel_h = modeinfo.height;
mode.refresh_rate = RPI_GetRefreshRate();
/* 32 bpp for default */
current_mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.format = SDL_PIXELFORMAT_ABGR8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
display.desktop_mode = mode;
display.current_mode = mode;
/* Allocate display internal data */
data = (SDL_DisplayData *)SDL_calloc(1, sizeof(SDL_DisplayData));

View file

@ -137,8 +137,8 @@ static SDL_bool read_mode_block(int *block, SDL_DisplayMode *mode, SDL_bool exte
}
SDL_zerop(mode);
mode->w = xres;
mode->h = yres;
mode->pixel_w = xres;
mode->pixel_h = yres;
mode->format = RISCOS_ModeToPixelFormat(ncolour, modeflags, log2bpp);
mode->refresh_rate = (float)rate;

View file

@ -269,8 +269,8 @@ static int UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h,
return -1;
}
mode.w = w;
mode.h = h;
mode.pixel_w = w;
mode.pixel_h = h;
mode.display_scale = uiscreen.scale;
mode.refresh_rate = UIKit_GetDisplayModeRefreshRate(uiscreen);
mode.format = SDL_PIXELFORMAT_ABGR8888;
@ -315,8 +315,8 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
}
SDL_zero(mode);
mode.w = (int)size.width;
mode.h = (int)size.height;
mode.pixel_w = (int)size.width;
mode.pixel_h = (int)size.height;
mode.display_scale = uiscreen.scale;
mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.refresh_rate = UIKit_GetDisplayModeRefreshRate(uiscreen);
@ -455,11 +455,11 @@ int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode
/* [UIApplication setStatusBarOrientation:] no longer works reliably
* in recent iOS versions, so we can't rotate the screen when setting
* the display mode. */
if (mode->w > mode->h) {
if (mode->pixel_w > mode->pixel_h) {
if (!UIKit_IsDisplayLandscape(data.uiscreen)) {
return SDL_SetError("Screen orientation does not match display mode size");
}
} else if (mode->w < mode->h) {
} else if (mode->pixel_w < mode->pixel_h) {
if (UIKit_IsDisplayLandscape(data.uiscreen)) {
return SDL_SetError("Screen orientation does not match display mode size");
}
@ -531,17 +531,23 @@ void SDL_OnApplicationDidChangeStatusBarOrientation()
* orientation so that updating a window's fullscreen state to
* SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
* correct orientation. */
if (isLandscape != (desktopmode->w > desktopmode->h)) {
int height = desktopmode->w;
desktopmode->w = desktopmode->h;
desktopmode->h = height;
if (isLandscape != (desktopmode->pixel_w > desktopmode->pixel_h)) {
int height = desktopmode->pixel_w;
desktopmode->pixel_w = desktopmode->pixel_h;
desktopmode->pixel_h = height;
height = desktopmode->screen_w;
desktopmode->screen_w = desktopmode->screen_h;
desktopmode->screen_h = height;
}
/* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
if (isLandscape != (currentmode->w > currentmode->h)) {
int height = currentmode->w;
currentmode->w = currentmode->h;
currentmode->h = height;
if (isLandscape != (currentmode->pixel_w > currentmode->pixel_h)) {
int height = currentmode->pixel_w;
currentmode->pixel_w = currentmode->pixel_h;
currentmode->pixel_h = height;
height = currentmode->screen_w;
currentmode->screen_w = currentmode->screen_h;
currentmode->screen_h = height;
}
switch ([UIApplication sharedApplication].statusBarOrientation) {

View file

@ -177,7 +177,7 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
const SDL_DisplayMode *bestmode = NULL;
for (i = display->num_display_modes; i >= 0; i--) {
const SDL_DisplayMode *mode = &display->display_modes[i];
if ((mode->w >= window->w) && (mode->h >= window->h)) {
if ((mode->screen_w >= window->w) && (mode->screen_h >= window->h)) {
bestmode = mode;
}
}

View file

@ -180,45 +180,41 @@ VideoBootStrap VITA_bootstrap = {
/*****************************************************************************/
int VITA_VideoInit(_THIS)
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayMode mode;
#if defined(SDL_VIDEO_VITA_PVR)
char *res = SDL_getenv("VITA_RESOLUTION");
#endif
SDL_zero(current_mode);
SDL_zero(mode);
#if defined(SDL_VIDEO_VITA_PVR)
if (res) {
/* 1088i for PSTV (Or Sharpscale) */
if (!SDL_strncmp(res, "1080", 4)) {
current_mode.w = 1920;
current_mode.h = 1088;
mode.pixel_w = 1920;
mode.pixel_h = 1088;
}
/* 725p for PSTV (Or Sharpscale) */
else if (!SDL_strncmp(res, "720", 3)) {
current_mode.w = 1280;
current_mode.h = 725;
mode.pixel_w = 1280;
mode.pixel_h = 725;
}
}
/* 544p */
else {
#endif
current_mode.w = 960;
current_mode.h = 544;
mode.pixel_w = 960;
mode.pixel_h = 544;
#if defined(SDL_VIDEO_VITA_PVR)
}
#endif
current_mode.refresh_rate = 60.0f;
mode.refresh_rate = 60.0f;
/* 32 bpp for default */
current_mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.format = SDL_PIXELFORMAT_ABGR8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
SDL_AddBasicVideoDisplay(&mode);
SDL_AddVideoDisplay(&display, SDL_FALSE);
VITA_InitTouch();
VITA_InitKeyboard();
VITA_InitMouse();

View file

@ -125,7 +125,7 @@ static int VIVANTE_AddVideoDisplays(_THIS)
{
SDL_VideoData *videodata = _this->driverdata;
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayMode mode;
SDL_DisplayData *data;
int pitch = 0, bpp = 0;
unsigned long pixels = 0;
@ -135,33 +135,33 @@ static int VIVANTE_AddVideoDisplays(_THIS)
return SDL_OutOfMemory();
}
SDL_zero(current_mode);
SDL_zero(mode);
#if SDL_VIDEO_DRIVER_VIVANTE_VDK
data->native_display = vdkGetDisplay(videodata->vdk_private);
vdkGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
vdkGetDisplayInfo(data->native_display, &mode.pixel_w, &mode.pixel_h, &pixels, &pitch, &bpp);
#else
data->native_display = videodata->fbGetDisplayByIndex(0);
videodata->fbGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
videodata->fbGetDisplayInfo(data->native_display, &mode.pixel_w, &mode.pixel_h, &pixels, &pitch, &bpp);
#endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */
switch (bpp) {
default: /* Is another format used? */
case 32:
current_mode.format = SDL_PIXELFORMAT_ARGB8888;
mode.format = SDL_PIXELFORMAT_ARGB8888;
break;
case 16:
current_mode.format = SDL_PIXELFORMAT_RGB565;
mode.format = SDL_PIXELFORMAT_RGB565;
break;
}
/* FIXME: How do we query refresh rate? */
current_mode.refresh_rate = 60.0f;
mode.refresh_rate = 60.0f;
SDL_zero(display);
display.name = VIVANTE_GetDisplayName(_this);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = data;
SDL_AddVideoDisplay(&display, SDL_FALSE);
return 0;

View file

@ -422,17 +422,17 @@ static void AddEmulatedModes(SDL_VideoDisplay *dpy, SDL_bool rot_90)
mode.display_scale = 1.0f;
if (rot_90) {
mode.w = mode_list[i].h;
mode.h = mode_list[i].w;
mode.pixel_w = mode_list[i].h;
mode.pixel_h = mode_list[i].w;
} else {
mode.w = mode_list[i].w;
mode.h = mode_list[i].h;
mode.pixel_w = mode_list[i].w;
mode.pixel_h = mode_list[i].h;
}
/* Only add modes that are smaller than the native mode. */
if ((mode.w < native_width && mode.h < native_height) ||
(mode.w < native_width && mode.h == native_height) ||
(mode.w == native_width && mode.h < native_height)) {
if ((mode.pixel_w < native_width && mode.pixel_h < native_height) ||
(mode.pixel_w < native_width && mode.pixel_h == native_height) ||
(mode.pixel_w == native_width && mode.pixel_h < native_height)) {
SDL_AddDisplayMode(dpy, &mode);
}
}
@ -565,11 +565,11 @@ static void display_handle_done(void *data,
native_mode.format = SDL_PIXELFORMAT_RGB888;
if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) {
native_mode.w = driverdata->native_height;
native_mode.h = driverdata->native_width;
native_mode.pixel_w = driverdata->native_height;
native_mode.pixel_h = driverdata->native_width;
} else {
native_mode.w = driverdata->native_width;
native_mode.h = driverdata->native_height;
native_mode.pixel_w = driverdata->native_width;
native_mode.pixel_h = driverdata->native_height;
}
native_mode.display_scale = 1.0f;
native_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */
@ -590,11 +590,11 @@ static void display_handle_done(void *data,
/* xdg-output dimensions are already transformed, so no need to rotate. */
if (driverdata->has_logical_size || !(driverdata->transform & WL_OUTPUT_TRANSFORM_90)) {
desktop_mode.w = driverdata->width;
desktop_mode.h = driverdata->height;
desktop_mode.pixel_w = driverdata->width;
desktop_mode.pixel_h = driverdata->height;
} else {
desktop_mode.w = driverdata->height;
desktop_mode.h = driverdata->width;
desktop_mode.pixel_w = driverdata->height;
desktop_mode.pixel_h = driverdata->width;
}
desktop_mode.display_scale = driverdata->scale_factor;
desktop_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */
@ -976,8 +976,8 @@ static int Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *
SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *)display->driverdata;
rect->x = driverdata->x;
rect->y = driverdata->y;
rect->w = display->current_mode.w;
rect->h = display->current_mode.h;
rect->w = display->current_mode.screen_w;
rect->h = display->current_mode.screen_h;
return 0;
}

View file

@ -38,9 +38,7 @@ static void WIN_UpdateDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_Di
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
HDC hdc;
data->DeviceMode.dmFields =
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
DM_DISPLAYFLAGS);
data->DeviceMode.dmFields = (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS);
/* NOLINTNEXTLINE(bugprone-assignment-in-if-condition): No simple way to extract the assignment */
if (index == ENUM_CURRENT_SETTINGS && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
@ -180,14 +178,14 @@ static SDL_bool WIN_GetDisplayMode(_THIS, HMONITOR hMonitor, LPCWSTR deviceName,
data->DeviceMode = devmode;
mode->format = SDL_PIXELFORMAT_UNKNOWN;
mode->w = data->DeviceMode.dmPelsWidth;
mode->h = data->DeviceMode.dmPelsHeight;
mode->pixel_w = data->DeviceMode.dmPelsWidth;
mode->pixel_h = data->DeviceMode.dmPelsHeight;
mode->refresh_rate = WIN_GetRefreshRate(&data->DeviceMode);
if (index == ENUM_CURRENT_SETTINGS && videodata->GetDpiForMonitor) {
UINT hdpi_uint, vdpi_uint;
if (videodata->GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &hdpi_uint, &vdpi_uint) == S_OK) {
mode->display_scale = (float)hdpi_uint / 96;
mode->display_scale = hdpi_uint / 96.0f;
}
}

View file

@ -423,19 +423,14 @@ int WIN_VideoInit(_THIS)
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* For Xbox, we just need to create the single display */
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayMode mode;
SDL_zero(current_mode);
D3D12_XBOX_GetResolution(&current_mode.w, &current_mode.h);
current_mode.refresh_rate = 60.0f;
current_mode.format = SDL_PIXELFORMAT_ARGB8888;
SDL_zero(mode);
D3D12_XBOX_GetResolution(&mode.pixel_w, &mode.pixel_h);
mode.refresh_rate = 60.0f;
mode.format = SDL_PIXELFORMAT_ARGB8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
SDL_AddVideoDisplay(&display, SDL_FALSE);
SDL_AddBasicVideoDisplay(&mode);
}
#else /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
if (WIN_InitModes(_this) < 0) {

View file

@ -253,8 +253,8 @@ extern "C" Uint32 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat);
static void WINRT_DXGIModeToSDLDisplayMode(const DXGI_MODE_DESC *dxgiMode, SDL_DisplayMode *sdlMode)
{
SDL_zerop(sdlMode);
sdlMode->w = dxgiMode->Width;
sdlMode->h = dxgiMode->Height;
sdlMode->pixel_w = dxgiMode->Width;
sdlMode->pixel_h = dxgiMode->Height;
sdlMode->refresh_rate = (((100 * dxgiMode->RefreshRate.Numerator) / dxgiMode->RefreshRate.Denominator) / 100.0f);
sdlMode->format = D3D11_DXGIFormatToSDLPixelFormat(dxgiMode->Format);
}
@ -303,10 +303,9 @@ static int WINRT_AddDisplaysForOutput(_THIS, IDXGIAdapter1 *dxgiAdapter1, int ou
SDL_DisplayMode mode;
SDL_zero(mode);
display.name = SDL_strdup("Windows Simulator / Terminal Services Display");
mode.w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
mode.h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
mode.pixel_w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
mode.pixel_h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
mode.refresh_rate = 0.0f; /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
display.desktop_mode = mode;
display.current_mode = mode;
if (!SDL_AddDisplayMode(&display, &mode)) {
@ -415,18 +414,23 @@ static int WINRT_AddDisplaysForAdapter(_THIS, IDXGIFactory2 *dxgiFactory2, int a
*/
#if (NTDDI_VERSION >= NTDDI_WIN10) || (SDL_WINRT_USE_APPLICATIONVIEW && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Width);
mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Height);
mode.pixel_w = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Width);
mode.pixel_h = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Height);
mode.screen_w = appView->VisibleBounds.Width;
mode.screen_h = appView->VisibleBounds.Height;
mode.display_scale = WINRT_DISPLAY_PROPERTY(LogicalDpi) / 96.0f;
#else
/* On platform(s) that do not support VisibleBounds, such as Windows 8.1,
fall back to CoreWindow's Bounds property.
*/
mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Width);
mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Height);
mode.pixel_w = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Width);
mode.pixel_h = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Height);
mode.screen_w = coreWin->Bounds.Width;
mode.screen_h = coreWin->Bounds.Height;
mode.display_scale = WINRT_DISPLAY_PROPERTY(LogicalDpi) / 96.0f;
#endif
mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
mode.refresh_rate = 0.0f; /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
display.desktop_mode = mode;
display.current_mode = mode;
bool error = SDL_AddDisplayMode(&display, &mode) < 0 ||
@ -532,7 +536,7 @@ WINRT_DetectWindowFlags(SDL_Window *window)
}
#endif
if (display->desktop_mode.w != w || display->desktop_mode.h != h) {
if (display->desktop_mode.pixel_w != w || display->desktop_mode.pixel_h != h) {
latestFlags |= SDL_WINDOW_MAXIMIZED;
} else {
latestFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
@ -701,12 +705,12 @@ int WINRT_CreateWindow(_THIS, SDL_Window *window)
user choice of various things. For now, just adapt the SDL_Window to
whatever Windows set-up as the native-window's geometry.
*/
window->x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
window->y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
window->x = (int)SDL_lroundf(data->coreWindow->Bounds.Left);
window->y = (int)SDL_lroundf(data->coreWindow->Bounds.Top);
#if NTDDI_VERSION < NTDDI_WIN10
/* On WinRT 8.x / pre-Win10, just use the size we were given. */
window->w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
window->h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
window->w = (int)SDL_floorf(data->coreWindow->Bounds.Width);
window->h = (int)SDL_floorf(data->coreWindow->Bounds.Height);
#else
/* On Windows 10, we occasionally get control over window size. For windowed
mode apps, try this.
@ -721,8 +725,8 @@ int WINRT_CreateWindow(_THIS, SDL_Window *window)
/* We either weren't able to set the window size, or a request for
fullscreen was made. Get window-size info from the OS.
*/
window->w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
window->h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
window->w = (int)SDL_floorf(data->coreWindow->Bounds.Width);
window->h = (int)SDL_floorf(data->coreWindow->Bounds.Height);
}
#endif

View file

@ -471,8 +471,8 @@ static int X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
if ((dev) && (dev->displays) && (dev->num_displays > 0)) {
const SDL_VideoDisplay *dpy = &dev->displays[0];
const SDL_DisplayData *dpydata = (SDL_DisplayData *)dpy->driverdata;
x = dpydata->x + ((dpy->current_mode.w - data->dialog_width) / 2);
y = dpydata->y + ((dpy->current_mode.h - data->dialog_height) / 3);
x = dpydata->x + ((dpy->current_mode.pixel_w - data->dialog_width) / 2);
y = dpydata->y + ((dpy->current_mode.pixel_h - data->dialog_height) / 3);
} else { /* oh well. This will misposition on a multi-head setup. Init first next time. */
x = (DisplayWidth(display, data->screen) - data->dialog_width) / 2;
y = (DisplayHeight(display, data->screen) - data->dialog_height) / 3;

View file

@ -217,11 +217,11 @@ static SDL_bool SetXRandRModeInfo(Display *display, XRRScreenResources *res, RRC
}
if (rotation & (XRANDR_ROTATION_LEFT | XRANDR_ROTATION_RIGHT)) {
mode->w = info->height;
mode->h = info->width;
mode->pixel_w = info->height;
mode->pixel_h = info->width;
} else {
mode->w = info->width;
mode->h = info->height;
mode->pixel_w = info->width;
mode->pixel_h = info->height;
}
mode->refresh_rate = CalculateXRandRRefreshRate(info);
((SDL_DisplayModeData *)mode->driverdata)->xrandr_mode = modeID;
@ -343,8 +343,8 @@ static int X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput output
SDL_zero(mode);
modeID = crtc->mode;
mode.w = crtc->width;
mode.h = crtc->height;
mode.pixel_w = crtc->width;
mode.pixel_h = crtc->height;
mode.format = pixelformat;
display_x = crtc->x;
@ -369,9 +369,9 @@ static int X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput output
displaydata->screen = screen;
displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;
displaydata->hdpi = display_mm_width ? (((float)mode.w) * 25.4f / display_mm_width) : 0.0f;
displaydata->vdpi = display_mm_height ? (((float)mode.h) * 25.4f / display_mm_height) : 0.0f;
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float)display_mm_width) / 25.4f, ((float)display_mm_height) / 25.4f);
displaydata->hdpi = display_mm_width ? (((float)mode.pixel_w) * 25.4f / display_mm_width) : 0.0f;
displaydata->vdpi = display_mm_height ? (((float)mode.pixel_h) * 25.4f / display_mm_height) : 0.0f;
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.pixel_w, mode.pixel_h, ((float)display_mm_width) / 25.4f, ((float)display_mm_height) / 25.4f);
displaydata->scanline_pad = scanline_pad;
displaydata->x = display_x;
displaydata->y = display_y;
@ -574,8 +574,8 @@ static int X11_InitModes_StdXlib(_THIS)
}
SDL_zero(mode);
mode.w = WidthOfScreen(screen);
mode.h = HeightOfScreen(screen);
mode.pixel_w = WidthOfScreen(screen);
mode.pixel_h = HeightOfScreen(screen);
mode.format = pixelformat;
displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata));
@ -596,9 +596,9 @@ static int X11_InitModes_StdXlib(_THIS)
displaydata->screen = default_screen;
displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;
displaydata->hdpi = display_mm_width ? (((float)mode.w) * 25.4f / display_mm_width) : 0.0f;
displaydata->vdpi = display_mm_height ? (((float)mode.h) * 25.4f / display_mm_height) : 0.0f;
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float)display_mm_width) / 25.4f, ((float)display_mm_height) / 25.4f);
displaydata->hdpi = display_mm_width ? (((float)mode.pixel_w) * 25.4f / display_mm_width) : 0.0f;
displaydata->vdpi = display_mm_height ? (((float)mode.pixel_h) * 25.4f / display_mm_height) : 0.0f;
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.pixel_w, mode.pixel_h, ((float)display_mm_width) / 25.4f, ((float)display_mm_height) / 25.4f);
xft_dpi = GetXftDPI(dpy);
if (xft_dpi > 0) {
@ -783,8 +783,8 @@ int X11_SetDisplayMode(_THIS, SDL_VideoDisplay *sdl_display, SDL_DisplayMode *mo
goto ungrabServer;
}
mm_width = mode->w * DisplayWidthMM(display, data->screen) / DisplayWidth(display, data->screen);
mm_height = mode->h * DisplayHeightMM(display, data->screen) / DisplayHeight(display, data->screen);
mm_width = mode->pixel_w * DisplayWidthMM(display, data->screen) / DisplayWidth(display, data->screen);
mm_height = mode->pixel_h * DisplayHeightMM(display, data->screen) / DisplayHeight(display, data->screen);
/* !!! FIXME: this can get into a problem scenario when a window is
bigger than a physical monitor in a configuration where one screen
@ -795,7 +795,7 @@ int X11_SetDisplayMode(_THIS, SDL_VideoDisplay *sdl_display, SDL_DisplayMode *mo
crashing */
X11_XSync(display, False);
PreXRRSetScreenSizeErrorHandler = X11_XSetErrorHandler(SDL_XRRSetScreenSizeErrHandler);
X11_XRRSetScreenSize(display, RootWindow(display, data->screen), mode->w, mode->h, mm_width, mm_height);
X11_XRRSetScreenSize(display, RootWindow(display, data->screen), mode->pixel_w, mode->pixel_h, mm_width, mm_height);
X11_XSync(display, False);
X11_XSetErrorHandler(PreXRRSetScreenSizeErrorHandler);
@ -831,8 +831,8 @@ int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect)
rect->x = data->x;
rect->y = data->y;
rect->w = sdl_display->current_mode.w;
rect->h = sdl_display->current_mode.h;
rect->w = sdl_display->current_mode.screen_w;
rect->h = sdl_display->current_mode.screen_h;
return 0;
}

View file

@ -425,8 +425,9 @@ int video_getClosestDisplayModeCurrentResolution(void *arg)
}
/* Set the desired resolution equals to current resolution */
target.w = current.w;
target.h = current.h;
SDL_zero(target);
target.pixel_w = current.pixel_w;
target.pixel_h = current.pixel_h;
for (variation = 0; variation < 8; variation++) {
/* Vary constraints on other query parameters */
target.format = (variation & 1) ? current.format : 0;
@ -439,11 +440,11 @@ int video_getClosestDisplayModeCurrentResolution(void *arg)
SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL");
/* Check that one gets the current resolution back again */
SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
SDLTest_AssertCheck(closest.pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest.pixel_w);
SDLTest_AssertCheck(closest.pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest.pixel_h);
/* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */
SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
SDLTest_AssertCheck(closest.pixel_w == dResult->pixel_w, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_w, dResult->pixel_w);
SDLTest_AssertCheck(closest.pixel_h == dResult->pixel_h, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_h, dResult->pixel_h);
/* NOLINTEND(clang-analyzer-core.NullDereference) */
}
}
@ -473,11 +474,11 @@ int video_getClosestDisplayModeRandomResolution(void *arg)
for (variation = 0; variation < 16; variation++) {
/* Set random constraints */
target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
SDL_zero(target);
target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
target.driverdata = 0;
/* Make call; may or may not find anything, so don't validate any further */
SDL_GetClosestDisplayMode(i, &target, &closest);
@ -501,8 +502,8 @@ int video_getWindowDisplayMode(void *arg)
int result;
/* Invalidate part of the mode content so we can check values later */
mode.w = -1;
mode.h = -1;
mode.pixel_w = -1;
mode.pixel_h = -1;
mode.refresh_rate = -1.0f;
/* Call against new test window */
@ -511,8 +512,8 @@ int video_getWindowDisplayMode(void *arg)
result = SDL_GetWindowDisplayMode(window, &mode);
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
SDLTest_AssertCheck(mode.pixel_w > 0, "Validate mode.w content; expected: >0, got: %d", mode.pixel_w);
SDLTest_AssertCheck(mode.pixel_h > 0, "Validate mode.h content; expected: >0, got: %d", mode.pixel_h);
SDLTest_AssertCheck(mode.refresh_rate > 0.0f, "Validate mode.refresh_rate content; expected: >0, got: %g", mode.refresh_rate);
}

View file

@ -24,9 +24,9 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
return;
}
SDL_Log("%s: fmt=%s w=%d h=%d refresh=%gHz\n",
SDL_Log("%s: fmt=%s w=%d h=%d scale=%d%% refresh=%gHz\n",
prefix, SDL_GetPixelFormatName(mode->format),
mode->w, mode->h, mode->refresh_rate);
mode->pixel_w, mode->pixel_h, (int)(mode->display_scale * 100.0f), mode->refresh_rate);
}
int main(int argc, char *argv[])

View file

@ -108,7 +108,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
}
(void)SDL_snprintf(text, sizeof text, "%d: %dx%d@%gHz",
i, mode.w, mode.h, mode.refresh_rate);
i, mode.pixel_w, mode.pixel_h, mode.refresh_rate);
/* Update column width */
text_length = (int)SDL_strlen(text);