| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,284 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> | ||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
|
|
||
| #ifndef _SDL_assert_h | ||
| #define _SDL_assert_h | ||
|
|
||
| #include "SDL_config.h" | ||
|
|
||
| #include "begin_code.h" | ||
| /* Set up for C function definitions, even when using C++ */ | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #ifndef SDL_ASSERT_LEVEL | ||
| #ifdef SDL_DEFAULT_ASSERT_LEVEL | ||
| #define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL | ||
| #elif defined(_DEBUG) || defined(DEBUG) || \ | ||
| (defined(__GNUC__) && !defined(__OPTIMIZE__)) | ||
| #define SDL_ASSERT_LEVEL 2 | ||
| #else | ||
| #define SDL_ASSERT_LEVEL 1 | ||
| #endif | ||
| #endif /* SDL_ASSERT_LEVEL */ | ||
|
|
||
| /* | ||
| These are macros and not first class functions so that the debugger breaks | ||
| on the assertion line and not in some random guts of SDL, and so each | ||
| assert can have unique static variables associated with it. | ||
| */ | ||
|
|
||
| #if defined(_MSC_VER) | ||
| /* Don't include intrin.h here because it contains C++ code */ | ||
| extern void __cdecl __debugbreak(void); | ||
| #define SDL_TriggerBreakpoint() __debugbreak() | ||
| #elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) | ||
| #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" ) | ||
| #elif defined(HAVE_SIGNAL_H) | ||
| #include <signal.h> | ||
| #define SDL_TriggerBreakpoint() raise(SIGTRAP) | ||
| #else | ||
| /* How do we trigger breakpoints on this platform? */ | ||
| #define SDL_TriggerBreakpoint() | ||
| #endif | ||
|
|
||
| #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */ | ||
| # define SDL_FUNCTION __func__ | ||
| #elif ((__GNUC__ >= 2) || defined(_MSC_VER)) | ||
| # define SDL_FUNCTION __FUNCTION__ | ||
| #else | ||
| # define SDL_FUNCTION "???" | ||
| #endif | ||
| #define SDL_FILE __FILE__ | ||
| #define SDL_LINE __LINE__ | ||
|
|
||
| /* | ||
| sizeof (x) makes the compiler still parse the expression even without | ||
| assertions enabled, so the code is always checked at compile time, but | ||
| doesn't actually generate code for it, so there are no side effects or | ||
| expensive checks at run time, just the constant size of what x WOULD be, | ||
| which presumably gets optimized out as unused. | ||
| This also solves the problem of... | ||
| int somevalue = blah(); | ||
| SDL_assert(somevalue == 1); | ||
| ...which would cause compiles to complain that somevalue is unused if we | ||
| disable assertions. | ||
| */ | ||
|
|
||
| #ifdef _MSC_VER /* stupid /W4 warnings. */ | ||
| #define SDL_NULL_WHILE_LOOP_CONDITION (-1 == __LINE__) | ||
| #else | ||
| #define SDL_NULL_WHILE_LOOP_CONDITION (0) | ||
| #endif | ||
|
|
||
| #define SDL_disabled_assert(condition) \ | ||
| do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION) | ||
|
|
||
| typedef enum | ||
| { | ||
| SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */ | ||
| SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */ | ||
| SDL_ASSERTION_ABORT, /**< Terminate the program. */ | ||
| SDL_ASSERTION_IGNORE, /**< Ignore the assert. */ | ||
| SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */ | ||
| } SDL_assert_state; | ||
|
|
||
| typedef struct SDL_assert_data | ||
| { | ||
| int always_ignore; | ||
| unsigned int trigger_count; | ||
| const char *condition; | ||
| const char *filename; | ||
| int linenum; | ||
| const char *function; | ||
| const struct SDL_assert_data *next; | ||
| } SDL_assert_data; | ||
|
|
||
| #if (SDL_ASSERT_LEVEL > 0) | ||
|
|
||
| /* Never call this directly. Use the SDL_assert* macros. */ | ||
| extern DECLSPEC SDL_assert_state SDLCALL SDL_ReportAssertion(SDL_assert_data *, | ||
| const char *, | ||
| const char *, int) | ||
| #if defined(__clang__) | ||
| #if __has_feature(attribute_analyzer_noreturn) | ||
| /* this tells Clang's static analysis that we're a custom assert function, | ||
| and that the analyzer should assume the condition was always true past this | ||
| SDL_assert test. */ | ||
| __attribute__((analyzer_noreturn)) | ||
| #endif | ||
| #endif | ||
| ; | ||
|
|
||
| /* the do {} while(0) avoids dangling else problems: | ||
| if (x) SDL_assert(y); else blah(); | ||
| ... without the do/while, the "else" could attach to this macro's "if". | ||
| We try to handle just the minimum we need here in a macro...the loop, | ||
| the static vars, and break points. The heavy lifting is handled in | ||
| SDL_ReportAssertion(), in SDL_assert.c. | ||
| */ | ||
| #define SDL_enabled_assert(condition) \ | ||
| do { \ | ||
| while ( !(condition) ) { \ | ||
| static struct SDL_assert_data assert_data = { \ | ||
| 0, 0, #condition, 0, 0, 0, 0 \ | ||
| }; \ | ||
| const SDL_assert_state state = SDL_ReportAssertion(&assert_data, \ | ||
| SDL_FUNCTION, \ | ||
| SDL_FILE, \ | ||
| SDL_LINE); \ | ||
| if (state == SDL_ASSERTION_RETRY) { \ | ||
| continue; /* go again. */ \ | ||
| } else if (state == SDL_ASSERTION_BREAK) { \ | ||
| SDL_TriggerBreakpoint(); \ | ||
| } \ | ||
| break; /* not retrying. */ \ | ||
| } \ | ||
| } while (SDL_NULL_WHILE_LOOP_CONDITION) | ||
|
|
||
| #endif /* enabled assertions support code */ | ||
|
|
||
| /* Enable various levels of assertions. */ | ||
| #if SDL_ASSERT_LEVEL == 0 /* assertions disabled */ | ||
| # define SDL_assert(condition) SDL_disabled_assert(condition) | ||
| # define SDL_assert_release(condition) SDL_disabled_assert(condition) | ||
| # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition) | ||
| #elif SDL_ASSERT_LEVEL == 1 /* release settings. */ | ||
| # define SDL_assert(condition) SDL_disabled_assert(condition) | ||
| # define SDL_assert_release(condition) SDL_enabled_assert(condition) | ||
| # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition) | ||
| #elif SDL_ASSERT_LEVEL == 2 /* normal settings. */ | ||
| # define SDL_assert(condition) SDL_enabled_assert(condition) | ||
| # define SDL_assert_release(condition) SDL_enabled_assert(condition) | ||
| # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition) | ||
| #elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */ | ||
| # define SDL_assert(condition) SDL_enabled_assert(condition) | ||
| # define SDL_assert_release(condition) SDL_enabled_assert(condition) | ||
| # define SDL_assert_paranoid(condition) SDL_enabled_assert(condition) | ||
| #else | ||
| # error Unknown assertion level. | ||
| #endif | ||
|
|
||
| /* this assertion is never disabled at any level. */ | ||
| #define SDL_assert_always(condition) SDL_enabled_assert(condition) | ||
|
|
||
|
|
||
| typedef SDL_assert_state (SDLCALL *SDL_AssertionHandler)( | ||
| const SDL_assert_data* data, void* userdata); | ||
|
|
||
| /** | ||
| * \brief Set an application-defined assertion handler. | ||
| * | ||
| * This allows an app to show its own assertion UI and/or force the | ||
| * response to an assertion failure. If the app doesn't provide this, SDL | ||
| * will try to do the right thing, popping up a system-specific GUI dialog, | ||
| * and probably minimizing any fullscreen windows. | ||
| * | ||
| * This callback may fire from any thread, but it runs wrapped in a mutex, so | ||
| * it will only fire from one thread at a time. | ||
| * | ||
| * Setting the callback to NULL restores SDL's original internal handler. | ||
| * | ||
| * This callback is NOT reset to SDL's internal handler upon SDL_Quit()! | ||
| * | ||
| * \return SDL_assert_state value of how to handle the assertion failure. | ||
| * | ||
| * \param handler Callback function, called when an assertion fails. | ||
| * \param userdata A pointer passed to the callback as-is. | ||
| */ | ||
| extern DECLSPEC void SDLCALL SDL_SetAssertionHandler( | ||
| SDL_AssertionHandler handler, | ||
| void *userdata); | ||
|
|
||
| /** | ||
| * \brief Get the default assertion handler. | ||
| * | ||
| * This returns the function pointer that is called by default when an | ||
| * assertion is triggered. This is an internal function provided by SDL, | ||
| * that is used for assertions when SDL_SetAssertionHandler() hasn't been | ||
| * used to provide a different function. | ||
| * | ||
| * \return The default SDL_AssertionHandler that is called when an assert triggers. | ||
| */ | ||
| extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void); | ||
|
|
||
| /** | ||
| * \brief Get the current assertion handler. | ||
| * | ||
| * This returns the function pointer that is called when an assertion is | ||
| * triggered. This is either the value last passed to | ||
| * SDL_SetAssertionHandler(), or if no application-specified function is | ||
| * set, is equivalent to calling SDL_GetDefaultAssertionHandler(). | ||
| * | ||
| * \param puserdata Pointer to a void*, which will store the "userdata" | ||
| * pointer that was passed to SDL_SetAssertionHandler(). | ||
| * This value will always be NULL for the default handler. | ||
| * If you don't care about this data, it is safe to pass | ||
| * a NULL pointer to this function to ignore it. | ||
| * \return The SDL_AssertionHandler that is called when an assert triggers. | ||
| */ | ||
| extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puserdata); | ||
|
|
||
| /** | ||
| * \brief Get a list of all assertion failures. | ||
| * | ||
| * Get all assertions triggered since last call to SDL_ResetAssertionReport(), | ||
| * or the start of the program. | ||
| * | ||
| * The proper way to examine this data looks something like this: | ||
| * | ||
| * <code> | ||
| * const SDL_assert_data *item = SDL_GetAssertionReport(); | ||
| * while (item) { | ||
| * printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n", | ||
| * item->condition, item->function, item->filename, | ||
| * item->linenum, item->trigger_count, | ||
| * item->always_ignore ? "yes" : "no"); | ||
| * item = item->next; | ||
| * } | ||
| * </code> | ||
| * | ||
| * \return List of all assertions. | ||
| * \sa SDL_ResetAssertionReport | ||
| */ | ||
| extern DECLSPEC const SDL_assert_data * SDLCALL SDL_GetAssertionReport(void); | ||
|
|
||
| /** | ||
| * \brief Reset the list of all assertion failures. | ||
| * | ||
| * Reset list of all assertions triggered. | ||
| * | ||
| * \sa SDL_GetAssertionReport | ||
| */ | ||
| extern DECLSPEC void SDLCALL SDL_ResetAssertionReport(void); | ||
|
|
||
| /* Ends C function definitions when using C++ */ | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #include "close_code.h" | ||
|
|
||
| #endif /* _SDL_assert_h */ | ||
|
|
||
| /* vi: set ts=4 sw=4 expandtab: */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,260 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> | ||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
|
|
||
| /** | ||
| * \file SDL_atomic.h | ||
| * | ||
| * Atomic operations. | ||
| * | ||
| * IMPORTANT: | ||
| * If you are not an expert in concurrent lockless programming, you should | ||
| * only be using the atomic lock and reference counting functions in this | ||
| * file. In all other cases you should be protecting your data structures | ||
| * with full mutexes. | ||
| * | ||
| * The list of "safe" functions to use are: | ||
| * SDL_AtomicLock() | ||
| * SDL_AtomicUnlock() | ||
| * SDL_AtomicIncRef() | ||
| * SDL_AtomicDecRef() | ||
| * | ||
| * Seriously, here be dragons! | ||
| * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| * | ||
| * You can find out a little more about lockless programming and the | ||
| * subtle issues that can arise here: | ||
| * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx | ||
| * | ||
| * There's also lots of good information here: | ||
| * http://www.1024cores.net/home/lock-free-algorithms | ||
| * http://preshing.com/ | ||
| * | ||
| * These operations may or may not actually be implemented using | ||
| * processor specific atomic operations. When possible they are | ||
| * implemented as true processor specific atomic operations. When that | ||
| * is not possible the are implemented using locks that *do* use the | ||
| * available atomic operations. | ||
| * | ||
| * All of the atomic operations that modify memory are full memory barriers. | ||
| */ | ||
|
|
||
| #ifndef _SDL_atomic_h_ | ||
| #define _SDL_atomic_h_ | ||
|
|
||
| #include "SDL_stdinc.h" | ||
| #include "SDL_platform.h" | ||
|
|
||
| #include "begin_code.h" | ||
|
|
||
| /* Set up for C function definitions, even when using C++ */ | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * \name SDL AtomicLock | ||
| * | ||
| * The atomic locks are efficient spinlocks using CPU instructions, | ||
| * but are vulnerable to starvation and can spin forever if a thread | ||
| * holding a lock has been terminated. For this reason you should | ||
| * minimize the code executed inside an atomic lock and never do | ||
| * expensive things like API or system calls while holding them. | ||
| * | ||
| * The atomic locks are not safe to lock recursively. | ||
| * | ||
| * Porting Note: | ||
| * The spin lock functions and type are required and can not be | ||
| * emulated because they are used in the atomic emulation code. | ||
| */ | ||
| /* @{ */ | ||
|
|
||
| typedef int SDL_SpinLock; | ||
|
|
||
| /** | ||
| * \brief Try to lock a spin lock by setting it to a non-zero value. | ||
| * | ||
| * \param lock Points to the lock. | ||
| * | ||
| * \return SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held. | ||
| */ | ||
| extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock); | ||
|
|
||
| /** | ||
| * \brief Lock a spin lock by setting it to a non-zero value. | ||
| * | ||
| * \param lock Points to the lock. | ||
| */ | ||
| extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock); | ||
|
|
||
| /** | ||
| * \brief Unlock a spin lock by setting it to 0. Always returns immediately | ||
| * | ||
| * \param lock Points to the lock. | ||
| */ | ||
| extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); | ||
|
|
||
| /* @} *//* SDL AtomicLock */ | ||
|
|
||
|
|
||
| /** | ||
| * The compiler barrier prevents the compiler from reordering | ||
| * reads and writes to globally visible variables across the call. | ||
| */ | ||
| #if defined(_MSC_VER) && (_MSC_VER > 1200) | ||
| void _ReadWriteBarrier(void); | ||
| #pragma intrinsic(_ReadWriteBarrier) | ||
| #define SDL_CompilerBarrier() _ReadWriteBarrier() | ||
| #elif defined(__GNUC__) | ||
| #define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory") | ||
| #else | ||
| #define SDL_CompilerBarrier() \ | ||
| { SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); } | ||
| #endif | ||
|
|
||
| /** | ||
| * Memory barriers are designed to prevent reads and writes from being | ||
| * reordered by the compiler and being seen out of order on multi-core CPUs. | ||
| * | ||
| * A typical pattern would be for thread A to write some data and a flag, | ||
| * and for thread B to read the flag and get the data. In this case you | ||
| * would insert a release barrier between writing the data and the flag, | ||
| * guaranteeing that the data write completes no later than the flag is | ||
| * written, and you would insert an acquire barrier between reading the | ||
| * flag and reading the data, to ensure that all the reads associated | ||
| * with the flag have completed. | ||
| * | ||
| * In this pattern you should always see a release barrier paired with | ||
| * an acquire barrier and you should gate the data reads/writes with a | ||
| * single flag variable. | ||
| * | ||
| * For more information on these semantics, take a look at the blog post: | ||
| * http://preshing.com/20120913/acquire-and-release-semantics | ||
| */ | ||
| #if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) | ||
| #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory") | ||
| #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory") | ||
| #elif defined(__GNUC__) && defined(__arm__) | ||
| #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) | ||
| #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory") | ||
| #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory") | ||
| #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) | ||
| #ifdef __thumb__ | ||
| /* The mcr instruction isn't available in thumb mode, use real functions */ | ||
| extern DECLSPEC void SDLCALL SDL_MemoryBarrierRelease(); | ||
| extern DECLSPEC void SDLCALL SDL_MemoryBarrierAcquire(); | ||
| #else | ||
| #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory") | ||
| #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory") | ||
| #endif /* __thumb__ */ | ||
| #else | ||
| #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("" : : : "memory") | ||
| #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("" : : : "memory") | ||
| #endif /* __GNUC__ && __arm__ */ | ||
| #else | ||
| /* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */ | ||
| #define SDL_MemoryBarrierRelease() SDL_CompilerBarrier() | ||
| #define SDL_MemoryBarrierAcquire() SDL_CompilerBarrier() | ||
| #endif | ||
|
|
||
| /** | ||
| * \brief A type representing an atomic integer value. It is a struct | ||
| * so people don't accidentally use numeric operations on it. | ||
| */ | ||
| typedef struct { int value; } SDL_atomic_t; | ||
|
|
||
| /** | ||
| * \brief Set an atomic variable to a new value if it is currently an old value. | ||
| * | ||
| * \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise. | ||
| * | ||
| * \note If you don't know what this function is for, you shouldn't use it! | ||
| */ | ||
| extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval); | ||
|
|
||
| /** | ||
| * \brief Set an atomic variable to a value. | ||
| * | ||
| * \return The previous value of the atomic variable. | ||
| */ | ||
| extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int v); | ||
|
|
||
| /** | ||
| * \brief Get the value of an atomic variable | ||
| */ | ||
| extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a); | ||
|
|
||
| /** | ||
| * \brief Add to an atomic variable. | ||
| * | ||
| * \return The previous value of the atomic variable. | ||
| * | ||
| * \note This same style can be used for any number operation | ||
| */ | ||
| extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int v); | ||
|
|
||
| /** | ||
| * \brief Increment an atomic variable used as a reference count. | ||
| */ | ||
| #ifndef SDL_AtomicIncRef | ||
| #define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1) | ||
| #endif | ||
|
|
||
| /** | ||
| * \brief Decrement an atomic variable used as a reference count. | ||
| * | ||
| * \return SDL_TRUE if the variable reached zero after decrementing, | ||
| * SDL_FALSE otherwise | ||
| */ | ||
| #ifndef SDL_AtomicDecRef | ||
| #define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1) | ||
| #endif | ||
|
|
||
| /** | ||
| * \brief Set a pointer to a new value if it is currently an old value. | ||
| * | ||
| * \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise. | ||
| * | ||
| * \note If you don't know what this function is for, you shouldn't use it! | ||
| */ | ||
| extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval); | ||
|
|
||
| /** | ||
| * \brief Set a pointer to a value atomically. | ||
| * | ||
| * \return The previous value of the pointer. | ||
| */ | ||
| extern DECLSPEC void* SDLCALL SDL_AtomicSetPtr(void **a, void* v); | ||
|
|
||
| /** | ||
| * \brief Get the value of a pointer atomically. | ||
| */ | ||
| extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void **a); | ||
|
|
||
| /* Ends C function definitions when using C++ */ | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #include "close_code.h" | ||
|
|
||
| #endif /* _SDL_atomic_h_ */ | ||
|
|
||
| /* vi: set ts=4 sw=4 expandtab: */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> | ||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
|
|
||
| /** | ||
| * \file SDL_bits.h | ||
| * | ||
| * Functions for fiddling with bits and bitmasks. | ||
| */ | ||
|
|
||
| #ifndef _SDL_bits_h | ||
| #define _SDL_bits_h | ||
|
|
||
| #include "SDL_stdinc.h" | ||
|
|
||
| #include "begin_code.h" | ||
| /* Set up for C function definitions, even when using C++ */ | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * \file SDL_bits.h | ||
| */ | ||
|
|
||
| /** | ||
| * Get the index of the most significant bit. Result is undefined when called | ||
| * with 0. This operation can also be stated as "count leading zeroes" and | ||
| * "log base 2". | ||
| * | ||
| * \return Index of the most significant bit, or -1 if the value is 0. | ||
| */ | ||
| SDL_FORCE_INLINE int | ||
| SDL_MostSignificantBitIndex32(Uint32 x) | ||
| { | ||
| #if defined(__GNUC__) && __GNUC__ >= 4 | ||
| /* Count Leading Zeroes builtin in GCC. | ||
| * http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html | ||
| */ | ||
| if (x == 0) { | ||
| return -1; | ||
| } | ||
| return 31 - __builtin_clz(x); | ||
| #else | ||
| /* Based off of Bit Twiddling Hacks by Sean Eron Anderson | ||
| * <seander@cs.stanford.edu>, released in the public domain. | ||
| * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog | ||
| */ | ||
| const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; | ||
| const int S[] = {1, 2, 4, 8, 16}; | ||
|
|
||
| int msbIndex = 0; | ||
| int i; | ||
|
|
||
| if (x == 0) { | ||
| return -1; | ||
| } | ||
|
|
||
| for (i = 4; i >= 0; i--) | ||
| { | ||
| if (x & b[i]) | ||
| { | ||
| x >>= S[i]; | ||
| msbIndex |= S[i]; | ||
| } | ||
| } | ||
|
|
||
| return msbIndex; | ||
| #endif | ||
| } | ||
|
|
||
| /* Ends C function definitions when using C++ */ | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #include "close_code.h" | ||
|
|
||
| #endif /* _SDL_bits_h */ | ||
|
|
||
| /* vi: set ts=4 sw=4 expandtab: */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> | ||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
|
|
||
| /** | ||
| * \file SDL_blendmode.h | ||
| * | ||
| * Header file declaring the SDL_BlendMode enumeration | ||
| */ | ||
|
|
||
| #ifndef _SDL_blendmode_h | ||
| #define _SDL_blendmode_h | ||
|
|
||
| #include "begin_code.h" | ||
| /* Set up for C function definitions, even when using C++ */ | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * \brief The blend mode used in SDL_RenderCopy() and drawing operations. | ||
| */ | ||
| typedef enum | ||
| { | ||
| SDL_BLENDMODE_NONE = 0x00000000, /**< no blending | ||
| dstRGBA = srcRGBA */ | ||
| SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending | ||
| dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) | ||
| dstA = srcA + (dstA * (1-srcA)) */ | ||
| SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending | ||
| dstRGB = (srcRGB * srcA) + dstRGB | ||
| dstA = dstA */ | ||
| SDL_BLENDMODE_MOD = 0x00000004 /**< color modulate | ||
| dstRGB = srcRGB * dstRGB | ||
| dstA = dstA */ | ||
| } SDL_BlendMode; | ||
|
|
||
| /* Ends C function definitions when using C++ */ | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #include "close_code.h" | ||
|
|
||
| #endif /* _SDL_video_h */ | ||
|
|
||
| /* vi: set ts=4 sw=4 expandtab: */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> | ||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
|
|
||
| /** | ||
| * \file SDL_clipboard.h | ||
| * | ||
| * Include file for SDL clipboard handling | ||
| */ | ||
|
|
||
| #ifndef _SDL_clipboard_h | ||
| #define _SDL_clipboard_h | ||
|
|
||
| #include "SDL_stdinc.h" | ||
|
|
||
| #include "begin_code.h" | ||
| /* Set up for C function definitions, even when using C++ */ | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* Function prototypes */ | ||
|
|
||
| /** | ||
| * \brief Put UTF-8 text into the clipboard | ||
| * | ||
| * \sa SDL_GetClipboardText() | ||
| */ | ||
| extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text); | ||
|
|
||
| /** | ||
| * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free() | ||
| * | ||
| * \sa SDL_SetClipboardText() | ||
| */ | ||
| extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void); | ||
|
|
||
| /** | ||
| * \brief Returns a flag indicating whether the clipboard exists and contains a text string that is non-empty | ||
| * | ||
| * \sa SDL_GetClipboardText() | ||
| */ | ||
| extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void); | ||
|
|
||
|
|
||
| /* Ends C function definitions when using C++ */ | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #include "close_code.h" | ||
|
|
||
| #endif /* _SDL_clipboard_h */ | ||
|
|
||
| /* vi: set ts=4 sw=4 expandtab: */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,210 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> | ||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
|
|
||
| #ifndef _SDL_config_windows_h | ||
| #define _SDL_config_windows_h | ||
|
|
||
| #include "SDL_platform.h" | ||
|
|
||
| /* This is a set of defines to configure the SDL features */ | ||
|
|
||
| #if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) | ||
| #if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__) | ||
| #define HAVE_STDINT_H 1 | ||
| #elif defined(_MSC_VER) | ||
| typedef signed __int8 int8_t; | ||
| typedef unsigned __int8 uint8_t; | ||
| typedef signed __int16 int16_t; | ||
| typedef unsigned __int16 uint16_t; | ||
| typedef signed __int32 int32_t; | ||
| typedef unsigned __int32 uint32_t; | ||
| typedef signed __int64 int64_t; | ||
| typedef unsigned __int64 uint64_t; | ||
| #ifndef _UINTPTR_T_DEFINED | ||
| #ifdef _WIN64 | ||
| typedef unsigned __int64 uintptr_t; | ||
| #else | ||
| typedef unsigned int uintptr_t; | ||
| #endif | ||
| #define _UINTPTR_T_DEFINED | ||
| #endif | ||
| /* Older Visual C++ headers don't have the Win64-compatible typedefs... */ | ||
| #if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) | ||
| #define DWORD_PTR DWORD | ||
| #endif | ||
| #if ((_MSC_VER <= 1200) && (!defined(LONG_PTR))) | ||
| #define LONG_PTR LONG | ||
| #endif | ||
| #else /* !__GNUC__ && !_MSC_VER */ | ||
| typedef signed char int8_t; | ||
| typedef unsigned char uint8_t; | ||
| typedef signed short int16_t; | ||
| typedef unsigned short uint16_t; | ||
| typedef signed int int32_t; | ||
| typedef unsigned int uint32_t; | ||
| typedef signed long long int64_t; | ||
| typedef unsigned long long uint64_t; | ||
| #ifndef _SIZE_T_DEFINED_ | ||
| #define _SIZE_T_DEFINED_ | ||
| typedef unsigned int size_t; | ||
| #endif | ||
| typedef unsigned int uintptr_t; | ||
| #endif /* __GNUC__ || _MSC_VER */ | ||
| #endif /* !_STDINT_H_ && !HAVE_STDINT_H */ | ||
|
|
||
| #ifdef _WIN64 | ||
| # define SIZEOF_VOIDP 8 | ||
| #else | ||
| # define SIZEOF_VOIDP 4 | ||
| #endif | ||
|
|
||
| /* This is disabled by default to avoid C runtime dependencies and manifest requirements */ | ||
| #ifdef HAVE_LIBC | ||
| /* Useful headers */ | ||
| #define HAVE_STDIO_H 1 | ||
| #define STDC_HEADERS 1 | ||
| #define HAVE_STRING_H 1 | ||
| #define HAVE_CTYPE_H 1 | ||
| #define HAVE_MATH_H 1 | ||
| #define HAVE_SIGNAL_H 1 | ||
|
|
||
| /* C library functions */ | ||
| #define HAVE_MALLOC 1 | ||
| #define HAVE_CALLOC 1 | ||
| #define HAVE_REALLOC 1 | ||
| #define HAVE_FREE 1 | ||
| #define HAVE_ALLOCA 1 | ||
| #define HAVE_QSORT 1 | ||
| #define HAVE_ABS 1 | ||
| #define HAVE_MEMSET 1 | ||
| #define HAVE_MEMCPY 1 | ||
| #define HAVE_MEMMOVE 1 | ||
| #define HAVE_MEMCMP 1 | ||
| #define HAVE_STRLEN 1 | ||
| #define HAVE__STRREV 1 | ||
| #define HAVE__STRUPR 1 | ||
| #define HAVE__STRLWR 1 | ||
| #define HAVE_STRCHR 1 | ||
| #define HAVE_STRRCHR 1 | ||
| #define HAVE_STRSTR 1 | ||
| #define HAVE__LTOA 1 | ||
| #define HAVE__ULTOA 1 | ||
| #define HAVE_STRTOL 1 | ||
| #define HAVE_STRTOUL 1 | ||
| #define HAVE_STRTOD 1 | ||
| #define HAVE_ATOI 1 | ||
| #define HAVE_ATOF 1 | ||
| #define HAVE_STRCMP 1 | ||
| #define HAVE_STRNCMP 1 | ||
| #define HAVE__STRICMP 1 | ||
| #define HAVE__STRNICMP 1 | ||
| #define HAVE_ATAN 1 | ||
| #define HAVE_ATAN2 1 | ||
| #define HAVE_ACOS 1 | ||
| #define HAVE_ASIN 1 | ||
| #define HAVE_CEIL 1 | ||
| #define HAVE_COS 1 | ||
| #define HAVE_COSF 1 | ||
| #define HAVE_FABS 1 | ||
| #define HAVE_FLOOR 1 | ||
| #define HAVE_LOG 1 | ||
| #define HAVE_POW 1 | ||
| #define HAVE_SIN 1 | ||
| #define HAVE_SINF 1 | ||
| #define HAVE_SQRT 1 | ||
| #if _MSC_VER >= 1800 | ||
| #define HAVE_STRTOLL 1 | ||
| #define HAVE_VSSCANF 1 | ||
| #define HAVE_COPYSIGN 1 | ||
| #define HAVE_SCALBN 1 | ||
| #endif | ||
| #if !defined(_MSC_VER) || defined(_USE_MATH_DEFINES) | ||
| #define HAVE_M_PI 1 | ||
| #endif | ||
| #else | ||
| #define HAVE_STDARG_H 1 | ||
| #define HAVE_STDDEF_H 1 | ||
| #endif | ||
|
|
||
| /* Enable various audio drivers */ | ||
| #define SDL_AUDIO_DRIVER_DSOUND 1 | ||
| #define SDL_AUDIO_DRIVER_XAUDIO2 1 | ||
| #define SDL_AUDIO_DRIVER_WINMM 1 | ||
| #define SDL_AUDIO_DRIVER_DISK 1 | ||
| #define SDL_AUDIO_DRIVER_DUMMY 1 | ||
|
|
||
| /* Enable various input drivers */ | ||
| #define SDL_JOYSTICK_DINPUT 1 | ||
| #define SDL_HAPTIC_DINPUT 1 | ||
|
|
||
| /* Enable various shared object loading systems */ | ||
| #define SDL_LOADSO_WINDOWS 1 | ||
|
|
||
| /* Enable various threading systems */ | ||
| #define SDL_THREAD_WINDOWS 1 | ||
|
|
||
| /* Enable various timer systems */ | ||
| #define SDL_TIMER_WINDOWS 1 | ||
|
|
||
| /* Enable various video drivers */ | ||
| #define SDL_VIDEO_DRIVER_DUMMY 1 | ||
| #define SDL_VIDEO_DRIVER_WINDOWS 1 | ||
|
|
||
| #ifndef SDL_VIDEO_RENDER_D3D | ||
| #define SDL_VIDEO_RENDER_D3D 1 | ||
| #endif | ||
| #ifndef SDL_VIDEO_RENDER_D3D11 | ||
| #define SDL_VIDEO_RENDER_D3D11 0 | ||
| #endif | ||
|
|
||
| /* Enable OpenGL support */ | ||
| #ifndef SDL_VIDEO_OPENGL | ||
| #define SDL_VIDEO_OPENGL 1 | ||
| #endif | ||
| #ifndef SDL_VIDEO_OPENGL_WGL | ||
| #define SDL_VIDEO_OPENGL_WGL 1 | ||
| #endif | ||
| #ifndef SDL_VIDEO_RENDER_OGL | ||
| #define SDL_VIDEO_RENDER_OGL 1 | ||
| #endif | ||
| #ifndef SDL_VIDEO_RENDER_OGL_ES2 | ||
| #define SDL_VIDEO_RENDER_OGL_ES2 1 | ||
| #endif | ||
| #ifndef SDL_VIDEO_OPENGL_ES2 | ||
| #define SDL_VIDEO_OPENGL_ES2 1 | ||
| #endif | ||
| #ifndef SDL_VIDEO_OPENGL_EGL | ||
| #define SDL_VIDEO_OPENGL_EGL 1 | ||
| #endif | ||
|
|
||
|
|
||
| /* Enable system power support */ | ||
| #define SDL_POWER_WINDOWS 1 | ||
|
|
||
| /* Enable filesystem support */ | ||
| #define SDL_FILESYSTEM_WINDOWS 1 | ||
|
|
||
| /* Enable assembly routines (Win64 doesn't have inline asm) */ | ||
| #ifndef _WIN64 | ||
| #define SDL_ASSEMBLY_ROUTINES 1 | ||
| #endif | ||
|
|
||
| #endif /* _SDL_config_windows_h */ |