Update SDL3 from 3.2.4 to 3.2.20

This commit is contained in:
Sven Balzer
2025-08-27 21:24:05 +02:00
parent 6283160467
commit ad651462df
332 changed files with 20334 additions and 4852 deletions
+1 -1
View File
@@ -411,7 +411,7 @@ add_sdl_test_executable(testdialog SOURCES testdialog.c)
add_sdl_test_executable(testtime SOURCES testtime.c)
add_sdl_test_executable(testmanymouse SOURCES testmanymouse.c)
add_sdl_test_executable(testmodal SOURCES testmodal.c)
add_sdl_test_executable(testtray SOURCES testtray.c)
add_sdl_test_executable(testtray NEEDS_RESOURCES TESTUTILS SOURCES testtray.c)
add_sdl_test_executable(testprocess
+1
View File
@@ -300,6 +300,7 @@ static void DestroyThing(Thing *thing)
}
if (thing->prev) {
SDL_assert(thing != things);
thing->prev->next = thing->next;
} else {
SDL_assert(thing == things);
+2 -2
View File
@@ -69,7 +69,7 @@ static void iteration(void)
done = 1;
}
} else if (e.type == SDL_EVENT_AUDIO_DEVICE_ADDED) {
const SDL_AudioDeviceID which = (SDL_AudioDeviceID) e.adevice.which;
const SDL_AudioDeviceID which = e.adevice.which;
const bool recording = e.adevice.recording ? true : false;
const char *name = SDL_GetAudioDeviceName(which);
if (name) {
@@ -93,7 +93,7 @@ static void iteration(void)
}
}
} else if (e.type == SDL_EVENT_AUDIO_DEVICE_REMOVED) {
dev = (SDL_AudioDeviceID)e.adevice.which;
dev = e.adevice.which;
SDL_Log("%s device %u removed.", devtypestr(e.adevice.recording), (unsigned int)dev);
/* !!! FIXME: we need to keep track of our streams and destroy them here. */
}
+15
View File
@@ -809,6 +809,7 @@ static int SDLCALL audio_convertAudio(void *arg)
src_buf = (Uint8 *)SDL_malloc(src_len);
SDLTest_AssertCheck(src_buf != NULL, "Check src data buffer to convert is not NULL");
if (src_buf == NULL) {
SDL_DestroyAudioStream(stream);
return TEST_ABORTED;
}
@@ -819,6 +820,8 @@ static int SDLCALL audio_convertAudio(void *arg)
dst_buf = (Uint8 *)SDL_malloc(dst_len);
SDLTest_AssertCheck(dst_buf != NULL, "Check dst data buffer to convert is not NULL");
if (dst_buf == NULL) {
SDL_DestroyAudioStream(stream);
SDL_free(src_buf);
return TEST_ABORTED;
}
@@ -828,6 +831,9 @@ static int SDLCALL audio_convertAudio(void *arg)
/* Run the audio converter */
if (!SDL_PutAudioStreamData(stream, src_buf, src_len) ||
!SDL_FlushAudioStream(stream)) {
SDL_DestroyAudioStream(stream);
SDL_free(src_buf);
SDL_free(dst_buf);
return TEST_ABORTED;
}
@@ -837,6 +843,9 @@ static int SDLCALL audio_convertAudio(void *arg)
real_dst_len = SDL_GetAudioStreamData(stream, dst_buf, dst_len);
SDLTest_AssertCheck(dst_len == real_dst_len, "Verify result value; expected: %i; got: %i", dst_len, real_dst_len);
if (dst_len != real_dst_len) {
SDL_DestroyAudioStream(stream);
SDL_free(src_buf);
SDL_free(dst_buf);
return TEST_ABORTED;
}
@@ -848,6 +857,9 @@ static int SDLCALL audio_convertAudio(void *arg)
for (m = 0; m < dst_len; ++m) {
if (dst_buf[m] != dst_silence) {
SDLTest_LogError("Output buffer is not silent");
SDL_DestroyAudioStream(stream);
SDL_free(src_buf);
SDL_free(dst_buf);
return TEST_ABORTED;
}
}
@@ -1104,6 +1116,7 @@ static int SDLCALL audio_resampleLoss(void *arg)
SDLTest_AssertCheck(buf_out != NULL, "Expected output buffer to be created.");
if (buf_out == NULL) {
SDL_DestroyAudioStream(stream);
SDL_free(buf_in);
return TEST_ABORTED;
}
@@ -1114,6 +1127,7 @@ static int SDLCALL audio_resampleLoss(void *arg)
SDL_free(buf_in);
if (len_out != len_target) {
SDL_DestroyAudioStream(stream);
SDL_free(buf_out);
return TEST_ABORTED;
}
@@ -1130,6 +1144,7 @@ static int SDLCALL audio_resampleLoss(void *arg)
sum_squared_value += target * target;
}
}
SDL_DestroyAudioStream(stream);
SDL_free(buf_out);
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
+57 -12
View File
@@ -211,48 +211,93 @@ static int SDLCALL events_addDelEventWatchWithUserdata(void *arg)
*
*/
typedef struct IncrementCounterData_t
{
Uint32 delay;
int counter;
} IncrementCounterData_t;
static void SDLCALL IncrementCounter(void *userdata)
{
int *value = (int *)userdata;
*value = *value + 1;
IncrementCounterData_t *data = (IncrementCounterData_t *)userdata;
++data->counter;
}
#ifndef SDL_PLATFORM_EMSCRIPTEN /* Emscripten doesn't have threads */
static int SDLCALL IncrementCounterThread(void *userdata)
{
IncrementCounterData_t *data = (IncrementCounterData_t *)userdata;
SDL_Event event;
SDL_assert(!SDL_IsMainThread());
SDL_RunOnMainThread(IncrementCounter, userdata, false);
SDL_RunOnMainThread(IncrementCounter, userdata, true);
if (data->delay > 0) {
SDL_Delay(data->delay);
}
if (!SDL_RunOnMainThread(IncrementCounter, userdata, false)) {
SDLTest_LogError("Couldn't run IncrementCounter asynchronously on main thread: %s", SDL_GetError());
}
if (!SDL_RunOnMainThread(IncrementCounter, userdata, true)) {
SDLTest_LogError("Couldn't run IncrementCounter synchronously on main thread: %s", SDL_GetError());
}
/* Send an event to unblock the main thread, which is waiting in SDL_WaitEvent() */
event.type = SDL_EVENT_USER;
SDL_PushEvent(&event);
return 0;
}
#endif /* !SDL_PLATFORM_EMSCRIPTEN */
static int SDLCALL events_mainThreadCallbacks(void *arg)
{
int counter = 0;
IncrementCounterData_t data = { 0, 0 };
/* Make sure we're on the main thread */
SDLTest_AssertCheck(SDL_IsMainThread(), "Verify we're on the main thread");
SDL_RunOnMainThread(IncrementCounter, &counter, true);
SDLTest_AssertCheck(counter == 1, "Incremented counter on main thread, expected 1, got %d", counter);
SDL_RunOnMainThread(IncrementCounter, &data, true);
SDLTest_AssertCheck(data.counter == 1, "Incremented counter on main thread, expected 1, got %d", data.counter);
#ifndef SDL_PLATFORM_EMSCRIPTEN /* Emscripten doesn't have threads */
{
SDL_Window *window;
SDL_Thread *thread;
SDL_Event event;
thread = SDL_CreateThread(IncrementCounterThread, NULL, &counter);
window = SDL_CreateWindow("test", 0, 0, SDL_WINDOW_HIDDEN);
SDLTest_AssertCheck(window != NULL, "Create window, expected non-NULL, got %p", window);
/* Flush any pending events */
SDL_PumpEvents();
SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST);
/* Increment the counter on a thread, waiting for both calls to be queued */
thread = SDL_CreateThread(IncrementCounterThread, NULL, &data);
SDLTest_AssertCheck(thread != NULL, "Create counter thread");
/* Wait for both increment calls to be queued up */
SDL_Delay(100);
/* Run the main callbacks */
while (counter < 3) {
SDL_PumpEvents();
}
SDL_WaitEvent(&event);
SDLTest_AssertCheck(event.type == SDL_EVENT_USER, "Expected user event (0x%.4x), got 0x%.4x", SDL_EVENT_USER, (int)event.type);
SDL_WaitThread(thread, NULL);
SDLTest_AssertCheck(counter == 3, "Incremented counter on main thread, expected 3, got %d", counter);
SDLTest_AssertCheck(data.counter == 3, "Incremented counter on main thread, expected 3, got %d", data.counter);
/* Try again, but this time delay the calls until we've started waiting for events */
data.delay = 100;
thread = SDL_CreateThread(IncrementCounterThread, NULL, &data);
SDLTest_AssertCheck(thread != NULL, "Create counter thread");
/* Run the main callbacks */
SDL_WaitEvent(&event);
SDLTest_AssertCheck(event.type == SDL_EVENT_USER, "Expected user event (0x%.4x), got 0x%.4x", SDL_EVENT_USER, (int)event.type);
SDL_WaitThread(thread, NULL);
SDLTest_AssertCheck(data.counter == 5, "Incremented counter on main thread, expected 5, got %d", data.counter);
SDL_DestroyWindow(window);
}
#endif /* !SDL_PLATFORM_EMSCRIPTEN */
@@ -323,6 +323,7 @@ static int SDLCALL intrinsics_selftest(void *arg)
size_t size;
Uint32 *dest, *a, *b;
if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_uints_mul_cpu(dest, a, b, size);
@@ -333,6 +334,7 @@ static int SDLCALL intrinsics_selftest(void *arg)
size_t size;
Uint32 *dest, *a, *b;
if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_uints_add_cpu(dest, a, b, size);
@@ -343,6 +345,7 @@ static int SDLCALL intrinsics_selftest(void *arg)
size_t size;
float *dest, *a, *b;
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_floats_add_cpu(dest, a, b, size);
@@ -353,6 +356,7 @@ static int SDLCALL intrinsics_selftest(void *arg)
size_t size;
double *dest, *a, *b;
if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_doubles_add_cpu(dest, a, b, size);
@@ -373,6 +377,7 @@ static int SDLCALL intrinsics_testMMX(void *arg)
SDLTest_AssertCheck(true, "Test executable uses MMX intrinsics.");
if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_uints_add_mmx(dest, a, b, size);
@@ -401,6 +406,7 @@ static int SDLCALL intrinsics_testSSE(void *arg)
SDLTest_AssertCheck(true, "Test executable uses SSE intrinsics.");
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_floats_add_sse(dest, a, b, size);
@@ -429,6 +435,7 @@ static int SDLCALL intrinsics_testSSE2(void *arg)
SDLTest_AssertCheck(true, "Test executable uses SSE2 intrinsics.");
if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_doubles_add_sse2(dest, a, b, size);
@@ -457,6 +464,7 @@ static int SDLCALL intrinsics_testSSE3(void *arg)
SDLTest_AssertCheck(true, "Test executable uses SSE3 intrinsics.");
if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_uints_add_sse3(dest, a, b, size);
@@ -485,6 +493,7 @@ static int SDLCALL intrinsics_testSSE4_1(void *arg)
SDLTest_AssertCheck(true, "Test executable uses SSE4.1 intrinsics.");
if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_uints_mul_sse4_1(dest, a, b, size);
@@ -548,6 +557,7 @@ static int SDLCALL intrinsics_testAVX(void *arg)
SDLTest_AssertCheck(true, "Test executable uses AVX intrinsics.");
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_floats_add_avx(dest, a, b, size);
@@ -576,6 +586,7 @@ static int SDLCALL intrinsics_testAVX2(void *arg)
SDLTest_AssertCheck(true, "Test executable uses AVX2 intrinsics.");
if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_uints_add_avx2(dest, a, b, size);
@@ -604,6 +615,7 @@ static int SDLCALL intrinsics_testAVX512F(void *arg)
SDLTest_AssertCheck(true, "Test executable uses AVX512F intrinsics.");
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
free_arrays(dest, a, b);
return TEST_ABORTED;
}
kernel_floats_add_avx512f(dest, a, b, size);
+133 -2
View File
@@ -1439,8 +1439,8 @@ static int SDLCALL render_testUVWrapping(void *arg)
rect.w = (float)tface->w * 2;
rect.h = (float)tface->h * 2;
rect.x = (float)(TESTRENDER_SCREEN_W - rect.w) / 2;
rect.y = (float)(TESTRENDER_SCREEN_H - rect.h) / 2;
rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
/*
* 0--1
@@ -1512,6 +1512,132 @@ static int SDLCALL render_testUVWrapping(void *arg)
return TEST_COMPLETED;
}
/**
* Tests texture state changes
*/
static int SDLCALL render_testTextureState(void *arg)
{
const Uint8 pixels[8] = {
0x00, 0x00, 0x00, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
const SDL_Color expected[] = {
/* Step 0: plain copy */
{ 0x00, 0x00, 0x00, 0xFF },
{ 0xFF, 0xFF, 0xFF, 0xFF },
/* Step 1: color mod to red */
{ 0x00, 0x00, 0x00, 0xFF },
{ 0xFF, 0x00, 0x00, 0xFF },
/* Step 2: alpha mod to 128 (cleared to green) */
{ 0x00, 0x7F, 0x00, 0xFF },
{ 0x80, 0xFF, 0x80, 0xFF },
/* Step 3: nearest stretch */
{ 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x00, 0xFF, 0x00, 0xFF },
/* Step 4: linear stretch */
{ 0x80, 0x80, 0x80, 0xFF },
{ 0x00, 0xFF, 0x00, 0xFF },
};
SDL_Texture *texture;
SDL_Rect rect;
SDL_FRect dst;
int i;
/* Clear surface to green */
SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
/* Create 2-pixel surface. */
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 2, 1);
SDLTest_AssertCheck(texture != NULL, "Verify SDL_CreateTexture() result");
if (texture == NULL) {
return TEST_ABORTED;
}
SDL_UpdateTexture(texture, NULL, pixels, sizeof(pixels));
dst.x = 0.0f;
dst.y = 0.0f;
dst.w = 2.0f;
dst.h = 1.0f;
/* Step 0: plain copy */
SDL_RenderTexture(renderer, texture, NULL, &dst);
dst.y += 1;
/* Step 1: color mod to red */
SDL_SetTextureColorMod(texture, 0xFF, 0x00, 0x00);
SDL_RenderTexture(renderer, texture, NULL, &dst);
SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
dst.y += 1;
/* Step 2: alpha mod to 128 */
SDL_SetTextureAlphaMod(texture, 0x80);
SDL_RenderTexture(renderer, texture, NULL, &dst);
SDL_SetTextureAlphaMod(texture, 0xFF);
dst.y += 1;
/* Step 3: nearest stretch */
dst.w = 1;
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
SDL_RenderTexture(renderer, texture, NULL, &dst);
dst.y += 1;
/* Step 4: linear stretch */
dst.w = 1;
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR);
SDL_RenderTexture(renderer, texture, NULL, &dst);
dst.y += 1;
/* Verify results */
rect.x = 0;
rect.y = 0;
rect.w = 2;
rect.h = 1;
for (i = 0; i < SDL_arraysize(expected); ) {
const int MAX_DELTA = 1;
SDL_Color actual;
int deltaR, deltaG, deltaB, deltaA;
SDL_Surface *surface = SDL_RenderReadPixels(renderer, &rect);
SDL_ReadSurfacePixel(surface, 0, 0, &actual.r, &actual.g, &actual.b, &actual.a);
deltaR = (actual.r - expected[i].r);
deltaG = (actual.g - expected[i].g);
deltaB = (actual.b - expected[i].b);
deltaA = (actual.a - expected[i].a);
SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
SDL_abs(deltaG) <= MAX_DELTA &&
SDL_abs(deltaB) <= MAX_DELTA &&
SDL_abs(deltaA) <= MAX_DELTA,
"Validate left pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
expected[i].r, expected[i].g, expected[i].b, expected[i].a,
actual.r, actual.g, actual.b, actual.a);
++i;
SDL_ReadSurfacePixel(surface, 1, 0, &actual.r, &actual.g, &actual.b, &actual.a);
deltaR = (actual.r - expected[i].r);
deltaG = (actual.g - expected[i].g);
deltaB = (actual.b - expected[i].b);
deltaA = (actual.a - expected[i].a);
SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
SDL_abs(deltaG) <= MAX_DELTA &&
SDL_abs(deltaB) <= MAX_DELTA &&
SDL_abs(deltaA) <= MAX_DELTA,
"Validate right pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
expected[i].r, expected[i].g, expected[i].b, expected[i].a,
actual.r, actual.g, actual.b, actual.a);
++i;
SDL_DestroySurface(surface);
rect.y += 1;
}
/* Clean up. */
SDL_DestroyTexture(texture);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Render test cases */
@@ -1563,6 +1689,10 @@ static const SDLTest_TestCaseReference renderTestUVWrapping = {
render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED
};
static const SDLTest_TestCaseReference renderTestTextureState = {
render_testTextureState, "render_testTextureState", "Tests texture state changes", TEST_ENABLED
};
/* Sequence of Render test cases */
static const SDLTest_TestCaseReference *renderTests[] = {
&renderTestGetNumRenderDrivers,
@@ -1577,6 +1707,7 @@ static const SDLTest_TestCaseReference *renderTests[] = {
&renderTestClipRect,
&renderTestLogicalSize,
&renderTestUVWrapping,
&renderTestTextureState,
NULL
};
+49 -27
View File
@@ -731,6 +731,7 @@ static int SDLCALL stdlib_getsetenv(void *arg)
#endif
#define FMT_PRILLd "%" SDL_PRILLd
#define FMT_PRILLdn "%" SDL_PRILLd "%" SDL_PRILL_PREFIX "n"
#define FMT_PRILLu "%" SDL_PRILLu
/**
@@ -740,14 +741,16 @@ static int SDLCALL stdlib_sscanf(void *arg)
{
int output;
int result;
int length;
int expected_output;
int expected_result;
short short_output, expected_short_output;
long long_output, expected_long_output;
long long long_long_output, expected_long_long_output;
short short_output, expected_short_output, short_length;
long long_output, expected_long_output, long_length;
long long long_long_output, expected_long_long_output, long_long_length;
size_t size_output, expected_size_output;
void *ptr_output, *expected_ptr_output;
char text[128], text2[128];
unsigned int r = 0, g = 0, b = 0;
expected_output = output = 123;
expected_result = -1;
@@ -764,43 +767,62 @@ static int SDLCALL stdlib_sscanf(void *arg)
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
output = 123;
length = 0;
expected_output = 2;
expected_result = 1;
result = SDL_sscanf("2", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
result = SDL_sscanf("2", "%i%n", &output, &length);
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i%%n\", &output, &length)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
output = 123;
length = 0;
expected_output = 0xa;
expected_result = 1;
result = SDL_sscanf("aa", "%1x", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x\", &output)");
result = SDL_sscanf("aa", "%1x%n", &output, &length);
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x%%n\", &output, &length)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
#define SIZED_TEST_CASE(type, var, format_specifier) \
var##_output = 123; \
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
\
var##_output = 123; \
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
expected_result = 3;
result = SDL_sscanf("#026", "#%1x%1x%1x", &r, &g, &b);
SDLTest_AssertPass("Call to SDL_sscanf(\"#026\", \"#%%1x%%1x%%1x\", &r, &g, &b)");
expected_output = 0;
SDLTest_AssertCheck(r == expected_output, "Check output for r, expected: %i, got: %i", expected_output, r);
expected_output = 2;
SDLTest_AssertCheck(g == expected_output, "Check output for g, expected: %i, got: %i", expected_output, g);
expected_output = 6;
SDLTest_AssertCheck(b == expected_output, "Check output for b, expected: %i, got: %i", expected_output, b);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SIZED_TEST_CASE(short, short, "%hd")
SIZED_TEST_CASE(long, long, "%ld")
SIZED_TEST_CASE(long long, long_long, FMT_PRILLd)
#define SIZED_TEST_CASE(type, var, printf_specifier, scanf_specifier) \
var##_output = 123; \
var##_length = 0; \
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), printf_specifier, expected_##var##_output); \
result = SDL_sscanf(text, scanf_specifier, &var##_output, &var##_length); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", %s, &output, &length)", text, #scanf_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " printf_specifier ", got: " printf_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
SDLTest_AssertCheck(var##_length == (type)SDL_strlen(text), "Check length, expected: %i, got: %i", (int)SDL_strlen(text), (int)var##_length); \
\
var##_output = 123; \
var##_length = 0; \
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), printf_specifier, expected_##var##_output); \
result = SDL_sscanf(text, scanf_specifier, &var##_output, &var##_length); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", %s, &output, &length)", text, #scanf_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " printf_specifier ", got: " printf_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
SDLTest_AssertCheck(var##_length == (type)SDL_strlen(text), "Check length, expected: %i, got: %i", (int)SDL_strlen(text), (int)var##_length); \
SIZED_TEST_CASE(short, short, "%hd", "%hd%hn")
SIZED_TEST_CASE(long, long, "%ld", "%ld%ln")
SIZED_TEST_CASE(long long, long_long, FMT_PRILLd, FMT_PRILLdn)
size_output = 123;
expected_size_output = ~((size_t)0);
+104 -2
View File
@@ -112,7 +112,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S
int deltaR, deltaG, deltaB, deltaA;
/* Create dst surface */
dst = SDL_CreateSurface(1, 1, dst_format);
dst = SDL_CreateSurface(9, 1, dst_format);
SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
if (dst == NULL) {
return;
@@ -137,7 +137,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S
SDL_GetRGBA(color, SDL_GetPixelFormatDetails(dst->format), SDL_GetSurfacePalette(dst), &dstR, &dstG, &dstB, &dstA);
/* Create src surface */
src = SDL_CreateSurface(1, 1, src_format);
src = SDL_CreateSurface(9, 1, src_format);
SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
if (src == NULL) {
return;
@@ -313,6 +313,24 @@ static void AssertFileExist(const char *filename)
/* Test case functions */
/**
* Tests creating surface with invalid format
*/
static int SDLCALL surface_testInvalidFormat(void *arg)
{
SDL_Surface *surface;
surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_UNKNOWN);
SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurface(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(32, 32, SDL_PIXELFORMAT_UNKNOWN, NULL, 0);
SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurfaceFrom(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
SDL_DestroySurface(surface);
return TEST_COMPLETED;
}
/**
* Tests sprite saving and loading
*/
@@ -941,6 +959,75 @@ static int SDLCALL surface_testBlitBlendMul(void *arg)
return TEST_COMPLETED;
}
/**
* Tests blitting invalid surfaces.
*/
static int SDLCALL surface_testBlitInvalid(void *arg)
{
SDL_Surface *valid, *invalid;
bool result;
valid = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
SDLTest_AssertCheck(valid != NULL, "Check surface creation");
invalid = SDL_CreateSurface(0, 0, SDL_PIXELFORMAT_RGBA8888);
SDLTest_AssertCheck(invalid != NULL, "Check surface creation");
SDLTest_AssertCheck(invalid->pixels == NULL, "Check surface pixels are NULL");
result = SDL_BlitSurface(invalid, NULL, valid, NULL);
SDLTest_AssertCheck(result == true, "SDL_BlitSurface(invalid, NULL, valid, NULL), result = %s\n", result ? "true" : "false");
result = SDL_BlitSurface(valid, NULL, invalid, NULL);
SDLTest_AssertCheck(result == true, "SDL_BlitSurface(valid, NULL, invalid, NULL), result = %s\n", result ? "true" : "false");
result = SDL_BlitSurfaceScaled(invalid, NULL, valid, NULL, SDL_SCALEMODE_NEAREST);
SDLTest_AssertCheck(result == false, "SDL_BlitSurfaceScaled(invalid, NULL, valid, NULL, SDL_SCALEMODE_NEAREST), result = %s\n", result ? "true" : "false");
result = SDL_BlitSurfaceScaled(valid, NULL, invalid, NULL, SDL_SCALEMODE_NEAREST);
SDLTest_AssertCheck(result == false, "SDL_BlitSurfaceScaled(valid, NULL, invalid, NULL, SDL_SCALEMODE_NEAREST), result = %s\n", result ? "true" : "false");
SDL_DestroySurface(valid);
SDL_DestroySurface(invalid);
return TEST_COMPLETED;
}
static int SDLCALL surface_testBlitsWithBadCoordinates(void *arg)
{
const SDL_Rect rect[8] = {
{ SDL_MAX_SINT32, 0, 2, 2 },
{ 0, SDL_MAX_SINT32, 2, 2 },
{ 0, 0, SDL_MAX_SINT32, 2 },
{ 0, 0, 2, SDL_MAX_SINT32 },
{ SDL_MIN_SINT32, 0, 2, 2 },
{ 0, SDL_MIN_SINT32, 2, 2 },
{ 0, 0, SDL_MIN_SINT32, 2 },
{ 0, 0, 2, SDL_MIN_SINT32 }
};
SDL_Surface *s;
bool result;
int i;
s = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
SDLTest_AssertCheck(s != NULL, "Check surface creation");
for (i = 0; i < 8; i++) {
result = SDL_BlitSurface(s, NULL, s, &rect[i]);
SDLTest_AssertCheck(result == true, "SDL_BlitSurface(valid, NULL, valid, &rect), result = %s", result ? "true" : "false");
result = SDL_BlitSurface(s, &rect[i], s, NULL);
SDLTest_AssertCheck(result == true, "SDL_BlitSurface(valid, &rect, valid, NULL), result = %s", result ? "true" : "false");
result = SDL_BlitSurfaceScaled(s, NULL, s, &rect[i], SDL_SCALEMODE_NEAREST);
SDLTest_AssertCheck(result == true, "SDL_BlitSurfaceScaled(valid, NULL, valid, &rect, SDL_SCALEMODE_NEAREST), result = %s", result ? "true" : "false");
result = SDL_BlitSurfaceScaled(s, &rect[i], s, NULL, SDL_SCALEMODE_NEAREST);
SDLTest_AssertCheck(result == true, "SDL_BlitSurfaceScaled(valid, &rect, valid, NULL, SDL_SCALEMODE_NEAREST), result = %s", result ? "true" : "false");
}
SDL_DestroySurface(s);
return TEST_COMPLETED;
}
static int SDLCALL surface_testOverflow(void *arg)
{
char buf[1024];
@@ -1540,6 +1627,10 @@ static int SDLCALL surface_testScale(void *arg)
/* ================= Test References ================== */
/* Surface test cases */
static const SDLTest_TestCaseReference surfaceTestInvalidFormat = {
surface_testInvalidFormat, "surface_testInvalidFormat", "Tests creating surface with invalid format", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
};
@@ -1608,6 +1699,14 @@ static const SDLTest_TestCaseReference surfaceTestBlitBlendMul = {
surface_testBlitBlendMul, "surface_testBlitBlendMul", "Tests blitting routines with mul blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTestBlitInvalid = {
surface_testBlitInvalid, "surface_testBlitInvalid", "Tests blitting routines with invalid surfaces.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTestBlitsWithBadCoordinates = {
surface_testBlitsWithBadCoordinates, "surface_testBlitsWithBadCoordinates", "Test blitting routines with bad coordinates.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTestOverflow = {
surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
};
@@ -1638,6 +1737,7 @@ static const SDLTest_TestCaseReference surfaceTestScale = {
/* Sequence of Surface test cases */
static const SDLTest_TestCaseReference *surfaceTests[] = {
&surfaceTestInvalidFormat,
&surfaceTestSaveLoadBitmap,
&surfaceTestBlitZeroSource,
&surfaceTestBlit,
@@ -1655,6 +1755,8 @@ static const SDLTest_TestCaseReference *surfaceTests[] = {
&surfaceTestBlitBlendAddPremultiplied,
&surfaceTestBlitBlendMod,
&surfaceTestBlitBlendMul,
&surfaceTestBlitInvalid,
&surfaceTestBlitsWithBadCoordinates,
&surfaceTestOverflow,
&surfaceTestFlip,
&surfaceTestPalette,
-2
View File
@@ -97,8 +97,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
NULL,
};
SDLTest_CommonLogUsage(state, argv[0], options);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return SDL_APP_FAILURE;
}
i += consumed;
+23 -2
View File
@@ -63,6 +63,8 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
if (event->key.key == SDLK_C && event->key.mod & SDL_KMOD_CTRL) {
SDL_SetClipboardData(ClipboardDataCallback, NULL, NULL, mime_types, SDL_arraysize(mime_types));
break;
} else if (event->key.key == SDLK_P && event->key.mod & SDL_KMOD_CTRL) {
SDL_SetPrimarySelectionText("SDL Primary Selection Text!");
}
break;
@@ -99,6 +101,15 @@ static float PrintClipboardText(float x, float y, const char *mime_type)
return 0.0f;
}
static float PrintPrimarySelectionText(float x, float y)
{
if (SDL_HasPrimarySelectionText()) {
SDL_RenderDebugText(renderer, x, y, SDL_GetPrimarySelectionText());
return SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE + 2.0f;
}
return 0.0f;
}
static float PrintClipboardImage(float x, float y, const char *mime_type)
{
/* We don't actually need to read this data each frame, but this is a simple example */
@@ -134,7 +145,7 @@ static float PrintClipboardImage(float x, float y, const char *mime_type)
return 0.0f;
}
static void PrintClipboardContents(float x, float y)
static float PrintClipboardContents(float x, float y)
{
char **clipboard_mime_types = SDL_GetClipboardMimeTypes(NULL);
if (clipboard_mime_types) {
@@ -152,6 +163,8 @@ static void PrintClipboardContents(float x, float y)
}
SDL_free(clipboard_mime_types);
}
return y;
}
SDL_AppResult SDL_AppIterate(void *appstate)
@@ -164,10 +177,18 @@ SDL_AppResult SDL_AppIterate(void *appstate)
float y = 4.0f;
SDL_RenderDebugText(renderer, x, y, "Press Ctrl+C to copy content to the clipboard");
y += SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * 2;
SDL_RenderDebugText(renderer, x, y, "Press Ctrl+P to set the primary selection text");
y += SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * 2;
SDL_RenderDebugText(renderer, x, y, "Clipboard contents:");
x += SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * 2;
y += SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE + 2;
PrintClipboardContents(x, y);
y = PrintClipboardContents(x, y);
if (SDL_HasPrimarySelectionText()) {
x = 4.0f;
SDL_RenderDebugText(renderer, x, y, "Primary selection text contents:");
y += SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE + 2;
PrintPrimarySelectionText(x + SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * 2, y);
}
SDL_RenderPresent(renderer);
+1 -1
View File
@@ -2101,7 +2101,7 @@ SDL_AppResult SDLCALL SDL_AppInit(void **appstate, int argc, char *argv[])
}
screen_width = (int)SDL_ceilf(SCREEN_WIDTH * content_scale);
screen_height = (int)SDL_ceilf(SCREEN_HEIGHT * content_scale);
window = SDL_CreateWindow("SDL Controller Test", screen_width, screen_height, 0);
window = SDL_CreateWindow("SDL Controller Test", screen_width, screen_height, SDL_WINDOW_HIGH_PIXEL_DENSITY);
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s", SDL_GetError());
return SDL_APP_FAILURE;
+4 -4
View File
@@ -15,8 +15,9 @@
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
const SDL_DialogFileFilter filters[3] = {
const SDL_DialogFileFilter filters[] = {
{ "All files", "*" },
{ "SVI Session Indexes", "index;svi-index;index.pb" },
{ "JPG images", "jpg;jpeg" },
{ "PNG images", "png" }
};
@@ -54,7 +55,6 @@ int main(int argc, char *argv[])
const SDL_FRect open_folder_rect = { 370, 50, 220, 140 };
int i;
const char *initial_path = NULL;
const int nfilters = sizeof(filters) / sizeof(*filters);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
@@ -112,11 +112,11 @@ int main(int argc, char *argv[])
* - Nonzero if the user is allowed to choose multiple entries (not for SDL_ShowSaveFileDialog)
*/
if (SDL_PointInRectFloat(&p, &open_file_rect)) {
SDL_ShowOpenFileDialog(callback, NULL, w, filters, nfilters, initial_path, 1);
SDL_ShowOpenFileDialog(callback, NULL, w, filters, SDL_arraysize(filters), initial_path, 1);
} else if (SDL_PointInRectFloat(&p, &open_folder_rect)) {
SDL_ShowOpenFolderDialog(callback, NULL, w, initial_path, 1);
} else if (SDL_PointInRectFloat(&p, &save_file_rect)) {
SDL_ShowSaveFileDialog(callback, NULL, w, filters, nfilters, initial_path);
SDL_ShowSaveFileDialog(callback, NULL, w, filters, SDL_arraysize(filters), initial_path);
}
}
}
+2 -2
View File
@@ -167,8 +167,8 @@ static void DrawRects(SDL_Renderer *renderer)
rect.w = (float)SDL_rand(viewport.h / 2);
rect.h = (float)SDL_rand(viewport.h / 2);
rect.x = (float)((SDL_rand(viewport.w * 2) - viewport.w) - (rect.w / 2));
rect.y = (float)((SDL_rand(viewport.h * 2) - viewport.h) - (rect.h / 2));
rect.x = (SDL_rand(viewport.w * 2) - viewport.w) - (rect.w / 2);
rect.y = (SDL_rand(viewport.h * 2) - viewport.h) - (rect.h / 2);
SDL_RenderFillRect(renderer, &rect);
}
}
+2 -2
View File
@@ -50,8 +50,8 @@ static void DrawChessBoard(void)
rect.w = (float)(darea.w / 8);
rect.h = (float)(darea.h / 8);
rect.x = (float)(x * rect.w);
rect.y = (float)(row * rect.h);
rect.x = x * rect.w;
rect.y = row * rect.h;
x = x + 2;
SDL_RenderFillRect(renderer, &rect);
+17
View File
@@ -679,6 +679,16 @@ void SetupVulkanRenderProperties(VulkanVideoContext *context, SDL_PropertiesID p
SDL_SetNumberProperty(props, SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER, context->graphicsQueueFamilyIndex);
}
#if LIBAVUTIL_VERSION_MAJOR >= 59
static void AddQueueFamily(AVVulkanDeviceContext *ctx, int idx, int num, VkQueueFlagBits flags)
{
AVVulkanDeviceQueueFamily *entry = &ctx->qf[ctx->nb_qf++];
entry->idx = idx;
entry->num = num;
entry->flags = flags;
}
#endif /* LIBAVUTIL_VERSION_MAJOR */
void SetupVulkanDeviceContextData(VulkanVideoContext *context, AVVulkanDeviceContext *ctx)
{
ctx->get_proc_addr = context->vkGetInstanceProcAddr;
@@ -690,6 +700,12 @@ void SetupVulkanDeviceContextData(VulkanVideoContext *context, AVVulkanDeviceCon
ctx->nb_enabled_inst_extensions = context->instanceExtensionsCount;
ctx->enabled_dev_extensions = context->deviceExtensions;
ctx->nb_enabled_dev_extensions = context->deviceExtensionsCount;
#if LIBAVUTIL_VERSION_MAJOR >= 59
AddQueueFamily(ctx, context->graphicsQueueFamilyIndex, context->graphicsQueueCount, VK_QUEUE_GRAPHICS_BIT);
AddQueueFamily(ctx, context->transferQueueFamilyIndex, context->transferQueueCount, VK_QUEUE_TRANSFER_BIT);
AddQueueFamily(ctx, context->computeQueueFamilyIndex, context->computeQueueCount, VK_QUEUE_COMPUTE_BIT);
AddQueueFamily(ctx, context->decodeQueueFamilyIndex, context->decodeQueueCount, VK_QUEUE_VIDEO_DECODE_BIT_KHR);
#else
ctx->queue_family_index = context->graphicsQueueFamilyIndex;
ctx->nb_graphics_queues = context->graphicsQueueCount;
ctx->queue_family_tx_index = context->transferQueueFamilyIndex;
@@ -700,6 +716,7 @@ void SetupVulkanDeviceContextData(VulkanVideoContext *context, AVVulkanDeviceCon
ctx->nb_encode_queues = 0;
ctx->queue_family_decode_index = context->decodeQueueFamilyIndex;
ctx->nb_decode_queues = context->decodeQueueCount;
#endif /* LIBAVUTIL_VERSION_MAJOR */
}
static int CreateCommandBuffers(VulkanVideoContext *context, SDL_Renderer *renderer)
+1 -1
View File
@@ -152,7 +152,7 @@ perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
* major. In-place multiplication is supported.
*/
static void
multiply_matrix(float *lhs, float *rhs, float *r)
multiply_matrix(const float *lhs, const float *rhs, float *r)
{
int i, j, k;
float tmp[16];
+1 -1
View File
@@ -97,7 +97,7 @@ int main(int argc, char *argv[])
}
if (e.key.key == SDLK_M) {
if (SDL_SetWindowParent(w2, w2)) {
if (SDL_SetWindowParent(w2, w1)) {
if (SDL_SetWindowModal(w2, true)) {
SDL_SetWindowTitle(w2, "Modal Window");
}
+43 -5
View File
@@ -49,6 +49,9 @@ struct PopupWindow
static struct PopupWindow *menus;
static struct PopupWindow tooltip;
static bool no_constraints;
static bool no_grab;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void quit(int rc)
{
@@ -95,14 +98,27 @@ static bool create_popup(struct PopupWindow *new_popup, bool is_menu)
const int w = is_menu ? MENU_WIDTH : TOOLTIP_WIDTH;
const int h = is_menu ? MENU_HEIGHT : TOOLTIP_HEIGHT;
const int v_off = is_menu ? 0 : 32;
const SDL_WindowFlags flags = is_menu ? SDL_WINDOW_POPUP_MENU : SDL_WINDOW_TOOLTIP;
float x, y;
focus = SDL_GetMouseFocus();
SDL_GetMouseState(&x, &y);
new_win = SDL_CreatePopupWindow(focus,
(int)x, (int)y + v_off, w, h, flags);
SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_PARENT_POINTER, focus);
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN, !no_constraints);
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN, !no_grab);
if (is_menu) {
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_MENU_BOOLEAN, true);
} else {
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_TOOLTIP_BOOLEAN, true);
}
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, w);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, (int)x);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, (int)y + v_off);
new_win = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
if (new_win) {
new_renderer = SDL_CreateRenderer(new_win, state->renderdriver);
@@ -249,8 +265,30 @@ int main(int argc, char *argv[])
}
/* Parse commandline */
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
consumed = -1;
if (SDL_strcasecmp(argv[i], "--no-constraints") == 0) {
no_constraints = true;
consumed = 1;
} else if (SDL_strcasecmp(argv[i], "--no-grab") == 0) {
no_grab = true;
consumed = 1;
}
}
if (consumed < 0) {
static const char *options[] = {
"[--no-constraints]",
"[--no-grab]",
NULL
};
SDLTest_CommonLogUsage(state, argv[0], options);
return 1;
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
+2 -2
View File
@@ -75,8 +75,8 @@ static void Draw(DrawState *s)
s->scale_direction = 1;
}
}
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
SDL_RenderTextureRotated(s->renderer, s->sprite, NULL, &s->sprite_rect, (double)s->sprite_rect.w, center, SDL_FLIP_NONE);
+4 -4
View File
@@ -113,8 +113,8 @@ DrawComposite(DrawState *s)
s->scale_direction = 1;
}
}
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
SDL_RenderTexture(s->renderer, s->sprite, NULL, &s->sprite_rect);
@@ -168,8 +168,8 @@ Draw(DrawState *s)
s->scale_direction = 1;
}
}
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
SDL_RenderTexture(s->renderer, s->sprite, NULL, &s->sprite_rect);
+2 -2
View File
@@ -68,8 +68,8 @@ static void Draw(DrawState *s)
s->scale_direction = 1;
}
}
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
SDL_RenderTexture(s->renderer, s->sprite, NULL, &s->sprite_rect);
+7 -3
View File
@@ -1,3 +1,4 @@
#include "testutils.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
@@ -520,14 +521,17 @@ int main(int argc, char **argv)
goto quit;
}
/* TODO: Resource paths? */
SDL_Surface *icon = SDL_LoadBMP("../test/sdl-test_round.bmp");
char *icon1filename = GetResourceFilename(NULL, "sdl-test_round.bmp");
SDL_Surface *icon = SDL_LoadBMP(icon1filename);
SDL_free(icon1filename);
if (!icon) {
SDL_Log("Couldn't load icon 1, proceeding without: %s", SDL_GetError());
}
SDL_Surface *icon2 = SDL_LoadBMP("../test/speaker.bmp");
char *icon2filename = GetResourceFilename(NULL, "speaker.bmp");
SDL_Surface *icon2 = SDL_LoadBMP(icon2filename);
SDL_free(icon2filename);
if (!icon2) {
SDL_Log("Couldn't load icon 2, proceeding without: %s", SDL_GetError());
+1 -1
View File
@@ -85,7 +85,7 @@ static void DrawOnViewport(SDL_Renderer *renderer)
/* Add a box at the top */
rect.w = 8.0f;
rect.h = 8.0f;
rect.x = (float)((viewport.w - rect.w) / 2);
rect.x = (viewport.w - rect.w) / 2;
rect.y = 0.0f;
SDL_RenderFillRect(renderer, &rect);