update sdl Merge commit '644725478f4de0f074a6834e8423ac36dce3974f'
This commit is contained in:
52
external/sdl/SDL/src/test/SDL_test_common.c
vendored
52
external/sdl/SDL/src/test/SDL_test_common.c
vendored
@ -25,6 +25,7 @@
|
||||
static const char *common_usage[] = {
|
||||
"[-h | --help]",
|
||||
"[--trackmem]",
|
||||
"[--randmem]",
|
||||
"[--log all|error|system|audio|video|render|input]",
|
||||
};
|
||||
|
||||
@ -70,7 +71,7 @@ static const char *video_usage[] = {
|
||||
|
||||
/* !!! FIXME: Float32? Sint32? */
|
||||
static const char *audio_usage[] = {
|
||||
"[--audio driver]", "[--rate N]", "[--format U8|S8|S16|S16LE|S16BE]",
|
||||
"[--audio driver]", "[--rate N]", "[--format U8|S8|S16|S16LE|S16BE|S32|S32LE|S32BE|F32|F32LE|F32BE]",
|
||||
"[--channels N]"
|
||||
};
|
||||
|
||||
@ -95,7 +96,8 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags)
|
||||
for (i = 1; argv[i]; ++i) {
|
||||
if (SDL_strcasecmp(argv[i], "--trackmem") == 0) {
|
||||
SDLTest_TrackAllocations();
|
||||
break;
|
||||
} else if (SDL_strcasecmp(argv[i], "--randmem") == 0) {
|
||||
SDLTest_RandFillAllocations();
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,8 +147,8 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags)
|
||||
}
|
||||
|
||||
void SDLTest_CommonDestroyState(SDLTest_CommonState *state) {
|
||||
SDLTest_LogAllocations();
|
||||
SDL_free(state);
|
||||
SDLTest_LogAllocations();
|
||||
}
|
||||
|
||||
#define SEARCHARG(dim) \
|
||||
@ -170,6 +172,10 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
|
||||
/* Already handled in SDLTest_CommonCreateState() */
|
||||
return 1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--randmem") == 0) {
|
||||
/* Already handled in SDLTest_CommonCreateState() */
|
||||
return 1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--log") == 0) {
|
||||
++index;
|
||||
if (!argv[index]) {
|
||||
@ -624,16 +630,37 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
|
||||
state->audio_format = SDL_AUDIO_S16LSB;
|
||||
state->audio_format = SDL_AUDIO_S16LE;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
|
||||
state->audio_format = SDL_AUDIO_S16MSB;
|
||||
state->audio_format = SDL_AUDIO_S16BE;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "S32") == 0) {
|
||||
state->audio_format = SDL_AUDIO_S32;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "S32LE") == 0) {
|
||||
state->audio_format = SDL_AUDIO_S32LE;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "S32BE") == 0) {
|
||||
state->audio_format = SDL_AUDIO_S32BE;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "F32") == 0) {
|
||||
state->audio_format = SDL_AUDIO_F32;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "F32LE") == 0) {
|
||||
state->audio_format = SDL_AUDIO_F32LE;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "F32BE") == 0) {
|
||||
state->audio_format = SDL_AUDIO_F32BE;
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* !!! FIXME: Float32? Sint32? */
|
||||
|
||||
return -1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--channels") == 0) {
|
||||
@ -2019,6 +2046,8 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
|
||||
{
|
||||
SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
|
||||
if (window) {
|
||||
/* Clear cache to avoid stale textures */
|
||||
SDLTest_CleanupTextDrawing();
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (window == state->windows[i]) {
|
||||
if (state->targets[i]) {
|
||||
@ -2408,7 +2437,6 @@ void SDLTest_CommonQuit(SDLTest_CommonState *state)
|
||||
common_usage_audio = NULL;
|
||||
common_usage_videoaudio = NULL;
|
||||
|
||||
SDL_free(state->windows);
|
||||
if (state->targets) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->targets[i]) {
|
||||
@ -2425,6 +2453,12 @@ void SDLTest_CommonQuit(SDLTest_CommonState *state)
|
||||
}
|
||||
SDL_free(state->renderers);
|
||||
}
|
||||
if (state->windows) {
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
SDL_DestroyWindow(state->windows[i]);
|
||||
}
|
||||
SDL_free(state->windows);
|
||||
}
|
||||
if (state->flags & SDL_INIT_VIDEO) {
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
}
|
||||
|
11
external/sdl/SDL/src/test/SDL_test_font.c
vendored
11
external/sdl/SDL/src/test/SDL_test_font.c
vendored
@ -3126,11 +3126,12 @@ struct SDLTest_CharTextureCache
|
||||
*/
|
||||
static struct SDLTest_CharTextureCache *SDLTest_CharTextureCacheList;
|
||||
|
||||
int FONT_CHARACTER_SIZE = 8;
|
||||
|
||||
int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
|
||||
{
|
||||
const Uint32 charWidth = FONT_CHARACTER_SIZE;
|
||||
const Uint32 charHeight = FONT_CHARACTER_SIZE;
|
||||
const Uint32 charSize = FONT_CHARACTER_SIZE;
|
||||
SDL_FRect srect;
|
||||
SDL_FRect drect;
|
||||
int result;
|
||||
@ -3149,8 +3150,8 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
|
||||
*/
|
||||
srect.x = 0.0f;
|
||||
srect.y = 0.0f;
|
||||
srect.w = (float)charWidth;
|
||||
srect.h = (float)charHeight;
|
||||
srect.w = 8.0f;
|
||||
srect.h = 8.0f;
|
||||
|
||||
/*
|
||||
* Setup destination rectangle
|
||||
@ -3190,7 +3191,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
|
||||
return -1;
|
||||
}
|
||||
|
||||
charpos = SDLTest_FontData + ci * charSize;
|
||||
charpos = SDLTest_FontData + ci * 8;
|
||||
linepos = (Uint8 *)character->pixels;
|
||||
pitch = character->pitch;
|
||||
|
||||
@ -3221,6 +3222,8 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
|
||||
if (cache->charTextureCache[ci] == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_SetTextureScaleMode(cache->charTextureCache[ci], SDL_SCALEMODE_NEAREST);
|
||||
}
|
||||
|
||||
/*
|
||||
|
149
external/sdl/SDL/src/test/SDL_test_memory.c
vendored
149
external/sdl/SDL/src/test/SDL_test_memory.c
vendored
@ -25,6 +25,26 @@
|
||||
#include <libunwind.h>
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
static void *s_dbghelp;
|
||||
|
||||
typedef BOOL (__stdcall *dbghelp_SymInitialize_fn)(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
|
||||
|
||||
typedef BOOL (__stdcall *dbghelp_SymFromAddr_fn)(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol);
|
||||
static dbghelp_SymFromAddr_fn dbghelp_SymFromAddr;
|
||||
|
||||
#ifdef _WIN64
|
||||
typedef BOOL (__stdcall *dbghelp_SymGetLineFromAddr_fn)(HANDLE hProcess, DWORD64 qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
|
||||
#else
|
||||
typedef BOOL (__stdcall *dbghelp_SymGetLineFromAddr_fn)(HANDLE hProcess, DWORD qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE Line);
|
||||
#endif
|
||||
static dbghelp_SymGetLineFromAddr_fn dbghelp_SymGetLineFromAddr;
|
||||
|
||||
#endif
|
||||
|
||||
/* This is a simple tracking allocator to demonstrate the use of SDL's
|
||||
memory allocation replacement functionality.
|
||||
|
||||
@ -32,12 +52,14 @@
|
||||
for production code.
|
||||
*/
|
||||
|
||||
#define MAXIMUM_TRACKED_STACK_DEPTH 32
|
||||
|
||||
typedef struct SDL_tracked_allocation
|
||||
{
|
||||
void *mem;
|
||||
size_t size;
|
||||
Uint64 stack[10];
|
||||
char stack_names[10][256];
|
||||
Uint64 stack[MAXIMUM_TRACKED_STACK_DEPTH];
|
||||
char stack_names[MAXIMUM_TRACKED_STACK_DEPTH][256];
|
||||
struct SDL_tracked_allocation *next;
|
||||
} SDL_tracked_allocation;
|
||||
|
||||
@ -48,6 +70,7 @@ static SDL_realloc_func SDL_realloc_orig = NULL;
|
||||
static SDL_free_func SDL_free_orig = NULL;
|
||||
static int s_previous_allocations = 0;
|
||||
static SDL_tracked_allocation *s_tracked_allocations[256];
|
||||
static SDL_bool s_randfill_allocations = SDL_FALSE;
|
||||
|
||||
static unsigned int get_allocation_bucket(void *mem)
|
||||
{
|
||||
@ -58,16 +81,28 @@ static unsigned int get_allocation_bucket(void *mem)
|
||||
return index;
|
||||
}
|
||||
|
||||
static SDL_bool SDL_IsAllocationTracked(void *mem)
|
||||
static SDL_tracked_allocation* SDL_GetTrackedAllocation(void *mem)
|
||||
{
|
||||
SDL_tracked_allocation *entry;
|
||||
int index = get_allocation_bucket(mem);
|
||||
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
|
||||
if (mem == entry->mem) {
|
||||
return SDL_TRUE;
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static size_t SDL_GetTrackedAllocationSize(void *mem)
|
||||
{
|
||||
SDL_tracked_allocation *entry = SDL_GetTrackedAllocation(mem);
|
||||
|
||||
return entry ? entry->size : SIZE_MAX;
|
||||
}
|
||||
|
||||
static SDL_bool SDL_IsAllocationTracked(void *mem)
|
||||
{
|
||||
return SDL_GetTrackedAllocation(mem) != NULL;
|
||||
}
|
||||
|
||||
static void SDL_TrackAllocation(void *mem, size_t size)
|
||||
@ -114,6 +149,40 @@ static void SDL_TrackAllocation(void *mem, size_t size)
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(__WINDOWS__)
|
||||
{
|
||||
Uint32 count;
|
||||
PVOID frames[63];
|
||||
Uint32 i;
|
||||
|
||||
count = CaptureStackBackTrace(1, SDL_arraysize(frames), frames, NULL);
|
||||
|
||||
entry->size = SDL_min(count, MAXIMUM_TRACKED_STACK_DEPTH);
|
||||
for (i = 0; i < entry->size; i++) {
|
||||
char symbol_buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
|
||||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)symbol_buffer;
|
||||
DWORD64 dwDisplacement = 0;
|
||||
DWORD lineColumn = 0;
|
||||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
pSymbol->MaxNameLen = MAX_SYM_NAME;
|
||||
IMAGEHLP_LINE line;
|
||||
line.SizeOfStruct = sizeof(line);
|
||||
|
||||
entry->stack[i] = (Uint64)(uintptr_t)frames[i];
|
||||
if (s_dbghelp) {
|
||||
if (!dbghelp_SymFromAddr(GetCurrentProcess(), (DWORD64)(uintptr_t)frames[i], &dwDisplacement, pSymbol)) {
|
||||
SDL_strlcpy(pSymbol->Name, "???", MAX_SYM_NAME);
|
||||
dwDisplacement = 0;
|
||||
}
|
||||
if (!dbghelp_SymGetLineFromAddr(GetCurrentProcess(), (DWORD64)(uintptr_t)frames[i], &lineColumn, &line)) {
|
||||
line.FileName = "";
|
||||
line.LineNumber = 0;
|
||||
}
|
||||
|
||||
SDL_snprintf(entry->stack_names[i], sizeof(entry->stack_names[i]), "%s+0x%llx %s:%u", pSymbol->Name, (unsigned long long)dwDisplacement, line.FileName, (Uint32)line.LineNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_LIBUNWIND_H */
|
||||
|
||||
entry->next = s_tracked_allocations[index];
|
||||
@ -140,6 +209,19 @@ static void SDL_UntrackAllocation(void *mem)
|
||||
}
|
||||
}
|
||||
|
||||
static void rand_fill_memory(void* ptr, size_t start, size_t end)
|
||||
{
|
||||
Uint8* mem = (Uint8*) ptr;
|
||||
size_t i;
|
||||
|
||||
if (!s_randfill_allocations)
|
||||
return;
|
||||
|
||||
for (i = start; i < end; ++i) {
|
||||
mem[i] = SDLTest_RandomUint8();
|
||||
}
|
||||
}
|
||||
|
||||
static void *SDLCALL SDLTest_TrackedMalloc(size_t size)
|
||||
{
|
||||
void *mem;
|
||||
@ -147,6 +229,7 @@ static void *SDLCALL SDLTest_TrackedMalloc(size_t size)
|
||||
mem = SDL_malloc_orig(size);
|
||||
if (mem) {
|
||||
SDL_TrackAllocation(mem, size);
|
||||
rand_fill_memory(mem, 0, size);
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
@ -165,14 +248,20 @@ static void *SDLCALL SDLTest_TrackedCalloc(size_t nmemb, size_t size)
|
||||
static void *SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size)
|
||||
{
|
||||
void *mem;
|
||||
|
||||
SDL_assert(ptr == NULL || SDL_IsAllocationTracked(ptr));
|
||||
size_t old_size = 0;
|
||||
if (ptr) {
|
||||
old_size = SDL_GetTrackedAllocationSize(ptr);
|
||||
SDL_assert(old_size != SIZE_MAX);
|
||||
}
|
||||
mem = SDL_realloc_orig(ptr, size);
|
||||
if (mem && mem != ptr) {
|
||||
if (ptr) {
|
||||
SDL_UntrackAllocation(ptr);
|
||||
}
|
||||
if (ptr) {
|
||||
SDL_UntrackAllocation(ptr);
|
||||
}
|
||||
if (mem) {
|
||||
SDL_TrackAllocation(mem, size);
|
||||
if (size > old_size) {
|
||||
rand_fill_memory(mem, old_size, size);
|
||||
}
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
@ -190,10 +279,10 @@ static void SDLCALL SDLTest_TrackedFree(void *ptr)
|
||||
SDL_free_orig(ptr);
|
||||
}
|
||||
|
||||
int SDLTest_TrackAllocations(void)
|
||||
void SDLTest_TrackAllocations(void)
|
||||
{
|
||||
if (SDL_malloc_orig) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
SDLTest_Crc32Init(&s_crc32_context);
|
||||
@ -202,6 +291,30 @@ int SDLTest_TrackAllocations(void)
|
||||
if (s_previous_allocations != 0) {
|
||||
SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
|
||||
}
|
||||
#ifdef __WINDOWS__
|
||||
{
|
||||
s_dbghelp = SDL_LoadObject("dbghelp.dll");
|
||||
if (s_dbghelp) {
|
||||
dbghelp_SymInitialize_fn dbghelp_SymInitialize;
|
||||
dbghelp_SymInitialize = (dbghelp_SymInitialize_fn)SDL_LoadFunction(s_dbghelp, "SymInitialize");
|
||||
dbghelp_SymFromAddr = (dbghelp_SymFromAddr_fn)SDL_LoadFunction(s_dbghelp, "SymFromAddr");
|
||||
#ifdef _WIN64
|
||||
dbghelp_SymGetLineFromAddr = (dbghelp_SymGetLineFromAddr_fn)SDL_LoadFunction(s_dbghelp, "SymGetLineFromAddr64");
|
||||
#else
|
||||
dbghelp_SymGetLineFromAddr = (dbghelp_SymGetLineFromAddr_fn)SDL_LoadFunction(s_dbghelp, "SymGetLineFromAddr");
|
||||
#endif
|
||||
if (!dbghelp_SymFromAddr || !dbghelp_SymFromAddr || !dbghelp_SymGetLineFromAddr) {
|
||||
SDL_UnloadObject(s_dbghelp);
|
||||
s_dbghelp = NULL;
|
||||
} else {
|
||||
if (!dbghelp_SymInitialize(GetCurrentProcess(), NULL, TRUE)) {
|
||||
SDL_UnloadObject(s_dbghelp);
|
||||
s_dbghelp = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_GetMemoryFunctions(&SDL_malloc_orig,
|
||||
&SDL_calloc_orig,
|
||||
@ -212,7 +325,13 @@ int SDLTest_TrackAllocations(void)
|
||||
SDLTest_TrackedCalloc,
|
||||
SDLTest_TrackedRealloc,
|
||||
SDLTest_TrackedFree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDLTest_RandFillAllocations()
|
||||
{
|
||||
SDLTest_TrackAllocations();
|
||||
|
||||
s_randfill_allocations = SDL_TRUE;
|
||||
}
|
||||
|
||||
void SDLTest_LogAllocations(void)
|
||||
@ -245,8 +364,6 @@ void SDLTest_LogAllocations(void)
|
||||
|
||||
SDL_strlcpy(line, "Memory allocations:\n", sizeof(line));
|
||||
ADD_LINE();
|
||||
SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line));
|
||||
ADD_LINE();
|
||||
|
||||
count = 0;
|
||||
total_allocated = 0;
|
||||
|
Reference in New Issue
Block a user