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/7709main
parent
0fbb9c779c
commit
c699f3d1d8
|
@ -2284,26 +2284,6 @@ expression e;
|
|||
- SDL_WINDOW_INPUT_GRABBED
|
||||
+ SDL_WINDOW_MOUSE_GRABBED
|
||||
@@
|
||||
SDL_DisplayMode *e;
|
||||
@@
|
||||
(
|
||||
- e->w
|
||||
+ e->screen_w
|
||||
|
|
||||
- e->h
|
||||
+ e->screen_h
|
||||
)
|
||||
@@
|
||||
SDL_DisplayMode e;
|
||||
@@
|
||||
(
|
||||
- e.w
|
||||
+ e.screen_w
|
||||
|
|
||||
- e.h
|
||||
+ e.screen_h
|
||||
)
|
||||
@@
|
||||
@@
|
||||
- SDL_GetWindowDisplayIndex
|
||||
+ SDL_GetDisplayForWindow
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
SDL 3.0 has new support for high DPI displays
|
||||
|
||||
Displays now have a content display scale.
|
||||
|
||||
The display scale is the expected scale for content based on the DPI settings of the display. For example, a 4K display might have a 2.0 (200%) display scale, which means that the user expects UI elements to be twice as big on this display, to aid in readability.
|
||||
|
||||
The window size is now distinct from the window pixel size.
|
||||
|
||||
The window also has a display scale, which is the content display scale relative to the window pixel size.
|
||||
|
||||
For example, a 3840x2160 window displayed at 200% on Windows, and a 1920x1080 window on a 2x display on macOS will both have a pixel size of 3840x2160 and a display scale of 2.0.
|
||||
|
||||
You can query the window size using SDL_GetWindowSize(), and when this changes you get an SDL_EVENT_WINDOW_RESIZED event.
|
||||
|
||||
You can query the window pixel size using SDL_GetWindowSizeInPixels(), and when this changes you get an SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. You are guaranteed to get a SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event when a window is created and resized, and you can use this event to create and resize your graphics context for the window.
|
||||
|
||||
You can query the window display scale using SDL_GetWindowDisplayScale(), and when this changes you get an SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED event.
|
|
@ -1085,9 +1085,9 @@ The SDL_WINDOWPOS_UNDEFINED_DISPLAY() and SDL_WINDOWPOS_CENTERED_DISPLAY() macro
|
|||
|
||||
The SDL_WINDOW_SHOWN flag has been removed. Windows are shown by default and can be created hidden by using the SDL_WINDOW_HIDDEN flag.
|
||||
|
||||
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.
|
||||
The SDL_WINDOW_ALLOW_HIGHDPI flag has been replaced by the SDL_HINT_VIDEO_ENABLE_HIGH_PIXEL_DENSITY hint, which is enabled by default.
|
||||
|
||||
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.
|
||||
SDL_DisplayMode now includes the pixel density which can be greater than 1.0 for display modes that have a higher pixel size than the mode size. You should use SDL_GetWindowSizeInPixels() to get the actual pixel size of the window back buffer.
|
||||
|
||||
The refresh rate in SDL_DisplayMode is now a float.
|
||||
|
||||
|
@ -1100,8 +1100,8 @@ Rather than iterating over display modes using an index, there is a new function
|
|||
if (modes) {
|
||||
for (i = 0; i < num_modes; ++i) {
|
||||
SDL_DisplayMode *mode = modes[i];
|
||||
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
|
||||
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
|
||||
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gx %gHz\n",
|
||||
display, i, mode->w, mode->h, mode->pixel_density, mode->refresh_rate);
|
||||
}
|
||||
SDL_free(modes);
|
||||
}
|
||||
|
|
|
@ -95,9 +95,9 @@ typedef enum
|
|||
SDL_EVENT_DISPLAY_CONNECTED, /**< Display has been added to the system */
|
||||
SDL_EVENT_DISPLAY_DISCONNECTED, /**< Display has been removed from the system */
|
||||
SDL_EVENT_DISPLAY_MOVED, /**< Display has changed position */
|
||||
SDL_EVENT_DISPLAY_SCALE_CHANGED, /**< Display has changed desktop display scale */
|
||||
SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, /**< Display has changed content scale */
|
||||
SDL_EVENT_DISPLAY_FIRST = SDL_EVENT_DISPLAY_ORIENTATION,
|
||||
SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_SCALE_CHANGED,
|
||||
SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED,
|
||||
|
||||
/* Window events */
|
||||
/* 0x200 was SDL_WINDOWEVENT, reserve the number for sdl2-compat */
|
||||
|
@ -120,6 +120,7 @@ typedef enum
|
|||
SDL_EVENT_WINDOW_HIT_TEST, /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL */
|
||||
SDL_EVENT_WINDOW_ICCPROF_CHANGED, /**< The ICC profile of the window's display has changed */
|
||||
SDL_EVENT_WINDOW_DISPLAY_CHANGED, /**< Window has been moved to display data1 */
|
||||
SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED, /**< Window display scale has been changed */
|
||||
SDL_EVENT_WINDOW_DESTROYED, /**< The window with the associated ID is being or has been destroyed. If this message is being handled
|
||||
in an event watcher, the window handle is still valid and can still be used to retrieve any userdata
|
||||
associated with the window. Otherwise, the handle has already been destroyed and all resources
|
||||
|
|
|
@ -1638,6 +1638,17 @@ extern "C" {
|
|||
*/
|
||||
#define SDL_HINT_VIDEO_EXTERNAL_CONTEXT "SDL_VIDEO_EXTERNAL_CONTEXT"
|
||||
|
||||
/**
|
||||
* \brief A variable controlling whether to use high pixel density display modes
|
||||
*
|
||||
* The variable can be set to the following values:
|
||||
* "0" - Disable high pixel density display modes
|
||||
* "1" - Enable high pixel density display modes
|
||||
*
|
||||
* The default value is "1". This hint must be set before display modes are queried and windows are created.
|
||||
*/
|
||||
#define SDL_HINT_VIDEO_ENABLE_HIGH_PIXEL_DENSITY "SDL_VIDEO_ENABLE_HIGH_PIXEL_DENSITY"
|
||||
|
||||
/**
|
||||
* \brief A variable that dictates policy for fullscreen Spaces on macOS.
|
||||
*
|
||||
|
|
|
@ -140,7 +140,6 @@ typedef enum
|
|||
typedef enum
|
||||
{
|
||||
SDL_LOGICAL_PRESENTATION_DISABLED, /**< There is no logical size in effect */
|
||||
SDL_LOGICAL_PRESENTATION_MATCH, /**< The rendered content matches the window size in points */
|
||||
SDL_LOGICAL_PRESENTATION_STRETCH, /**< The rendered content is stretched to the output resolution */
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with black bars */
|
||||
SDL_LOGICAL_PRESENTATION_OVERSCAN, /**< The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds */
|
||||
|
@ -235,9 +234,8 @@ extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(int width, int height, U
|
|||
* need a specific renderer, specify NULL and SDL will attempt to chooes the
|
||||
* best option for you, based on what is available on the user's system.
|
||||
*
|
||||
* By default the rendering size matches the window size in points, but you
|
||||
* can call SDL_SetRenderLogicalPresentation() to enable high DPI rendering or
|
||||
* change the content size and scaling options.
|
||||
* By default the rendering size matches the window size in pixels, but you
|
||||
* can call SDL_SetRenderLogicalPresentation() to change the content size and scaling options.
|
||||
*
|
||||
* \param window the window where rendering is displayed
|
||||
* \param name the name of the rendering driver to initialize, or NULL to
|
||||
|
@ -316,24 +314,6 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_GetRenderWindow(SDL_Renderer *renderer);
|
|||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_RendererInfo *info);
|
||||
|
||||
/**
|
||||
* Get the output size in points of a rendering context.
|
||||
*
|
||||
* This returns the true output size in points, ignoring any render targets or
|
||||
* logical size and presentation.
|
||||
*
|
||||
* \param renderer the rendering context
|
||||
* \param w a pointer filled in with the width in points
|
||||
* \param h a pointer filled in with the height in points
|
||||
* \returns 0 on success or a negative error code on failure; call
|
||||
* SDL_GetError() for more information.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_GetRenderer
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetRenderWindowSize(SDL_Renderer *renderer, int *w, int *h);
|
||||
|
||||
/**
|
||||
* Get the output size in pixels of a rendering context.
|
||||
*
|
||||
|
@ -840,13 +820,9 @@ extern DECLSPEC SDL_Texture *SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer)
|
|||
* render target is created at the specified size and used for rendering and
|
||||
* then copied to the output during presentation.
|
||||
*
|
||||
* When a renderer is created, the logical size is set to match the window
|
||||
* size in points. The actual output size may be higher pixel density, and can
|
||||
* be queried with SDL_GetRenderOutputSize().
|
||||
*
|
||||
* You can disable logical coordinates by setting the mode to
|
||||
* SDL_LOGICAL_PRESENTATION_DISABLED, and in that case you get the full
|
||||
* resolution of the output window.
|
||||
* pixel resolution of the output window.
|
||||
*
|
||||
* You can convert coordinates in an event into rendering coordinates using
|
||||
* SDL_ConvertEventToRenderCoordinates().
|
||||
|
@ -887,8 +863,7 @@ extern DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *rende
|
|||
extern DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
|
||||
|
||||
/**
|
||||
* Get a point in render coordinates when given a point in window coordinates
|
||||
* (points).
|
||||
* Get a point in render coordinates when given a point in window coordinates.
|
||||
*
|
||||
* \param renderer the rendering context
|
||||
* \param window_x the x coordinate in window coordinates
|
||||
|
@ -906,8 +881,7 @@ extern DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *rende
|
|||
extern DECLSPEC int SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y);
|
||||
|
||||
/**
|
||||
* Get a point in window coordinates (points) when given a point in render
|
||||
* coordinates.
|
||||
* Get a point in window coordinates when given a point in render coordinates.
|
||||
*
|
||||
* \param renderer the rendering context
|
||||
* \param x the x coordinate in render coordinates
|
||||
|
|
|
@ -77,6 +77,7 @@ typedef struct
|
|||
int window_maxH;
|
||||
int logical_w;
|
||||
int logical_h;
|
||||
SDL_bool auto_scale_content;
|
||||
SDL_RendererLogicalPresentation logical_presentation;
|
||||
SDL_ScaleMode logical_scale_mode;
|
||||
float scale;
|
||||
|
|
|
@ -66,11 +66,9 @@ typedef struct
|
|||
{
|
||||
SDL_DisplayID displayID; /**< the display this mode is associated with */
|
||||
Uint32 format; /**< pixel format */
|
||||
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) */
|
||||
int w; /**< width */
|
||||
int h; /**< height */
|
||||
float pixel_density; /**< scale converting size to pixels (e.g. a 1920x1080 mode with 2.0 scale would have 3840x2160 pixels) */
|
||||
float refresh_rate; /**< refresh rate (or zero for unspecified) */
|
||||
void *driverdata; /**< driver-specific data, initialize to 0 */
|
||||
} SDL_DisplayMode;
|
||||
|
@ -356,7 +354,7 @@ extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetPrimaryDisplay(void);
|
|||
extern DECLSPEC const char *SDLCALL SDL_GetDisplayName(SDL_DisplayID displayID);
|
||||
|
||||
/**
|
||||
* Get the desktop area represented by a display, in screen coordinates.
|
||||
* Get the desktop area represented by a display.
|
||||
*
|
||||
* The primary display is always located at (0,0).
|
||||
*
|
||||
|
@ -409,18 +407,31 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(SDL_DisplayID displayID,
|
|||
*/
|
||||
extern DECLSPEC SDL_DisplayOrientation SDLCALL SDL_GetDisplayOrientation(SDL_DisplayID displayID);
|
||||
|
||||
/**
|
||||
* Get the content scale of a display.
|
||||
*
|
||||
* The content scale is the expected scale for content based on the DPI settings of the display. For example, a 4K display might have a 2.0 (200%) display scale, which means that the user expects UI elements to be twice as big on this display, to aid in readability.
|
||||
*
|
||||
* \param displayID the instance ID of the display to query
|
||||
* \returns The content scale of the display, or 0.0f on error; call SDL_GetError() for more details.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_GetDisplays
|
||||
*/
|
||||
extern DECLSPEC float SDLCALL SDL_GetDisplayContentScale(SDL_DisplayID displayID);
|
||||
|
||||
/**
|
||||
* Get a list of fullscreen display modes available on a display.
|
||||
*
|
||||
* The display modes are sorted in this priority:
|
||||
*
|
||||
* - screen_w -> largest to smallest
|
||||
* - screen_h -> largest to smallest
|
||||
* - pixel_w -> largest to smallest
|
||||
* - pixel_h -> largest to smallest
|
||||
* - w -> largest to smallest
|
||||
* - h -> largest to smallest
|
||||
* - bits per pixel -> more colors to fewer colors
|
||||
* - packed pixel layout -> largest to smallest
|
||||
* - refresh rate -> highest to lowest
|
||||
* - pixel density -> lowest to highest
|
||||
*
|
||||
* \param displayID the instance ID of the display to query
|
||||
* \param count a pointer filled in with the number of displays returned
|
||||
|
@ -499,7 +510,7 @@ extern DECLSPEC const SDL_DisplayMode *SDLCALL SDL_GetDesktopDisplayMode(SDL_Dis
|
|||
extern DECLSPEC const SDL_DisplayMode *SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayID displayID);
|
||||
|
||||
/**
|
||||
* Get the display containing a point, in screen coordinates.
|
||||
* Get the display containing a point.
|
||||
*
|
||||
* \param point the point to query
|
||||
* \returns the instance ID of the display containing the point or 0 on
|
||||
|
@ -513,7 +524,7 @@ extern DECLSPEC const SDL_DisplayMode *SDLCALL SDL_GetCurrentDisplayMode(SDL_Dis
|
|||
extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetDisplayForPoint(const SDL_Point *point);
|
||||
|
||||
/**
|
||||
* Get the display primarily containing a rect, in screen coordinates.
|
||||
* Get the display primarily containing a rect.
|
||||
*
|
||||
* \param rect the rect to query
|
||||
* \returns the instance ID of the display entirely containing the rect or
|
||||
|
@ -542,6 +553,20 @@ extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetDisplayForRect(const SDL_Rect *rect
|
|||
*/
|
||||
extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetDisplayForWindow(SDL_Window *window);
|
||||
|
||||
/**
|
||||
* Get the content display scale relative to a window's pixel size.
|
||||
*
|
||||
* This is a combination of the window pixel density and the display content scale, and is the expected scale for displaying content in this window. For example, if a 3840x2160 window had a display scale of 2.0, the user expects the content to take twice as many pixels and be the same physical size as if it were being displayed in a 1920x1080 window with a display scale of 1.0.
|
||||
*
|
||||
* Conceptually this value corresponds to the scale display setting, and is updated when that setting is changed, or the window moves to a display with a different scale setting.
|
||||
*
|
||||
* \param window the window to query
|
||||
* \returns the display scale, or 0.0f on failure; call SDL_GetError() for more information.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*/
|
||||
extern DECLSPEC float SDLCALL SDL_GetWindowDisplayScale(SDL_Window *window);
|
||||
|
||||
/**
|
||||
* Set the display mode to use when a window is visible and fullscreen.
|
||||
*
|
||||
|
@ -623,9 +648,8 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window *window);
|
|||
* On Apple's macOS, you **must** set the NSHighResolutionCapable Info.plist
|
||||
* property to YES, otherwise you will not receive a High-DPI OpenGL canvas.
|
||||
*
|
||||
* The window size in pixels may differ from its size in screen coordinates if
|
||||
* the window is on a high density display (one with an OS scaling factor).
|
||||
* Use SDL_GetWindowSize() to query the client area's size in screen
|
||||
* The window pixel size may differ from its window coordinate size if the window is on a high pixel density display.
|
||||
* Use SDL_GetWindowSize() to query the client area's size in window
|
||||
* coordinates, and SDL_GetWindowSizeInPixels() or SDL_GetRenderOutputSize()
|
||||
* to query the drawable size in pixels. Note that the drawable size can vary
|
||||
* after the window is created and should be queried again if you get an
|
||||
|
@ -652,8 +676,8 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window *window);
|
|||
* in a future version of SDL.
|
||||
*
|
||||
* \param title the title of the window, in UTF-8 encoding
|
||||
* \param w the width of the window, in screen coordinates
|
||||
* \param h the height of the window, in screen coordinates
|
||||
* \param w the width of the window
|
||||
* \param h the height of the window
|
||||
* \param flags 0, or one or more SDL_WindowFlags OR'd together
|
||||
* \returns the window that was created or NULL on failure; call
|
||||
* SDL_GetError() for more information.
|
||||
|
@ -688,9 +712,8 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int w, i
|
|||
* On Apple's macOS, you **must** set the NSHighResolutionCapable Info.plist
|
||||
* property to YES, otherwise you will not receive a High-DPI OpenGL canvas.
|
||||
*
|
||||
* The window size in pixels may differ from its size in screen coordinates if
|
||||
* the window is on a high density display (one with an OS scaling factor).
|
||||
* Use SDL_GetWindowSize() to query the client area's size in screen
|
||||
* The window pixel size may differ from its window coordinate size if the window is on a high pixel density display.
|
||||
* Use SDL_GetWindowSize() to query the client area's size in window
|
||||
* coordinates, and SDL_GetWindowSizeInPixels() or SDL_GetRenderOutputSize()
|
||||
* to query the drawable size in pixels. Note that the drawable size can vary
|
||||
* after the window is created and should be queried again if you get an
|
||||
|
@ -719,8 +742,8 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int w, i
|
|||
* \param title the title of the window, in UTF-8 encoding
|
||||
* \param x the x position of the window, or `SDL_WINDOWPOS_CENTERED`
|
||||
* \param y the y position of the window, or `SDL_WINDOWPOS_CENTERED`
|
||||
* \param w the width of the window, in screen coordinates
|
||||
* \param h the height of the window, in screen coordinates
|
||||
* \param w the width of the window
|
||||
* \param h the height of the window
|
||||
* \param flags 0, or one or more SDL_WindowFlags OR'd together
|
||||
* \returns the window that was created or NULL on failure; call
|
||||
* SDL_GetError() for more information.
|
||||
|
@ -767,11 +790,11 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithPosition(const char *tit
|
|||
*
|
||||
* \param parent the parent of the window, must not be NULL
|
||||
* \param offset_x the x position of the popup window relative to the origin
|
||||
* of the parent, in screen coordinates
|
||||
* of the parent
|
||||
* \param offset_y the y position of the popup window relative to the origin
|
||||
* of the parent window, in screen coordinates
|
||||
* \param w the width of the window, in screen coordinates
|
||||
* \param h the height of the window, in screen coordinates
|
||||
* of the parent window
|
||||
* \param w the width of the window
|
||||
* \param h the height of the window
|
||||
* \param flags SDL_WINDOW_TOOLTIP or SDL_WINDOW_POPUP MENU, and zero or more
|
||||
* additional SDL_WindowFlags OR'd together.
|
||||
* \returns the window that was created or NULL on failure; call
|
||||
|
@ -938,7 +961,7 @@ extern DECLSPEC void *SDLCALL SDL_SetWindowData(SDL_Window *window, const char *
|
|||
extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_Window *window, const char *name);
|
||||
|
||||
/**
|
||||
* Set the position of a window, in screen coordinates.
|
||||
* Set the position of a window.
|
||||
*
|
||||
* \param window the window to reposition
|
||||
* \param x the x coordinate of the window, or `SDL_WINDOWPOS_CENTERED` or
|
||||
|
@ -955,7 +978,7 @@ extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_Window *window, const char *
|
|||
extern DECLSPEC int SDLCALL SDL_SetWindowPosition(SDL_Window *window, int x, int y);
|
||||
|
||||
/**
|
||||
* Get the position of a window, in screen coordinates.
|
||||
* Get the position of a window.
|
||||
*
|
||||
* If you do not need the value for one of the positions a NULL may be passed
|
||||
* in the `x` or `y` parameter.
|
||||
|
@ -973,10 +996,7 @@ extern DECLSPEC int SDLCALL SDL_SetWindowPosition(SDL_Window *window, int x, int
|
|||
extern DECLSPEC int SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x, int *y);
|
||||
|
||||
/**
|
||||
* Set the size of a window's client area, in screen coordinates.
|
||||
*
|
||||
* The window size in screen coordinates may differ from the size in pixels if
|
||||
* the window is on a high density display (one with an OS scaling factor).
|
||||
* Set the size of a window's client area.
|
||||
*
|
||||
* This only affects the size of the window when not in fullscreen mode. To
|
||||
* change the fullscreen mode of a window, use SDL_SetWindowFullscreenMode()
|
||||
|
@ -995,13 +1015,12 @@ extern DECLSPEC int SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x, in
|
|||
extern DECLSPEC int SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int h);
|
||||
|
||||
/**
|
||||
* Get the size of a window's client area, in screen coordinates.
|
||||
* Get the size of a window's client area.
|
||||
*
|
||||
* NULL can safely be passed as the `w` or `h` parameter if the width or
|
||||
* height value is not desired.
|
||||
*
|
||||
* The window size in screen coordinates may differ from the size in pixels if
|
||||
* the window is on a high density display (one with an OS scaling factor).
|
||||
* The window pixel size may differ from its window coordinate size if the window is on a high pixel density display.
|
||||
* Use SDL_GetWindowSizeInPixels() or SDL_GetRenderOutputSize() to get the
|
||||
* real client area size in pixels.
|
||||
*
|
||||
|
@ -1020,8 +1039,7 @@ extern DECLSPEC int SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int h);
|
|||
extern DECLSPEC int SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h);
|
||||
|
||||
/**
|
||||
* Get the size of a window's borders (decorations) around the client area, in
|
||||
* screen coordinates.
|
||||
* Get the size of a window's borders (decorations) around the client area.
|
||||
*
|
||||
* Note: If this function fails (returns -1), the size values will be
|
||||
* initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as if the
|
||||
|
@ -1057,9 +1075,6 @@ extern DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window *window, int *to
|
|||
/**
|
||||
* Get the size of a window's client area, in pixels.
|
||||
*
|
||||
* The window size in pixels may differ from the size in screen coordinates if
|
||||
* the window is on a high density display (one with an OS scaling factor).
|
||||
*
|
||||
* \param window the window from which the drawable size should be queried
|
||||
* \param w a pointer to variable for storing the width in pixels, may be NULL
|
||||
* \param h a pointer to variable for storing the height in pixels, may be
|
||||
|
@ -1075,7 +1090,7 @@ extern DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window *window, int *to
|
|||
extern DECLSPEC int SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h);
|
||||
|
||||
/**
|
||||
* Set the minimum size of a window's client area, in screen coordinates.
|
||||
* Set the minimum size of a window's client area.
|
||||
*
|
||||
* \param window the window to change
|
||||
* \param min_w the minimum width of the window, or 0 for no limit
|
||||
|
@ -1091,7 +1106,7 @@ extern DECLSPEC int SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, int *w
|
|||
extern DECLSPEC int SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h);
|
||||
|
||||
/**
|
||||
* Get the minimum size of a window's client area, in screen coordinates.
|
||||
* Get the minimum size of a window's client area.
|
||||
*
|
||||
* \param window the window to query
|
||||
* \param w a pointer filled in with the minimum width of the window, may be
|
||||
|
@ -1109,7 +1124,7 @@ extern DECLSPEC int SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int min
|
|||
extern DECLSPEC int SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int *w, int *h);
|
||||
|
||||
/**
|
||||
* Set the maximum size of a window's client area, in screen coordinates.
|
||||
* Set the maximum size of a window's client area.
|
||||
*
|
||||
* \param window the window to change
|
||||
* \param max_w the maximum width of the window, or 0 for no limit
|
||||
|
@ -1125,7 +1140,7 @@ extern DECLSPEC int SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int *w,
|
|||
extern DECLSPEC int SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h);
|
||||
|
||||
/**
|
||||
* Get the maximum size of a window's client area, in screen coordinates.
|
||||
* Get the maximum size of a window's client area.
|
||||
*
|
||||
* \param window the window to query
|
||||
* \param w a pointer filled in with the maximum width of the window, may be
|
||||
|
|
|
@ -837,7 +837,6 @@ SDL3_0.0.0 {
|
|||
SDL_ConvertEventToRenderCoordinates;
|
||||
SDL_SetRenderScale;
|
||||
SDL_GetRenderScale;
|
||||
SDL_GetRenderWindowSize;
|
||||
SDL_GetSystemTheme;
|
||||
SDL_CreatePopupWindow;
|
||||
SDL_GetWindowParent;
|
||||
|
@ -856,6 +855,8 @@ SDL3_0.0.0 {
|
|||
SDL_UnlockRWLock;
|
||||
SDL_DestroyRWLock;
|
||||
SDL_GetPath;
|
||||
SDL_GetDisplayContentScale;
|
||||
SDL_GetWindowDisplayScale;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
|
|
@ -863,7 +863,6 @@
|
|||
#define SDL_ConvertEventToRenderCoordinates SDL_ConvertEventToRenderCoordinates_REAL
|
||||
#define SDL_SetRenderScale SDL_SetRenderScale_REAL
|
||||
#define SDL_GetRenderScale SDL_GetRenderScale_REAL
|
||||
#define SDL_GetRenderWindowSize SDL_GetRenderWindowSize_REAL
|
||||
#define SDL_GetSystemTheme SDL_GetSystemTheme_REAL
|
||||
#define SDL_CreatePopupWindow SDL_CreatePopupWindow_REAL
|
||||
#define SDL_GetWindowParent SDL_GetWindowParent_REAL
|
||||
|
@ -882,3 +881,5 @@
|
|||
#define SDL_UnlockRWLock SDL_UnlockRWLock_REAL
|
||||
#define SDL_DestroyRWLock SDL_DestroyRWLock_REAL
|
||||
#define SDL_GetPath SDL_GetPath_REAL
|
||||
#define SDL_GetDisplayContentScale SDL_GetDisplayContentScale_REAL
|
||||
#define SDL_GetWindowDisplayScale SDL_GetWindowDisplayScale_REAL
|
||||
|
|
|
@ -908,7 +908,6 @@ SDL_DYNAPI_PROC(int,SDL_GetRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a
|
|||
SDL_DYNAPI_PROC(int,SDL_ConvertEventToRenderCoordinates,(SDL_Renderer *a, SDL_Event *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SetRenderScale,(SDL_Renderer *a, float b, float c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetRenderScale,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetRenderWindowSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_SystemTheme,SDL_GetSystemTheme,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreatePopupWindow,(SDL_Window *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
|
||||
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowParent,(SDL_Window *a),(a),return)
|
||||
|
@ -927,3 +926,5 @@ SDL_DYNAPI_PROC(int,SDL_TryLockRWLockForWriting,(SDL_RWLock *a),(a),return)
|
|||
SDL_DYNAPI_PROC(int,SDL_UnlockRWLock,(SDL_RWLock *a),(a),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_DestroyRWLock,(SDL_RWLock *a),(a),)
|
||||
SDL_DYNAPI_PROC(char*,SDL_GetPath,(SDL_Folder a),(a),return)
|
||||
SDL_DYNAPI_PROC(float,SDL_GetDisplayContentScale,(SDL_DisplayID a),(a),return)
|
||||
SDL_DYNAPI_PROC(float,SDL_GetWindowDisplayScale,(SDL_Window *a),(a),return)
|
||||
|
|
|
@ -225,7 +225,7 @@ static void SDL_LogEvent(const SDL_Event *event)
|
|||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CONNECTED);
|
||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_DISCONNECTED);
|
||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_MOVED);
|
||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_SCALE_CHANGED);
|
||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED);
|
||||
#undef SDL_DISPLAYEVENT_CASE
|
||||
|
||||
#define SDL_WINDOWEVENT_CASE(x) \
|
||||
|
@ -239,6 +239,7 @@ static void SDL_LogEvent(const SDL_Event *event)
|
|||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_EXPOSED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_MOVED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_RESIZED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_MINIMIZED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_MAXIMIZED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_RESTORED);
|
||||
|
@ -251,7 +252,8 @@ static void SDL_LogEvent(const SDL_Event *event)
|
|||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_HIT_TEST);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_ICCPROF_CHANGED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_DISPLAY_CHANGED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED);
|
||||
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_DESTROYED);
|
||||
#undef SDL_WINDOWEVENT_CASE
|
||||
|
||||
SDL_EVENT_CASE(SDL_EVENT_SYSWM)
|
||||
|
|
|
@ -655,11 +655,16 @@ static void UpdateMainViewDimensions(SDL_Renderer *renderer)
|
|||
{
|
||||
int window_w = 0, window_h = 0;
|
||||
|
||||
SDL_GetRenderWindowSize(renderer, &window_w, &window_h);
|
||||
if (renderer->window) {
|
||||
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
|
||||
}
|
||||
SDL_GetRenderOutputSize(renderer, &renderer->main_view.pixel_w, &renderer->main_view.pixel_h);
|
||||
if (window_w > 0 && window_h > 0) {
|
||||
renderer->dpi_scale.x = (float)renderer->main_view.pixel_w / window_w;
|
||||
renderer->dpi_scale.y = (float)renderer->main_view.pixel_h / window_h;
|
||||
} else {
|
||||
renderer->dpi_scale.x = 1.0f;
|
||||
renderer->dpi_scale.y = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1001,21 +1006,6 @@ int SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_RendererInfo *info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int SDL_GetRenderWindowSize(SDL_Renderer *renderer, int *w, int *h)
|
||||
{
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
if (renderer->window) {
|
||||
/*return */SDL_GetWindowSize(renderer->window, w, h);
|
||||
return 0;
|
||||
} else if (renderer->GetOutputSize) {
|
||||
return renderer->GetOutputSize(renderer, w, h);
|
||||
} else {
|
||||
SDL_assert(0 && "This should never happen");
|
||||
return SDL_SetError("Renderer doesn't support querying output size");
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
||||
{
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
@ -1023,8 +1013,7 @@ int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
|||
if (renderer->GetOutputSize) {
|
||||
return renderer->GetOutputSize(renderer, w, h);
|
||||
} else if (renderer->window) {
|
||||
SDL_GetWindowSizeInPixels(renderer->window, w, h);
|
||||
return 0;
|
||||
return SDL_GetWindowSizeInPixels(renderer->window, w, h);
|
||||
} else {
|
||||
SDL_assert(0 && "This should never happen");
|
||||
return SDL_SetError("Renderer doesn't support querying output size");
|
||||
|
@ -2117,37 +2106,13 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_MATCH) {
|
||||
if (SDL_GetRenderWindowSize(renderer, &logical_w, &logical_h) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (renderer->logical_target) {
|
||||
int existing_w = 0, existing_h = 0;
|
||||
|
||||
if (SDL_QueryTexture(renderer->logical_target, NULL, NULL, &existing_w, &existing_h) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (logical_w != existing_w || logical_h != existing_h) {
|
||||
SDL_DestroyTexture(renderer->logical_target);
|
||||
}
|
||||
}
|
||||
if (!renderer->logical_target) {
|
||||
renderer->logical_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_TARGET, logical_w, logical_h);
|
||||
if (!renderer->logical_target) {
|
||||
goto error;
|
||||
}
|
||||
SDL_SetTextureBlendMode(renderer->logical_target, SDL_BLENDMODE_NONE);
|
||||
}
|
||||
} else {
|
||||
if (SDL_QueryTexture(renderer->logical_target, NULL, NULL, &logical_w, &logical_h) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
want_aspect = (float)logical_w / logical_h;
|
||||
real_aspect = (float)output_w / output_h;
|
||||
if (SDL_QueryTexture(renderer->logical_target, NULL, NULL, &logical_w, &logical_h) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
want_aspect = (float)logical_w / logical_h;
|
||||
real_aspect = (float)output_w / output_h;
|
||||
|
||||
renderer->logical_src_rect.x = 0.0f;
|
||||
renderer->logical_src_rect.y = 0.0f;
|
||||
renderer->logical_src_rect.w = (float)logical_w;
|
||||
|
@ -2169,8 +2134,7 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
|
|||
renderer->logical_dst_rect.h = SDL_floorf(logical_h * scale);
|
||||
renderer->logical_dst_rect.y = (output_h - renderer->logical_dst_rect.h) / 2.0f;
|
||||
|
||||
} else if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_MATCH ||
|
||||
renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_STRETCH ||
|
||||
} else if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_STRETCH ||
|
||||
SDL_fabsf(want_aspect - real_aspect) < 0.0001f) {
|
||||
renderer->logical_dst_rect.x = 0.0f;
|
||||
renderer->logical_dst_rect.y = 0.0f;
|
||||
|
@ -2238,7 +2202,7 @@ int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_R
|
|||
if (renderer->logical_target) {
|
||||
SDL_DestroyTexture(renderer->logical_target);
|
||||
}
|
||||
} else if (mode != SDL_LOGICAL_PRESENTATION_MATCH) {
|
||||
} else {
|
||||
if (renderer->logical_target) {
|
||||
int existing_w = 0, existing_h = 0;
|
||||
|
||||
|
@ -2438,11 +2402,13 @@ int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event
|
|||
event->type == SDL_EVENT_FINGER_UP ||
|
||||
event->type == SDL_EVENT_FINGER_MOTION) {
|
||||
/* FIXME: Are these events guaranteed to be window relative? */
|
||||
int w, h;
|
||||
if (SDL_GetRenderWindowSize(renderer, &w, &h) < 0) {
|
||||
return -1;
|
||||
if (renderer->window) {
|
||||
int w, h;
|
||||
if (SDL_GetWindowSize(renderer->window, &w, &h) < 0) {
|
||||
return -1;
|
||||
}
|
||||
SDL_RenderCoordinatesFromWindow(renderer, event->tfinger.x * w, event->tfinger.y * h, &event->tfinger.x, &event->tfinger.y);
|
||||
}
|
||||
SDL_RenderCoordinatesFromWindow(renderer, event->tfinger.x * w, event->tfinger.y * h, &event->tfinger.x, &event->tfinger.y);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -35,13 +35,14 @@ static const char *video_usage[] = {
|
|||
"[--fullscreen | --fullscreen-desktop | --windows N]", "[--title title]",
|
||||
"[--icon icon.bmp]", "[--center | --position X,Y]", "[--geometry WxH]",
|
||||
"[--min-geometry WxH]", "[--max-geometry WxH]", "[--logical WxH]",
|
||||
"[--disable-high-pixel-density]", "[--auto-scale-content]",
|
||||
"[--logical-presentation disabled|match|stretch|letterbox|overscan|integer_scale]",
|
||||
"[--logical-scale-quality nearest|linear|best]",
|
||||
"[--scale N]", "[--depth N]", "[--refresh R]", "[--vsync]", "[--noframe]",
|
||||
"[--resizable]", "[--transparent]", "[--skip-taskbar]", "[--always-on-top]",
|
||||
"[--minimize]", "[--maximize]", "[--grab]", "[--keyboard-grab]",
|
||||
"[--hidden]", "[--input-focus]", "[--mouse-focus]",
|
||||
"[--flash-on-focus-loss]", "[--allow-highdpi]", "[--confine-cursor X,Y,W,H]",
|
||||
"[--flash-on-focus-loss]", "[--confine-cursor X,Y,W,H]",
|
||||
"[--usable-bounds]"
|
||||
};
|
||||
|
||||
|
@ -92,7 +93,7 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags)
|
|||
state->window_y = SDL_WINDOWPOS_UNDEFINED;
|
||||
state->window_w = DEFAULT_WINDOW_WIDTH;
|
||||
state->window_h = DEFAULT_WINDOW_HEIGHT;
|
||||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_MATCH;
|
||||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_DISABLED;
|
||||
state->logical_scale_mode = SDL_SCALEMODE_LINEAR;
|
||||
state->num_windows = 1;
|
||||
state->audiospec.freq = 22050;
|
||||
|
@ -428,6 +429,19 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
|
|||
state->logical_h = SDL_atoi(h);
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--disable-high-pixel-density") == 0) {
|
||||
/* Note that on some platforms it's not possible to disable high density modes */
|
||||
SDL_SetHint(SDL_HINT_VIDEO_ENABLE_HIGH_PIXEL_DENSITY, "0");
|
||||
return 1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--auto-scale-content") == 0) {
|
||||
state->auto_scale_content = SDL_TRUE;
|
||||
|
||||
if (state->logical_presentation == SDL_LOGICAL_PRESENTATION_DISABLED) {
|
||||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_STRETCH;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--logical-presentation") == 0) {
|
||||
++index;
|
||||
if (!argv[index]) {
|
||||
|
@ -437,10 +451,6 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
|
|||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_DISABLED;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "match") == 0) {
|
||||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_MATCH;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "stretch") == 0) {
|
||||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_STRETCH;
|
||||
return 2;
|
||||
|
@ -960,9 +970,6 @@ static void SDLTest_PrintLogicalPresentation(char *text, size_t maxlen, SDL_Rend
|
|||
case SDL_LOGICAL_PRESENTATION_DISABLED:
|
||||
SDL_snprintfcat(text, maxlen, "DISABLED");
|
||||
break;
|
||||
case SDL_LOGICAL_PRESENTATION_MATCH:
|
||||
SDL_snprintfcat(text, maxlen, "MATCH");
|
||||
break;
|
||||
case SDL_LOGICAL_PRESENTATION_STRETCH:
|
||||
SDL_snprintfcat(text, maxlen, "STRETCH");
|
||||
break;
|
||||
|
@ -1195,8 +1202,8 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
|||
mode = SDL_GetDesktopDisplayMode(displayID);
|
||||
SDL_GetMasksForPixelFormatEnum(mode->format, &bpp, &Rmask, &Gmask,
|
||||
&Bmask, &Amask);
|
||||
SDL_Log(" Desktop mode: %dx%d@%gHz, %d%% scale, %d bits-per-pixel (%s)\n",
|
||||
mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f), bpp,
|
||||
SDL_Log(" Desktop mode: %dx%d@%gx %gHz, %d bits-per-pixel (%s)\n",
|
||||
mode->w, mode->h, mode->pixel_density, mode->refresh_rate, bpp,
|
||||
SDL_GetPixelFormatName(mode->format));
|
||||
if (Rmask || Gmask || Bmask) {
|
||||
SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n", Rmask);
|
||||
|
@ -1217,8 +1224,8 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
|||
mode = modes[j];
|
||||
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->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f), bpp,
|
||||
SDL_Log(" Mode %d: %dx%d@%gx %gHz, %d bits-per-pixel (%s)\n",
|
||||
j, mode->w, mode->h, mode->pixel_density, mode->refresh_rate, bpp,
|
||||
SDL_GetPixelFormatName(mode->format));
|
||||
if (Rmask || Gmask || Bmask) {
|
||||
SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n",
|
||||
|
@ -1300,6 +1307,11 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
|||
r.y = state->window_y;
|
||||
r.w = state->window_w;
|
||||
r.h = state->window_h;
|
||||
if (state->auto_scale_content) {
|
||||
float scale = SDL_GetDisplayContentScale(state->displayID);
|
||||
r.w = (int)SDL_ceilf(r.w * scale);
|
||||
r.h = (int)SDL_ceilf(r.h * scale);
|
||||
}
|
||||
|
||||
/* !!! FIXME: hack to make --usable-bounds work for now. */
|
||||
if ((r.x == -1) && (r.y == -1) && (r.w == -1) && (r.h == -1)) {
|
||||
|
@ -1325,9 +1337,8 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
|||
SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
|
||||
}
|
||||
SDL_GetWindowSize(state->windows[i], &w, &h);
|
||||
if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
|
||||
(w != state->window_w || h != state->window_h)) {
|
||||
SDL_Log("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
|
||||
if (!(state->window_flags & SDL_WINDOW_RESIZABLE) && (w != r.w || h != r.h)) {
|
||||
SDL_Log("Window requested size %dx%d, got %dx%d\n", r.w, r.h, w, h);
|
||||
state->window_w = w;
|
||||
state->window_h = h;
|
||||
}
|
||||
|
@ -1513,15 +1524,11 @@ static void SDLTest_PrintEvent(SDL_Event *event)
|
|||
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " connected",
|
||||
event->display.displayID);
|
||||
break;
|
||||
case SDL_EVENT_DISPLAY_SCALE_CHANGED:
|
||||
case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
|
||||
{
|
||||
float display_scale = 1.0f;
|
||||
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(event->display.displayID);
|
||||
if (mode) {
|
||||
display_scale = mode->display_scale;
|
||||
}
|
||||
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed scale to %d%%",
|
||||
event->display.displayID, (int)(display_scale * 100.0f));
|
||||
float scale = SDL_GetDisplayContentScale(event->display.displayID);
|
||||
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed content scale to %d%%",
|
||||
event->display.displayID, (int)(scale * 100.0f));
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_DISPLAY_MOVED:
|
||||
|
@ -1553,6 +1560,10 @@ static void SDLTest_PrintEvent(SDL_Event *event)
|
|||
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " resized to %" SDL_PRIs32 "x%" SDL_PRIs32,
|
||||
event->window.windowID, event->window.data1, event->window.data2);
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed pixel size to %" SDL_PRIs32 "x%" SDL_PRIs32,
|
||||
event->window.windowID, event->window.data1, event->window.data2);
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_MINIMIZED:
|
||||
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " minimized", event->window.windowID);
|
||||
break;
|
||||
|
@ -1592,9 +1603,8 @@ static void SDLTest_PrintEvent(SDL_Event *event)
|
|||
case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
|
||||
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display changed to %" SDL_PRIs32 "", event->window.windowID, event->window.data1);
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed pixel size to %" SDL_PRIs32 "x%" SDL_PRIs32,
|
||||
event->window.windowID, event->window.data1, event->window.data2);
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display scale changed to %d%%", event->window.windowID, (int)(SDL_GetWindowDisplayScale(SDL_GetWindowFromID(event->window.windowID)) * 100.0f));
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
SDL_Log("SDL EVENT: Keyboard: key pressed in window %" SDL_PRIu32 ": scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s",
|
||||
|
@ -1897,6 +1907,20 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
|
|||
}
|
||||
}
|
||||
} break;
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
if (state->auto_scale_content) {
|
||||
SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
|
||||
if (window) {
|
||||
float scale = SDL_GetDisplayContentScale(SDL_GetDisplayForWindow(window));
|
||||
int w = state->window_w;
|
||||
int h = state->window_h;
|
||||
|
||||
w = (int)SDL_ceilf(w * scale);
|
||||
h = (int)SDL_ceilf(h * scale);
|
||||
SDL_SetWindowSize(window, w, h);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||
if (state->flash_on_focus_loss) {
|
||||
SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
|
||||
|
@ -2390,8 +2414,8 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
|
|||
|
||||
mode = SDL_GetWindowFullscreenMode(window);
|
||||
if (mode) {
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetWindowFullscreenMode: %dx%d@%gHz %d%% scale, (%s)",
|
||||
mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f), SDL_GetPixelFormatName(mode->format));
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetWindowFullscreenMode: %dx%d@%gx %gHz, (%s)",
|
||||
mode->w, mode->h, mode->pixel_density, mode->refresh_rate, SDL_GetPixelFormatName(mode->format));
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
@ -2421,16 +2445,16 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
|
|||
|
||||
mode = SDL_GetCurrentDisplayMode(windowDisplayID);
|
||||
if (mode) {
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetCurrentDisplayMode: %dx%d@%gHz %d%% scale, (%s)",
|
||||
mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f), SDL_GetPixelFormatName(mode->format));
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetCurrentDisplayMode: %dx%d@%gx %gHz, (%s)",
|
||||
mode->w, mode->h, mode->pixel_density, mode->refresh_rate, SDL_GetPixelFormatName(mode->format));
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
mode = SDL_GetDesktopDisplayMode(windowDisplayID);
|
||||
if (mode) {
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetDesktopDisplayMode: %dx%d@%gHz %d%% scale, (%s)",
|
||||
mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f), SDL_GetPixelFormatName(mode->format));
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetDesktopDisplayMode: %dx%d@%gx %gHz, (%s)",
|
||||
mode->w, mode->h, mode->pixel_density, mode->refresh_rate, SDL_GetPixelFormatName(mode->format));
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ struct SDL_Window
|
|||
int max_w, max_h;
|
||||
int last_pixel_w, last_pixel_h;
|
||||
Uint32 flags;
|
||||
float display_scale;
|
||||
SDL_bool fullscreen_exclusive; /* The window is currently fullscreen exclusive */
|
||||
SDL_DisplayID last_fullscreen_exclusive_display; /* The last fullscreen_exclusive display */
|
||||
SDL_DisplayID last_displayID;
|
||||
|
@ -144,6 +145,7 @@ struct SDL_VideoDisplay
|
|||
SDL_DisplayMode desktop_mode;
|
||||
const SDL_DisplayMode *current_mode;
|
||||
SDL_DisplayOrientation orientation;
|
||||
float content_scale;
|
||||
|
||||
SDL_Window *fullscreen_window;
|
||||
|
||||
|
@ -499,6 +501,7 @@ extern SDL_bool SDL_AddFullscreenDisplayMode(SDL_VideoDisplay *display, const SD
|
|||
extern void SDL_ResetFullscreenDisplayModes(SDL_VideoDisplay *display);
|
||||
extern void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode);
|
||||
extern void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode);
|
||||
extern void SDL_SetDisplayContentScale(SDL_VideoDisplay *display, float scale);
|
||||
extern SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID display);
|
||||
extern SDL_VideoDisplay *SDL_GetVideoDisplayForWindow(SDL_Window *window);
|
||||
extern int SDL_GetDisplayIndex(SDL_DisplayID displayID);
|
||||
|
|
|
@ -160,6 +160,8 @@ extern SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window);
|
|||
extern SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state);
|
||||
#endif
|
||||
|
||||
static void SDL_CheckWindowDisplayScaleChanged(SDL_Window *window);
|
||||
|
||||
/* Convenience functions for reading driver flags */
|
||||
static SDL_bool ModeSwitchingEmulated(SDL_VideoDevice *_this)
|
||||
{
|
||||
|
@ -390,20 +392,23 @@ 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;
|
||||
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;
|
||||
int a_refresh_rate = (int)(a->refresh_rate * 100);
|
||||
int b_refresh_rate = (int)(b->refresh_rate * 100);
|
||||
int a_pixel_density = (int)(a->pixel_density * 100);
|
||||
int b_pixel_density = (int)(b->pixel_density * 100);
|
||||
|
||||
if (a->w != b->w) {
|
||||
return b->w - a->w;
|
||||
} else if (a->h != b->h) {
|
||||
return b->h - a->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)) {
|
||||
return SDL_PIXELLAYOUT(b->format) - SDL_PIXELLAYOUT(a->format);
|
||||
} else if (a->refresh_rate != b->refresh_rate) {
|
||||
return (int)(b->refresh_rate * 100) - (int)(a->refresh_rate * 100);
|
||||
} else if (a_refresh_rate != b_refresh_rate) {
|
||||
return b_refresh_rate - a_refresh_rate;
|
||||
} else if (a_pixel_density != b_pixel_density) {
|
||||
return a_pixel_density - b_pixel_density;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -616,34 +621,8 @@ SDL_SystemTheme SDL_GetSystemTheme(void)
|
|||
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);
|
||||
if (mode->pixel_density <= 0.0f) {
|
||||
mode->pixel_density = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -694,6 +673,9 @@ SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send
|
|||
SDL_itoa(id, name, 10);
|
||||
new_display->name = SDL_strdup(name);
|
||||
}
|
||||
if (new_display->content_scale == 0.0f) {
|
||||
new_display->content_scale = 1.0f;
|
||||
}
|
||||
|
||||
new_display->desktop_mode.displayID = id;
|
||||
new_display->current_mode = &new_display->desktop_mode;
|
||||
|
@ -861,8 +843,8 @@ int SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect)
|
|||
SDL_GetDisplayBounds(_this->displays[SDL_GetDisplayIndex(displayID) - 1].id, rect);
|
||||
rect->x += rect->w;
|
||||
}
|
||||
rect->w = display->current_mode->screen_w;
|
||||
rect->h = display->current_mode->screen_h;
|
||||
rect->w = display->current_mode->w;
|
||||
rect->h = display->current_mode->h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -905,12 +887,38 @@ SDL_DisplayOrientation SDL_GetDisplayOrientation(SDL_DisplayID displayID)
|
|||
return display->orientation;
|
||||
}
|
||||
|
||||
void SDL_SetDisplayContentScale(SDL_VideoDisplay *display, float scale)
|
||||
{
|
||||
if (scale != display->content_scale) {
|
||||
SDL_Window *window;
|
||||
|
||||
display->content_scale = scale;
|
||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, 0);
|
||||
|
||||
/* Check the windows on this display */
|
||||
for (window = _this->windows; window; window = window->next) {
|
||||
if (display->id == window->last_displayID) {
|
||||
SDL_CheckWindowDisplayScaleChanged(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float SDL_GetDisplayContentScale(SDL_DisplayID displayID)
|
||||
{
|
||||
SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
|
||||
|
||||
CHECK_DISPLAY_MAGIC(display, 0.0f);
|
||||
|
||||
return display->content_scale;
|
||||
}
|
||||
|
||||
static const SDL_DisplayMode *SDL_GetFullscreenModeMatch(const SDL_DisplayMode *mode)
|
||||
{
|
||||
const SDL_DisplayMode **modes;
|
||||
SDL_DisplayMode fullscreen_mode;
|
||||
|
||||
if (mode->screen_w <= 0 || mode->screen_h <= 0) {
|
||||
if (mode->w <= 0 || mode->h <= 0) {
|
||||
/* Use the desktop mode */
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1079,18 +1087,18 @@ const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID display
|
|||
for (i = 0; modes[i]; ++i) {
|
||||
mode = modes[i];
|
||||
|
||||
if (w > mode->pixel_w) {
|
||||
if (w > mode->w) {
|
||||
/* Out of sorted modes large enough here */
|
||||
break;
|
||||
}
|
||||
if (h > mode->pixel_h) {
|
||||
if (h > mode->h) {
|
||||
/* Wider, but not tall enough, due to a different aspect ratio.
|
||||
* This mode must be skipped, but closer modes may still follow */
|
||||
continue;
|
||||
}
|
||||
if (closest) {
|
||||
float current_aspect_ratio = (float)mode->pixel_w / mode->pixel_h;
|
||||
float closest_aspect_ratio = (float)closest->pixel_w / closest->pixel_h;
|
||||
float current_aspect_ratio = (float)mode->w / mode->h;
|
||||
float closest_aspect_ratio = (float)closest->w / closest->h;
|
||||
if (SDL_fabsf(aspect_ratio - closest_aspect_ratio) < SDL_fabsf(aspect_ratio - current_aspect_ratio)) {
|
||||
/* The mode we already found has a better aspect ratio match */
|
||||
continue;
|
||||
|
@ -1112,15 +1120,9 @@ const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID display
|
|||
|
||||
void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
|
||||
{
|
||||
float display_scale = display->desktop_mode.display_scale;
|
||||
|
||||
SDL_memcpy(&display->desktop_mode, mode, sizeof(*mode));
|
||||
display->desktop_mode.displayID = display->id;
|
||||
SDL_FinalizeDisplayMode(&display->desktop_mode);
|
||||
|
||||
if (display_scale != display->desktop_mode.display_scale) {
|
||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_SCALE_CHANGED, 0);
|
||||
}
|
||||
}
|
||||
|
||||
const SDL_DisplayMode *SDL_GetDesktopDisplayMode(SDL_DisplayID displayID)
|
||||
|
@ -1379,6 +1381,32 @@ static void SDL_CheckWindowDisplayChanged(SDL_Window *window)
|
|||
}
|
||||
}
|
||||
|
||||
float SDL_GetWindowDisplayScale(SDL_Window *window)
|
||||
{
|
||||
CHECK_WINDOW_MAGIC(window, 0.0f);
|
||||
|
||||
return window->display_scale;
|
||||
}
|
||||
|
||||
static void SDL_CheckWindowDisplayScaleChanged(SDL_Window *window)
|
||||
{
|
||||
int window_w, window_h, pixel_w, pixel_h;
|
||||
float pixel_density = 1.0f;
|
||||
float content_scale = SDL_GetDisplayContentScale(SDL_GetDisplayForWindowPosition(window));
|
||||
float display_scale;
|
||||
|
||||
if (SDL_GetWindowSize(window, &window_w, &window_h) == 0 &&
|
||||
SDL_GetWindowSizeInPixels(window, &pixel_w, &pixel_h) == 0) {
|
||||
pixel_density = (float)pixel_w / window_w;
|
||||
}
|
||||
|
||||
display_scale = (pixel_density * content_scale);
|
||||
if (display_scale != window->display_scale) {
|
||||
window->display_scale = display_scale;
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __WINRT__
|
||||
extern Uint32 WINRT_DetectWindowFlags(SDL_Window *window);
|
||||
#endif
|
||||
|
@ -1548,11 +1576,11 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
|
|||
*/
|
||||
#else
|
||||
if (mode) {
|
||||
mode_w = mode->screen_w;
|
||||
mode_h = mode->screen_h;
|
||||
mode_w = mode->w;
|
||||
mode_h = mode->h;
|
||||
} else {
|
||||
mode_w = display->desktop_mode.screen_w;
|
||||
mode_h = display->desktop_mode.screen_h;
|
||||
mode_w = display->desktop_mode.w;
|
||||
mode_h = display->desktop_mode.h;
|
||||
}
|
||||
if (window->w != mode_w || window->h != mode_h) {
|
||||
resized = SDL_TRUE;
|
||||
|
@ -1851,7 +1879,7 @@ static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int
|
|||
}
|
||||
}
|
||||
|
||||
if (!SDL_GetHintBoolean("SDL_VIDEO_HIGHDPI_DISABLED", SDL_FALSE)) {
|
||||
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_ENABLE_HIGH_PIXEL_DENSITY, SDL_TRUE)) {
|
||||
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
}
|
||||
|
||||
|
@ -1881,6 +1909,7 @@ static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int
|
|||
}
|
||||
|
||||
window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
|
||||
window->display_scale = 1.0f;
|
||||
window->opacity = 1.0f;
|
||||
window->next = _this->windows;
|
||||
window->is_destroying = SDL_FALSE;
|
||||
|
@ -2024,6 +2053,7 @@ SDL_Window *SDL_CreateWindowFrom(const void *data)
|
|||
window->id = _this->next_object_id++;
|
||||
window->flags = flags;
|
||||
window->is_destroying = SDL_FALSE;
|
||||
window->display_scale = 1.0f;
|
||||
window->opacity = 1.0f;
|
||||
window->next = _this->windows;
|
||||
if (_this->windows) {
|
||||
|
@ -2610,16 +2640,8 @@ int SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h)
|
|||
mode = SDL_GetDesktopDisplayMode(displayID);
|
||||
}
|
||||
if (mode) {
|
||||
if (*w == mode->screen_w) {
|
||||
*w = mode->pixel_w;
|
||||
} else {
|
||||
*w = (int)SDL_ceilf(*w * mode->display_scale);
|
||||
}
|
||||
if (*h == mode->screen_h) {
|
||||
*h = mode->pixel_h;
|
||||
} else {
|
||||
*h = (int)SDL_ceilf(*h * mode->display_scale);
|
||||
}
|
||||
*w = (int)SDL_ceilf(*w * mode->pixel_density);
|
||||
*h = (int)SDL_ceilf(*h * mode->pixel_density);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -3245,8 +3267,8 @@ void SDL_OnWindowDisplayChanged(SDL_Window *window)
|
|||
SDL_DisplayID displayID = SDL_GetDisplayForWindowPosition(window);
|
||||
const SDL_DisplayMode *new_mode = NULL;
|
||||
|
||||
if (window->requested_fullscreen_mode.pixel_w != 0 || window->requested_fullscreen_mode.pixel_h != 0) {
|
||||
new_mode = SDL_GetClosestFullscreenDisplayMode(displayID, window->requested_fullscreen_mode.pixel_w, window->requested_fullscreen_mode.pixel_h, window->requested_fullscreen_mode.refresh_rate);
|
||||
if (window->requested_fullscreen_mode.w != 0 || window->requested_fullscreen_mode.h != 0) {
|
||||
new_mode = SDL_GetClosestFullscreenDisplayMode(displayID, window->requested_fullscreen_mode.w, window->requested_fullscreen_mode.h, window->requested_fullscreen_mode.refresh_rate);
|
||||
}
|
||||
|
||||
if (new_mode) {
|
||||
|
@ -3280,6 +3302,8 @@ void SDL_CheckWindowPixelSizeChanged(SDL_Window *window)
|
|||
|
||||
SDL_GetWindowSizeInPixels(window, &pixel_w, &pixel_h);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED, pixel_w, pixel_h);
|
||||
|
||||
SDL_CheckWindowDisplayScaleChanged(window);
|
||||
}
|
||||
|
||||
void SDL_OnWindowPixelSizeChanged(SDL_Window *window)
|
||||
|
|
|
@ -219,9 +219,6 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y
|
|||
return;
|
||||
}
|
||||
|
||||
x /= Android_ScreenDensity;
|
||||
y /= Android_ScreenDensity;
|
||||
|
||||
switch (action) {
|
||||
case ACTION_DOWN:
|
||||
changes = state & ~last_state;
|
||||
|
|
|
@ -179,9 +179,8 @@ int Android_VideoInit(SDL_VideoDevice *_this)
|
|||
|
||||
SDL_zero(mode);
|
||||
mode.format = Android_ScreenFormat;
|
||||
mode.pixel_w = Android_DeviceWidth;
|
||||
mode.pixel_h = Android_DeviceHeight;
|
||||
mode.display_scale = Android_ScreenDensity;
|
||||
mode.w = Android_DeviceWidth;
|
||||
mode.h = Android_DeviceHeight;
|
||||
mode.refresh_rate = Android_ScreenRate;
|
||||
mode.driverdata = NULL;
|
||||
|
||||
|
@ -191,6 +190,7 @@ int Android_VideoInit(SDL_VideoDevice *_this)
|
|||
}
|
||||
display = SDL_GetVideoDisplay(displayID);
|
||||
display->orientation = Android_JNI_GetDisplayOrientation();
|
||||
display->content_scale = Android_ScreenDensity;
|
||||
|
||||
Android_InitTouch();
|
||||
|
||||
|
@ -272,17 +272,14 @@ void Android_SendResize(SDL_Window *window)
|
|||
|
||||
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.w = Android_DeviceWidth;
|
||||
desktop_mode.h = Android_DeviceHeight;
|
||||
desktop_mode.refresh_rate = Android_ScreenRate;
|
||||
SDL_SetDesktopDisplayMode(display, &desktop_mode);
|
||||
}
|
||||
|
||||
if (window) {
|
||||
int w = (int)SDL_floorf(Android_SurfaceWidth / Android_ScreenDensity);
|
||||
int h = (int)SDL_floorf(Android_SurfaceHeight / Android_ScreenDensity);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, w, h);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, Android_SurfaceWidth, Android_SurfaceWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
|||
/* Adjust the window data to match the screen */
|
||||
window->x = 0;
|
||||
window->y = 0;
|
||||
window->w = (int)SDL_ceilf(Android_SurfaceWidth / Android_ScreenDensity);
|
||||
window->h = (int)SDL_ceilf(Android_SurfaceHeight / Android_ScreenDensity);
|
||||
window->w = Android_SurfaceWidth;
|
||||
window->h = Android_SurfaceHeight;
|
||||
|
||||
/* One window, it always has focus */
|
||||
SDL_SetMouseFocus(window);
|
||||
|
@ -139,8 +139,8 @@ void Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL
|
|||
old_w = window->w;
|
||||
old_h = window->h;
|
||||
|
||||
new_w = (int)SDL_ceilf(ANativeWindow_getWidth(data->native_window) / Android_ScreenDensity);
|
||||
new_h = (int)SDL_ceilf(ANativeWindow_getHeight(data->native_window) / Android_ScreenDensity);
|
||||
new_w = ANativeWindow_getWidth(data->native_window);
|
||||
new_h = ANativeWindow_getHeight(data->native_window);
|
||||
|
||||
if (new_w < 0 || new_h < 0) {
|
||||
SDL_SetError("ANativeWindow_getWidth/Height() fails");
|
||||
|
|
|
@ -174,6 +174,13 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
|||
pixelW = CGDisplayModeGetPixelWidth(vidmode);
|
||||
pixelH = CGDisplayModeGetPixelHeight(vidmode);
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_ENABLE_HIGH_PIXEL_DENSITY, SDL_TRUE)) {
|
||||
if (width != pixelW) {
|
||||
/* We don't want high pixel density modes */
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (modelist != NULL) {
|
||||
CFIndex modescount = CFArrayGetCount(modelist);
|
||||
int i;
|
||||
|
@ -253,10 +260,9 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
|||
}
|
||||
data->modes = modes;
|
||||
mode->format = format;
|
||||
mode->pixel_w = (int)pixelW;
|
||||
mode->pixel_h = (int)pixelH;
|
||||
mode->screen_w = (int)width;
|
||||
mode->screen_h = (int)height;
|
||||
mode->w = (int)width;
|
||||
mode->h = (int)height;
|
||||
mode->pixel_density = (float)pixelW / width;
|
||||
mode->refresh_rate = refreshrate;
|
||||
mode->driverdata = data;
|
||||
return SDL_TRUE;
|
||||
|
|
|
@ -144,8 +144,8 @@ int DUMMY_VideoInit(SDL_VideoDevice *_this)
|
|||
/* Use a fake 32-bpp desktop mode */
|
||||
SDL_zero(mode);
|
||||
mode.format = SDL_PIXELFORMAT_RGB888;
|
||||
mode.pixel_w = 1024;
|
||||
mode.pixel_h = 768;
|
||||
mode.w = 1024;
|
||||
mode.h = 768;
|
||||
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -127,8 +127,8 @@ int Emscripten_VideoInit(SDL_VideoDevice *_this)
|
|||
/* Use a fake 32-bpp desktop mode */
|
||||
SDL_zero(mode);
|
||||
mode.format = SDL_PIXELFORMAT_RGB888;
|
||||
emscripten_get_screen_size(&mode.screen_w, &mode.screen_h);
|
||||
mode.display_scale = emscripten_get_device_pixel_ratio();
|
||||
emscripten_get_screen_size(&mode.w, &mode.h);
|
||||
mode.pixel_density = emscripten_get_device_pixel_ratio();
|
||||
|
||||
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
|
||||
return -1;
|
||||
|
|
|
@ -167,8 +167,8 @@ int32 HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace)
|
|||
|
||||
static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) {
|
||||
SDL_zerop(mode);
|
||||
mode->pixel_w = bmode->virtual_width;
|
||||
mode->pixel_h = bmode->virtual_height;
|
||||
mode->w = bmode->virtual_width;
|
||||
mode->h = bmode->virtual_height;
|
||||
mode->refresh_rate = get_refresh_rate(*bmode);
|
||||
|
||||
#if WRAP_BMODE
|
||||
|
|
|
@ -865,8 +865,8 @@ static void KMSDRM_AddDisplay(SDL_VideoDevice *_this, drmModeConnector *connecto
|
|||
modedata->mode_index = mode_index;
|
||||
|
||||
display.driverdata = dispdata;
|
||||
display.desktop_mode.pixel_w = dispdata->mode.hdisplay;
|
||||
display.desktop_mode.pixel_h = dispdata->mode.vdisplay;
|
||||
display.desktop_mode.w = dispdata->mode.hdisplay;
|
||||
display.desktop_mode.h = dispdata->mode.vdisplay;
|
||||
display.desktop_mode.refresh_rate = CalculateRefreshRate(&dispdata->mode);
|
||||
display.desktop_mode.format = SDL_PIXELFORMAT_ARGB8888;
|
||||
display.desktop_mode.driverdata = modedata;
|
||||
|
@ -1179,8 +1179,8 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
|
|||
|
||||
/*
|
||||
SDL_zero(current_mode);
|
||||
current_mode.pixel_w = dispdata->mode.hdisplay;
|
||||
current_mode.pixel_h = dispdata->mode.vdisplay;
|
||||
current_mode.w = dispdata->mode.hdisplay;
|
||||
current_mode.h = dispdata->mode.vdisplay;
|
||||
current_mode.refresh_rate = CalculateRefreshRate(&dispdata->mode);
|
||||
current_mode.format = SDL_PIXELFORMAT_ARGB8888;
|
||||
SDL_SetCurrentDisplayMode(display, ¤t_mode);
|
||||
|
@ -1295,8 +1295,8 @@ int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
|||
}
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = conn->modes[i].hdisplay;
|
||||
mode.pixel_h = conn->modes[i].vdisplay;
|
||||
mode.w = conn->modes[i].hdisplay;
|
||||
mode.h = conn->modes[i].vdisplay;
|
||||
mode.refresh_rate = CalculateRefreshRate(&conn->modes[i]);
|
||||
mode.format = SDL_PIXELFORMAT_ARGB8888;
|
||||
mode.driverdata = modedata;
|
||||
|
|
|
@ -114,8 +114,8 @@ static int AddN3DSDisplay(gfxScreen_t screen)
|
|||
|
||||
display_driver_data->screen = screen;
|
||||
|
||||
mode.pixel_w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM;
|
||||
mode.pixel_h = GSP_SCREEN_WIDTH;
|
||||
mode.w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM;
|
||||
mode.h = GSP_SCREEN_WIDTH;
|
||||
mode.refresh_rate = 60.0f;
|
||||
mode.format = FRAMEBUFFER_FORMAT;
|
||||
|
||||
|
@ -146,8 +146,8 @@ static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
|
|||
|
||||
rect->x = 0;
|
||||
rect->y = (driver_data->screen == GFX_TOP) ? 0 : GSP_SCREEN_WIDTH;
|
||||
rect->w = display->current_mode->screen_w;
|
||||
rect->h = display->current_mode->screen_h;
|
||||
rect->w = display->current_mode->w;
|
||||
rect->h = display->current_mode->h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,8 +148,8 @@ int NGAGE_VideoInit(SDL_VideoDevice *_this)
|
|||
/* Use 12-bpp desktop mode */
|
||||
SDL_zero(mode);
|
||||
mode.format = SDL_PIXELFORMAT_RGB444;
|
||||
mode.pixel_w = 176;
|
||||
mode.pixel_h = 208;
|
||||
mode.w = 176;
|
||||
mode.h = 208;
|
||||
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -103,8 +103,8 @@ int OFFSCREEN_VideoInit(SDL_VideoDevice *_this)
|
|||
/* Use a fake 32-bpp desktop mode */
|
||||
SDL_zero(mode);
|
||||
mode.format = SDL_PIXELFORMAT_RGB888;
|
||||
mode.pixel_w = 1024;
|
||||
mode.pixel_h = 768;
|
||||
mode.w = 1024;
|
||||
mode.h = 768;
|
||||
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ static int PS2_VideoInit(SDL_VideoDevice *_this)
|
|||
SDL_DisplayMode mode;
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = 640;
|
||||
mode.pixel_h = 480;
|
||||
mode.w = 640;
|
||||
mode.h = 480;
|
||||
mode.refresh_rate = 60.0f;
|
||||
|
||||
/* 32 bpp for default */
|
||||
|
|
|
@ -135,8 +135,8 @@ int PSP_VideoInit(SDL_VideoDevice *_this)
|
|||
SDL_DisplayMode mode;
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = 480;
|
||||
mode.pixel_h = 272;
|
||||
mode.w = 480;
|
||||
mode.h = 272;
|
||||
mode.refresh_rate = 60.0f;
|
||||
|
||||
/* 32 bpp for default */
|
||||
|
@ -157,8 +157,8 @@ int PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
|||
SDL_DisplayMode mode;
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = 480;
|
||||
mode.pixel_h = 272;
|
||||
mode.w = 480;
|
||||
mode.h = 272;
|
||||
mode.refresh_rate = 60.0f;
|
||||
|
||||
/* 32 bpp for default */
|
||||
|
|
|
@ -160,8 +160,8 @@ static void AddDispManXDisplay(const int display_id)
|
|||
|
||||
/* RPI_GetRefreshRate() doesn't distinguish between displays. I'm not sure the hardware distinguishes either */
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = modeinfo.width;
|
||||
mode.pixel_h = modeinfo.height;
|
||||
mode.w = modeinfo.width;
|
||||
mode.h = modeinfo.height;
|
||||
mode.refresh_rate = RPI_GetRefreshRate();
|
||||
|
||||
/* 32 bpp for default */
|
||||
|
@ -245,8 +245,8 @@ int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
|||
displaydata = display->driverdata;
|
||||
|
||||
/* Windows have one size for now */
|
||||
window->w = display->desktop_mode.screen_w;
|
||||
window->h = display->desktop_mode.screen_h;
|
||||
window->w = display->desktop_mode.w;
|
||||
window->h = display->desktop_mode.h;
|
||||
|
||||
/* OpenGL ES is the law here, buddy */
|
||||
window->flags |= SDL_WINDOW_OPENGL;
|
||||
|
|
|
@ -137,8 +137,8 @@ static SDL_bool read_mode_block(int *block, SDL_DisplayMode *mode, SDL_bool exte
|
|||
}
|
||||
|
||||
SDL_zerop(mode);
|
||||
mode->pixel_w = xres;
|
||||
mode->pixel_h = yres;
|
||||
mode->w = xres;
|
||||
mode->h = yres;
|
||||
mode->format = RISCOS_ModeToPixelFormat(ncolour, modeflags, log2bpp);
|
||||
mode->refresh_rate = (float)rate;
|
||||
|
||||
|
|
|
@ -141,9 +141,9 @@ static int UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h,
|
|||
return -1;
|
||||
}
|
||||
|
||||
mode.pixel_w = w;
|
||||
mode.pixel_h = h;
|
||||
mode.display_scale = uiscreen.nativeScale;
|
||||
mode.w = w;
|
||||
mode.h = h;
|
||||
mode.pixel_density = uiscreen.nativeScale;
|
||||
mode.refresh_rate = UIKit_GetDisplayModeRefreshRate(uiscreen);
|
||||
mode.format = SDL_PIXELFORMAT_ABGR8888;
|
||||
|
||||
|
@ -209,9 +209,9 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
|
|||
}
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = (int)size.width;
|
||||
mode.pixel_h = (int)size.height;
|
||||
mode.display_scale = uiscreen.nativeScale;
|
||||
mode.w = (int)size.width;
|
||||
mode.h = (int)size.height;
|
||||
mode.pixel_density = uiscreen.nativeScale;
|
||||
mode.format = SDL_PIXELFORMAT_ABGR8888;
|
||||
mode.refresh_rate = UIKit_GetDisplayModeRefreshRate(uiscreen);
|
||||
|
||||
|
@ -337,11 +337,11 @@ int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_
|
|||
/* [UIApplication setStatusBarOrientation:] no longer works reliably
|
||||
* in recent iOS versions, so we can't rotate the screen when setting
|
||||
* the display mode. */
|
||||
if (mode->pixel_w > mode->pixel_h) {
|
||||
if (mode->w > mode->h) {
|
||||
if (!UIKit_IsDisplayLandscape(data.uiscreen)) {
|
||||
return SDL_SetError("Screen orientation does not match display mode size");
|
||||
}
|
||||
} else if (mode->pixel_w < mode->pixel_h) {
|
||||
} else if (mode->w < mode->h) {
|
||||
if (UIKit_IsDisplayLandscape(data.uiscreen)) {
|
||||
return SDL_SetError("Screen orientation does not match display mode size");
|
||||
}
|
||||
|
@ -412,25 +412,19 @@ void SDL_OnApplicationDidChangeStatusBarOrientation()
|
|||
* orientation so that updating a window's fullscreen state to
|
||||
* fullscreen desktop keeps the window dimensions in the
|
||||
* correct orientation. */
|
||||
if (isLandscape != (mode->pixel_w > mode->pixel_h)) {
|
||||
int height = mode->pixel_w;
|
||||
mode->pixel_w = mode->pixel_h;
|
||||
mode->pixel_h = height;
|
||||
height = mode->screen_w;
|
||||
mode->screen_w = mode->screen_h;
|
||||
mode->screen_h = height;
|
||||
if (isLandscape != (mode->w > mode->h)) {
|
||||
int height = mode->w;
|
||||
mode->w = mode->h;
|
||||
mode->h = height;
|
||||
}
|
||||
|
||||
/* Same deal with the fullscreen modes */
|
||||
for (i = 0; i < display->num_fullscreen_modes; ++i) {
|
||||
mode = &display->fullscreen_modes[i];
|
||||
if (isLandscape != (mode->pixel_w > mode->pixel_h)) {
|
||||
int height = mode->pixel_w;
|
||||
mode->pixel_w = mode->pixel_h;
|
||||
mode->pixel_h = height;
|
||||
height = mode->screen_w;
|
||||
mode->screen_w = mode->screen_h;
|
||||
mode->screen_h = height;
|
||||
if (isLandscape != (mode->w > mode->h)) {
|
||||
int height = mode->w;
|
||||
mode->w = mode->h;
|
||||
mode->h = height;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -182,20 +182,20 @@ int VITA_VideoInit(SDL_VideoDevice *_this)
|
|||
if (res) {
|
||||
/* 1088i for PSTV (Or Sharpscale) */
|
||||
if (!SDL_strncmp(res, "1080", 4)) {
|
||||
mode.pixel_w = 1920;
|
||||
mode.pixel_h = 1088;
|
||||
mode.w = 1920;
|
||||
mode.h = 1088;
|
||||
}
|
||||
/* 725p for PSTV (Or Sharpscale) */
|
||||
else if (!SDL_strncmp(res, "720", 3)) {
|
||||
mode.pixel_w = 1280;
|
||||
mode.pixel_h = 725;
|
||||
mode.w = 1280;
|
||||
mode.h = 725;
|
||||
}
|
||||
}
|
||||
/* 544p */
|
||||
else {
|
||||
#endif
|
||||
mode.pixel_w = 960;
|
||||
mode.pixel_h = 544;
|
||||
mode.w = 960;
|
||||
mode.h = 544;
|
||||
#ifdef SDL_VIDEO_VITA_PVR
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -135,11 +135,13 @@ static int VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this)
|
|||
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
|
||||
data->native_display = vdkGetDisplay(videodata->vdk_private);
|
||||
|
||||
vdkGetDisplayInfo(data->native_display, &mode.pixel_w, &mode.pixel_h, &pixels, &pitch, &bpp);
|
||||
vdkGetDisplayInfo(data->native_display, &mode.w, &mode.h, &pixels, &pitch,
|
||||
&bpp);
|
||||
#else
|
||||
data->native_display = videodata->fbGetDisplayByIndex(0);
|
||||
|
||||
videodata->fbGetDisplayInfo(data->native_display, &mode.pixel_w, &mode.pixel_h, &pixels, &pitch, &bpp);
|
||||
videodata->fbGetDisplayInfo(data->native_display, &mode.w, &mode.h,
|
||||
&pixels, &pitch, &bpp);
|
||||
#endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */
|
||||
|
||||
switch (bpp) {
|
||||
|
|
|
@ -423,22 +423,21 @@ static void AddEmulatedModes(SDL_DisplayData *dispdata, int native_width, int na
|
|||
for (i = 0; i < SDL_arraysize(mode_list); ++i) {
|
||||
SDL_zero(mode);
|
||||
mode.format = dpy->desktop_mode.format;
|
||||
mode.display_scale = 1.0f;
|
||||
mode.refresh_rate = dpy->desktop_mode.refresh_rate;
|
||||
mode.driverdata = dpy->desktop_mode.driverdata;
|
||||
|
||||
if (rot_90) {
|
||||
mode.pixel_w = mode_list[i].h;
|
||||
mode.pixel_h = mode_list[i].w;
|
||||
mode.w = mode_list[i].h;
|
||||
mode.h = mode_list[i].w;
|
||||
} else {
|
||||
mode.pixel_w = mode_list[i].w;
|
||||
mode.pixel_h = mode_list[i].h;
|
||||
mode.w = mode_list[i].w;
|
||||
mode.h = mode_list[i].h;
|
||||
}
|
||||
|
||||
/* Only add modes that are smaller than the native mode. */
|
||||
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)) {
|
||||
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)) {
|
||||
SDL_AddFullscreenDisplayMode(dpy, &mode);
|
||||
}
|
||||
}
|
||||
|
@ -570,22 +569,21 @@ static void display_handle_done(void *data,
|
|||
|
||||
/* Transform the pixel values, if necessary. */
|
||||
if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
native_mode.pixel_w = driverdata->pixel_height;
|
||||
native_mode.pixel_h = driverdata->pixel_width;
|
||||
native_mode.w = driverdata->pixel_height;
|
||||
native_mode.h = driverdata->pixel_width;
|
||||
} else {
|
||||
native_mode.pixel_w = driverdata->pixel_width;
|
||||
native_mode.pixel_h = driverdata->pixel_height;
|
||||
native_mode.w = driverdata->pixel_width;
|
||||
native_mode.h = driverdata->pixel_height;
|
||||
}
|
||||
native_mode.display_scale = 1.0f;
|
||||
native_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */
|
||||
native_mode.driverdata = driverdata->output;
|
||||
|
||||
if (driverdata->has_logical_size) { /* If xdg-output is present... */
|
||||
if (native_mode.pixel_w != driverdata->screen_width || native_mode.pixel_h != driverdata->screen_height) {
|
||||
if (native_mode.w != driverdata->screen_width || native_mode.h != driverdata->screen_height) {
|
||||
/* ...and the compositor scales the logical viewport... */
|
||||
if (video->viewporter) {
|
||||
/* ...and viewports are supported, calculate the true scale of the output. */
|
||||
driverdata->scale_factor = (float)native_mode.pixel_w / (float)driverdata->screen_width;
|
||||
driverdata->scale_factor = (float) native_mode.w / (float)driverdata->screen_width;
|
||||
} else {
|
||||
/* ...otherwise, the 'native' pixel values are a multiple of the logical screen size. */
|
||||
driverdata->pixel_width = driverdata->screen_width * (int)driverdata->scale_factor;
|
||||
|
@ -602,17 +600,17 @@ static void display_handle_done(void *data,
|
|||
/* Calculate the points from the pixel values, if xdg-output isn't present.
|
||||
* Use the native mode pixel values since they are pre-transformed.
|
||||
*/
|
||||
driverdata->screen_width = native_mode.pixel_w / (int)driverdata->scale_factor;
|
||||
driverdata->screen_height = native_mode.pixel_h / (int)driverdata->scale_factor;
|
||||
driverdata->screen_width = native_mode.w / (int)driverdata->scale_factor;
|
||||
driverdata->screen_height = native_mode.h / (int)driverdata->scale_factor;
|
||||
}
|
||||
|
||||
/* The scaled desktop mode */
|
||||
SDL_zero(desktop_mode);
|
||||
desktop_mode.format = SDL_PIXELFORMAT_RGB888;
|
||||
|
||||
desktop_mode.screen_w = driverdata->screen_width;
|
||||
desktop_mode.screen_h = driverdata->screen_height;
|
||||
desktop_mode.display_scale = driverdata->scale_factor;
|
||||
desktop_mode.w = driverdata->screen_width;
|
||||
desktop_mode.h = driverdata->screen_height;
|
||||
desktop_mode.pixel_density = driverdata->scale_factor;
|
||||
desktop_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */
|
||||
desktop_mode.driverdata = driverdata->output;
|
||||
|
||||
|
@ -632,13 +630,11 @@ static void display_handle_done(void *data,
|
|||
/* ...otherwise expose the integer scaled variants of the desktop resolution down to 1. */
|
||||
int i;
|
||||
|
||||
desktop_mode.pixel_w = 0;
|
||||
desktop_mode.pixel_h = 0;
|
||||
desktop_mode.screen_w = driverdata->screen_width;
|
||||
desktop_mode.screen_h = driverdata->screen_height;
|
||||
desktop_mode.w = driverdata->screen_width;
|
||||
desktop_mode.h = driverdata->screen_height;
|
||||
|
||||
for (i = (int)driverdata->scale_factor; i > 0; --i) {
|
||||
desktop_mode.display_scale = (float)i;
|
||||
desktop_mode.pixel_density = (float)i;
|
||||
SDL_AddFullscreenDisplayMode(dpy, &desktop_mode);
|
||||
}
|
||||
}
|
||||
|
@ -646,7 +642,7 @@ static void display_handle_done(void *data,
|
|||
/* Add emulated modes if wp_viewporter is supported and mode emulation is enabled. */
|
||||
if (video->viewporter && mode_emulation_enabled) {
|
||||
/* The transformed display pixel width/height must be used here. */
|
||||
AddEmulatedModes(driverdata, native_mode.pixel_w, native_mode.pixel_h);
|
||||
AddEmulatedModes(driverdata, native_mode.w, native_mode.h);
|
||||
}
|
||||
|
||||
if (driverdata->display == 0) {
|
||||
|
@ -971,13 +967,13 @@ static int Wayland_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *di
|
|||
if (display->fullscreen_window &&
|
||||
display->fullscreen_window->fullscreen_exclusive &&
|
||||
display->fullscreen_window == SDL_GetFocusWindow() &&
|
||||
display->fullscreen_window->current_fullscreen_mode.screen_w != 0 &&
|
||||
display->fullscreen_window->current_fullscreen_mode.screen_h != 0) {
|
||||
rect->w = display->fullscreen_window->current_fullscreen_mode.screen_w;
|
||||
rect->h = display->fullscreen_window->current_fullscreen_mode.screen_h;
|
||||
display->fullscreen_window->current_fullscreen_mode.w != 0 &&
|
||||
display->fullscreen_window->current_fullscreen_mode.h != 0) {
|
||||
rect->w = display->fullscreen_window->current_fullscreen_mode.w;
|
||||
rect->h = display->fullscreen_window->current_fullscreen_mode.h;
|
||||
} else {
|
||||
rect->w = display->current_mode->screen_w;
|
||||
rect->h = display->current_mode->screen_h;
|
||||
rect->w = display->current_mode->w;
|
||||
rect->h = display->current_mode->h;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ SDL_FORCE_INLINE SDL_bool FloatEqual(float a, float b)
|
|||
static SDL_bool SurfaceScaleIsFractional(SDL_Window *window)
|
||||
{
|
||||
SDL_WindowData *data = window->driverdata;
|
||||
const float scale_value = !(window->fullscreen_exclusive) ? data->windowed_scale_factor : window->current_fullscreen_mode.display_scale;
|
||||
const float scale_value = !(window->fullscreen_exclusive) ? data->windowed_scale_factor : window->current_fullscreen_mode.pixel_density;
|
||||
return !FloatEqual(SDL_roundf(scale_value), scale_value);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ static SDL_bool WindowNeedsViewport(SDL_Window *window)
|
|||
if (SurfaceScaleIsFractional(window)) {
|
||||
return SDL_TRUE;
|
||||
} else if (window->fullscreen_exclusive) {
|
||||
if (window->current_fullscreen_mode.screen_w != output_width || window->current_fullscreen_mode.screen_h != output_height) {
|
||||
if (window->current_fullscreen_mode.w != output_width || window->current_fullscreen_mode.h != output_height) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -92,12 +92,12 @@ static void GetBufferSize(SDL_Window *window, int *width, int *height)
|
|||
int buf_height;
|
||||
|
||||
if (data->is_fullscreen && window->fullscreen_exclusive) {
|
||||
buf_width = window->current_fullscreen_mode.pixel_w;
|
||||
buf_height = window->current_fullscreen_mode.pixel_h;
|
||||
buf_width = (int)SDL_lroundf(window->current_fullscreen_mode.w * window->current_fullscreen_mode.pixel_density);
|
||||
buf_height = (int)SDL_lroundf(window->current_fullscreen_mode.h * window->current_fullscreen_mode.pixel_density);
|
||||
} else {
|
||||
/* Round fractional backbuffer sizes halfway away from zero. */
|
||||
buf_width = (int)SDL_lroundf((float)data->requested_window_width * data->windowed_scale_factor);
|
||||
buf_height = (int)SDL_lroundf((float)data->requested_window_height * data->windowed_scale_factor);
|
||||
buf_width = (int)SDL_lroundf(data->requested_window_width * data->windowed_scale_factor);
|
||||
buf_height = (int)SDL_lroundf(data->requested_window_height * data->windowed_scale_factor);
|
||||
}
|
||||
|
||||
if (width) {
|
||||
|
@ -213,8 +213,8 @@ static void ConfigureWindowGeometry(SDL_Window *window)
|
|||
/* If the compositor supplied fullscreen dimensions, use them, otherwise fall back to the display dimensions. */
|
||||
const int output_width = data->requested_window_width ? data->requested_window_width : output->screen_width;
|
||||
const int output_height = data->requested_window_height ? data->requested_window_height : output->screen_height;
|
||||
window_width = window->current_fullscreen_mode.screen_w;
|
||||
window_height = window->current_fullscreen_mode.screen_h;
|
||||
window_width = window->current_fullscreen_mode.w;
|
||||
window_height = window->current_fullscreen_mode.h;
|
||||
|
||||
window_size_changed = window_width != window->w || window_height != window->h ||
|
||||
data->wl_window_width != output_width || data->wl_window_height != output_height;
|
||||
|
@ -231,10 +231,10 @@ static void ConfigureWindowGeometry(SDL_Window *window)
|
|||
} else {
|
||||
/* Always use the mode dimensions for integer scaling. */
|
||||
UnsetDrawSurfaceViewport(window);
|
||||
wl_surface_set_buffer_scale(data->surface, (int32_t)window->current_fullscreen_mode.display_scale);
|
||||
wl_surface_set_buffer_scale(data->surface, (int32_t)window->current_fullscreen_mode.pixel_density);
|
||||
|
||||
data->wl_window_width = window->current_fullscreen_mode.screen_w;
|
||||
data->wl_window_height = window->current_fullscreen_mode.screen_h;
|
||||
data->wl_window_width = window->current_fullscreen_mode.w;
|
||||
data->wl_window_height = window->current_fullscreen_mode.h;
|
||||
}
|
||||
|
||||
data->pointer_scale_x = (float)window_width / (float)data->wl_window_width;
|
||||
|
|
|
@ -517,11 +517,9 @@ static void WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus)
|
|||
|
||||
/* In relative mode we are guaranteed to have mouse focus if we have keyboard focus */
|
||||
if (!SDL_GetMouse()->relative_mode) {
|
||||
SDL_FPoint point;
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
WIN_ClientPointToSDLFloat(data->window, cursorPos.x, cursorPos.y, &point.x, &point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), window, 0, 0, point.x, point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), window, 0, 0, (float)cursorPos.x, (float)cursorPos.y);
|
||||
}
|
||||
|
||||
WIN_CheckAsyncMouseRelease(data);
|
||||
|
@ -835,11 +833,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
/* Only generate mouse events for real mouse */
|
||||
if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH &&
|
||||
lParam != data->last_pointer_update) {
|
||||
float x, y;
|
||||
|
||||
WIN_ClientPointToSDLFloat(data->window, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &x, &y);
|
||||
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, x, y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -995,19 +989,17 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode && !IsIconic(hwnd)) {
|
||||
SDL_Mouse *mouse;
|
||||
POINT cursorPos;
|
||||
SDL_FPoint point;
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
WIN_ClientPointToSDLFloat(data->window, cursorPos.x, cursorPos.y, &point.x, &point.y);
|
||||
mouse = SDL_GetMouse();
|
||||
if (!mouse->was_touch_mouse_events) { /* we're not a touch handler causing a mouse leave? */
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, point.x, point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, (float)cursorPos.x, (float)cursorPos.y);
|
||||
} else { /* touch handling? */
|
||||
mouse->was_touch_mouse_events = SDL_FALSE; /* not anymore */
|
||||
if (mouse->touch_mouse_events) { /* convert touch to mouse events */
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, SDL_TOUCH_MOUSEID, 0, point.x, point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, SDL_TOUCH_MOUSEID, 0, (float)cursorPos.x, (float)cursorPos.y);
|
||||
} else { /* normal handling */
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, point.x, point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, (float)cursorPos.x, (float)cursorPos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1154,12 +1146,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
|
||||
SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);
|
||||
|
||||
/* Convert w, h, min_w, min_h, max_w, max_h from dpi-scaled points to pixels,
|
||||
treating them as coordinates within the client area. */
|
||||
WIN_ClientPointFromSDL(data->window, &w, &h);
|
||||
WIN_ClientPointFromSDL(data->window, &min_w, &min_h);
|
||||
WIN_ClientPointFromSDL(data->window, &max_w, &max_h);
|
||||
|
||||
/* Store in min_w and min_h difference between current size and minimal
|
||||
size so we don't need to call AdjustWindowRectEx twice */
|
||||
min_w -= w;
|
||||
|
@ -1267,7 +1253,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
x = rect.left;
|
||||
y = rect.top;
|
||||
WIN_ScreenPointToSDL(&x, &y);
|
||||
|
||||
SDL_GlobalToRelativeForWindow(data->window, x, y, &x, &y);
|
||||
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MOVED, x, y);
|
||||
|
@ -1281,20 +1266,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
x = rect.left;
|
||||
y = rect.top;
|
||||
WIN_ScreenPointToSDL(&x, &y);
|
||||
}
|
||||
|
||||
/* Convert client area width/height from pixels to dpi-scaled points */
|
||||
w = rect.right - rect.left;
|
||||
h = rect.bottom - rect.top;
|
||||
WIN_ClientPointToSDL(data->window, &w, &h);
|
||||
|
||||
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESIZED, w, h);
|
||||
|
||||
#ifdef HIGHDPI_DEBUG
|
||||
SDL_Log("WM_WINDOWPOSCHANGED: Windows client rect (pixels): (%d, %d) (%d x %d)\tSDL client rect (points): (%d, %d) (%d x %d) cached dpi %d, windows reported dpi %d",
|
||||
SDL_Log("WM_WINDOWPOSCHANGED: Windows client rect (pixels): (%d, %d) (%d x %d)\tSDL client rect (points): (%d, %d) (%d x %d) windows reported dpi %d",
|
||||
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
|
||||
x, y, w, h, data->scaling_dpi, data->videodata->GetDpiForWindow ? data->videodata->GetDpiForWindow(data->hwnd) : 0);
|
||||
x, y, w, h, data->videodata->GetDpiForWindow ? data->videodata->GetDpiForWindow(data->hwnd) : 0);
|
||||
#endif
|
||||
|
||||
/* Forces a WM_PAINT event */
|
||||
|
@ -1524,7 +1505,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
NCCALCSIZE_PARAMS *params = (NCCALCSIZE_PARAMS *)lParam;
|
||||
w = data->window->windowed.w;
|
||||
h = data->window->windowed.h;
|
||||
WIN_ClientPointFromSDL(data->window, &w, &h);
|
||||
params->rgrc[0].right = params->rgrc[0].left + w;
|
||||
params->rgrc[0].bottom = params->rgrc[0].top + h;
|
||||
}
|
||||
|
@ -1549,7 +1529,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
SDL_HitTestResult rc;
|
||||
point.x = winpoint.x;
|
||||
point.y = winpoint.y;
|
||||
WIN_ClientPointToSDL(data->window, &point.x, &point.y);
|
||||
rc = window->hit_test(window, &point, window->hit_test_data);
|
||||
switch (rc) {
|
||||
#define POST_HIT_TEST(ret) \
|
||||
|
@ -1632,14 +1611,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
query_client_h_win = sizeInOut->cy - frame_h;
|
||||
}
|
||||
|
||||
/* Convert to new dpi if we are using scaling.
|
||||
* Otherwise leave as pixels.
|
||||
*/
|
||||
if (data->videodata->dpi_scaling_enabled) {
|
||||
query_client_w_win = MulDiv(query_client_w_win, nextDPI, prevDPI);
|
||||
query_client_h_win = MulDiv(query_client_h_win, nextDPI, prevDPI);
|
||||
}
|
||||
|
||||
/* Add the window frame size that would be used at nextDPI */
|
||||
{
|
||||
RECT rect = { 0 };
|
||||
|
@ -1678,14 +1649,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
/* This DPI change is coming from an explicit SetWindowPos call within SDL.
|
||||
Assume all call sites are calculating the DPI-aware frame correctly, so
|
||||
we don't need to do any further adjustment. */
|
||||
|
||||
if (data->videodata->dpi_scaling_enabled) {
|
||||
/* Update the cached DPI value for this window */
|
||||
data->scaling_dpi = newDPI;
|
||||
|
||||
SDL_CheckWindowPixelSizeChanged(data->window);
|
||||
}
|
||||
|
||||
#ifdef HIGHDPI_DEBUG
|
||||
SDL_Log("WM_DPICHANGED: Doing nothing, assuming window is already sized correctly");
|
||||
#endif
|
||||
|
@ -1693,18 +1656,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
|
||||
/* Interactive user-initiated resizing/movement */
|
||||
|
||||
if (WIN_IsPerMonitorV2DPIAware(SDL_GetVideoDevice())) {
|
||||
/* WM_GETDPISCALEDSIZE should have been called prior, so we can trust the given
|
||||
suggestedRect. */
|
||||
w = suggestedRect->right - suggestedRect->left;
|
||||
h = suggestedRect->bottom - suggestedRect->top;
|
||||
|
||||
#ifdef HIGHDPI_DEBUG
|
||||
SDL_Log("WM_DPICHANGED: using suggestedRect");
|
||||
#endif
|
||||
} else {
|
||||
/* permonitor and earlier DPI awareness: calculate the new frame w/h such that
|
||||
{
|
||||
/* Calculate the new frame w/h such that
|
||||
the client area size is maintained. */
|
||||
const DWORD style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
const BOOL menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
|
||||
|
@ -1713,14 +1666,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
rect.right = data->window->w;
|
||||
rect.bottom = data->window->h;
|
||||
|
||||
if (data->videodata->dpi_scaling_enabled) {
|
||||
/* scale client size to from points to the new DPI */
|
||||
rect.right = MulDiv(rect.right, newDPI, 96);
|
||||
rect.bottom = MulDiv(rect.bottom, newDPI, 96);
|
||||
}
|
||||
|
||||
if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) {
|
||||
AdjustWindowRectEx(&rect, style, menu, 0);
|
||||
if (data->videodata->GetDpiForWindow && data->videodata->AdjustWindowRectExForDpi) {
|
||||
data->videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, newDPI);
|
||||
} else {
|
||||
AdjustWindowRectEx(&rect, style, menu, 0);
|
||||
}
|
||||
}
|
||||
|
||||
w = rect.right - rect.left;
|
||||
|
@ -1742,14 +1693,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
h,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
data->expected_resize = SDL_FALSE;
|
||||
|
||||
if (data->videodata->dpi_scaling_enabled) {
|
||||
/* Update the cached DPI value for this window */
|
||||
data->scaling_dpi = newDPI;
|
||||
|
||||
SDL_CheckWindowPixelSizeChanged(data->window);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
@ -1813,10 +1756,8 @@ static void WIN_UpdateMouseCapture()
|
|||
if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
|
||||
SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
|
||||
SDL_MouseID mouseID = SDL_GetMouse()->mouseID;
|
||||
SDL_FPoint point;
|
||||
WIN_ClientPointToSDLFloat(data->window, cursorPos.x, cursorPos.y, &point.x, &point.y);
|
||||
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 0, point.x, point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 0, (float)cursorPos.x, (float)cursorPos.y);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, !swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_RBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, !swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE);
|
||||
|
|
|
@ -156,9 +156,34 @@ static float WIN_GetRefreshRate(DEVMODE *mode)
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_bool WIN_GetDisplayMode(SDL_VideoDevice *_this, HMONITOR hMonitor, LPCWSTR deviceName, DWORD index, SDL_DisplayMode *mode, SDL_DisplayOrientation *orientation)
|
||||
static float WIN_GetContentScale(SDL_VideoDevice *_this, HMONITOR hMonitor)
|
||||
{
|
||||
const SDL_VideoData *videodata = (const SDL_VideoData *)_this->driverdata;
|
||||
int dpi = 0;
|
||||
|
||||
if (videodata->GetDpiForMonitor) {
|
||||
UINT hdpi_uint, vdpi_uint;
|
||||
if (videodata->GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &hdpi_uint, &vdpi_uint) == S_OK) {
|
||||
dpi = (int)hdpi_uint;
|
||||
}
|
||||
}
|
||||
if (dpi == 0) {
|
||||
/* Window 8.0 and below: same DPI for all monitors */
|
||||
HDC hdc = GetDC(NULL);
|
||||
if (hdc) {
|
||||
dpi = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
ReleaseDC(NULL, hdc);
|
||||
}
|
||||
}
|
||||
if (dpi == 0) {
|
||||
/* Safe default */
|
||||
dpi = 96;
|
||||
}
|
||||
return dpi / 96.0f;
|
||||
}
|
||||
|
||||
static SDL_bool WIN_GetDisplayMode(SDL_VideoDevice *_this, HMONITOR hMonitor, LPCWSTR deviceName, DWORD index, SDL_DisplayMode *mode, SDL_DisplayOrientation *orientation)
|
||||
{
|
||||
SDL_DisplayModeData *data;
|
||||
DEVMODE devmode;
|
||||
|
||||
|
@ -178,17 +203,10 @@ static SDL_bool WIN_GetDisplayMode(SDL_VideoDevice *_this, HMONITOR hMonitor, LP
|
|||
data->DeviceMode = devmode;
|
||||
|
||||
mode->format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
mode->pixel_w = data->DeviceMode.dmPelsWidth;
|
||||
mode->pixel_h = data->DeviceMode.dmPelsHeight;
|
||||
mode->w = data->DeviceMode.dmPelsWidth;
|
||||
mode->h = data->DeviceMode.dmPelsHeight;
|
||||
mode->refresh_rate = WIN_GetRefreshRate(&data->DeviceMode);
|
||||
|
||||
if (index == ENUM_CURRENT_SETTINGS && videodata->GetDpiForMonitor && videodata->dpi_scaling_enabled) {
|
||||
UINT hdpi_uint, vdpi_uint;
|
||||
if (videodata->GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &hdpi_uint, &vdpi_uint) == S_OK) {
|
||||
mode->display_scale = hdpi_uint / 96.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill in the mode information */
|
||||
WIN_UpdateDisplayMode(_this, deviceName, index, mode);
|
||||
|
||||
|
@ -308,6 +326,7 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI
|
|||
SDL_DisplayData *displaydata;
|
||||
SDL_DisplayMode mode;
|
||||
SDL_DisplayOrientation orientation;
|
||||
float content_scale = WIN_GetContentScale(_this, hMonitor);
|
||||
|
||||
#ifdef DEBUG_MODES
|
||||
SDL_Log("Display: %s\n", WIN_StringToUTF8W(info->szDevice));
|
||||
|
@ -354,6 +373,7 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI
|
|||
SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_MOVED, 0);
|
||||
}
|
||||
SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_ORIENTATION, orientation);
|
||||
SDL_SetDisplayContentScale(existing_display, content_scale);
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
@ -380,6 +400,7 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI
|
|||
|
||||
display.desktop_mode = mode;
|
||||
display.orientation = orientation;
|
||||
display.content_scale = content_scale;
|
||||
display.device = _this;
|
||||
display.driverdata = displaydata;
|
||||
WIN_GetDisplayBounds(_this, &display, &displaydata->bounds);
|
||||
|
@ -446,44 +467,9 @@ int WIN_InitModes(SDL_VideoDevice *_this)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the monitor rect and work rect from pixels to the SDL coordinate system (monitor origins are in pixels,
|
||||
* monitor size in DPI-scaled points).
|
||||
*
|
||||
* No-op if DPI scaling is not enabled.
|
||||
*/
|
||||
static void WIN_MonitorInfoToSDL(const SDL_VideoData *videodata, HMONITOR monitor, MONITORINFO *info)
|
||||
{
|
||||
UINT xdpi, ydpi;
|
||||
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check for Windows < 8.1*/
|
||||
if (!videodata->GetDpiForMonitor) {
|
||||
return;
|
||||
}
|
||||
if (videodata->GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi) != S_OK) {
|
||||
/* Shouldn't happen? */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Convert monitor size to points, leaving the monitor position in pixels */
|
||||
info->rcMonitor.right = info->rcMonitor.left + MulDiv(info->rcMonitor.right - info->rcMonitor.left, 96, xdpi);
|
||||
info->rcMonitor.bottom = info->rcMonitor.top + MulDiv(info->rcMonitor.bottom - info->rcMonitor.top, 96, ydpi);
|
||||
|
||||
/* Convert monitor work rect to points */
|
||||
info->rcWork.left = info->rcMonitor.left + MulDiv(info->rcWork.left - info->rcMonitor.left, 96, xdpi);
|
||||
info->rcWork.right = info->rcMonitor.left + MulDiv(info->rcWork.right - info->rcMonitor.left, 96, xdpi);
|
||||
info->rcWork.top = info->rcMonitor.top + MulDiv(info->rcWork.top - info->rcMonitor.top, 96, ydpi);
|
||||
info->rcWork.bottom = info->rcMonitor.top + MulDiv(info->rcWork.bottom - info->rcMonitor.top, 96, ydpi);
|
||||
}
|
||||
|
||||
int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
{
|
||||
const SDL_DisplayData *data = display->driverdata;
|
||||
const SDL_VideoData *videodata = display->device->driverdata;
|
||||
MONITORINFO minfo;
|
||||
BOOL rc;
|
||||
|
||||
|
@ -495,7 +481,6 @@ int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_
|
|||
return SDL_SetError("Couldn't find monitor data");
|
||||
}
|
||||
|
||||
WIN_MonitorInfoToSDL(videodata, data->MonitorHandle, &minfo);
|
||||
rect->x = minfo.rcMonitor.left;
|
||||
rect->y = minfo.rcMonitor.top;
|
||||
rect->w = minfo.rcMonitor.right - minfo.rcMonitor.left;
|
||||
|
@ -504,38 +489,9 @@ int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int WIN_GetDisplayDPI(SDL_DisplayID displayID, int *dpi)
|
||||
{
|
||||
const SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
|
||||
const SDL_DisplayData *displaydata = display ? display->driverdata : NULL;
|
||||
const SDL_VideoData *videodata = display ? display->device->driverdata : NULL;
|
||||
|
||||
*dpi = 0;
|
||||
|
||||
if (videodata && videodata->GetDpiForMonitor) {
|
||||
/* Windows 8.1 + codepath */
|
||||
UINT xdpi, ydpi;
|
||||
videodata->GetDpiForMonitor(displaydata->MonitorHandle, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
|
||||
*dpi = (int)xdpi; /* xdpi and hdpi are the same value */
|
||||
}
|
||||
if (*dpi == 0) {
|
||||
/* Window 8.0 and below: same DPI for all monitors */
|
||||
HDC hdc = GetDC(NULL);
|
||||
if (hdc) {
|
||||
*dpi = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
ReleaseDC(NULL, hdc);
|
||||
}
|
||||
}
|
||||
if (*dpi == 0) {
|
||||
return SDL_SetError("Couldn't get display DPI");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
{
|
||||
const SDL_DisplayData *data = display->driverdata;
|
||||
const SDL_VideoData *videodata = display->device->driverdata;
|
||||
MONITORINFO minfo;
|
||||
BOOL rc;
|
||||
|
||||
|
@ -547,7 +503,6 @@ int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display
|
|||
return SDL_SetError("Couldn't find monitor data");
|
||||
}
|
||||
|
||||
WIN_MonitorInfoToSDL(videodata, data->MonitorHandle, &minfo);
|
||||
rect->x = minfo.rcWork.left;
|
||||
rect->y = minfo.rcWork.top;
|
||||
rect->w = minfo.rcWork.right - minfo.rcWork.left;
|
||||
|
@ -556,143 +511,6 @@ int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point from the SDL coordinate system (monitor origins are in pixels,
|
||||
* offset within a monitor in DPI-scaled points) to Windows virtual screen coordinates (pixels).
|
||||
*
|
||||
* No-op if DPI scaling is not enabled (returns 96 dpi).
|
||||
*
|
||||
* Returns the DPI of the monitor that was closest to x, y and used for the conversion.
|
||||
*/
|
||||
void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut)
|
||||
{
|
||||
POINT pt = { 0, 0 };
|
||||
WIN_ScreenPointFromSDLFloat((float)*x, (float)*y, &pt.x, &pt.y, dpiOut);
|
||||
*x = pt.x;
|
||||
*y = pt.y;
|
||||
}
|
||||
|
||||
void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *dpiOut)
|
||||
{
|
||||
const SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
||||
const SDL_VideoData *videodata;
|
||||
SDL_DisplayID displayID;
|
||||
SDL_Rect bounds;
|
||||
int dpi;
|
||||
SDL_Point point;
|
||||
|
||||
point.x = (int)x;
|
||||
point.y = (int)y;
|
||||
|
||||
if (dpiOut) {
|
||||
*dpiOut = 96;
|
||||
}
|
||||
|
||||
if (videodevice == NULL || !videodevice->driverdata) {
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
videodata = videodevice->driverdata;
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
/* Can't use MonitorFromPoint for this because we currently have SDL points, not pixels */
|
||||
displayID = SDL_GetDisplayForPoint(&point);
|
||||
if (displayID == 0) {
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || WIN_GetDisplayDPI(displayID, &dpi) < 0) {
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
if (dpiOut) {
|
||||
*dpiOut = dpi;
|
||||
}
|
||||
|
||||
/* Undo the DPI-scaling within the monitor bounds to convert back to pixels */
|
||||
*xOut = bounds.x + SDL_lroundf(((x - bounds.x) * dpi) / 96.0f);
|
||||
*yOut = bounds.y + SDL_lroundf(((y - bounds.y) * dpi) / 96.0f);
|
||||
|
||||
#ifdef HIGHDPI_DEBUG_VERBOSE
|
||||
SDL_Log("WIN_ScreenPointFromSDL: (%g, %g) points -> (%d x %d) pixels, using %g DPI monitor",
|
||||
x, y, *xOut, *yOut, ddpi);
|
||||
#endif
|
||||
return;
|
||||
|
||||
passthrough:
|
||||
*xOut = SDL_lroundf(x);
|
||||
*yOut = SDL_lroundf(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point from Windows virtual screen coordinates (pixels) to the SDL
|
||||
* coordinate system (monitor origins are in pixels, offset within a monitor in DPI-scaled points).
|
||||
*
|
||||
* No-op if DPI scaling is not enabled.
|
||||
*/
|
||||
void WIN_ScreenPointToSDL(int *x, int *y)
|
||||
{
|
||||
SDL_FPoint pt;
|
||||
WIN_ScreenPointToSDLFloat(*x, *y, &pt.x, &pt.y);
|
||||
*x = SDL_lroundf(pt.x);
|
||||
*y = SDL_lroundf(pt.y);
|
||||
}
|
||||
|
||||
void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut)
|
||||
{
|
||||
const SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
||||
const SDL_VideoData *videodata;
|
||||
POINT point;
|
||||
HMONITOR monitor;
|
||||
int i;
|
||||
SDL_DisplayID displayID;
|
||||
SDL_Rect bounds;
|
||||
int dpi;
|
||||
|
||||
if (videodevice == NULL || !videodevice->driverdata) {
|
||||
return;
|
||||
}
|
||||
|
||||
videodata = videodevice->driverdata;
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
*xOut = (float)x;
|
||||
*yOut = (float)y;
|
||||
return;
|
||||
}
|
||||
|
||||
point.x = x;
|
||||
point.y = y;
|
||||
monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
/* Search for the corresponding SDL monitor */
|
||||
displayID = 0;
|
||||
for (i = 0; i < videodevice->num_displays; ++i) {
|
||||
SDL_DisplayData *driverdata = videodevice->displays[i].driverdata;
|
||||
if (driverdata->MonitorHandle == monitor) {
|
||||
displayID = videodevice->displays[i].id;
|
||||
}
|
||||
}
|
||||
if (displayID == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get SDL display properties */
|
||||
if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || WIN_GetDisplayDPI(displayID, &dpi) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Convert the point's offset within the monitor from pixels to DPI-scaled points */
|
||||
*xOut = (float)bounds.x + ((float)(x - bounds.x) * 96.0f) / dpi;
|
||||
*yOut = (float)bounds.y + ((float)(y - bounds.y) * 96.0f) / dpi;
|
||||
|
||||
#ifdef HIGHDPI_DEBUG_VERBOSE
|
||||
SDL_Log("WIN_ScreenPointToSDL: (%d, %d) pixels -> (%g x %g) points, using %g DPI monitor",
|
||||
x, y, *xOut, *yOut, ddpi);
|
||||
#endif
|
||||
}
|
||||
|
||||
int WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
{
|
||||
SDL_DisplayData *data = display->driverdata;
|
||||
|
|
|
@ -39,10 +39,6 @@ struct SDL_DisplayModeData
|
|||
extern int WIN_InitModes(SDL_VideoDevice *_this);
|
||||
extern int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
extern int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
extern void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut);
|
||||
extern void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *dpiOut);
|
||||
extern void WIN_ScreenPointToSDL(int *x, int *y);
|
||||
extern void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut);
|
||||
extern int WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
|
||||
extern int WIN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
extern void WIN_RefreshDisplays(SDL_VideoDevice *_this);
|
||||
|
|
|
@ -288,7 +288,8 @@ static int WIN_WarpMouse(SDL_Window *window, float x, float y)
|
|||
return 0;
|
||||
}
|
||||
|
||||
WIN_ClientPointFromSDLFloat(window, x, y, &pt.x, &pt.y);
|
||||
pt.x = (int)SDL_roundf(x);
|
||||
pt.y = (int)SDL_roundf(y);
|
||||
ClientToScreen(hwnd, &pt);
|
||||
WIN_SetCursorPos(pt.x, pt.y);
|
||||
|
||||
|
@ -301,7 +302,8 @@ static int WIN_WarpMouseGlobal(float x, float y)
|
|||
{
|
||||
POINT pt;
|
||||
|
||||
WIN_ScreenPointFromSDLFloat(x, y, &pt.x, &pt.y, NULL);
|
||||
pt.x = (int)SDL_roundf(x);
|
||||
pt.y = (int)SDL_roundf(y);
|
||||
SetCursorPos(pt.x, pt.y);
|
||||
return 0;
|
||||
}
|
||||
|
@ -338,7 +340,8 @@ static Uint32 WIN_GetGlobalMouseState(float *x, float *y)
|
|||
SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
|
||||
|
||||
GetCursorPos(&pt);
|
||||
WIN_ScreenPointToSDLFloat(pt.x, pt.y, x, y);
|
||||
*x = (float)pt.x;
|
||||
*y = (float)pt.y;
|
||||
|
||||
retval |= GetAsyncKeyState(!swapButtons ? VK_LBUTTON : VK_RBUTTON) & 0x8000 ? SDL_BUTTON_LMASK : 0;
|
||||
retval |= GetAsyncKeyState(!swapButtons ? VK_RBUTTON : VK_LBUTTON) & 0x8000 ? SDL_BUTTON_RMASK : 0;
|
||||
|
|
|
@ -401,23 +401,11 @@ static void WIN_InitDPIAwareness(SDL_VideoDevice *_this)
|
|||
}
|
||||
}
|
||||
|
||||
static void WIN_InitDPIScaling(SDL_VideoDevice *_this)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
|
||||
if (SDL_GetHintBoolean("SDL_WINDOWS_DPI_SCALING", SDL_TRUE)) {
|
||||
WIN_DeclareDPIAwarePerMonitorV2(_this);
|
||||
|
||||
data->dpi_scaling_enabled = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
int WIN_VideoInit(SDL_VideoDevice *_this)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
|
||||
WIN_InitDPIAwareness(_this);
|
||||
WIN_InitDPIScaling(_this);
|
||||
|
||||
#ifdef HIGHDPI_DEBUG
|
||||
SDL_Log("DPI awareness: %s", WIN_GetDPIAwareness(_this));
|
||||
|
@ -429,7 +417,7 @@ int WIN_VideoInit(SDL_VideoDevice *_this)
|
|||
SDL_DisplayMode mode;
|
||||
|
||||
SDL_zero(mode);
|
||||
D3D12_XBOX_GetResolution(&mode.pixel_w, &mode.pixel_h);
|
||||
D3D12_XBOX_GetResolution(&mode.w, &mode.h);
|
||||
mode.refresh_rate = 60.0f;
|
||||
mode.format = SDL_PIXELFORMAT_ARGB8888;
|
||||
|
||||
|
|
|
@ -399,7 +399,6 @@ struct SDL_VideoData
|
|||
/* *INDENT-ON* */ /* clang-format on */
|
||||
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
|
||||
|
||||
SDL_bool dpi_scaling_enabled;
|
||||
SDL_bool cleared;
|
||||
|
||||
#ifndef SDL_DISABLE_WINDOWS_IME
|
||||
|
|
|
@ -134,7 +134,6 @@ static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL m
|
|||
{
|
||||
SDL_VideoData *videodata = SDL_GetVideoDevice() ? SDL_GetVideoDevice()->driverdata : NULL;
|
||||
RECT rect;
|
||||
int dpi = 96;
|
||||
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
||||
UINT frame_dpi;
|
||||
#endif
|
||||
|
@ -147,21 +146,6 @@ static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL m
|
|||
*width = (use_current ? window->w : window->windowed.w);
|
||||
*height = (use_current ? window->h : window->windowed.h);
|
||||
|
||||
/* Convert client rect from points to pixels (no-op if DPI scaling not enabled) */
|
||||
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
||||
WIN_ScreenPointFromSDL(x, y, &dpi);
|
||||
#endif
|
||||
/* Note, use the guessed DPI returned from WIN_ScreenPointFromSDL rather than the cached one in
|
||||
data->scaling_dpi.
|
||||
|
||||
- This is called before the window is created, so we can't rely on data->scaling_dpi
|
||||
- Bug workaround: when leaving exclusive fullscreen, the cached DPI and window DPI reported
|
||||
by GetDpiForWindow will be wrong, and would cause windows shrinking slightly when
|
||||
going from exclusive fullscreen to windowed on a HighDPI monitor with scaling if we used them.
|
||||
*/
|
||||
*width = MulDiv(*width, dpi, 96);
|
||||
*height = MulDiv(*height, dpi, 96);
|
||||
|
||||
/* Copy the client size in pixels into this rect structure,
|
||||
which we'll then adjust with AdjustWindowRectEx */
|
||||
rect.left = 0;
|
||||
|
@ -281,46 +265,6 @@ static void SDLCALL WIN_MouseRelativeModeCenterChanged(void *userdata, const cha
|
|||
data->mouse_relative_mode_center = SDL_GetStringBoolean(hint, SDL_TRUE);
|
||||
}
|
||||
|
||||
static int WIN_GetScalingDPIForHWND(const SDL_VideoData *videodata, HWND hwnd)
|
||||
{
|
||||
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
|
||||
return 96;
|
||||
#else
|
||||
/* DPI scaling not requested? */
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
return 96;
|
||||
}
|
||||
|
||||
/* Window 10+ */
|
||||
if (videodata->GetDpiForWindow) {
|
||||
return videodata->GetDpiForWindow(hwnd);
|
||||
}
|
||||
|
||||
/* Window 8.1+ */
|
||||
if (videodata->GetDpiForMonitor) {
|
||||
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
if (monitor) {
|
||||
UINT dpi_uint, unused;
|
||||
if (S_OK == videodata->GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpi_uint, &unused)) {
|
||||
return (int)dpi_uint;
|
||||
}
|
||||
}
|
||||
return 96;
|
||||
}
|
||||
|
||||
/* Windows Vista-8.0 */
|
||||
{
|
||||
HDC hdc = GetDC(NULL);
|
||||
if (hdc) {
|
||||
int dpi = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
ReleaseDC(NULL, hdc);
|
||||
return dpi;
|
||||
}
|
||||
return 96;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd, HWND parent, SDL_bool created)
|
||||
{
|
||||
SDL_VideoData *videodata = _this->driverdata;
|
||||
|
@ -347,7 +291,6 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
|
|||
data->videodata = videodata;
|
||||
data->initializing = SDL_TRUE;
|
||||
data->last_displayID = window->last_displayID;
|
||||
data->scaling_dpi = WIN_GetScalingDPIForHWND(videodata, hwnd);
|
||||
if (SDL_GetHintBoolean("SDL_WINDOW_RETAIN_CONTENT", SDL_FALSE)) {
|
||||
data->copybits_flag = 0;
|
||||
} else {
|
||||
|
@ -395,7 +338,6 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
|
|||
int w = rect.right;
|
||||
int h = rect.bottom;
|
||||
|
||||
WIN_ClientPointToSDL(window, &w, &h);
|
||||
if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
|
||||
/* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */
|
||||
int x, y;
|
||||
|
@ -416,11 +358,8 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
|
|||
point.x = 0;
|
||||
point.y = 0;
|
||||
if (ClientToScreen(hwnd, &point)) {
|
||||
int x = point.x;
|
||||
int y = point.y;
|
||||
WIN_ScreenPointToSDL(&x, &y);
|
||||
window->x = x;
|
||||
window->y = y;
|
||||
window->x = point.x;
|
||||
window->y = point.y;
|
||||
}
|
||||
}
|
||||
WIN_UpdateWindowICCProfile(window, SDL_FALSE);
|
||||
|
@ -482,11 +421,6 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Force the SDL_WINDOW_ALLOW_HIGHDPI window flag if we are doing DPI scaling */
|
||||
if (videodata->dpi_scaling_enabled) {
|
||||
window->flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
}
|
||||
|
||||
if (data->parent && !window->parent) {
|
||||
data->destroy_parent_with_window = SDL_TRUE;
|
||||
}
|
||||
|
@ -1401,8 +1335,6 @@ void WIN_UpdateClipCursor(SDL_Window *window)
|
|||
|
||||
/* mouse_rect_win_client is the mouse rect in Windows client space */
|
||||
mouse_rect_win_client = window->mouse_rect;
|
||||
WIN_ClientPointFromSDL(window, &mouse_rect_win_client.x, &mouse_rect_win_client.y);
|
||||
WIN_ClientPointFromSDL(window, &mouse_rect_win_client.w, &mouse_rect_win_client.h);
|
||||
|
||||
/* mouse_rect is the rect in Windows screen space */
|
||||
mouse_rect.left = rect.left + mouse_rect_win_client.x;
|
||||
|
@ -1487,70 +1419,6 @@ int WIN_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opaci
|
|||
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point in the client area from pixels to DPI-scaled points.
|
||||
*
|
||||
* No-op if DPI scaling is not enabled.
|
||||
*/
|
||||
void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y)
|
||||
{
|
||||
const SDL_WindowData *data = window->driverdata;
|
||||
const SDL_VideoData *videodata = data->videodata;
|
||||
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
*x = MulDiv(*x, 96, data->scaling_dpi);
|
||||
*y = MulDiv(*y, 96, data->scaling_dpi);
|
||||
}
|
||||
|
||||
void WIN_ClientPointToSDLFloat(const SDL_Window *window, LONG x, LONG y, float *xOut, float *yOut)
|
||||
{
|
||||
const SDL_WindowData *data = window->driverdata;
|
||||
const SDL_VideoData *videodata = data->videodata;
|
||||
|
||||
if (videodata->dpi_scaling_enabled) {
|
||||
*xOut = (float)(x * 96) / data->scaling_dpi;
|
||||
*yOut = (float)(y * 96) / data->scaling_dpi;
|
||||
} else {
|
||||
*xOut = (float)x;
|
||||
*yOut = (float)y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point in the client area from DPI-scaled points to pixels.
|
||||
*
|
||||
* No-op if DPI scaling is not enabled.
|
||||
*/
|
||||
void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y)
|
||||
{
|
||||
const SDL_WindowData *data = window->driverdata;
|
||||
const SDL_VideoData *videodata = data->videodata;
|
||||
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
*x = MulDiv(*x, data->scaling_dpi, 96);
|
||||
*y = MulDiv(*y, data->scaling_dpi, 96);
|
||||
}
|
||||
|
||||
void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float y, LONG *xOut, LONG *yOut)
|
||||
{
|
||||
const SDL_WindowData *data = window->driverdata;
|
||||
const SDL_VideoData *videodata = data->videodata;
|
||||
|
||||
if (videodata->dpi_scaling_enabled) {
|
||||
*xOut = (LONG)SDL_roundf((x * data->scaling_dpi) / 96.0f);
|
||||
*yOut = (LONG)SDL_roundf((y * data->scaling_dpi) / 96.0f);
|
||||
} else {
|
||||
*xOut = (LONG)SDL_roundf(x);
|
||||
*yOut = (LONG)SDL_roundf(y);
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
||||
void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
|
||||
{
|
||||
|
|
|
@ -70,11 +70,6 @@ struct SDL_WindowData
|
|||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
/**
|
||||
* Cached value of GetDpiForWindow, for use for scaling points in the client area
|
||||
* between dpi-scaled points and pixels. Only used if videodata->dpi_scaling_enabled.
|
||||
*/
|
||||
int scaling_dpi;
|
||||
|
||||
/* Whether we retain the content of the window when changing state */
|
||||
UINT copybits_flag;
|
||||
|
@ -109,10 +104,6 @@ extern int WIN_GetWindowWMInfo(SDL_VideoDevice *_this, SDL_Window *window, struc
|
|||
extern void WIN_OnWindowEnter(SDL_VideoDevice *_this, SDL_Window *window);
|
||||
extern void WIN_UpdateClipCursor(SDL_Window *window);
|
||||
extern int WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
|
||||
extern void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y);
|
||||
extern void WIN_ClientPointToSDLFloat(const SDL_Window *window, LONG x, LONG y, float *xOut, float *yOut);
|
||||
extern void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y);
|
||||
extern void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float y, LONG *xOut, LONG *yOut);
|
||||
extern void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
|
||||
extern int WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
||||
extern void WIN_UpdateDarkModeForHWND(HWND hwnd);
|
||||
|
|
|
@ -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->pixel_w = dxgiMode->Width;
|
||||
sdlMode->pixel_h = dxgiMode->Height;
|
||||
sdlMode->w = dxgiMode->Width;
|
||||
sdlMode->h = dxgiMode->Height;
|
||||
sdlMode->refresh_rate = (((100 * dxgiMode->RefreshRate.Numerator) / dxgiMode->RefreshRate.Denominator) / 100.0f);
|
||||
sdlMode->format = D3D11_DXGIFormatToSDLPixelFormat(dxgiMode->Format);
|
||||
}
|
||||
|
@ -303,8 +303,8 @@ static int WINRT_AddDisplaysForOutput(SDL_VideoDevice *_this, IDXGIAdapter1 *dxg
|
|||
SDL_DisplayMode mode;
|
||||
SDL_zero(mode);
|
||||
display.name = SDL_strdup("Windows Simulator / Terminal Services Display");
|
||||
mode.pixel_w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
|
||||
mode.pixel_h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
|
||||
mode.w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
|
||||
mode.h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
|
||||
mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
display.desktop_mode = mode;
|
||||
} else if (FAILED(hr)) {
|
||||
|
@ -409,23 +409,18 @@ static int WINRT_AddDisplaysForAdapter(SDL_VideoDevice *_this, IDXGIFactory2 *dx
|
|||
*/
|
||||
|
||||
#if (NTDDI_VERSION >= NTDDI_WIN10) || (SDL_WINRT_USE_APPLICATIONVIEW && SDL_WINAPI_FAMILY_PHONE)
|
||||
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 = (int)SDL_floorf(appView->VisibleBounds.Width);
|
||||
mode.screen_h = (int)SDL_floorf(appView->VisibleBounds.Height);
|
||||
mode.display_scale = WINRT_DISPLAY_PROPERTY(LogicalDpi) / 96.0f;
|
||||
mode.w = (int)SDL_floorf(appView->VisibleBounds.Width);
|
||||
mode.h = (int)SDL_floorf(appView->VisibleBounds.Height);
|
||||
#else
|
||||
/* On platform(s) that do not support VisibleBounds, such as Windows 8.1,
|
||||
fall back to CoreWindow's Bounds property.
|
||||
*/
|
||||
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 = (int)SDL_floorf(coreWin->Bounds.Width);
|
||||
mode.screen_h = (int)SDL_floorf(coreWin->Bounds.Height);
|
||||
mode.display_scale = WINRT_DISPLAY_PROPERTY(LogicalDpi) / 96.0f;
|
||||
mode.w = (int)SDL_floorf(coreWin->Bounds.Width);
|
||||
mode.h = (int)SDL_floorf(coreWin->Bounds.Height);
|
||||
#endif
|
||||
|
||||
mode.pixel_density = WINRT_DISPLAY_PROPERTY(LogicalDpi) / 96.0f;
|
||||
mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
|
||||
display.desktop_mode = mode;
|
||||
bool error = (SDL_AddVideoDisplay(&display, SDL_FALSE) == 0);
|
||||
if (display.name) {
|
||||
|
@ -529,7 +524,7 @@ WINRT_DetectWindowFlags(SDL_Window *window)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (display->desktop_mode.pixel_w != w || display->desktop_mode.pixel_h != h) {
|
||||
if (display->desktop_mode.w != w || display->desktop_mode.h != h) {
|
||||
latestFlags |= SDL_WINDOW_MAXIMIZED;
|
||||
} else {
|
||||
latestFlags |= SDL_WINDOW_FULLSCREEN;
|
||||
|
|
|
@ -470,8 +470,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 = dpy->driverdata;
|
||||
x = dpydata->x + ((dpy->current_mode->pixel_w - data->dialog_width) / 2);
|
||||
y = dpydata->y + ((dpy->current_mode->pixel_h - data->dialog_height) / 3);
|
||||
x = dpydata->x + ((dpy->current_mode->w - data->dialog_width) / 2);
|
||||
y = dpydata->y + ((dpy->current_mode->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;
|
||||
|
|
|
@ -217,11 +217,11 @@ static SDL_bool SetXRandRModeInfo(Display *display, XRRScreenResources *res, RRC
|
|||
}
|
||||
|
||||
if (rotation & (XRANDR_ROTATION_LEFT | XRANDR_ROTATION_RIGHT)) {
|
||||
mode->pixel_w = info->height;
|
||||
mode->pixel_h = info->width;
|
||||
mode->w = info->height;
|
||||
mode->h = info->width;
|
||||
} else {
|
||||
mode->pixel_w = info->width;
|
||||
mode->pixel_h = info->height;
|
||||
mode->w = info->width;
|
||||
mode->h = info->height;
|
||||
}
|
||||
mode->refresh_rate = CalculateXRandRRefreshRate(info);
|
||||
((SDL_DisplayModeData *)mode->driverdata)->xrandr_mode = modeID;
|
||||
|
@ -344,8 +344,8 @@ static int X11_AddXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int screen
|
|||
|
||||
SDL_zero(mode);
|
||||
modeID = crtc->mode;
|
||||
mode.pixel_w = crtc->width;
|
||||
mode.pixel_h = crtc->height;
|
||||
mode.w = crtc->width;
|
||||
mode.h = crtc->height;
|
||||
mode.format = pixelformat;
|
||||
|
||||
display_x = crtc->x;
|
||||
|
@ -551,8 +551,8 @@ static int X11_InitModes_StdXlib(SDL_VideoDevice *_this)
|
|||
}
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.pixel_w = WidthOfScreen(screen);
|
||||
mode.pixel_h = HeightOfScreen(screen);
|
||||
mode.w = WidthOfScreen(screen);
|
||||
mode.h = HeightOfScreen(screen);
|
||||
mode.format = pixelformat;
|
||||
|
||||
displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata));
|
||||
|
@ -734,8 +734,8 @@ int X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SD
|
|||
goto ungrabServer;
|
||||
}
|
||||
|
||||
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);
|
||||
mm_width = mode->w * DisplayWidthMM(display, data->screen) / DisplayWidth(display, data->screen);
|
||||
mm_height = mode->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
|
||||
|
@ -746,7 +746,8 @@ int X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SD
|
|||
crashing */
|
||||
X11_XSync(display, False);
|
||||
PreXRRSetScreenSizeErrorHandler = X11_XSetErrorHandler(SDL_XRRSetScreenSizeErrHandler);
|
||||
X11_XRRSetScreenSize(display, RootWindow(display, data->screen), mode->pixel_w, mode->pixel_h, mm_width, mm_height);
|
||||
X11_XRRSetScreenSize(display, RootWindow(display, data->screen),
|
||||
mode->w, mode->h, mm_width, mm_height);
|
||||
X11_XSync(display, False);
|
||||
X11_XSetErrorHandler(PreXRRSetScreenSizeErrorHandler);
|
||||
|
||||
|
@ -782,8 +783,8 @@ int X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display,
|
|||
|
||||
rect->x = data->x;
|
||||
rect->y = data->y;
|
||||
rect->w = sdl_display->current_mode->screen_w;
|
||||
rect->h = sdl_display->current_mode->screen_h;
|
||||
rect->w = sdl_display->current_mode->w;
|
||||
rect->h = sdl_display->current_mode->h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue