mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-26 01:04:17 +00:00
Updated SDL high DPI support
We have gotten feedback that abstracting the coordinate system based on the display scale is unexpected and it is difficult to adapt existing applications to the proposed API. The new approach is to provide the coordinate systems that people expect, but provide additional information that will help applications properly handle high DPI situations. The concepts needed for high DPI support are documented in README-highdpi.md. An example of automatically adapting the content to display scale changes can be found in SDL_test_common.c, where auto_scale_content is checked. Also, the SDL_WINDOW_ALLOW_HIGHDPI window flag has been replaced by the SDL_HINT_VIDEO_ENABLE_HIGH_PIXEL_DENSITY hint. Fixes https://github.com/libsdl-org/SDL/issues/7709
This commit is contained in:
@@ -303,14 +303,21 @@ static int video_getClosestDisplayModeCurrentResolution(void *arg)
|
||||
SDL_memcpy(¤t, modes[0], sizeof(current));
|
||||
|
||||
/* Make call */
|
||||
closest = SDL_GetClosestFullscreenDisplayMode(displays[i], current.pixel_w, current.pixel_h, current.refresh_rate);
|
||||
closest = SDL_GetClosestFullscreenDisplayMode(displays[i],
|
||||
current.w,
|
||||
current.h,
|
||||
current.refresh_rate);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)");
|
||||
SDLTest_Assert(closest != NULL, "Verify returned value is not NULL");
|
||||
|
||||
/* Check that one gets the current resolution back again */
|
||||
if (closest) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
SDL_free((void *)modes);
|
||||
@@ -344,12 +351,14 @@ static int video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
|
||||
/* Set random constraints */
|
||||
SDL_zero(target);
|
||||
target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
|
||||
target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
|
||||
target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
|
||||
target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
|
||||
target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
|
||||
|
||||
/* Make call; may or may not find anything, so don't validate any further */
|
||||
SDL_GetClosestFullscreenDisplayMode(displays[i], target.pixel_w, target.pixel_h, target.refresh_rate);
|
||||
SDL_GetClosestFullscreenDisplayMode(displays[i], target.w,
|
||||
target.h,
|
||||
target.refresh_rate);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Log("%s: fmt=%s w=%d h=%d scale=%d%% refresh=%gHz\n",
|
||||
prefix, SDL_GetPixelFormatName(mode->format),
|
||||
mode->pixel_w, mode->pixel_h, (int)(mode->display_scale * 100.0f), mode->refresh_rate);
|
||||
SDL_Log("%s: %dx%d@%gx, %gHz, fmt=%s\n",
|
||||
prefix,
|
||||
mode->w, mode->h, mode->pixel_density, mode->refresh_rate,
|
||||
SDL_GetPixelFormatName(mode->format));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -39,7 +40,7 @@ int main(int argc, char *argv[])
|
||||
SDLTest_CommonState *state;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
@@ -70,7 +71,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
SDL_GetDisplayBounds(dpy, &rect);
|
||||
modes = SDL_GetFullscreenDisplayModes(dpy, &num_modes);
|
||||
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d fullscreen modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
|
||||
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d at %d,%d), content scale %.1f, %d fullscreen modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, SDL_GetDisplayContentScale(dpy), num_modes);
|
||||
|
||||
mode = SDL_GetCurrentDisplayMode(dpy);
|
||||
if (mode) {
|
||||
|
||||
@@ -339,7 +339,7 @@ int main(int argc, char **argv)
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture]->name);
|
||||
SDL_QueryTexture(pictures[current_picture]->texture, &pixelFormat, &access, &w, &h);
|
||||
/* We want to set the window size in pixels */
|
||||
SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->display_scale), (int)SDL_ceilf(h / mode->display_scale));
|
||||
SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->pixel_density), (int)SDL_ceilf(h / mode->pixel_density));
|
||||
SDL3_SetWindowShape(window, pictures[current_picture]->surface, &pictures[current_picture]->mode);
|
||||
while (should_exit == 0) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
@@ -358,7 +358,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture]->name);
|
||||
SDL_QueryTexture(pictures[current_picture]->texture, &pixelFormat, &access, &w, &h);
|
||||
SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->display_scale), (int)SDL_ceilf(h / mode->display_scale));
|
||||
SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->pixel_density), (int)SDL_ceilf(h / mode->pixel_density));
|
||||
SDL3_SetWindowShape(window, pictures[current_picture]->surface, &pictures[current_picture]->mode);
|
||||
}
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
|
||||
@@ -114,7 +114,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||
|
||||
(void)SDL_snprintf(text, sizeof(text), "%s mode %d: %dx%d@%gHz",
|
||||
SDL_GetDisplayName(display_id),
|
||||
j, mode->pixel_w, mode->pixel_h, mode->refresh_rate);
|
||||
j, mode->w, mode->h, mode->refresh_rate);
|
||||
|
||||
/* Update column width */
|
||||
text_length = (int)SDL_strlen(text);
|
||||
|
||||
Reference in New Issue
Block a user