video: Add video device quirk flags and apply them to the video subsystem

Add quirk flags to the video device struct and add flags to allow video backend drivers to disable mode switching and disable unsetting the fullscreen mode when minimizing a window. As certain platforms can have multiple video backends compiled in at once, #ifdefs, as used by other platforms, aren't suitable as different backends on the same platform may not need the same quirks.

This replaces the formerly dedicated 'disable_display_mode_switching' boolean as additional quirks are needed by the Wayland backend.  Helper functions have also been added to simplify reading the flag states.
main
Frank Praznik 2022-08-13 16:43:15 -04:00 committed by Sam Lantinga
parent 0cc8dfdb58
commit cc9cc2028d
3 changed files with 28 additions and 6 deletions

View File

@ -149,6 +149,12 @@ struct SDL_SysWMinfo;
/* Define the SDL video driver structure */
#define _THIS SDL_VideoDevice *_this
/* Video device flags */
typedef enum {
VIDEO_DEVICE_QUIRK_DISABLE_DISPLAY_MODE_SWITCHING = 0x01,
VIDEO_DEVICE_QUIRK_DISABLE_UNSET_FULLSCREEN_ON_MINIMIZE = 0x02,
} DeviceQuirkFlags;
struct SDL_VideoDevice
{
/* * * */
@ -347,7 +353,7 @@ struct SDL_VideoDevice
Uint32 next_object_id;
char *clipboard_text;
SDL_bool setting_display_mode;
SDL_bool disable_display_mode_switching;
Uint32 quirk_flags;
/* * * */
/* Data used by the GL drivers */

View File

@ -166,6 +166,18 @@ extern SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window * window);
extern SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state);
#endif
/* Convenience functions for reading driver flags */
static SDL_bool
DisableDisplayModeSwitching(_THIS)
{
return !!(_this->quirk_flags & VIDEO_DEVICE_QUIRK_DISABLE_DISPLAY_MODE_SWITCHING);
}
static SDL_bool
DisableUnsetFullscreenOnMinimize(_THIS)
{
return !!(_this->quirk_flags & VIDEO_DEVICE_QUIRK_DISABLE_UNSET_FULLSCREEN_ON_MINIMIZE);
}
/* Support for framebuffer emulation using an accelerated renderer */
@ -1419,7 +1431,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
}
/* Don't try to change the display mode if the driver doesn't want it. */
if (_this->disable_display_mode_switching == SDL_FALSE) {
if (DisableDisplayModeSwitching(_this) == SDL_FALSE) {
/* only do the mode change if we want exclusive fullscreen */
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
if (SDL_SetDisplayModeForDisplay(display, &fullscreen_mode) < 0) {
@ -2524,7 +2536,9 @@ SDL_MinimizeWindow(SDL_Window * window)
return;
}
SDL_UpdateFullscreenMode(window, SDL_FALSE);
if (!DisableUnsetFullscreenOnMinimize(_this)) {
SDL_UpdateFullscreenMode(window, SDL_FALSE);
}
if (_this->MinimizeWindow) {
_this->MinimizeWindow(_this, window);
@ -3072,7 +3086,9 @@ SDL_OnWindowMoved(SDL_Window * window)
void
SDL_OnWindowMinimized(SDL_Window * window)
{
SDL_UpdateFullscreenMode(window, SDL_FALSE);
if (!DisableUnsetFullscreenOnMinimize(_this)) {
SDL_UpdateFullscreenMode(window, SDL_FALSE);
}
}
void
@ -3153,7 +3169,7 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window)
hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
if (!hint || !*hint || SDL_strcasecmp(hint, "auto") == 0) {
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP ||
_this->disable_display_mode_switching == SDL_TRUE) {
DisableDisplayModeSwitching(_this) == SDL_TRUE) {
return SDL_FALSE;
} else {
return SDL_TRUE;

View File

@ -279,7 +279,7 @@ Wayland_CreateDevice(void)
device->free = Wayland_DeleteDevice;
device->disable_display_mode_switching = SDL_TRUE;
device->quirk_flags = VIDEO_DEVICE_QUIRK_DISABLE_DISPLAY_MODE_SWITCHING;
return device;
}