From 3bba33932fb2a3dd3137570255fb47a958c8d2fb Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 2 Mar 2023 10:15:14 -0800
Subject: [PATCH] Fixed testshape on high DPI displays
Since the shape is set based on the pixels in the image, we want the window to have the same number of pixels.
---
src/video/windows/SDL_windowsshape.c | 4 +---
test/testshape.c | 12 ++++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/video/windows/SDL_windowsshape.c b/src/video/windows/SDL_windowsshape.c
index dbf197d4cb0f..702c97585a91 100644
--- a/src/video/windows/SDL_windowsshape.c
+++ b/src/video/windows/SDL_windowsshape.c
@@ -80,9 +80,7 @@ int Win32_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
if ((shaper == NULL) ||
(shape == NULL) ||
- ((shape->format->Amask == 0) && (shape_mode->mode != ShapeModeColorKey)) ||
- (shape->w != shaper->window->w) ||
- (shape->h != shaper->window->h)) {
+ ((shape->format->Amask == 0) && (shape_mode->mode != ShapeModeColorKey))) {
return SDL_INVALID_SHAPE_ARGUMENT;
}
diff --git a/test/testshape.c b/test/testshape.c
index 939e0c978529..e846e1b14a12 100644
--- a/test/testshape.c
+++ b/test/testshape.c
@@ -42,6 +42,7 @@ int main(int argc, char **argv)
Uint8 num_pictures;
LoadedPicture *pictures;
int i, j;
+ const SDL_DisplayMode *mode;
SDL_PixelFormat *format = NULL;
SDL_Window *window;
SDL_Renderer *renderer;
@@ -66,6 +67,12 @@ int main(int argc, char **argv)
exit(-2);
}
+ mode = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
+ if (!mode) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't get desktop display mode: %s", SDL_GetError());
+ exit(-2);
+ }
+
num_pictures = argc - 1;
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture) * num_pictures);
if (pictures == NULL) {
@@ -151,7 +158,8 @@ int main(int argc, char **argv)
button_down = 0;
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, 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_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
while (should_exit == 0) {
while (SDL_PollEvent(&event)) {
@@ -170,7 +178,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, w, h);
+ SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->display_scale), (int)SDL_ceilf(h / mode->display_scale));
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
}
if (event.type == SDL_EVENT_QUIT) {