2015-06-21 23:33:46 +08:00
/**
* Video test suite
*/
2022-11-27 12:43:38 +08:00
# include <SDL3/SDL.h>
# include <SDL3/SDL_test.h>
2023-03-08 23:12:45 +08:00
# include "testautomation_suites.h"
2015-06-21 23:33:46 +08:00
/* Private helpers */
2023-02-02 07:21:53 +08:00
/**
2015-06-21 23:33:46 +08:00
* Create a test window
*/
2022-12-30 05:58:16 +08:00
static SDL_Window * createVideoSuiteTestWindow ( const char * title )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_Window * window ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
SDL_Event event ;
2023-03-06 06:44:38 +08:00
int w , h ;
2024-03-04 03:30:57 +08:00
SDL_WindowFlags flags ;
2023-07-23 23:25:15 +08:00
SDL_bool needs_renderer = SDL_FALSE ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
SDL_bool needs_events_pumped = SDL_FALSE ;
2022-12-01 04:51:59 +08:00
/* Standard window */
w = SDLTest_RandomIntegerInRange ( 320 , 1024 ) ;
h = SDLTest_RandomIntegerInRange ( 320 , 768 ) ;
2022-12-29 03:17:55 +08:00
flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS ;
2022-12-01 04:51:59 +08:00
2023-03-06 06:44:38 +08:00
window = SDL_CreateWindow ( title , w , h , flags ) ;
2024-05-10 01:11:44 +08:00
SDLTest_AssertPass ( " Call to SDL_CreateWindow('Title',%d,%d,% " SDL_PRIu64 " ) " , w , h , flags ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( window ! = NULL , " Validate that returned window struct is not NULL " ) ;
2023-07-23 23:25:15 +08:00
/* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen.
* This is required for the mouse / keyboard grab tests to pass .
*/
if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " wayland " ) = = 0 ) {
needs_renderer = SDL_TRUE ;
} else if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " x11 " ) = = 0 ) {
/* Try to detect if the x11 driver is running under XWayland */
const char * session_type = SDL_getenv ( " XDG_SESSION_TYPE " ) ;
if ( session_type & & SDL_strcasecmp ( session_type , " wayland " ) = = 0 ) {
needs_renderer = SDL_TRUE ;
}
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/* X11 needs the initial events pumped, or it can erroneously deliver old configuration events at a later time. */
needs_events_pumped = SDL_TRUE ;
2023-07-23 23:25:15 +08:00
}
if ( needs_renderer ) {
2024-05-14 01:31:55 +08:00
SDL_Renderer * renderer = SDL_CreateRenderer ( window , NULL ) ;
2023-07-23 23:25:15 +08:00
if ( renderer ) {
SDL_SetRenderDrawColor ( renderer , 0x00 , 0x00 , 0x00 , 0xFF ) ;
SDL_RenderClear ( renderer ) ;
SDL_RenderPresent ( renderer ) ;
/* Some desktops don't display the window immediately after presentation,
* so delay to give the window time to actually appear on the desktop .
*/
SDL_Delay ( 100 ) ;
} else {
SDLTest_Log ( " Unable to create a renderer, some tests may fail on Wayland/XWayland " ) ;
}
}
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
if ( needs_events_pumped ) {
/* Pump out the event queue */
while ( SDL_PollEvent ( & event ) ) {
}
}
2022-12-01 04:51:59 +08:00
return window ;
2015-06-21 23:33:46 +08:00
}
2023-02-02 07:21:53 +08:00
/**
2015-06-21 23:33:46 +08:00
* Destroy test window
*/
2022-12-30 05:58:16 +08:00
static void destroyVideoSuiteTestWindow ( SDL_Window * window )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
if ( window ! = NULL ) {
2024-04-20 00:19:10 +08:00
SDL_Renderer * renderer = SDL_GetRenderer ( window ) ;
if ( renderer ) {
SDL_DestroyRenderer ( renderer ) ;
}
2022-12-01 04:51:59 +08:00
SDL_DestroyWindow ( window ) ;
window = NULL ;
SDLTest_AssertPass ( " Call to SDL_DestroyWindow() " ) ;
}
2015-06-21 23:33:46 +08:00
}
/* Test case functions */
/**
2023-11-06 23:26:06 +08:00
* Enable and disable screensaver while checking state
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_enableDisableScreensaver ( void * arg )
2015-06-21 23:33:46 +08:00
{
SDL_bool initialResult ;
SDL_bool result ;
/* Get current state and proceed according to current state */
2022-12-29 11:34:01 +08:00
initialResult = SDL_ScreenSaverEnabled ( ) ;
SDLTest_AssertPass ( " Call to SDL_ScreenSaverEnabled() " ) ;
2015-06-21 23:33:46 +08:00
if ( initialResult = = SDL_TRUE ) {
2022-12-01 04:51:59 +08:00
/* Currently enabled: disable first, then enable again */
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
/* Disable screensaver and check */
SDL_DisableScreenSaver ( ) ;
SDLTest_AssertPass ( " Call to SDL_DisableScreenSaver() " ) ;
2022-12-29 11:34:01 +08:00
result = SDL_ScreenSaverEnabled ( ) ;
SDLTest_AssertPass ( " Call to SDL_ScreenSaverEnabled() " ) ;
SDLTest_AssertCheck ( result = = SDL_FALSE , " Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i " , SDL_FALSE , result ) ;
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
/* Enable screensaver and check */
SDL_EnableScreenSaver ( ) ;
SDLTest_AssertPass ( " Call to SDL_EnableScreenSaver() " ) ;
2022-12-29 11:34:01 +08:00
result = SDL_ScreenSaverEnabled ( ) ;
SDLTest_AssertPass ( " Call to SDL_ScreenSaverEnabled() " ) ;
SDLTest_AssertCheck ( result = = SDL_TRUE , " Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i " , SDL_TRUE , result ) ;
2015-06-21 23:33:46 +08:00
} else {
2022-12-01 04:51:59 +08:00
/* Currently disabled: enable first, then disable again */
/* Enable screensaver and check */
SDL_EnableScreenSaver ( ) ;
SDLTest_AssertPass ( " Call to SDL_EnableScreenSaver() " ) ;
2022-12-29 11:34:01 +08:00
result = SDL_ScreenSaverEnabled ( ) ;
SDLTest_AssertPass ( " Call to SDL_ScreenSaverEnabled() " ) ;
SDLTest_AssertCheck ( result = = SDL_TRUE , " Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i " , SDL_TRUE , result ) ;
2022-12-01 04:51:59 +08:00
/* Disable screensaver and check */
SDL_DisableScreenSaver ( ) ;
SDLTest_AssertPass ( " Call to SDL_DisableScreenSaver() " ) ;
2022-12-29 11:34:01 +08:00
result = SDL_ScreenSaverEnabled ( ) ;
SDLTest_AssertPass ( " Call to SDL_ScreenSaverEnabled() " ) ;
SDLTest_AssertCheck ( result = = SDL_FALSE , " Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i " , SDL_FALSE , result ) ;
2015-06-21 23:33:46 +08:00
}
return TEST_COMPLETED ;
}
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_CreateWindow function using different sizes
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_createWindowVariousSizes ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_Window * window ;
const char * title = " video_createWindowVariousSizes Test Window " ;
2023-03-08 23:12:45 +08:00
int w = 0 , h = 0 ;
2022-12-01 04:51:59 +08:00
int wVariation , hVariation ;
for ( wVariation = 0 ; wVariation < 3 ; wVariation + + ) {
for ( hVariation = 0 ; hVariation < 3 ; hVariation + + ) {
switch ( wVariation ) {
case 0 :
/* Width of 1 */
w = 1 ;
break ;
case 1 :
/* Random "normal" width */
w = SDLTest_RandomIntegerInRange ( 320 , 1920 ) ;
break ;
case 2 :
/* Random "large" width */
w = SDLTest_RandomIntegerInRange ( 2048 , 4095 ) ;
break ;
}
switch ( hVariation ) {
case 0 :
/* Height of 1 */
h = 1 ;
break ;
case 1 :
/* Random "normal" height */
h = SDLTest_RandomIntegerInRange ( 320 , 1080 ) ;
break ;
case 2 :
/* Random "large" height */
h = SDLTest_RandomIntegerInRange ( 2048 , 4095 ) ;
break ;
}
2023-03-06 06:44:38 +08:00
window = SDL_CreateWindow ( title , w , h , 0 ) ;
SDLTest_AssertPass ( " Call to SDL_CreateWindow('Title',%d,%d,SHOWN) " , w , h ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( window ! = NULL , " Validate that returned window struct is not NULL " ) ;
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
}
}
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_CreateWindow function using different flags
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_createWindowVariousFlags ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_Window * window ;
const char * title = " video_createWindowVariousFlags Test Window " ;
2023-03-06 06:44:38 +08:00
int w , h ;
2022-12-01 04:51:59 +08:00
int fVariation ;
2024-03-04 03:30:57 +08:00
SDL_WindowFlags flags ;
2022-12-01 04:51:59 +08:00
/* Standard window */
w = SDLTest_RandomIntegerInRange ( 320 , 1024 ) ;
h = SDLTest_RandomIntegerInRange ( 320 , 768 ) ;
2023-02-02 03:30:28 +08:00
for ( fVariation = 1 ; fVariation < 14 ; fVariation + + ) {
2022-12-01 04:51:59 +08:00
switch ( fVariation ) {
default :
case 1 :
2023-02-02 03:30:28 +08:00
flags = SDL_WINDOW_FULLSCREEN ;
2022-12-01 04:51:59 +08:00
/* Skip - blanks screen; comment out next line to run test */
continue ;
break ;
case 2 :
flags = SDL_WINDOW_OPENGL ;
2023-07-26 02:48:10 +08:00
/* Skip - not every video driver supports OpenGL; comment out next line to run test */
continue ;
2022-12-01 04:51:59 +08:00
break ;
case 3 :
2022-12-29 03:17:55 +08:00
flags = 0 ;
2022-12-01 04:51:59 +08:00
break ;
case 4 :
flags = SDL_WINDOW_HIDDEN ;
break ;
case 5 :
flags = SDL_WINDOW_BORDERLESS ;
break ;
case 6 :
flags = SDL_WINDOW_RESIZABLE ;
break ;
case 7 :
flags = SDL_WINDOW_MINIMIZED ;
break ;
case 8 :
flags = SDL_WINDOW_MAXIMIZED ;
break ;
case 9 :
flags = SDL_WINDOW_MOUSE_GRABBED ;
break ;
case 10 :
flags = SDL_WINDOW_INPUT_FOCUS ;
break ;
case 11 :
flags = SDL_WINDOW_MOUSE_FOCUS ;
break ;
case 12 :
2023-11-14 04:21:23 +08:00
flags = SDL_WINDOW_EXTERNAL ;
2022-12-01 04:51:59 +08:00
break ;
case 13 :
flags = SDL_WINDOW_KEYBOARD_GRABBED ;
break ;
}
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
window = SDL_CreateWindow ( title , w , h , flags ) ;
2024-05-10 01:11:44 +08:00
SDLTest_AssertPass ( " Call to SDL_CreateWindow('Title',%d,%d,% " SDL_PRIu64 " ) " , w , h , flags ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( window ! = NULL , " Validate that returned window struct is not NULL " ) ;
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
}
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_GetWindowFlags function
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getWindowFlags ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_Window * window ;
const char * title = " video_getWindowFlags Test Window " ;
2024-03-04 03:30:57 +08:00
SDL_WindowFlags flags ;
2024-05-10 01:11:44 +08:00
SDL_WindowFlags actualFlags ;
2022-12-01 04:51:59 +08:00
/* Reliable flag set always set in test window */
2022-12-29 03:17:55 +08:00
flags = 0 ;
2022-12-01 04:51:59 +08:00
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2022-12-01 04:51:59 +08:00
if ( window ! = NULL ) {
actualFlags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowFlags() " ) ;
2024-05-10 01:11:44 +08:00
SDLTest_AssertCheck ( ( flags & actualFlags ) = = flags , " Verify returned value has flags % " SDL_PRIu64 " set, got: % " SDL_PRIu64 , flags , actualFlags ) ;
2022-12-01 04:51:59 +08:00
}
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_GetFullscreenDisplayModes function
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getFullscreenDisplayModes ( void * arg )
2015-06-21 23:33:46 +08:00
{
2023-01-30 05:30:55 +08:00
SDL_DisplayID * displays ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
const SDL_DisplayMode * * modes ;
int count ;
2022-12-01 04:51:59 +08:00
int i ;
/* Get number of displays */
2023-01-30 05:30:55 +08:00
displays = SDL_GetDisplays ( NULL ) ;
if ( displays ) {
SDLTest_AssertPass ( " Call to SDL_GetDisplays() " ) ;
/* Make call for each display */
for ( i = 0 ; displays [ i ] ; + + i ) {
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
modes = SDL_GetFullscreenDisplayModes ( displays [ i ] , & count ) ;
SDLTest_AssertPass ( " Call to SDL_GetFullscreenDisplayModes(% " SDL_PRIu32 " ) " , displays [ i ] ) ;
SDLTest_AssertCheck ( modes ! = NULL , " Validate returned value from function; expected != NULL; got: %p " , modes ) ;
SDLTest_AssertCheck ( count > = 0 , " Validate number of modes; expected: >= 0; got: %d " , count ) ;
2023-02-02 01:20:14 +08:00
SDL_free ( ( void * ) modes ) ;
2023-01-30 05:30:55 +08:00
}
SDL_free ( displays ) ;
2022-12-01 04:51:59 +08:00
}
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against current resolution
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getClosestDisplayModeCurrentResolution ( void * arg )
2015-06-21 23:33:46 +08:00
{
2023-01-30 05:30:55 +08:00
SDL_DisplayID * displays ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
const SDL_DisplayMode * * modes ;
2022-12-01 04:51:59 +08:00
SDL_DisplayMode current ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
const SDL_DisplayMode * closest ;
int i , num_modes ;
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
/* Get number of displays */
2023-01-30 05:30:55 +08:00
displays = SDL_GetDisplays ( NULL ) ;
if ( displays ) {
SDLTest_AssertPass ( " Call to SDL_GetDisplays() " ) ;
/* Make calls for each display */
for ( i = 0 ; displays [ i ] ; + + i ) {
2024-01-18 22:25:50 +08:00
SDLTest_Log ( " Testing against display: % " SDL_PRIu32 , displays [ i ] ) ;
2023-01-30 05:30:55 +08:00
/* Get first display mode to get a sane resolution; this should always work */
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
modes = SDL_GetFullscreenDisplayModes ( displays [ i ] , & num_modes ) ;
SDLTest_AssertPass ( " Call to SDL_GetDisplayModes() " ) ;
SDLTest_Assert ( modes ! = NULL , " Verify returned value is not NULL " ) ;
if ( num_modes > 0 ) {
SDL_memcpy ( & current , modes [ 0 ] , sizeof ( current ) ) ;
2023-01-30 05:30:55 +08:00
/* Make call */
2023-05-19 03:15:23 +08:00
closest = SDL_GetClosestFullscreenDisplayMode ( displays [ i ] , current . w , current . h , current . refresh_rate , SDL_FALSE ) ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
SDLTest_AssertPass ( " Call to SDL_GetClosestFullscreenDisplayMode(target=current) " ) ;
SDLTest_Assert ( closest ! = NULL , " Verify returned value is not NULL " ) ;
2023-01-30 05:30:55 +08:00
/* Check that one gets the current resolution back again */
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
if ( closest ) {
2023-05-17 07:29:52 +08:00
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 ) ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
}
2023-01-30 05:30:55 +08:00
}
2023-03-24 16:37:04 +08:00
SDL_free ( ( void * ) modes ) ;
2022-12-01 04:51:59 +08:00
}
2023-01-30 05:30:55 +08:00
SDL_free ( displays ) ;
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against random resolution
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getClosestDisplayModeRandomResolution ( void * arg )
2015-06-21 23:33:46 +08:00
{
2023-01-30 05:30:55 +08:00
SDL_DisplayID * displays ;
2022-12-01 04:51:59 +08:00
SDL_DisplayMode target ;
int i ;
int variation ;
/* Get number of displays */
2023-01-30 05:30:55 +08:00
displays = SDL_GetDisplays ( NULL ) ;
if ( displays ) {
SDLTest_AssertPass ( " Call to SDL_GetDisplays() " ) ;
/* Make calls for each display */
for ( i = 0 ; displays [ i ] ; + + i ) {
2024-01-18 22:25:50 +08:00
SDLTest_Log ( " Testing against display: % " SDL_PRIu32 , displays [ i ] ) ;
2023-01-30 05:30:55 +08:00
for ( variation = 0 ; variation < 16 ; variation + + ) {
/* Set random constraints */
SDL_zero ( target ) ;
2023-05-17 07:29:52 +08:00
target . w = ( variation & 1 ) ? SDLTest_RandomIntegerInRange ( 1 , 4096 ) : 0 ;
target . h = ( variation & 2 ) ? SDLTest_RandomIntegerInRange ( 1 , 4096 ) : 0 ;
2023-01-30 05:30:55 +08:00
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 */
2023-05-19 03:15:23 +08:00
SDL_GetClosestFullscreenDisplayMode ( displays [ i ] , target . w , target . h , target . refresh_rate , SDL_FALSE ) ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
SDLTest_AssertPass ( " Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d) " , variation ) ;
2023-01-30 05:30:55 +08:00
}
2022-12-01 04:51:59 +08:00
}
2023-01-30 05:30:55 +08:00
SDL_free ( displays ) ;
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowFullscreenMode
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_GetWindowFullscreenMode
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getWindowDisplayMode ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_Window * window ;
const char * title = " video_getWindowDisplayMode Test Window " ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
const SDL_DisplayMode * mode ;
2022-12-01 04:51:59 +08:00
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2022-12-01 04:51:59 +08:00
if ( window ! = NULL ) {
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
mode = SDL_GetWindowFullscreenMode ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowFullscreenMode() " ) ;
SDLTest_AssertCheck ( mode = = NULL , " Validate result value; expected: NULL, got: %p " , mode ) ;
2022-12-01 04:51:59 +08:00
}
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/* Helper function that checks for an 'Invalid window' error */
2023-03-08 23:12:45 +08:00
static void checkInvalidWindowError ( void )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * invalidWindowError = " Invalid window " ;
2023-03-09 04:18:02 +08:00
const char * lastError ;
2022-12-01 04:51:59 +08:00
2023-03-09 04:18:02 +08:00
lastError = SDL_GetError ( ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " SDL_GetError() " ) ;
SDLTest_AssertCheck ( lastError ! = NULL , " Verify error message is not NULL " ) ;
if ( lastError ! = NULL ) {
SDLTest_AssertCheck ( SDL_strcmp ( lastError , invalidWindowError ) = = 0 ,
" SDL_GetError(): expected message '%s', was message: '%s' " ,
invalidWindowError ,
lastError ) ;
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
}
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowFullscreenMode with invalid input
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_GetWindowFullscreenMode
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getWindowDisplayModeNegative ( void * arg )
2015-06-21 23:33:46 +08:00
{
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
const SDL_DisplayMode * mode ;
2022-12-01 04:51:59 +08:00
/* Call against invalid window */
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
mode = SDL_GetWindowFullscreenMode ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowFullscreenMode(window=NULL) " ) ;
SDLTest_AssertCheck ( mode = = NULL , " Validate result value; expected: NULL, got: %p " , mode ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
2021-01-27 09:16:17 +08:00
/* Helper for setting and checking the window mouse grab state */
2022-12-30 05:58:16 +08:00
static void setAndCheckWindowMouseGrabState ( SDL_Window * window , SDL_bool desiredState )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_bool currentState ;
/* Set state */
SDL_SetWindowMouseGrab ( window , desiredState ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMouseGrab(%s) " , ( desiredState = = SDL_FALSE ) ? " SDL_FALSE " : " SDL_TRUE " ) ;
/* Get and check state */
currentState = SDL_GetWindowMouseGrab ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMouseGrab() " ) ;
2021-01-27 09:16:17 +08:00
SDLTest_AssertCheck (
2022-12-01 04:51:59 +08:00
currentState = = desiredState ,
" Validate returned state; expected: %s, got: %s " ,
( desiredState = = SDL_FALSE ) ? " SDL_FALSE " : " SDL_TRUE " ,
( currentState = = SDL_FALSE ) ? " SDL_FALSE " : " SDL_TRUE " ) ;
if ( desiredState ) {
SDLTest_AssertCheck (
SDL_GetGrabbedWindow ( ) = = window ,
" Grabbed window should be to our window " ) ;
SDLTest_AssertCheck (
SDL_GetWindowFlags ( window ) & SDL_WINDOW_MOUSE_GRABBED ,
" SDL_WINDOW_MOUSE_GRABBED should be set " ) ;
} else {
SDLTest_AssertCheck (
! ( SDL_GetWindowFlags ( window ) & SDL_WINDOW_MOUSE_GRABBED ) ,
" SDL_WINDOW_MOUSE_GRABBED should be unset " ) ;
}
2021-01-27 09:16:17 +08:00
}
/* Helper for setting and checking the window keyboard grab state */
2022-12-30 05:58:16 +08:00
static void setAndCheckWindowKeyboardGrabState ( SDL_Window * window , SDL_bool desiredState )
2021-01-27 09:16:17 +08:00
{
2022-12-01 04:51:59 +08:00
SDL_bool currentState ;
/* Set state */
SDL_SetWindowKeyboardGrab ( window , desiredState ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowKeyboardGrab(%s) " , ( desiredState = = SDL_FALSE ) ? " SDL_FALSE " : " SDL_TRUE " ) ;
/* Get and check state */
currentState = SDL_GetWindowKeyboardGrab ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowKeyboardGrab() " ) ;
2021-01-27 09:16:17 +08:00
SDLTest_AssertCheck (
2022-12-01 04:51:59 +08:00
currentState = = desiredState ,
" Validate returned state; expected: %s, got: %s " ,
( desiredState = = SDL_FALSE ) ? " SDL_FALSE " : " SDL_TRUE " ,
( currentState = = SDL_FALSE ) ? " SDL_FALSE " : " SDL_TRUE " ) ;
if ( desiredState ) {
SDLTest_AssertCheck (
SDL_GetGrabbedWindow ( ) = = window ,
" Grabbed window should be set to our window " ) ;
SDLTest_AssertCheck (
SDL_GetWindowFlags ( window ) & SDL_WINDOW_KEYBOARD_GRABBED ,
" SDL_WINDOW_KEYBOARD_GRABBED should be set " ) ;
} else {
SDLTest_AssertCheck (
! ( SDL_GetWindowFlags ( window ) & SDL_WINDOW_KEYBOARD_GRABBED ) ,
" SDL_WINDOW_KEYBOARD_GRABBED should be unset " ) ;
}
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests keyboard and mouse grab support
2015-06-21 23:33:46 +08:00
*
2024-03-25 07:35:40 +08:00
* \ sa SDL_GetWindowMouseGrab
* \ sa SDL_GetWindowKeyboardGrab
* \ sa SDL_SetWindowMouseGrab
* \ sa SDL_SetWindowKeyboardGrab
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getSetWindowGrab ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getSetWindowGrab Test Window " ;
SDL_Window * window ;
SDL_bool originalMouseState , originalKeyboardState ;
2023-03-20 19:34:36 +08:00
SDL_bool hasFocusGained = SDL_FALSE ;
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
}
2023-03-20 19:34:36 +08:00
/* Need to raise the window to have and SDL_EVENT_WINDOW_FOCUS_GAINED,
* so that the window gets the flags SDL_WINDOW_INPUT_FOCUS ,
* so that it can be " grabbed " */
SDL_RaiseWindow ( window ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
if ( ! ( SDL_GetWindowFlags ( window ) & SDL_WINDOW_INPUT_FOCUS ) ) {
int count = 0 ;
2023-03-20 19:34:36 +08:00
SDL_Event evt ;
SDL_zero ( evt ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
while ( ! hasFocusGained & & count + + < 3 ) {
while ( SDL_PollEvent ( & evt ) ) {
if ( evt . type = = SDL_EVENT_WINDOW_FOCUS_GAINED ) {
hasFocusGained = SDL_TRUE ;
}
2023-03-20 19:34:36 +08:00
}
}
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
} else {
hasFocusGained = SDL_TRUE ;
2023-03-20 19:34:36 +08:00
}
SDLTest_AssertCheck ( hasFocusGained = = SDL_TRUE , " Expectded window with focus " ) ;
2022-12-01 04:51:59 +08:00
/* Get state */
originalMouseState = SDL_GetWindowMouseGrab ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMouseGrab() " ) ;
originalKeyboardState = SDL_GetWindowKeyboardGrab ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowKeyboardGrab() " ) ;
/* F */
2022-12-30 05:58:16 +08:00
setAndCheckWindowKeyboardGrabState ( window , SDL_FALSE ) ;
setAndCheckWindowMouseGrabState ( window , SDL_FALSE ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( SDL_GetGrabbedWindow ( ) = = NULL ,
" Expected NULL grabbed window " ) ;
/* F --> F */
2022-12-30 05:58:16 +08:00
setAndCheckWindowMouseGrabState ( window , SDL_FALSE ) ;
setAndCheckWindowKeyboardGrabState ( window , SDL_FALSE ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( SDL_GetGrabbedWindow ( ) = = NULL ,
" Expected NULL grabbed window " ) ;
/* F --> T */
2022-12-30 05:58:16 +08:00
setAndCheckWindowMouseGrabState ( window , SDL_TRUE ) ;
setAndCheckWindowKeyboardGrabState ( window , SDL_TRUE ) ;
2022-12-01 04:51:59 +08:00
/* T --> T */
2022-12-30 05:58:16 +08:00
setAndCheckWindowKeyboardGrabState ( window , SDL_TRUE ) ;
setAndCheckWindowMouseGrabState ( window , SDL_TRUE ) ;
2022-12-01 04:51:59 +08:00
/* M: T --> F */
/* K: T --> T */
2022-12-30 05:58:16 +08:00
setAndCheckWindowKeyboardGrabState ( window , SDL_TRUE ) ;
setAndCheckWindowMouseGrabState ( window , SDL_FALSE ) ;
2022-12-01 04:51:59 +08:00
/* M: F --> T */
/* K: T --> F */
2022-12-30 05:58:16 +08:00
setAndCheckWindowMouseGrabState ( window , SDL_TRUE ) ;
setAndCheckWindowKeyboardGrabState ( window , SDL_FALSE ) ;
2022-12-01 04:51:59 +08:00
/* M: T --> F */
/* K: F --> F */
2022-12-30 05:58:16 +08:00
setAndCheckWindowMouseGrabState ( window , SDL_FALSE ) ;
setAndCheckWindowKeyboardGrabState ( window , SDL_FALSE ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( SDL_GetGrabbedWindow ( ) = = NULL ,
" Expected NULL grabbed window " ) ;
/* Negative tests */
2024-03-25 07:35:40 +08:00
SDL_GetWindowMouseGrab ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMouseGrab(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_GetWindowKeyboardGrab ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowKeyboardGrab(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
2024-03-25 07:35:40 +08:00
SDL_SetWindowMouseGrab ( NULL , SDL_FALSE ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMouseGrab(window=NULL,SDL_FALSE) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_SetWindowKeyboardGrab ( NULL , SDL_FALSE ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
2024-03-25 07:35:40 +08:00
SDL_SetWindowMouseGrab ( NULL , SDL_TRUE ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMouseGrab(window=NULL,SDL_TRUE) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_SetWindowKeyboardGrab ( NULL , SDL_TRUE ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
/* Restore state */
2022-12-30 05:58:16 +08:00
setAndCheckWindowMouseGrabState ( window , originalMouseState ) ;
setAndCheckWindowKeyboardGrabState ( window , originalKeyboardState ) ;
2022-12-01 04:51:59 +08:00
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
}
2015-06-21 23:33:46 +08:00
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowID and SDL_GetWindowFromID
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_GetWindowID
* \ sa SDL_SetWindowFromID
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getWindowId ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getWindowId Test Window " ;
SDL_Window * window ;
SDL_Window * result ;
Uint32 id , randomId ;
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
}
/* Get ID */
id = SDL_GetWindowID ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID() " ) ;
/* Get window from ID */
result = SDL_GetWindowFromID ( id ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID(% " SDL_PRIu32 " ) " , id ) ;
SDLTest_AssertCheck ( result = = window , " Verify result matches window pointer " ) ;
/* Get window from random large ID, no result check */
randomId = SDLTest_RandomIntegerInRange ( UINT8_MAX , UINT16_MAX ) ;
result = SDL_GetWindowFromID ( randomId ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID(% " SDL_PRIu32 " /random_large) " , randomId ) ;
/* Get window from 0 and Uint32 max ID, no result check */
result = SDL_GetWindowFromID ( 0 ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID(0) " ) ;
result = SDL_GetWindowFromID ( UINT32_MAX ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID(UINT32_MAX) " ) ;
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
/* Get window from ID for closed window */
result = SDL_GetWindowFromID ( id ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID(% " SDL_PRIu32 " /closed_window) " , id ) ;
SDLTest_AssertCheck ( result = = NULL , " Verify result is NULL " ) ;
/* Negative test */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
id = SDL_GetWindowID ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowID(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowPixelFormat
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_GetWindowPixelFormat
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getWindowPixelFormat ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getWindowPixelFormat Test Window " ;
SDL_Window * window ;
Uint32 format ;
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
}
/* Get format */
format = SDL_GetWindowPixelFormat ( window ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPixelFormat() " ) ;
SDLTest_AssertCheck ( format ! = SDL_PIXELFORMAT_UNKNOWN , " Verify that returned format is valid; expected: != %d, got: % " SDL_PRIu32 , SDL_PIXELFORMAT_UNKNOWN , format ) ;
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
/* Negative test */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
format = SDL_GetWindowPixelFormat ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPixelFormat(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
2023-03-20 18:25:10 +08:00
static SDL_bool getPositionFromEvent ( int * x , int * y )
{
SDL_bool ret = SDL_FALSE ;
SDL_Event evt ;
SDL_zero ( evt ) ;
while ( SDL_PollEvent ( & evt ) ) {
if ( evt . type = = SDL_EVENT_WINDOW_MOVED ) {
* x = evt . window . data1 ;
* y = evt . window . data2 ;
ret = SDL_TRUE ;
}
}
return ret ;
}
static SDL_bool getSizeFromEvent ( int * w , int * h )
{
SDL_bool ret = SDL_FALSE ;
SDL_Event evt ;
SDL_zero ( evt ) ;
while ( SDL_PollEvent ( & evt ) ) {
if ( evt . type = = SDL_EVENT_WINDOW_RESIZED ) {
* w = evt . window . data1 ;
* h = evt . window . data2 ;
ret = SDL_TRUE ;
}
}
return ret ;
}
2015-06-21 23:33:46 +08:00
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_GetWindowPosition
* \ sa SDL_SetWindowPosition
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getSetWindowPosition ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getSetWindowPosition Test Window " ;
SDL_Window * window ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
int result ;
int maxxVariation , maxyVariation ;
2022-12-01 04:51:59 +08:00
int xVariation , yVariation ;
int referenceX , referenceY ;
int currentX , currentY ;
int desiredX , desiredY ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
SDL_Rect display_bounds ;
2022-12-01 04:51:59 +08:00
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
2015-06-21 23:33:46 +08:00
}
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/* Sanity check */
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
if ( SDL_SetWindowPosition ( window , currentX , currentY ) < 0 ) {
SDLTest_Log ( " Skipping window positioning tests: %s reports window positioning as unsupported " , SDL_GetCurrentVideoDriver ( ) ) ;
goto null_tests ;
}
if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " x11 " ) = = 0 ) {
/* The X11 server allows arbitrary window placement, but compositing
* window managers such as GNOME and KDE force windows to be within
* desktop bounds .
*/
maxxVariation = 2 ;
maxyVariation = 2 ;
SDL_GetDisplayUsableBounds ( SDL_GetPrimaryDisplay ( ) , & display_bounds ) ;
} else if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " cocoa " ) = = 0 ) {
/* Platform doesn't allow windows with negative Y desktop bounds */
maxxVariation = 4 ;
maxyVariation = 3 ;
SDL_GetDisplayUsableBounds ( SDL_GetPrimaryDisplay ( ) , & display_bounds ) ;
} else {
/* Platform allows windows to be placed out of bounds */
maxxVariation = 4 ;
maxyVariation = 4 ;
SDL_GetDisplayBounds ( SDL_GetPrimaryDisplay ( ) , & display_bounds ) ;
}
for ( xVariation = 0 ; xVariation < maxxVariation ; xVariation + + ) {
for ( yVariation = 0 ; yVariation < maxyVariation ; yVariation + + ) {
2022-12-01 04:51:59 +08:00
switch ( xVariation ) {
default :
case 0 :
/* Zero X Position */
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
desiredX = display_bounds . x > 0 ? display_bounds . x : 0 ;
2022-12-01 04:51:59 +08:00
break ;
case 1 :
/* Random X position inside screen */
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
desiredX = SDLTest_RandomIntegerInRange ( display_bounds . x + 1 , display_bounds . x + 100 ) ;
2022-12-01 04:51:59 +08:00
break ;
case 2 :
/* Random X position outside screen (positive) */
desiredX = SDLTest_RandomIntegerInRange ( 10000 , 11000 ) ;
break ;
case 3 :
/* Random X position outside screen (negative) */
desiredX = SDLTest_RandomIntegerInRange ( - 1000 , - 100 ) ;
break ;
}
switch ( yVariation ) {
default :
case 0 :
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/* Zero Y Position */
desiredY = display_bounds . y > 0 ? display_bounds . y : 0 ;
2022-12-01 04:51:59 +08:00
break ;
case 1 :
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/* Random Y position inside screen */
desiredY = SDLTest_RandomIntegerInRange ( display_bounds . y + 1 , display_bounds . y + 100 ) ;
2022-12-01 04:51:59 +08:00
break ;
case 2 :
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/* Random Y position outside screen (positive) */
2022-12-01 04:51:59 +08:00
desiredY = SDLTest_RandomIntegerInRange ( 10000 , 11000 ) ;
break ;
case 3 :
/* Random Y position outside screen (negative) */
desiredY = SDLTest_RandomIntegerInRange ( - 1000 , - 100 ) ;
break ;
}
/* Set position */
SDL_SetWindowPosition ( window , desiredX , desiredY ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowPosition(...,%d,%d) " , desiredX , desiredY ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
2022-12-01 04:51:59 +08:00
/* Get position */
currentX = desiredX + 1 ;
currentY = desiredY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
2023-03-20 18:25:10 +08:00
if ( desiredX = = currentX & & desiredY = = currentY ) {
SDLTest_AssertCheck ( desiredX = = currentX , " Verify returned X position; expected: %d, got: %d " , desiredX , currentX ) ;
SDLTest_AssertCheck ( desiredY = = currentY , " Verify returned Y position; expected: %d, got: %d " , desiredY , currentY ) ;
} else {
SDL_bool hasEvent ;
/* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
* and then we get events signaling what actually happened , and they get passed on to the application if they ' re not what we expect . */
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
currentX = desiredX + 1 ;
currentY = desiredY + 1 ;
hasEvent = getPositionFromEvent ( & currentX , & currentY ) ;
2023-03-20 18:25:10 +08:00
SDLTest_AssertCheck ( hasEvent = = SDL_TRUE , " Changing position was not honored by WM, checking present of SDL_EVENT_WINDOW_MOVED " ) ;
if ( hasEvent ) {
SDLTest_AssertCheck ( desiredX = = currentX , " Verify returned X position is the position from SDL event; expected: %d, got: %d " , desiredX , currentX ) ;
SDLTest_AssertCheck ( desiredY = = currentY , " Verify returned Y position is the position from SDL event; expected: %d, got: %d " , desiredY , currentY ) ;
}
}
2022-12-01 04:51:59 +08:00
/* Get position X */
currentX = desiredX + 1 ;
SDL_GetWindowPosition ( window , & currentX , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition(&y=NULL) " ) ;
SDLTest_AssertCheck ( desiredX = = currentX , " Verify returned X position; expected: %d, got: %d " , desiredX , currentX ) ;
/* Get position Y */
currentY = desiredY + 1 ;
SDL_GetWindowPosition ( window , NULL , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition(&x=NULL) " ) ;
SDLTest_AssertCheck ( desiredY = = currentY , " Verify returned Y position; expected: %d, got: %d " , desiredY , currentY ) ;
}
2015-06-21 23:33:46 +08:00
}
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
null_tests :
2022-12-01 04:51:59 +08:00
/* Dummy call with both pointers NULL */
SDL_GetWindowPosition ( window , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition(&x=NULL,&y=NULL) " ) ;
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
/* Set some 'magic' value for later check that nothing was changed */
referenceX = SDLTest_RandomSint32 ( ) ;
referenceY = SDLTest_RandomSint32 ( ) ;
currentX = referenceX ;
currentY = referenceY ;
desiredX = SDLTest_RandomSint32 ( ) ;
desiredY = SDLTest_RandomSint32 ( ) ;
/* Negative tests */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
SDL_GetWindowPosition ( NULL , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition(window=NULL) " ) ;
SDLTest_AssertCheck (
currentX = = referenceX & & currentY = = referenceY ,
" Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d " ,
referenceX , referenceY ,
currentX , currentY ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_GetWindowPosition ( NULL , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition(NULL, NULL, NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_SetWindowPosition ( NULL , desiredX , desiredY ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowPosition(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/* Helper function that checks for an 'Invalid parameter' error */
2023-03-08 23:12:45 +08:00
static void checkInvalidParameterError ( void )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * invalidParameterError = " Parameter " ;
2023-03-09 04:18:02 +08:00
const char * lastError ;
2022-12-01 04:51:59 +08:00
2023-03-09 04:18:02 +08:00
lastError = SDL_GetError ( ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " SDL_GetError() " ) ;
SDLTest_AssertCheck ( lastError ! = NULL , " Verify error message is not NULL " ) ;
if ( lastError ! = NULL ) {
SDLTest_AssertCheck ( SDL_strncmp ( lastError , invalidParameterError , SDL_strlen ( invalidParameterError ) ) = = 0 ,
" SDL_GetError(): expected message starts with '%s', was message: '%s' " ,
invalidParameterError ,
lastError ) ;
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
}
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowSize and SDL_SetWindowSize
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_GetWindowSize
* \ sa SDL_SetWindowSize
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getSetWindowSize ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getSetWindowSize Test Window " ;
SDL_Window * window ;
int result ;
SDL_Rect display ;
int maxwVariation , maxhVariation ;
int wVariation , hVariation ;
int referenceW , referenceH ;
int currentW , currentH ;
int desiredW , desiredH ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
const SDL_bool restoreHint = SDL_GetHintBoolean ( " SDL_BORDERLESS_RESIZABLE_STYLE " , SDL_TRUE ) ;
/* Win32 borderless windows are not resizable by default and need this undocumented hint */
SDL_SetHint ( " SDL_BORDERLESS_RESIZABLE_STYLE " , " 1 " ) ;
2022-12-01 04:51:59 +08:00
/* Get display bounds for size range */
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
result = SDL_GetDisplayUsableBounds ( SDL_GetPrimaryDisplay ( ) , & display ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " SDL_GetDisplayBounds() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( result ! = 0 ) {
return TEST_ABORTED ;
}
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
}
2015-06-21 23:33:46 +08:00
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
if ( SDL_SetWindowSize ( window , currentW , currentH ) ) {
SDLTest_Log ( " Skipping window resize tests: %s reports window resizing as unsupported " , SDL_GetCurrentVideoDriver ( ) ) ;
goto null_tests ;
}
if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " windows " ) = = 0 | |
SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " x11 " ) = = 0 ) {
/* Platform clips window size to screen size */
maxwVariation = 4 ;
maxhVariation = 4 ;
} else {
/* Platform allows window size >= screen size */
maxwVariation = 5 ;
maxhVariation = 5 ;
}
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
for ( wVariation = 0 ; wVariation < maxwVariation ; wVariation + + ) {
for ( hVariation = 0 ; hVariation < maxhVariation ; hVariation + + ) {
switch ( wVariation ) {
default :
case 0 :
/* 1 Pixel Wide */
desiredW = 1 ;
break ;
case 1 :
/* Random width inside screen */
desiredW = SDLTest_RandomIntegerInRange ( 1 , 100 ) ;
break ;
case 2 :
/* Width 1 pixel smaller than screen */
desiredW = display . w - 1 ;
break ;
case 3 :
/* Width at screen size */
desiredW = display . w ;
break ;
case 4 :
/* Width 1 pixel larger than screen */
desiredW = display . w + 1 ;
break ;
}
switch ( hVariation ) {
default :
case 0 :
/* 1 Pixel High */
desiredH = 1 ;
break ;
case 1 :
/* Random height inside screen */
desiredH = SDLTest_RandomIntegerInRange ( 1 , 100 ) ;
break ;
case 2 :
/* Height 1 pixel smaller than screen */
desiredH = display . h - 1 ;
break ;
case 3 :
/* Height at screen size */
desiredH = display . h ;
break ;
case 4 :
/* Height 1 pixel larger than screen */
desiredH = display . h + 1 ;
break ;
}
/* Set size */
SDL_SetWindowSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowSize(...,%d,%d) " , desiredW , desiredH ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
2023-12-09 01:37:10 +08:00
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
2022-12-01 04:51:59 +08:00
/* Get size */
currentW = desiredW + 1 ;
currentH = desiredH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
2023-03-20 18:25:10 +08:00
if ( desiredW = = currentW & & desiredH = = currentH ) {
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
} else {
SDL_bool hasEvent ;
/* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
* and then we get events signaling what actually happened , and they get passed on to the application if they ' re not what we expect . */
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
currentW = desiredW + 1 ;
currentH = desiredH + 1 ;
hasEvent = getSizeFromEvent ( & currentW , & currentH ) ;
2023-03-20 18:25:10 +08:00
SDLTest_AssertCheck ( hasEvent = = SDL_TRUE , " Changing size was not honored by WM, checking presence of SDL_EVENT_WINDOW_RESIZED " ) ;
if ( hasEvent ) {
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width is the one from SDL event; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height is the one from SDL event; expected: %d, got: %d " , desiredH , currentH ) ;
}
}
2022-12-01 04:51:59 +08:00
/* Get just width */
currentW = desiredW + 1 ;
SDL_GetWindowSize ( window , & currentW , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize(&h=NULL) " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
/* Get just height */
currentH = desiredH + 1 ;
SDL_GetWindowSize ( window , NULL , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize(&w=NULL) " ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
}
2015-06-21 23:33:46 +08:00
}
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
null_tests :
2022-12-01 04:51:59 +08:00
/* Dummy call with both pointers NULL */
SDL_GetWindowSize ( window , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize(&w=NULL,&h=NULL) " ) ;
/* Negative tests for parameter input */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
for ( desiredH = - 2 ; desiredH < 2 ; desiredH + + ) {
for ( desiredW = - 2 ; desiredW < 2 ; desiredW + + ) {
if ( desiredW < = 0 | | desiredH < = 0 ) {
SDL_SetWindowSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowSize(...,%d,%d) " , desiredW , desiredH ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
}
}
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
/* Set some 'magic' value for later check that nothing was changed */
referenceW = SDLTest_RandomSint32 ( ) ;
referenceH = SDLTest_RandomSint32 ( ) ;
currentW = referenceW ;
currentH = referenceH ;
desiredW = SDLTest_RandomSint32 ( ) ;
desiredH = SDLTest_RandomSint32 ( ) ;
/* Negative tests for window input */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
SDL_GetWindowSize ( NULL , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize(window=NULL) " ) ;
SDLTest_AssertCheck (
currentW = = referenceW & & currentH = = referenceH ,
" Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d " ,
referenceW , referenceH ,
currentW , currentH ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_GetWindowSize ( NULL , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize(NULL, NULL, NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_SetWindowSize ( NULL , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowSize(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/* Restore the hint to the previous value */
SDL_SetHint ( " SDL_BORDERLESS_RESIZABLE_STYLE " , restoreHint ? " 1 " : " 0 " ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
2015-06-21 23:33:46 +08:00
*
*/
2023-03-08 23:12:45 +08:00
static int video_getSetWindowMinimumSize ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getSetWindowMinimumSize Test Window " ;
SDL_Window * window ;
int result ;
SDL_Rect display ;
int wVariation , hVariation ;
int referenceW , referenceH ;
int currentW , currentH ;
int desiredW = 1 ;
int desiredH = 1 ;
/* Get display bounds for size range */
2023-01-30 05:30:55 +08:00
result = SDL_GetDisplayBounds ( SDL_GetPrimaryDisplay ( ) , & display ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " SDL_GetDisplayBounds() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( result ! = 0 ) {
return TEST_ABORTED ;
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
}
for ( wVariation = 0 ; wVariation < 5 ; wVariation + + ) {
for ( hVariation = 0 ; hVariation < 5 ; hVariation + + ) {
switch ( wVariation ) {
case 0 :
/* 1 Pixel Wide */
desiredW = 1 ;
break ;
case 1 :
/* Random width inside screen */
desiredW = SDLTest_RandomIntegerInRange ( 2 , display . w - 1 ) ;
break ;
case 2 :
/* Width at screen size */
desiredW = display . w ;
break ;
}
switch ( hVariation ) {
case 0 :
/* 1 Pixel High */
desiredH = 1 ;
break ;
case 1 :
/* Random height inside screen */
desiredH = SDLTest_RandomIntegerInRange ( 2 , display . h - 1 ) ;
break ;
case 2 :
/* Height at screen size */
desiredH = display . h ;
break ;
case 4 :
/* Height 1 pixel larger than screen */
desiredH = display . h + 1 ;
break ;
}
/* Set size */
SDL_SetWindowMinimumSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMinimumSize(...,%d,%d) " , desiredW , desiredH ) ;
/* Get size */
currentW = desiredW + 1 ;
currentH = desiredH + 1 ;
SDL_GetWindowMinimumSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMinimumSize() " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
/* Get just width */
currentW = desiredW + 1 ;
SDL_GetWindowMinimumSize ( window , & currentW , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMinimumSize(&h=NULL) " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentH ) ;
/* Get just height */
currentH = desiredH + 1 ;
SDL_GetWindowMinimumSize ( window , NULL , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMinimumSize(&w=NULL) " ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredW , currentH ) ;
}
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
/* Dummy call with both pointers NULL */
SDL_GetWindowMinimumSize ( window , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL) " ) ;
/* Negative tests for parameter input */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
for ( desiredH = - 2 ; desiredH < 2 ; desiredH + + ) {
for ( desiredW = - 2 ; desiredW < 2 ; desiredW + + ) {
2023-03-16 07:13:56 +08:00
if ( desiredW < 0 | | desiredH < 0 ) {
2022-12-01 04:51:59 +08:00
SDL_SetWindowMinimumSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMinimumSize(...,%d,%d) " , desiredW , desiredH ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
}
}
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
/* Set some 'magic' value for later check that nothing was changed */
referenceW = SDLTest_RandomSint32 ( ) ;
referenceH = SDLTest_RandomSint32 ( ) ;
currentW = referenceW ;
currentH = referenceH ;
desiredW = SDLTest_RandomSint32 ( ) ;
desiredH = SDLTest_RandomSint32 ( ) ;
/* Negative tests for window input */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
SDL_GetWindowMinimumSize ( NULL , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMinimumSize(window=NULL) " ) ;
SDLTest_AssertCheck (
currentW = = referenceW & & currentH = = referenceH ,
" Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d " ,
referenceW , referenceH ,
currentW , currentH ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_GetWindowMinimumSize ( NULL , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_SetWindowMinimumSize ( NULL , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMinimumSize(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
2015-06-21 23:33:46 +08:00
}
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
2015-06-21 23:33:46 +08:00
*
*/
2023-03-08 23:12:45 +08:00
static int video_getSetWindowMaximumSize ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
const char * title = " video_getSetWindowMaximumSize Test Window " ;
SDL_Window * window ;
int result ;
SDL_Rect display ;
int wVariation , hVariation ;
int referenceW , referenceH ;
int currentW , currentH ;
2023-03-08 23:12:45 +08:00
int desiredW = 0 , desiredH = 0 ;
2022-12-01 04:51:59 +08:00
/* Get display bounds for size range */
2023-01-30 05:30:55 +08:00
result = SDL_GetDisplayBounds ( SDL_GetPrimaryDisplay ( ) , & display ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " SDL_GetDisplayBounds() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( result ! = 0 ) {
return TEST_ABORTED ;
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
for ( wVariation = 0 ; wVariation < 3 ; wVariation + + ) {
for ( hVariation = 0 ; hVariation < 3 ; hVariation + + ) {
switch ( wVariation ) {
case 0 :
/* 1 Pixel Wide */
desiredW = 1 ;
break ;
case 1 :
/* Random width inside screen */
desiredW = SDLTest_RandomIntegerInRange ( 2 , display . w - 1 ) ;
break ;
case 2 :
/* Width at screen size */
desiredW = display . w ;
break ;
}
switch ( hVariation ) {
case 0 :
/* 1 Pixel High */
desiredH = 1 ;
break ;
case 1 :
/* Random height inside screen */
desiredH = SDLTest_RandomIntegerInRange ( 2 , display . h - 1 ) ;
break ;
case 2 :
/* Height at screen size */
desiredH = display . h ;
break ;
}
/* Set size */
SDL_SetWindowMaximumSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMaximumSize(...,%d,%d) " , desiredW , desiredH ) ;
/* Get size */
currentW = desiredW + 1 ;
currentH = desiredH + 1 ;
SDL_GetWindowMaximumSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMaximumSize() " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
/* Get just width */
currentW = desiredW + 1 ;
SDL_GetWindowMaximumSize ( window , & currentW , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMaximumSize(&h=NULL) " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentH ) ;
/* Get just height */
currentH = desiredH + 1 ;
SDL_GetWindowMaximumSize ( window , NULL , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMaximumSize(&w=NULL) " ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredW , currentH ) ;
}
}
/* Dummy call with both pointers NULL */
SDL_GetWindowMaximumSize ( window , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL) " ) ;
/* Negative tests for parameter input */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
for ( desiredH = - 2 ; desiredH < 2 ; desiredH + + ) {
for ( desiredW = - 2 ; desiredW < 2 ; desiredW + + ) {
2023-03-16 07:13:56 +08:00
if ( desiredW < 0 | | desiredH < 0 ) {
2022-12-01 04:51:59 +08:00
SDL_SetWindowMaximumSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMaximumSize(...,%d,%d) " , desiredW , desiredH ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
}
}
2015-06-21 23:33:46 +08:00
}
2022-12-01 04:51:59 +08:00
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
/* Set some 'magic' value for later check that nothing was changed */
referenceW = SDLTest_RandomSint32 ( ) ;
referenceH = SDLTest_RandomSint32 ( ) ;
currentW = referenceW ;
currentH = referenceH ;
desiredW = SDLTest_RandomSint32 ( ) ;
desiredH = SDLTest_RandomSint32 ( ) ;
/* Negative tests */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
SDL_GetWindowMaximumSize ( NULL , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMaximumSize(window=NULL) " ) ;
SDLTest_AssertCheck (
currentW = = referenceW & & currentH = = referenceH ,
" Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d " ,
referenceW , referenceH ,
currentW , currentH ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_GetWindowMaximumSize ( NULL , NULL , NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
SDL_SetWindowMaximumSize ( NULL , desiredW , desiredH ) ;
SDLTest_AssertPass ( " Call to SDL_SetWindowMaximumSize(window=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidWindowError ( ) ;
2022-12-01 04:51:59 +08:00
return TEST_COMPLETED ;
}
2015-06-21 23:33:46 +08:00
/**
2023-11-06 23:26:06 +08:00
* Tests call to SDL_SetWindowData and SDL_GetWindowData
2015-06-21 23:33:46 +08:00
*
2023-02-02 07:21:53 +08:00
* \ sa SDL_SetWindowData
* \ sa SDL_GetWindowData
2015-06-21 23:33:46 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_getSetWindowData ( void * arg )
2015-06-21 23:33:46 +08:00
{
2022-12-01 04:51:59 +08:00
int returnValue = TEST_COMPLETED ;
const char * title = " video_setGetWindowData Test Window " ;
SDL_Window * window ;
const char * referenceName = " TestName " ;
const char * name = " TestName " ;
const char * referenceName2 = " TestName2 " ;
const char * name2 = " TestName2 " ;
int datasize ;
char * referenceUserdata = NULL ;
char * userdata = NULL ;
char * referenceUserdata2 = NULL ;
char * userdata2 = NULL ;
char * result ;
int iteration ;
/* Call against new test window */
2022-12-30 05:58:16 +08:00
window = createVideoSuiteTestWindow ( title ) ;
2023-11-10 05:29:15 +08:00
if ( ! window ) {
2022-12-01 04:51:59 +08:00
return TEST_ABORTED ;
}
/* Create testdata */
datasize = SDLTest_RandomIntegerInRange ( 1 , 32 ) ;
referenceUserdata = SDLTest_RandomAsciiStringOfSize ( datasize ) ;
2023-11-10 05:29:15 +08:00
if ( ! referenceUserdata ) {
2022-12-01 04:51:59 +08:00
returnValue = TEST_ABORTED ;
goto cleanup ;
}
userdata = SDL_strdup ( referenceUserdata ) ;
2023-11-10 05:29:15 +08:00
if ( ! userdata ) {
2022-12-01 04:51:59 +08:00
returnValue = TEST_ABORTED ;
goto cleanup ;
}
datasize = SDLTest_RandomIntegerInRange ( 1 , 32 ) ;
referenceUserdata2 = SDLTest_RandomAsciiStringOfSize ( datasize ) ;
2023-11-10 05:29:15 +08:00
if ( ! referenceUserdata2 ) {
2022-12-01 04:51:59 +08:00
returnValue = TEST_ABORTED ;
goto cleanup ;
}
2022-12-02 05:07:03 +08:00
userdata2 = SDL_strdup ( referenceUserdata2 ) ;
2023-11-10 05:29:15 +08:00
if ( ! userdata2 ) {
2022-12-01 04:51:59 +08:00
returnValue = TEST_ABORTED ;
goto cleanup ;
}
/* Get non-existent data */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) " , name ) ;
SDLTest_AssertCheck ( result = = NULL , " Validate that result is NULL " ) ;
2015-06-21 23:33:46 +08:00
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
2022-12-01 04:51:59 +08:00
/* Set data */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , userdata ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,%s) " , name , userdata ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
/* Get data (twice) */
for ( iteration = 1 ; iteration < = 2 ; iteration + + ) {
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) [iteration %d] " , name , iteration ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , result ) = = 0 , " Validate that correct result was returned; expected: %s, got: %s " , referenceUserdata , result ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
}
/* Set data again twice */
for ( iteration = 1 ; iteration < = 2 ; iteration + + ) {
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , userdata ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,%s) [iteration %d] " , name , userdata , iteration ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
}
/* Get data again */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) [again] " , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , result ) = = 0 , " Validate that correct result was returned; expected: %s, got: %s " , referenceUserdata , result ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
/* Set data with new data */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , userdata2 ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,%s) [new userdata] " , name , userdata2 ) ;
2015-06-21 23:33:46 +08:00
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata2 , userdata2 ) = = 0 , " Validate that userdata2 was not changed, expected: %s, got: %s " , referenceUserdata2 , userdata2 ) ;
/* Set data with new data again */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , userdata2 ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,%s) [new userdata again] " , name , userdata2 ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata2 , userdata2 ) = = 0 , " Validate that userdata2 was not changed, expected: %s, got: %s " , referenceUserdata2 , userdata2 ) ;
/* Get new data */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) " , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata2 , result ) = = 0 , " Validate that correct result was returned; expected: %s, got: %s " , referenceUserdata2 , result ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
/* Set data with NULL to clear */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,NULL) " , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata2 , userdata2 ) = = 0 , " Validate that userdata2 was not changed, expected: %s, got: %s " , referenceUserdata2 , userdata2 ) ;
/* Set data with NULL to clear again */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,NULL) [again] " , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata2 , userdata2 ) = = 0 , " Validate that userdata2 was not changed, expected: %s, got: %s " , referenceUserdata2 , userdata2 ) ;
/* Get non-existent data */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) " , name ) ;
SDLTest_AssertCheck ( result = = NULL , " Validate that result is NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
/* Get non-existent data new name */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name2 , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) " , name2 ) ;
SDLTest_AssertCheck ( result = = NULL , " Validate that result is NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName2 , name2 ) = = 0 , " Validate that name2 was not changed, expected: %s, got: %s " , referenceName2 , name2 ) ;
/* Set data (again) */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , name , userdata ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(...%s,%s) [again, after clear] " , name , userdata ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , userdata ) = = 0 , " Validate that userdata was not changed, expected: %s, got: %s " , referenceUserdata , userdata ) ;
/* Get data (again) */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , name , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(..,%s) [again, after clear] " , name ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceUserdata , result ) = = 0 , " Validate that correct result was returned; expected: %s, got: %s " , referenceUserdata , result ) ;
SDLTest_AssertCheck ( SDL_strcmp ( referenceName , name ) = = 0 , " Validate that name was not changed, expected: %s, got: %s " , referenceName , name ) ;
/* Set data with NULL name, valid userdata */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , NULL , userdata ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(name=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
/* Set data with empty name, valid userdata */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , " " , userdata ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(name='') " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
/* Set data with NULL name, NULL userdata */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , NULL , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(name=NULL,userdata=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
/* Set data with empty name, NULL userdata */
2023-11-08 04:33:43 +08:00
SDL_SetProperty ( SDL_GetWindowProperties ( window ) , " " , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_SetWindowData(name='',userdata=NULL) " ) ;
2022-12-30 05:58:16 +08:00
checkInvalidParameterError ( ) ;
2022-12-01 04:51:59 +08:00
/* Get data with NULL name */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , NULL , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(name=NULL) " ) ;
SDLTest_AssertCheck ( result = = NULL , " Validate that result is NULL " ) ;
/* Get data with empty name */
2023-11-13 01:47:31 +08:00
result = ( char * ) SDL_GetProperty ( SDL_GetWindowProperties ( window ) , " " , NULL ) ;
2022-12-01 04:51:59 +08:00
SDLTest_AssertPass ( " Call to SDL_GetWindowData(name='') " ) ;
SDLTest_AssertCheck ( result = = NULL , " Validate that result is NULL " ) ;
/* Clean up */
2022-12-30 05:58:16 +08:00
destroyVideoSuiteTestWindow ( window ) ;
2022-12-01 04:51:59 +08:00
cleanup :
SDL_free ( referenceUserdata ) ;
SDL_free ( referenceUserdata2 ) ;
SDL_free ( userdata ) ;
SDL_free ( userdata2 ) ;
return returnValue ;
2015-06-21 23:33:46 +08:00
}
2022-06-06 04:44:30 +08:00
/**
2023-11-06 23:26:06 +08:00
* Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN .
2022-12-01 04:51:59 +08:00
*
2023-07-03 23:29:42 +08:00
* Especially useful when run on a multi - monitor system with different DPI scales per monitor ,
2022-12-01 04:51:59 +08:00
* to test that the window size is maintained when moving between monitors .
2023-07-23 23:25:15 +08:00
*
* As the Wayland windowing protocol does not allow application windows to control their position in the
* desktop space , coupled with the general asynchronous nature of Wayland compositors , the positioning
* tests don ' t work in windowed mode and are unreliable in fullscreen mode , thus are disabled when using
* the Wayland video driver . All that can be done is check that the windows are the expected size .
2022-12-01 04:51:59 +08:00
*/
2023-03-08 23:12:45 +08:00
static int video_setWindowCenteredOnDisplay ( void * arg )
2022-06-06 04:44:30 +08:00
{
2023-01-30 05:30:55 +08:00
SDL_DisplayID * displays ;
2022-06-06 04:44:30 +08:00
SDL_Window * window ;
const char * title = " video_setWindowCenteredOnDisplay Test Window " ;
int x , y , w , h ;
int xVariation , yVariation ;
int displayNum ;
int result ;
SDL_Rect display0 , display1 ;
2023-07-23 23:25:15 +08:00
SDL_bool video_driver_is_wayland = SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " wayland " ) = = 0 ;
2022-06-06 04:44:30 +08:00
2023-01-30 05:30:55 +08:00
displays = SDL_GetDisplays ( & displayNum ) ;
if ( displays ) {
2022-06-06 04:44:30 +08:00
2023-01-30 05:30:55 +08:00
/* Get display bounds */
2024-05-22 00:26:40 +08:00
result = SDL_GetDisplayUsableBounds ( displays [ 0 % displayNum ] , & display0 ) ;
SDLTest_AssertPass ( " SDL_GetDisplayUsableBounds() " ) ;
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( result ! = 0 ) {
return TEST_ABORTED ;
}
2022-06-06 04:44:30 +08:00
2024-05-22 00:26:40 +08:00
result = SDL_GetDisplayUsableBounds ( displays [ 1 % displayNum ] , & display1 ) ;
SDLTest_AssertPass ( " SDL_GetDisplayUsableBounds() " ) ;
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( result ! = 0 ) {
return TEST_ABORTED ;
}
2022-06-06 04:44:30 +08:00
2023-01-30 05:30:55 +08:00
for ( xVariation = 0 ; xVariation < 2 ; xVariation + + ) {
for ( yVariation = 0 ; yVariation < 2 ; yVariation + + ) {
int currentX = 0 , currentY = 0 ;
int currentW = 0 , currentH = 0 ;
int expectedX = 0 , expectedY = 0 ;
int currentDisplay ;
int expectedDisplay ;
2024-01-22 00:38:23 +08:00
SDL_Rect expectedDisplayRect , expectedFullscreenRect ;
2023-11-14 03:29:30 +08:00
SDL_PropertiesID props ;
2023-01-30 05:30:55 +08:00
/* xVariation is the display we start on */
2023-03-16 07:12:54 +08:00
expectedDisplay = displays [ xVariation % displayNum ] ;
2023-01-30 05:30:55 +08:00
x = SDL_WINDOWPOS_CENTERED_DISPLAY ( expectedDisplay ) ;
y = SDL_WINDOWPOS_CENTERED_DISPLAY ( expectedDisplay ) ;
w = SDLTest_RandomIntegerInRange ( 640 , 800 ) ;
h = SDLTest_RandomIntegerInRange ( 400 , 600 ) ;
expectedDisplayRect = ( xVariation = = 0 ) ? display0 : display1 ;
expectedX = ( expectedDisplayRect . x + ( ( expectedDisplayRect . w - w ) / 2 ) ) ;
expectedY = ( expectedDisplayRect . y + ( ( expectedDisplayRect . h - h ) / 2 ) ) ;
2023-11-14 03:29:30 +08:00
props = SDL_CreateProperties ( ) ;
2024-01-28 05:00:37 +08:00
SDL_SetStringProperty ( props , SDL_PROP_WINDOW_CREATE_TITLE_STRING , title ) ;
SDL_SetNumberProperty ( props , SDL_PROP_WINDOW_CREATE_X_NUMBER , x ) ;
SDL_SetNumberProperty ( props , SDL_PROP_WINDOW_CREATE_Y_NUMBER , y ) ;
SDL_SetNumberProperty ( props , SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER , w ) ;
SDL_SetNumberProperty ( props , SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER , h ) ;
SDL_SetBooleanProperty ( props , SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN , SDL_TRUE ) ;
2023-11-14 03:29:30 +08:00
window = SDL_CreateWindowWithProperties ( props ) ;
SDL_DestroyProperties ( props ) ;
2023-01-30 05:30:55 +08:00
SDLTest_AssertPass ( " Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN) " , x , y , w , h ) ;
SDLTest_AssertCheck ( window ! = NULL , " Validate that returned window struct is not NULL " ) ;
2023-07-23 23:25:15 +08:00
/* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */
if ( video_driver_is_wayland ) {
2024-05-14 01:31:55 +08:00
SDL_Renderer * renderer = SDL_CreateRenderer ( window , NULL ) ;
2023-07-23 23:25:15 +08:00
if ( renderer ) {
SDL_SetRenderDrawColor ( renderer , 0x00 , 0x00 , 0x00 , 0xFF ) ;
SDL_RenderClear ( renderer ) ;
SDL_RenderPresent ( renderer ) ;
/* Some desktops don't display the window immediately after presentation,
* so delay to give the window time to actually appear on the desktop .
*/
SDL_Delay ( 100 ) ;
} else {
SDLTest_Log ( " Unable to create a renderer, tests may fail under Wayland " ) ;
}
}
2023-01-30 05:30:55 +08:00
/* Check the window is centered on the requested display */
currentDisplay = SDL_GetDisplayForWindow ( window ) ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentDisplay = = expectedDisplay , " Validate display ID (current: %d, expected: %d) " , currentDisplay , expectedDisplay ) ;
} else {
SDLTest_Log ( " Skipping display ID validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( currentW = = w , " Validate width (current: %d, expected: %d) " , currentW , w ) ;
SDLTest_AssertCheck ( currentH = = h , " Validate height (current: %d, expected: %d) " , currentH , h ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentX = = expectedX , " Validate x (current: %d, expected: %d) " , currentX , expectedX ) ;
SDLTest_AssertCheck ( currentY = = expectedY , " Validate y (current: %d, expected: %d) " , currentY , expectedY ) ;
} else {
SDLTest_Log ( " Skipping window position validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
/* Enter fullscreen desktop */
2023-07-23 23:25:15 +08:00
SDL_SetWindowPosition ( window , x , y ) ;
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
result = SDL_SetWindowFullscreen ( window , SDL_TRUE ) ;
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
2023-01-30 05:30:55 +08:00
/* Check we are filling the full display */
currentDisplay = SDL_GetDisplayForWindow ( window ) ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
2024-01-22 00:38:23 +08:00
/* Get the expected fullscreen rect.
* This needs to be queried after window creation and positioning as some drivers can alter the
* usable bounds based on the window scaling mode .
*/
result = SDL_GetDisplayBounds ( expectedDisplay , & expectedFullscreenRect ) ;
SDLTest_AssertPass ( " SDL_GetDisplayBounds() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentDisplay = = expectedDisplay , " Validate display ID (current: %d, expected: %d) " , currentDisplay , expectedDisplay ) ;
} else {
SDLTest_Log ( " Skipping display ID validation: Wayland driver does not support window positioning " ) ;
}
2024-01-22 00:38:23 +08:00
SDLTest_AssertCheck ( currentW = = expectedFullscreenRect . w , " Validate width (current: %d, expected: %d) " , currentW , expectedFullscreenRect . w ) ;
SDLTest_AssertCheck ( currentH = = expectedFullscreenRect . h , " Validate height (current: %d, expected: %d) " , currentH , expectedFullscreenRect . h ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
2024-01-22 00:38:23 +08:00
SDLTest_AssertCheck ( currentX = = expectedFullscreenRect . x , " Validate x (current: %d, expected: %d) " , currentX , expectedFullscreenRect . x ) ;
SDLTest_AssertCheck ( currentY = = expectedFullscreenRect . y , " Validate y (current: %d, expected: %d) " , currentY , expectedFullscreenRect . y ) ;
2023-07-23 23:25:15 +08:00
} else {
SDLTest_Log ( " Skipping window position validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
/* Leave fullscreen desktop */
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
result = SDL_SetWindowFullscreen ( window , SDL_FALSE ) ;
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
2023-01-30 05:30:55 +08:00
/* Check window was restored correctly */
currentDisplay = SDL_GetDisplayForWindow ( window ) ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentDisplay = = expectedDisplay , " Validate display index (current: %d, expected: %d) " , currentDisplay , expectedDisplay ) ;
} else {
SDLTest_Log ( " Skipping display ID validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( currentW = = w , " Validate width (current: %d, expected: %d) " , currentW , w ) ;
SDLTest_AssertCheck ( currentH = = h , " Validate height (current: %d, expected: %d) " , currentH , h ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentX = = expectedX , " Validate x (current: %d, expected: %d) " , currentX , expectedX ) ;
SDLTest_AssertCheck ( currentY = = expectedY , " Validate y (current: %d, expected: %d) " , currentY , expectedY ) ;
} else {
SDLTest_Log ( " Skipping window position validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
/* Center on display yVariation, and check window properties */
2023-03-16 07:12:54 +08:00
expectedDisplay = displays [ yVariation % displayNum ] ;
2023-01-30 05:30:55 +08:00
x = SDL_WINDOWPOS_CENTERED_DISPLAY ( expectedDisplay ) ;
y = SDL_WINDOWPOS_CENTERED_DISPLAY ( expectedDisplay ) ;
2023-03-16 07:12:54 +08:00
expectedDisplayRect = ( yVariation = = 0 ) ? display0 : display1 ;
2023-01-30 05:30:55 +08:00
expectedX = ( expectedDisplayRect . x + ( ( expectedDisplayRect . w - w ) / 2 ) ) ;
expectedY = ( expectedDisplayRect . y + ( ( expectedDisplayRect . h - h ) / 2 ) ) ;
SDL_SetWindowPosition ( window , x , y ) ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
2023-01-30 05:30:55 +08:00
currentDisplay = SDL_GetDisplayForWindow ( window ) ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentDisplay = = expectedDisplay , " Validate display ID (current: %d, expected: %d) " , currentDisplay , expectedDisplay ) ;
} else {
SDLTest_Log ( " Skipping display ID validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
SDLTest_AssertCheck ( currentW = = w , " Validate width (current: %d, expected: %d) " , currentW , w ) ;
SDLTest_AssertCheck ( currentH = = h , " Validate height (current: %d, expected: %d) " , currentH , h ) ;
2023-07-23 23:25:15 +08:00
if ( ! video_driver_is_wayland ) {
SDLTest_AssertCheck ( currentX = = expectedX , " Validate x (current: %d, expected: %d) " , currentX , expectedX ) ;
SDLTest_AssertCheck ( currentY = = expectedY , " Validate y (current: %d, expected: %d) " , currentY , expectedY ) ;
} else {
SDLTest_Log ( " Skipping window position validation: Wayland driver does not support window positioning " ) ;
}
2023-01-30 05:30:55 +08:00
/* Clean up */
destroyVideoSuiteTestWindow ( window ) ;
}
2022-06-06 04:44:30 +08:00
}
2023-01-30 05:30:55 +08:00
SDL_free ( displays ) ;
2022-06-06 04:44:30 +08:00
}
return TEST_COMPLETED ;
}
2015-06-21 23:33:46 +08:00
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
/**
* Tests calls to SDL_MaximizeWindow ( ) , SDL_RestoreWindow ( ) , and SDL_SetWindowFullscreen ( ) ,
* interspersed with calls to set the window size and position , and verifies the flags ,
* sizes , and positions of maximized , fullscreen , and restored windows .
*
* NOTE : This test is good on Mac , Win32 , GNOME , and KDE ( Wayland and X11 ) . Other * nix
* desktops , particularly tiling desktops , may not support the expected behavior ,
* so don ' t be surprised if this fails .
*/
static int video_getSetWindowState ( void * arg )
{
const char * title = " video_getSetWindowState Test Window " ;
SDL_Window * window ;
int result ;
SDL_Rect display ;
2024-03-04 03:30:57 +08:00
SDL_WindowFlags flags ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
int windowedX , windowedY ;
int currentX , currentY ;
int desiredX = 0 , desiredY = 0 ;
int windowedW , windowedH ;
int currentW , currentH ;
int desiredW = 0 , desiredH = 0 ;
2024-03-04 03:30:57 +08:00
SDL_WindowFlags skipFlags = 0 ;
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
const SDL_bool restoreHint = SDL_GetHintBoolean ( " SDL_BORDERLESS_RESIZABLE_STYLE " , SDL_TRUE ) ;
const SDL_bool skipPos = SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " wayland " ) = = 0 ;
/* This test is known to be good only on GNOME and KDE. At the time of writing, Weston seems to have maximize related bugs
* that prevent it from running correctly ( no configure events are received when unsetting maximize ) , and tiling window
* managers such as Sway have fundamental behavioral differences that conflict with it .
*
* Other desktops can be enabled in the future as required .
*/
if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " wayland " ) = = 0 | | SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " x11 " ) = = 0 ) {
const char * desktop = SDL_getenv ( " XDG_CURRENT_DESKTOP " ) ;
if ( SDL_strcmp ( desktop , " GNOME " ) ! = 0 & & SDL_strcmp ( desktop , " KDE " ) ! = 0 ) {
SDLTest_Log ( " Skipping test video_getSetWindowState: desktop environment %s not supported " , desktop ) ;
return TEST_SKIPPED ;
}
}
/* Win32 borderless windows are not resizable by default and need this undocumented hint */
SDL_SetHint ( " SDL_BORDERLESS_RESIZABLE_STYLE " , " 1 " ) ;
/* Call against new test window */
window = createVideoSuiteTestWindow ( title ) ;
if ( ! window ) {
return TEST_ABORTED ;
}
SDL_GetWindowSize ( window , & windowedW , & windowedH ) ;
SDLTest_AssertPass ( " SDL_GetWindowSize() " ) ;
2024-01-08 08:59:41 +08:00
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
SDL_GetWindowPosition ( window , & windowedX , & windowedY ) ;
SDLTest_AssertPass ( " SDL_GetWindowPosition() " ) ;
if ( skipPos ) {
SDLTest_Log ( " Skipping positioning tests: %s reports window positioning as unsupported " , SDL_GetCurrentVideoDriver ( ) ) ;
}
/* Maximize and check the dimensions */
result = SDL_MaximizeWindow ( window ) ;
SDLTest_AssertPass ( " SDL_MaximizeWindow() " ) ;
if ( result < 0 ) {
SDLTest_Log ( " Skipping state transition tests: %s reports window maximizing as unsupported " , SDL_GetCurrentVideoDriver ( ) ) ;
skipFlags | = SDL_WINDOW_MAXIMIZED ;
goto minimize_test ;
}
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( flags & SDL_WINDOW_MAXIMIZED , " Verify the `SDL_WINDOW_MAXIMIZED` flag is set: %s " , ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
/* Check that the maximized window doesn't extend beyond the usable display bounds.
* FIXME : Maximizing Win32 borderless windows is broken , so this always fails .
* Skip it for now .
*/
if ( SDL_strcmp ( SDL_GetCurrentVideoDriver ( ) , " windows " ) ! = 0 ) {
result = SDL_GetDisplayUsableBounds ( SDL_GetDisplayForWindow ( window ) , & display ) ;
SDLTest_AssertPass ( " SDL_GetDisplayUsableBounds() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
desiredW = display . w ;
desiredH = display . h ;
currentW = windowedW + 1 ;
currentH = windowedH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( currentW < = desiredW , " Verify returned width; expected: <= %d, got: %d " , desiredW ,
currentW ) ;
SDLTest_AssertCheck ( currentH < = desiredH , " Verify returned height; expected: <= %d, got: %d " , desiredH ,
currentH ) ;
}
/* Restore and check the dimensions */
result = SDL_RestoreWindow ( window ) ;
SDLTest_AssertPass ( " SDL_RestoreWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( ! ( flags & SDL_WINDOW_MAXIMIZED ) , " Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s " , ! ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
if ( ! skipPos ) {
currentX = windowedX + 1 ;
currentY = windowedY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
SDLTest_AssertCheck ( windowedX = = currentX , " Verify returned X coordinate; expected: %d, got: %d " , windowedX , currentX ) ;
SDLTest_AssertCheck ( windowedY = = currentY , " Verify returned Y coordinate; expected: %d, got: %d " , windowedY , currentY ) ;
}
currentW = windowedW + 1 ;
currentH = windowedH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( windowedW = = currentW , " Verify returned width; expected: %d, got: %d " , windowedW , currentW ) ;
SDLTest_AssertCheck ( windowedH = = currentH , " Verify returned height; expected: %d, got: %d " , windowedH , currentH ) ;
/* Maximize, then immediately restore */
result = SDL_MaximizeWindow ( window ) ;
SDLTest_AssertPass ( " SDL_MaximizeWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_RestoreWindow ( window ) ;
SDLTest_AssertPass ( " SDL_RestoreWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( ! ( flags & SDL_WINDOW_MAXIMIZED ) , " Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s " , ! ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
/* Make sure the restored size and position matches the original windowed size and position. */
if ( ! skipPos ) {
currentX = windowedX + 1 ;
currentY = windowedY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
SDLTest_AssertCheck ( windowedX = = currentX , " Verify returned X coordinate; expected: %d, got: %d " , windowedX , currentX ) ;
SDLTest_AssertCheck ( windowedY = = currentY , " Verify returned Y coordinate; expected: %d, got: %d " , windowedY , currentY ) ;
}
currentW = windowedW + 1 ;
currentH = windowedH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( windowedW = = currentW , " Verify returned width; expected: %d, got: %d " , windowedW , currentW ) ;
SDLTest_AssertCheck ( windowedH = = currentH , " Verify returned height; expected: %d, got: %d " , windowedH , currentH ) ;
/* Maximize, then enter fullscreen */
result = SDL_MaximizeWindow ( window ) ;
SDLTest_AssertPass ( " SDL_MaximizeWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SetWindowFullscreen ( window , SDL_TRUE ) ;
SDLTest_AssertPass ( " SDL_SetWindowFullscreen(SDL_TRUE) " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( flags & SDL_WINDOW_FULLSCREEN , " Verify the `SDL_WINDOW_FULLSCREEN` flag is set: %s " , ( flags & SDL_WINDOW_FULLSCREEN ) ? " true " : " false " ) ;
SDLTest_AssertCheck ( ! ( flags & SDL_WINDOW_MAXIMIZED ) , " Verify the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s " , ! ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
/* Verify the fullscreen size and position */
result = SDL_GetDisplayBounds ( SDL_GetDisplayForWindow ( window ) , & display ) ;
SDLTest_AssertPass ( " SDL_GetDisplayBounds() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( ! skipPos ) {
desiredX = display . x ;
desiredY = display . y ;
currentX = windowedX + 1 ;
currentY = windowedY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
SDLTest_AssertCheck ( desiredX = = currentX , " Verify returned X coordinate; expected: %d, got: %d " , desiredX , currentX ) ;
SDLTest_AssertCheck ( desiredY = = currentY , " Verify returned Y coordinate; expected: %d, got: %d " , desiredY , currentY ) ;
}
desiredW = display . w ;
desiredH = display . h ;
currentW = windowedW + 1 ;
currentH = windowedH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( currentW = = desiredW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( currentH = = desiredH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
/* Leave fullscreen and restore the window */
result = SDL_SetWindowFullscreen ( window , SDL_FALSE ) ;
SDLTest_AssertPass ( " SDL_SetWindowFullscreen(SDL_FALSE) " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_RestoreWindow ( window ) ;
SDLTest_AssertPass ( " SDL_RestoreWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( ! ( flags & SDL_WINDOW_MAXIMIZED ) , " Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s " , ! ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
/* Make sure the restored size and position matches the original windowed size and position. */
if ( ! skipPos ) {
currentX = windowedX + 1 ;
currentY = windowedY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
SDLTest_AssertCheck ( windowedX = = currentX , " Verify returned X coordinate; expected: %d, got: %d " , windowedX , currentX ) ;
SDLTest_AssertCheck ( windowedY = = currentY , " Verify returned Y coordinate; expected: %d, got: %d " , windowedY , currentY ) ;
}
currentW = windowedW + 1 ;
currentH = windowedH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( windowedW = = currentW , " Verify returned width; expected: %d, got: %d " , windowedW , currentW ) ;
SDLTest_AssertCheck ( windowedH = = currentH , " Verify returned height; expected: %d, got: %d " , windowedH , currentH ) ;
/* Maximize, change size, and restore */
result = SDL_MaximizeWindow ( window ) ;
SDLTest_AssertPass ( " SDL_MaximizeWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
desiredW = windowedW + 10 ;
desiredH = windowedH + 10 ;
result = SDL_SetWindowSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " SDL_SetWindowSize() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( ! skipPos ) {
desiredX = windowedX + 10 ;
desiredY = windowedY + 10 ;
result = SDL_SetWindowPosition ( window , desiredX , desiredY ) ;
SDLTest_AssertPass ( " SDL_SetWindowPosition() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
}
result = SDL_RestoreWindow ( window ) ;
SDLTest_AssertPass ( " SDL_RestoreWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( ! ( flags & SDL_WINDOW_MAXIMIZED ) , " Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s " , ! ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
if ( ! skipPos ) {
currentX = desiredX + 1 ;
currentY = desiredY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
SDLTest_AssertCheck ( desiredX = = currentX , " Verify returned X coordinate; expected: %d, got: %d " , desiredX , currentX ) ;
SDLTest_AssertCheck ( desiredY = = currentY , " Verify returned Y coordinate; expected: %d, got: %d " , desiredY , currentY ) ;
}
currentW = desiredW + 1 ;
currentH = desiredH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
/* Change size and position, maximize and restore */
desiredW = windowedW - 5 ;
desiredH = windowedH - 5 ;
result = SDL_SetWindowSize ( window , desiredW , desiredH ) ;
SDLTest_AssertPass ( " SDL_SetWindowSize() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
if ( ! skipPos ) {
desiredX = windowedX + 5 ;
desiredY = windowedY + 5 ;
result = SDL_SetWindowPosition ( window , desiredX , desiredY ) ;
SDLTest_AssertPass ( " SDL_SetWindowPosition() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
}
result = SDL_MaximizeWindow ( window ) ;
SDLTest_AssertPass ( " SDL_MaximizeWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_RestoreWindow ( window ) ;
SDLTest_AssertPass ( " SDL_RestoreWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( ! ( flags & SDL_WINDOW_MAXIMIZED ) , " Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s " , ! ( flags & SDL_WINDOW_MAXIMIZED ) ? " true " : " false " ) ;
if ( ! skipPos ) {
currentX = desiredX + 1 ;
currentY = desiredY + 1 ;
SDL_GetWindowPosition ( window , & currentX , & currentY ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowPosition() " ) ;
SDLTest_AssertCheck ( desiredX = = currentX , " Verify returned X coordinate; expected: %d, got: %d " , desiredX , currentX ) ;
SDLTest_AssertCheck ( desiredY = = currentY , " Verify returned Y coordinate; expected: %d, got: %d " , desiredY , currentY ) ;
}
currentW = desiredW + 1 ;
currentH = desiredH + 1 ;
SDL_GetWindowSize ( window , & currentW , & currentH ) ;
SDLTest_AssertPass ( " Call to SDL_GetWindowSize() " ) ;
SDLTest_AssertCheck ( desiredW = = currentW , " Verify returned width; expected: %d, got: %d " , desiredW , currentW ) ;
SDLTest_AssertCheck ( desiredH = = currentH , " Verify returned height; expected: %d, got: %d " , desiredH , currentH ) ;
minimize_test :
/* Minimize */
result = SDL_MinimizeWindow ( window ) ;
if ( result = = 0 ) {
SDLTest_AssertPass ( " SDL_MinimizeWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
result = SDL_SyncWindow ( window ) ;
SDLTest_AssertPass ( " SDL_SyncWindow() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify return value; expected: 0, got: %d " , result ) ;
flags = SDL_GetWindowFlags ( window ) ;
SDLTest_AssertPass ( " SDL_GetWindowFlags() " ) ;
SDLTest_AssertCheck ( flags & SDL_WINDOW_MINIMIZED , " Verify that the `SDL_WINDOW_MINIMIZED` flag is set: %s " , ( flags & SDL_WINDOW_MINIMIZED ) ? " true " : " false " ) ;
} else {
SDLTest_Log ( " Skipping minimize test: %s reports window minimizing as unsupported " , SDL_GetCurrentVideoDriver ( ) ) ;
skipFlags | = SDL_WINDOW_MINIMIZED ;
}
/* Clean up */
destroyVideoSuiteTestWindow ( window ) ;
/* Restore the hint to the previous value */
SDL_SetHint ( " SDL_BORDERLESS_RESIZABLE_STYLE " , restoreHint ? " 1 " : " 0 " ) ;
return skipFlags ! = ( SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED ) ? TEST_COMPLETED : TEST_SKIPPED ;
}
2015-06-21 23:33:46 +08:00
/* ================= Test References ================== */
/* Video test cases */
2022-12-01 04:51:59 +08:00
static const SDLTest_TestCaseReference videoTest1 = {
( SDLTest_TestCaseFp ) video_enableDisableScreensaver , " video_enableDisableScreensaver " , " Enable and disable screenaver while checking state " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2022-12-01 04:51:59 +08:00
static const SDLTest_TestCaseReference videoTest2 = {
( SDLTest_TestCaseFp ) video_createWindowVariousSizes , " video_createWindowVariousSizes " , " Create windows with various sizes " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest3 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_createWindowVariousFlags , " video_createWindowVariousFlags " , " Create windows using various flags " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest4 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getWindowFlags , " video_getWindowFlags " , " Get window flags set during SDL_CreateWindow " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest5 = {
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
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_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
( SDLTest_TestCaseFp ) video_getFullscreenDisplayModes , " video_getFullscreenDisplayModes " , " Use SDL_GetFullscreenDisplayModes function to get number of display modes " , TEST_ENABLED
2022-12-01 04:51:59 +08:00
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest6 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getClosestDisplayModeCurrentResolution , " video_getClosestDisplayModeCurrentResolution " , " Use function to get closes match to requested display mode for current resolution " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest7 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getClosestDisplayModeRandomResolution , " video_getClosestDisplayModeRandomResolution " , " Use function to get closes match to requested display mode for random resolution " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest8 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getWindowDisplayMode , " video_getWindowDisplayMode " , " Get window display mode " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest9 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getWindowDisplayModeNegative , " video_getWindowDisplayModeNegative " , " Get window display mode with invalid input " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest10 = {
2024-03-25 07:35:40 +08:00
( SDLTest_TestCaseFp ) video_getSetWindowGrab , " video_getSetWindowGrab " , " Checks input grab positive and negative cases " , TEST_ENABLED
2022-12-01 04:51:59 +08:00
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest11 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getWindowId , " video_getWindowId " , " Checks SDL_GetWindowID and SDL_GetWindowFromID " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest12 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getWindowPixelFormat , " video_getWindowPixelFormat " , " Checks SDL_GetWindowPixelFormat " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest13 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getSetWindowPosition , " video_getSetWindowPosition " , " Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest14 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getSetWindowSize , " video_getSetWindowSize " , " Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest15 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getSetWindowMinimumSize , " video_getSetWindowMinimumSize " , " Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest16 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getSetWindowMaximumSize , " video_getSetWindowMaximumSize " , " Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest17 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_getSetWindowData , " video_getSetWindowData " , " Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
2023-03-06 06:44:38 +08:00
static const SDLTest_TestCaseReference videoTest18 = {
2022-12-01 04:51:59 +08:00
( SDLTest_TestCaseFp ) video_setWindowCenteredOnDisplay , " video_setWindowCenteredOnDisplay " , " Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display " , TEST_ENABLED
} ;
2022-06-06 04:44:30 +08:00
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
static const SDLTest_TestCaseReference videoTest19 = {
( SDLTest_TestCaseFp ) video_getSetWindowState , " video_getSetWindowState " , " Checks transitioning between windowed, minimized, maximized, and fullscreen states " , TEST_ENABLED
} ;
2015-06-21 23:33:46 +08:00
/* Sequence of Video test cases */
2022-12-01 04:51:59 +08:00
static const SDLTest_TestCaseReference * videoTests [ ] = {
2015-06-21 23:33:46 +08:00
& videoTest1 , & videoTest2 , & videoTest3 , & videoTest4 , & videoTest5 , & videoTest6 ,
& videoTest7 , & videoTest8 , & videoTest9 , & videoTest10 , & videoTest11 , & videoTest12 ,
& videoTest13 , & videoTest14 , & videoTest15 , & videoTest16 , & videoTest17 ,
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-26 03:09:55 +08:00
& videoTest18 , & videoTest19 , NULL
2015-06-21 23:33:46 +08:00
} ;
/* Video test suite (global) */
SDLTest_TestSuiteReference videoTestSuite = {
" Video " ,
NULL ,
videoTests ,
NULL
} ;