SDL 3.0 is going to be high DPI aware and officially separates screen… (#7145)

* SDL 3.0 is going to be high DPI aware and officially separates screen coordinates from client pixel area

The public APIs to disable high DPI support have been removed

Work in progress on https://github.com/libsdl-org/SDL/issues/7134
This commit is contained in:
Sam Lantinga
2023-01-25 01:23:17 -08:00
committed by GitHub
parent 78cc95e34e
commit 4696c9556b
9 changed files with 158 additions and 289 deletions
+3 -59
View File
@@ -1147,10 +1147,10 @@ extern "C" {
* \brief A variable controlling whether relative mouse motion is affected by renderer scaling * \brief A variable controlling whether relative mouse motion is affected by renderer scaling
* *
* This variable can be set to the following values: * This variable can be set to the following values:
* "0" - Relative motion is unaffected by DPI or renderer's logical size * "0" - Relative motion is unaffected by display scale or renderer's logical size
* "1" - Relative motion is scaled according to DPI scaling and logical size * "1" - Relative motion is scaled according to display scale scaling and logical size
* *
* By default relative mouse deltas are affected by DPI and renderer scaling * By default relative mouse deltas are affected by display scale and renderer scaling
*/ */
#define SDL_HINT_MOUSE_RELATIVE_SCALING "SDL_MOUSE_RELATIVE_SCALING" #define SDL_HINT_MOUSE_RELATIVE_SCALING "SDL_MOUSE_RELATIVE_SCALING"
@@ -1662,11 +1662,6 @@ extern "C" {
*/ */
#define SDL_HINT_VIDEO_EXTERNAL_CONTEXT "SDL_VIDEO_EXTERNAL_CONTEXT" #define SDL_HINT_VIDEO_EXTERNAL_CONTEXT "SDL_VIDEO_EXTERNAL_CONTEXT"
/**
* \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
*/
#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
/** /**
* \brief A variable that dictates policy for fullscreen Spaces on macOS. * \brief A variable that dictates policy for fullscreen Spaces on macOS.
* *
@@ -2039,57 +2034,6 @@ extern "C" {
*/ */
#define SDL_HINT_WINDOWS_USE_D3D9EX "SDL_WINDOWS_USE_D3D9EX" #define SDL_HINT_WINDOWS_USE_D3D9EX "SDL_WINDOWS_USE_D3D9EX"
/**
* \brief Controls whether SDL will declare the process to be DPI aware.
*
* This hint must be set before initializing the video subsystem.
*
* The main purpose of declaring DPI awareness is to disable OS bitmap scaling of SDL windows on monitors with
* a DPI scale factor.
*
* This hint is equivalent to requesting DPI awareness via external means (e.g. calling SetProcessDpiAwarenessContext)
* and does not cause SDL to use a virtualized coordinate system, so it will generally give you 1 SDL coordinate = 1 pixel
* even on high-DPI displays.
*
* For more information, see:
* https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows
*
* This variable can be set to the following values:
* "" - Do not change the DPI awareness (default).
* "unaware" - Declare the process as DPI unaware. (Windows 8.1 and later).
* "system" - Request system DPI awareness. (Vista and later).
* "permonitor" - Request per-monitor DPI awareness. (Windows 8.1 and later).
* "permonitorv2" - Request per-monitor V2 DPI awareness. (Windows 10, version 1607 and later).
* The most visible difference from "permonitor" is that window title bar will be scaled
* to the visually correct size when dragging between monitors with different scale factors.
* This is the preferred DPI awareness level.
*
* If the requested DPI awareness is not available on the currently running OS, SDL will try to request the best
* available match.
*/
#define SDL_HINT_WINDOWS_DPI_AWARENESS "SDL_WINDOWS_DPI_AWARENESS"
/**
* \brief Uses DPI-scaled points as the SDL coordinate system on Windows.
*
* This changes the SDL coordinate system units to be DPI-scaled points, rather than pixels everywhere.
* This means windows will be appropriately sized, even when created on high-DPI displays with scaling.
*
* e.g. requesting a 640x480 window from SDL, on a display with 125% scaling in Windows display settings,
* will create a window with an 800x600 client area (in pixels).
*
* Setting this to "1" implicitly requests process DPI awareness (setting SDL_WINDOWS_DPI_AWARENESS is unnecessary),
* and forces SDL_WINDOW_ALLOW_HIGHDPI on all windows.
*
* This variable can be set to the following values:
* "0" - SDL coordinates equal Windows coordinates. No automatic window resizing when dragging
* between monitors with different scale factors (unless this is performed by
* Windows itself, which is the case when the process is DPI unaware).
* "1" - SDL coordinates are in DPI-scaled points. Automatically resize windows as needed on
* displays with non-100% scale factors.
*/
#define SDL_HINT_WINDOWS_DPI_SCALING "SDL_WINDOWS_DPI_SCALING"
/** /**
* \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden * \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden
* *
+114 -172
View File
File diff suppressed because it is too large Load Diff
-8
View File
@@ -251,10 +251,6 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
state->num_windows = 1; state->num_windows = 1;
return 1; return 1;
} }
if (SDL_strcasecmp(argv[index], "--allow-highdpi") == 0) {
state->window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
return 1;
}
if (SDL_strcasecmp(argv[index], "--windows") == 0) { if (SDL_strcasecmp(argv[index], "--windows") == 0) {
++index; ++index;
if (!argv[index] || !SDL_isdigit((unsigned char)*argv[index])) { if (!argv[index] || !SDL_isdigit((unsigned char)*argv[index])) {
@@ -716,9 +712,6 @@ static void SDLTest_PrintWindowFlag(char *text, size_t maxlen, Uint32 flag)
case SDL_WINDOW_FOREIGN: case SDL_WINDOW_FOREIGN:
SDL_snprintfcat(text, maxlen, "FOREIGN"); SDL_snprintfcat(text, maxlen, "FOREIGN");
break; break;
case SDL_WINDOW_ALLOW_HIGHDPI:
SDL_snprintfcat(text, maxlen, "ALLOW_HIGHDPI");
break;
case SDL_WINDOW_MOUSE_CAPTURE: case SDL_WINDOW_MOUSE_CAPTURE:
SDL_snprintfcat(text, maxlen, "MOUSE_CAPTURE"); SDL_snprintfcat(text, maxlen, "MOUSE_CAPTURE");
break; break;
@@ -767,7 +760,6 @@ static void SDLTest_PrintWindowFlags(char *text, size_t maxlen, Uint32 flags)
SDL_WINDOW_MOUSE_FOCUS, SDL_WINDOW_MOUSE_FOCUS,
SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_FULLSCREEN_DESKTOP,
SDL_WINDOW_FOREIGN, SDL_WINDOW_FOREIGN,
SDL_WINDOW_ALLOW_HIGHDPI,
SDL_WINDOW_MOUSE_CAPTURE, SDL_WINDOW_MOUSE_CAPTURE,
SDL_WINDOW_ALWAYS_ON_TOP, SDL_WINDOW_ALWAYS_ON_TOP,
SDL_WINDOW_SKIP_TASKBAR, SDL_WINDOW_SKIP_TASKBAR,
+3
View File
@@ -516,4 +516,7 @@ extern void SDL_ToggleDragAndDropSupport(void);
extern int SDL_GetDisplayIndexForPoint(const SDL_Point *point); extern int SDL_GetDisplayIndexForPoint(const SDL_Point *point);
/* This has been moved out of the public API, but is still available for now */
#define SDL_WINDOW_ALLOW_HIGHDPI 0x00002000
#endif /* SDL_sysvideo_h_ */ #endif /* SDL_sysvideo_h_ */
+5 -10
View File
@@ -1650,13 +1650,8 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint
} }
} }
/* Unless the user has specified the high-DPI disabling hint, respect the if (!SDL_GetHintBoolean("SDL_VIDEO_HIGHDPI_DISABLED", SDL_FALSE)) {
* SDL_WINDOW_ALLOW_HIGHDPI flag. flags |= SDL_WINDOW_ALLOW_HIGHDPI;
*/
if (flags & SDL_WINDOW_ALLOW_HIGHDPI) {
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_HIGHDPI_DISABLED, SDL_FALSE)) {
flags &= ~SDL_WINDOW_ALLOW_HIGHDPI;
}
} }
window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
@@ -3353,7 +3348,7 @@ void SDL_GL_UnloadLibrary(void)
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
typedef GLenum (APIENTRY* PFNGLGETERRORPROC) (void); typedef GLenum (APIENTRY* PFNGLGETERRORPROC) (void);
typedef void (APIENTRY* PFNGLGETINTEGERVPROC) (GLenum pname, GLint * params); typedef void (APIENTRY* PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
typedef const GLubyte *(APIENTRY* PFNGLGETSTRINGPROC) (GLenum name); typedef const GLubyte *(APIENTRY* PFNGLGETSTRINGPROC) (GLenum name);
#if !SDL_VIDEO_OPENGL #if !SDL_VIDEO_OPENGL
typedef const GLubyte *(APIENTRY* PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); typedef const GLubyte *(APIENTRY* PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
@@ -4136,7 +4131,7 @@ void SDL_GL_DeleteContext(SDL_GLContext context)
* Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
* & 2 for alpha channel. * & 2 for alpha channel.
*/ */
static void CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags) static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags)
{ {
int x, y; int x, y;
Uint32 colorkey; Uint32 colorkey;
@@ -4200,7 +4195,7 @@ static void CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int
/* /*
* Sets the window manager icon for the display window. * Sets the window manager icon for the display window.
*/ */
void SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) void SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
{ {
if (icon && _this->SetIcon) { if (icon && _this->SetIcon) {
/* Generate a mask if necessary, and create the icon! */ /* Generate a mask if necessary, and create the icon! */
+3 -5
View File
@@ -385,10 +385,9 @@ static const char *WIN_GetDPIAwareness(_THIS)
static void WIN_InitDPIAwareness(_THIS) static void WIN_InitDPIAwareness(_THIS)
{ {
const char *hint = SDL_GetHint(SDL_HINT_WINDOWS_DPI_AWARENESS); const char *hint = SDL_GetHint("SDL_WINDOWS_DPI_AWARENESS");
if (hint != NULL) { if (hint == NULL || SDL_strcmp(hint, "permonitorv2") == 0) {
if (SDL_strcmp(hint, "permonitorv2") == 0) {
WIN_DeclareDPIAwarePerMonitorV2(_this); WIN_DeclareDPIAwarePerMonitorV2(_this);
} else if (SDL_strcmp(hint, "permonitor") == 0) { } else if (SDL_strcmp(hint, "permonitor") == 0) {
WIN_DeclareDPIAwarePerMonitor(_this); WIN_DeclareDPIAwarePerMonitor(_this);
@@ -397,14 +396,13 @@ static void WIN_InitDPIAwareness(_THIS)
} else if (SDL_strcmp(hint, "unaware") == 0) { } else if (SDL_strcmp(hint, "unaware") == 0) {
WIN_DeclareDPIAwareUnaware(_this); WIN_DeclareDPIAwareUnaware(_this);
} }
}
} }
static void WIN_InitDPIScaling(_THIS) static void WIN_InitDPIScaling(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
if (SDL_GetHintBoolean(SDL_HINT_WINDOWS_DPI_SCALING, SDL_FALSE)) { if (SDL_GetHintBoolean("SDL_WINDOWS_DPI_SCALING", SDL_TRUE)) {
WIN_DeclareDPIAwarePerMonitorV2(_this); WIN_DeclareDPIAwarePerMonitorV2(_this);
data->dpi_scaling_enabled = SDL_TRUE; data->dpi_scaling_enabled = SDL_TRUE;
-2
View File
@@ -21,7 +21,6 @@ const char *HintsEnum[] = {
SDL_HINT_RENDER_VSYNC, SDL_HINT_RENDER_VSYNC,
SDL_HINT_TIMER_RESOLUTION, SDL_HINT_TIMER_RESOLUTION,
SDL_HINT_VIDEO_ALLOW_SCREENSAVER, SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
SDL_HINT_VIDEO_HIGHDPI_DISABLED,
SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT, SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
@@ -45,7 +44,6 @@ const char *HintsVerbose[] = {
"SDL_RENDER_VSYNC", "SDL_RENDER_VSYNC",
"SDL_TIMER_RESOLUTION", "SDL_TIMER_RESOLUTION",
"SDL_VIDEO_ALLOW_SCREENSAVER", "SDL_VIDEO_ALLOW_SCREENSAVER",
"SDL_VIDEO_HIGHDPI_DISABLED",
"SDL_VIDEO_MAC_FULLSCREEN_SPACES", "SDL_VIDEO_MAC_FULLSCREEN_SPACES",
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
+1 -1
View File
@@ -1753,7 +1753,7 @@ int video_setWindowCenteredOnDisplay(void *arg)
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_ALLOW_HIGHDPI); window = SDL_CreateWindow(title, x, y, w, h, 0);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
+1 -4
View File
@@ -103,9 +103,6 @@ int main(int argc, char *argv[])
/* Enable standard application logging */ /* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Enable highdpi scaling on Windows */
SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, "1");
/* Initialize SDL */ /* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
@@ -113,7 +110,7 @@ int main(int argc, char *argv[])
} }
/* Create window and renderer for given surface */ /* Create window and renderer for given surface */
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
if (window == NULL) { if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError());
return 1; return 1;