mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-27 09:44:15 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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[])
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user