Displays are now referenced by instance ID instead of index

This commit is contained in:
Sam Lantinga
2023-01-29 13:30:55 -08:00
parent 758c0dd6d8
commit 22c69bccdf
157 changed files with 1620 additions and 1589 deletions

View File

@@ -343,110 +343,83 @@ int video_getWindowFlags(void *arg)
*/
int video_getNumDisplayModes(void *arg)
{
SDL_DisplayID *displays;
int result;
int displayNum;
int i;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
displays = SDL_GetDisplays(NULL);
if (displays) {
SDLTest_AssertPass("Call to SDL_GetDisplays()");
/* Make call for each display */
for (i = 0; i < displayNum; i++) {
result = SDL_GetNumDisplayModes(i);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
/* Make call for each display */
for (i = 0; displays[i]; ++i) {
result = SDL_GetNumDisplayModes(displays[i]);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
}
SDL_free(displays);
}
return TEST_COMPLETED;
}
/**
* @brief Tests negative call to SDL_GetNumDisplayModes function
*/
int video_getNumDisplayModesNegative(void *arg)
{
int result;
int displayNum;
int displayIndex;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
/* Invalid boundary values */
displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
result = SDL_GetNumDisplayModes(displayIndex);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
/* Large (out-of-bounds) display index */
displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
result = SDL_GetNumDisplayModes(displayIndex);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
result = SDL_GetNumDisplayModes(displayIndex);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
return TEST_COMPLETED;
}
/**
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
*/
int video_getClosestDisplayModeCurrentResolution(void *arg)
{
int result;
SDL_DisplayID *displays;
SDL_DisplayMode current;
SDL_DisplayMode target;
SDL_DisplayMode closest;
SDL_DisplayMode *dResult;
int displayNum;
int i;
int variation;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
displays = SDL_GetDisplays(NULL);
if (displays) {
SDLTest_AssertPass("Call to SDL_GetDisplays()");
/* Make calls for each display */
for (i = 0; i < displayNum; i++) {
SDLTest_Log("Testing against display: %d", i);
/* Make calls for each display */
for (i = 0; displays[i]; ++i) {
SDLTest_Log("Testing against display: %" SDL_PRIu32 "", displays[i]);
/* Get first display mode to get a sane resolution; this should always work */
result = SDL_GetDisplayMode(i, 0, &current);
SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
/* Set the desired resolution equals to current resolution */
SDL_zero(target);
target.pixel_w = current.pixel_w;
target.pixel_h = current.pixel_h;
for (variation = 0; variation < 8; variation++) {
/* Vary constraints on other query parameters */
target.format = (variation & 1) ? current.format : 0;
target.refresh_rate = (variation & 2) ? current.refresh_rate : 0.0f;
target.driverdata = (variation & 4) ? current.driverdata : 0;
/* Make call */
dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL");
/* Check that one gets the current resolution back again */
SDLTest_AssertCheck(closest.pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest.pixel_w);
SDLTest_AssertCheck(closest.pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest.pixel_h);
/* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */
SDLTest_AssertCheck(closest.pixel_w == dResult->pixel_w, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_w, dResult->pixel_w);
SDLTest_AssertCheck(closest.pixel_h == dResult->pixel_h, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_h, dResult->pixel_h);
/* NOLINTEND(clang-analyzer-core.NullDereference) */
/* Get first display mode to get a sane resolution; this should always work */
result = SDL_GetDisplayMode(displays[i], 0, &current);
SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
/* Set the desired resolution equals to current resolution */
SDL_zero(target);
target.pixel_w = current.pixel_w;
target.pixel_h = current.pixel_h;
for (variation = 0; variation < 8; variation++) {
/* Vary constraints on other query parameters */
target.format = (variation & 1) ? current.format : 0;
target.refresh_rate = (variation & 2) ? current.refresh_rate : 0.0f;
target.driverdata = (variation & 4) ? current.driverdata : 0;
/* Make call */
dResult = SDL_GetClosestDisplayMode(displays[i], &target, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL");
/* Check that one gets the current resolution back again */
SDLTest_AssertCheck(closest.pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest.pixel_w);
SDLTest_AssertCheck(closest.pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest.pixel_h);
/* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */
SDLTest_AssertCheck(closest.pixel_w == dResult->pixel_w, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_w, dResult->pixel_w);
SDLTest_AssertCheck(closest.pixel_h == dResult->pixel_h, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_h, dResult->pixel_h);
/* NOLINTEND(clang-analyzer-core.NullDereference) */
}
}
SDL_free(displays);
}
return TEST_COMPLETED;
@@ -457,33 +430,36 @@ int video_getClosestDisplayModeCurrentResolution(void *arg)
*/
int video_getClosestDisplayModeRandomResolution(void *arg)
{
SDL_DisplayID *displays;
SDL_DisplayMode target;
SDL_DisplayMode closest;
int displayNum;
int i;
int variation;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
displays = SDL_GetDisplays(NULL);
if (displays) {
SDLTest_AssertPass("Call to SDL_GetDisplays()");
/* Make calls for each display */
for (i = 0; i < displayNum; i++) {
SDLTest_Log("Testing against display: %d", i);
/* Make calls for each display */
for (i = 0; displays[i]; ++i) {
SDLTest_Log("Testing against display: %" SDL_PRIu32 "", displays[i]);
for (variation = 0; variation < 16; variation++) {
for (variation = 0; variation < 16; variation++) {
/* Set random constraints */
SDL_zero(target);
target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
/* Set random constraints */
SDL_zero(target);
target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
/* Make call; may or may not find anything, so don't validate any further */
SDL_GetClosestDisplayMode(i, &target, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
/* Make call; may or may not find anything, so don't validate any further */
SDL_GetClosestDisplayMode(displays[i], &target, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
}
}
SDL_free(displays);
}
return TEST_COMPLETED;
@@ -1055,7 +1031,7 @@ int video_getSetWindowSize(void *arg)
int desiredW, desiredH;
/* Get display bounds for size range */
result = SDL_GetDisplayBounds(0, &display);
result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
@@ -1222,7 +1198,7 @@ int video_getSetWindowMinimumSize(void *arg)
int desiredH = 1;
/* Get display bounds for size range */
result = SDL_GetDisplayBounds(0, &display);
result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
@@ -1364,7 +1340,7 @@ int video_getSetWindowMaximumSize(void *arg)
int desiredW, desiredH;
/* Get display bounds for size range */
result = SDL_GetDisplayBounds(0, &display);
result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
@@ -1710,6 +1686,7 @@ cleanup:
*/
int video_setWindowCenteredOnDisplay(void *arg)
{
SDL_DisplayID *displays;
SDL_Window *window;
const char *title = "video_setWindowCenteredOnDisplay Test Window";
int x, y, w, h;
@@ -1718,110 +1695,114 @@ int video_setWindowCenteredOnDisplay(void *arg)
int result;
SDL_Rect display0, display1;
displayNum = SDL_GetNumVideoDisplays();
displays = SDL_GetDisplays(&displayNum);
if (displays) {
/* Get display bounds */
result = SDL_GetDisplayBounds(0 % displayNum, &display0);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
result = SDL_GetDisplayBounds(1 % displayNum, &display1);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
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;
SDL_Rect expectedDisplayRect;
/* xVariation is the display we start on */
expectedDisplay = xVariation % displayNum;
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));
window = SDL_CreateWindow(title, x, y, w, h, 0);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Check the window is centered on the requested display */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Enter fullscreen desktop */
result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check we are filling the full display */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
/* Leave fullscreen desktop */
result = SDL_SetWindowFullscreen(window, 0);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check window was restored correctly */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Center on display yVariation, and check window properties */
expectedDisplay = yVariation % displayNum;
x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1;
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
SDL_SetWindowPosition(window, x, y);
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Clean up */
destroyVideoSuiteTestWindow(window);
/* Get display bounds */
result = SDL_GetDisplayBounds(displays[0 % displayNum], &display0);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
result = SDL_GetDisplayBounds(displays[1 % displayNum], &display1);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
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;
SDL_Rect expectedDisplayRect;
/* xVariation is the display we start on */
expectedDisplay = xVariation % displayNum;
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));
window = SDL_CreateWindow(title, x, y, w, h, 0);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Check the window is centered on the requested display */
currentDisplay = SDL_GetDisplayForWindow(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Enter fullscreen desktop */
result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check we are filling the full display */
currentDisplay = SDL_GetDisplayForWindow(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
/* Leave fullscreen desktop */
result = SDL_SetWindowFullscreen(window, 0);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check window was restored correctly */
currentDisplay = SDL_GetDisplayForWindow(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Center on display yVariation, and check window properties */
expectedDisplay = yVariation % displayNum;
x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1;
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
SDL_SetWindowPosition(window, x, y);
currentDisplay = SDL_GetDisplayForWindow(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Clean up */
destroyVideoSuiteTestWindow(window);
}
}
SDL_free(displays);
}
return TEST_COMPLETED;
@@ -1855,58 +1836,54 @@ static const SDLTest_TestCaseReference videoTest6 = {
};
static const SDLTest_TestCaseReference videoTest7 = {
(SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest8 = {
(SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest9 = {
static const SDLTest_TestCaseReference videoTest8 = {
(SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest10 = {
static const SDLTest_TestCaseReference videoTest9 = {
(SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest11 = {
static const SDLTest_TestCaseReference videoTest10 = {
(SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest12 = {
static const SDLTest_TestCaseReference videoTest11 = {
(SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest13 = {
static const SDLTest_TestCaseReference videoTest12 = {
(SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest14 = {
static const SDLTest_TestCaseReference videoTest13 = {
(SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest15 = {
static const SDLTest_TestCaseReference videoTest14 = {
(SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest16 = {
static const SDLTest_TestCaseReference videoTest15 = {
(SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest17 = {
static const SDLTest_TestCaseReference videoTest16 = {
(SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest18 = {
static const SDLTest_TestCaseReference videoTest17 = {
(SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest19 = {
static const SDLTest_TestCaseReference videoTest18 = {
(SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference videoTest20 = {
static const SDLTest_TestCaseReference videoTest19 = {
(SDLTest_TestCaseFp)video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED
};
@@ -1915,7 +1892,7 @@ static const SDLTest_TestCaseReference *videoTests[] = {
&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
&videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
&videoTest18, &videoTest19, &videoTest20, NULL
&videoTest18, &videoTest19, NULL
};
/* Video test suite (global) */

View File

@@ -15,22 +15,26 @@
int main(int argc, char **argv)
{
int total, i;
SDL_DisplayID *displays;
int i;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_Log("SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError());
return 1;
}
total = SDL_GetNumVideoDisplays();
for (i = 0; i < total; i++) {
SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 };
SDL_GetDisplayBounds(i, &bounds);
SDL_GetDisplayUsableBounds(i, &usable);
SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}",
i, SDL_GetDisplayName(i),
bounds.x, bounds.y, bounds.w, bounds.h,
usable.x, usable.y, usable.w, usable.h);
displays = SDL_GetDisplays(NULL);
if (displays) {
for (i = 0; displays[i]; i++) {
SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 };
SDL_GetDisplayBounds(displays[i], &bounds);
SDL_GetDisplayUsableBounds(displays[i], &usable);
SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}",
i, SDL_GetDisplayName(displays[i]),
bounds.x, bounds.y, bounds.w, bounds.h,
usable.x, usable.y, usable.w, usable.h);
}
SDL_free(displays);
}
SDL_Quit();

View File

@@ -31,8 +31,9 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
int main(int argc, char *argv[])
{
SDL_DisplayID *displays;
SDL_DisplayMode mode;
int num_displays, dpy;
int num_displays, i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -44,18 +45,19 @@ int main(int argc, char *argv[])
}
SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
num_displays = SDL_GetNumVideoDisplays();
displays = SDL_GetDisplays(&num_displays);
SDL_Log("See %d displays.\n", num_displays);
for (dpy = 0; dpy < num_displays; dpy++) {
for (i = 0; i < num_displays; i++) {
SDL_DisplayID dpy = displays[i];
const int num_modes = SDL_GetNumDisplayModes(dpy);
SDL_Rect rect = { 0, 0, 0, 0 };
float ddpi, hdpi, vdpi;
int m;
SDL_GetDisplayBounds(dpy, &rect);
SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
if (SDL_GetDisplayPhysicalDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
@@ -87,6 +89,7 @@ int main(int argc, char *argv[])
SDL_Log("\n");
}
SDL_free(displays);
SDL_Quit();
return 0;

View File

@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
swap_interval = 0;
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
ret_interval = SDL_GL_GetSwapInterval(&interval);

View File

@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));

View File

@@ -714,7 +714,7 @@ int main(int argc, char *argv[])
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Threaded : %s\n", threaded ? "yes" : "no");
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");

View File

@@ -602,7 +602,7 @@ int main(int argc, char *argv[])
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));

View File

@@ -1104,7 +1104,7 @@ int main(int argc, char **argv)
return 1;
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
SDL_GetWindowSize(state->windows[0], &dw, &dh);
SDL_Log("Window Size : %d,%d\n", dw, dh);

View File

@@ -57,8 +57,8 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
SDL_DisplayMode mode;
char text[1024];
const int lineHeight = 10;
const int display_index = SDL_GetWindowDisplayIndex(window);
const int num_modes = SDL_GetNumDisplayModes(display_index);
const SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
const int num_modes = SDL_GetNumDisplayModes(displayID);
int i;
int column_chars = 0;
int text_length;
@@ -103,7 +103,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
for (i = 0; i < num_modes; ++i) {
SDL_FRect cell_rect;
if (0 != SDL_GetDisplayMode(display_index, i, &mode)) {
if (0 != SDL_GetDisplayMode(displayID, i, &mode)) {
return;
}
@@ -167,7 +167,7 @@ void loop()
event.window.windowID,
event.window.data1,
event.window.data2,
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
SDL_GetDisplayName(SDL_GetDisplayForWindow(window)));
}
}
if (event.type == SDL_EVENT_WINDOW_FOCUS_LOST) {
@@ -207,9 +207,9 @@ void loop()
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) {
SDL_Window *window = SDL_GetMouseFocus();
if (highlighted_mode != -1 && window != NULL) {
const int display_index = SDL_GetWindowDisplayIndex(window);
SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
SDL_DisplayMode mode;
if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) {
if (0 != SDL_GetDisplayMode(displayID, highlighted_mode, &mode)) {
SDL_Log("Couldn't get display mode");
} else {
SDL_SetWindowDisplayMode(window, &mode);