Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release-2.30.x' into MorphOS-S…
Browse files Browse the repository at this point in the history
…DL-2.30.x
  • Loading branch information
BeWorld2018 committed Jan 28, 2024
2 parents 1771975 + f6b9ebb commit 07c35e1
Show file tree
Hide file tree
Showing 81 changed files with 7,181 additions and 1,894 deletions.
1 change: 1 addition & 0 deletions VisualC/tests/testautomation/testautomation.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<ClCompile Include="..\..\..\test\testautomation_hints.c" />
<ClCompile Include="..\..\..\test\testautomation_joystick.c" />
<ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
<ClCompile Include="..\..\..\test\testautomation_log.c" />
<ClCompile Include="..\..\..\test\testautomation_main.c" />
<ClCompile Include="..\..\..\test\testautomation_math.c" />
<ClCompile Include="..\..\..\test\testautomation_mouse.c" />
Expand Down
1 change: 1 addition & 0 deletions WhatsNew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ General:
* Added support for 2 bits-per-pixel indexed surface formats
* Added the function SDL_GameControllerGetSteamHandle() to get the Steam API handle for a controller, if available
* Added the event SDL_CONTROLLERSTEAMHANDLEUPDATED which is sent when the Steam API handle for a controller changes. This could also change the name, VID, and PID of the controller.
* Added the environment variable SDL_LOGGING to control default log output

macOS:
* Added the hint SDL_HINT_JOYSTICK_IOKIT to control whether the IOKit controller driver should be used
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_blendmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ typedef enum
typedef enum
{
SDL_BLENDOPERATION_ADD = 0x1, /**< dst + src: supported by all renderers */
SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES */
SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES */
SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES */
SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES */
SDL_BLENDOPERATION_MINIMUM = 0x4, /**< min(dst, src) : supported by D3D9, D3D11 */
SDL_BLENDOPERATION_MAXIMUM = 0x5 /**< max(dst, src) : supported by D3D9, D3D11 */
} SDL_BlendOperation;
Expand Down
16 changes: 16 additions & 0 deletions include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,22 @@ extern "C" {
*/
#define SDL_HINT_LINUX_JOYSTICK_DEADZONES "SDL_LINUX_JOYSTICK_DEADZONES"

/**
* \brief A variable controlling the default SDL log levels.
*
* This variable is a comma separated set of category=level tokens that define the default logging levels for SDL applications.
*
* The category can be a numeric category, one of "app", "error", "assert", "system", "audio", "video", "render", "input", "test", or `*` for any unspecified category.
*
* The level can be a numeric level, one of "verbose", "debug", "info", "warn", "error", "critical", or "quiet" to disable that category.
*
* You can omit the category if you want to set the logging level for all categories.
*
* If this hint isn't set, the default log levels are equivalent to:
* "app=info,assert=warn,test=verbose,*=error"
*/
#define SDL_HINT_LOGGING "SDL_LOGGING"

/**
* \brief When set don't force the SDL app to become a foreground process
*
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" {
* By default the application category is enabled at the INFO level,
* the assert category is enabled at the WARN level, test is enabled
* at the VERBOSE level and all other categories are enabled at the
* CRITICAL level.
* ERROR level.
*/
typedef enum
{
Expand Down
162 changes: 134 additions & 28 deletions src/SDL_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "SDL_error.h"
#include "SDL_log.h"
#include "SDL_hints.h"
#include "SDL_mutex.h"
#include "SDL_log_c.h"

Expand All @@ -48,10 +49,7 @@
/* The size of the stack buffer to use for rendering log messages. */
#define SDL_MAX_LOG_MESSAGE_STACK 256

#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
#define DEFAULT_CATEGORY -1

typedef struct SDL_LogLevel
{
Expand All @@ -64,15 +62,14 @@ typedef struct SDL_LogLevel
static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message);

static SDL_LogLevel *SDL_loglevels;
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
static SDL_bool SDL_forced_priority = SDL_FALSE;
static SDL_LogPriority SDL_forced_priority_level;
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
static void *SDL_log_userdata = NULL;
static SDL_mutex *log_function_mutex = NULL;

static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
/* If this list changes, update the documentation for SDL_HINT_LOGGING */
static const char *SDL_priority_prefixes[] = {
NULL,
"VERBOSE",
"DEBUG",
Expand All @@ -81,8 +78,9 @@ static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
"ERROR",
"CRITICAL"
};
SDL_COMPILE_TIME_ASSERT(priority_prefixes, SDL_arraysize(SDL_priority_prefixes) == SDL_NUM_LOG_PRIORITIES);

#ifdef __ANDROID__
/* If this list changes, update the documentation for SDL_HINT_LOGGING */
static const char *SDL_category_prefixes[] = {
"APP",
"ERROR",
Expand All @@ -94,9 +92,9 @@ static const char *SDL_category_prefixes[] = {
"INPUT",
"TEST"
};
SDL_COMPILE_TIME_ASSERT(category_prefixes, SDL_arraysize(SDL_category_prefixes) == SDL_LOG_CATEGORY_RESERVED1);

SDL_COMPILE_TIME_ASSERT(category_prefixes_enum, SDL_TABLESIZE(SDL_category_prefixes) == SDL_LOG_CATEGORY_RESERVED1);

#ifdef __ANDROID__
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
ANDROID_LOG_UNKNOWN,
ANDROID_LOG_VERBOSE,
Expand Down Expand Up @@ -132,9 +130,9 @@ void SDL_LogSetAllPriority(SDL_LogPriority priority)
for (entry = SDL_loglevels; entry; entry = entry->next) {
entry->priority = priority;
}
SDL_default_priority = priority;
SDL_assert_priority = priority;
SDL_application_priority = priority;

SDL_forced_priority = SDL_TRUE;
SDL_forced_priority_level = priority;
}

void SDL_LogSetPriority(int category, SDL_LogPriority priority)
Expand All @@ -158,6 +156,122 @@ void SDL_LogSetPriority(int category, SDL_LogPriority priority)
}
}

static SDL_bool SDL_ParseLogCategory(const char *string, size_t length, int *category)
{
int i;

if (SDL_isdigit(*string)) {
*category = SDL_atoi(string);
return SDL_TRUE;
}

if (*string == '*') {
*category = DEFAULT_CATEGORY;
return SDL_TRUE;
}

for (i = 0; i < SDL_arraysize(SDL_category_prefixes); ++i) {
if (SDL_strncasecmp(string, SDL_category_prefixes[i], length) == 0) {
*category = i;
return SDL_TRUE;
}
}
return SDL_FALSE;
}

static SDL_bool SDL_ParseLogPriority(const char *string, size_t length, SDL_LogPriority *priority)
{
int i;

if (SDL_isdigit(*string)) {
i = SDL_atoi(string);
if (i == 0) {
/* 0 has a special meaning of "disable this category" */
*priority = SDL_NUM_LOG_PRIORITIES;
return SDL_TRUE;
}
if (i >= SDL_LOG_PRIORITY_VERBOSE && i < SDL_NUM_LOG_PRIORITIES) {
*priority = (SDL_LogPriority)i;
return SDL_TRUE;
}
return SDL_FALSE;
}

if (SDL_strncasecmp(string, "quiet", length) == 0) {
*priority = SDL_NUM_LOG_PRIORITIES;
return SDL_TRUE;
}

for (i = SDL_LOG_PRIORITY_VERBOSE; i < SDL_NUM_LOG_PRIORITIES; ++i) {
if (SDL_strncasecmp(string, SDL_priority_prefixes[i], length) == 0) {
*priority = (SDL_LogPriority)i;
return SDL_TRUE;
}
}
return SDL_FALSE;
}

static SDL_bool SDL_ParseLogCategoryPriority(const char *hint, int category, SDL_LogPriority *priority)
{
const char *name, *next;
int current_category;

if (category == DEFAULT_CATEGORY && SDL_strchr(hint, '=') == NULL) {
return SDL_ParseLogPriority(hint, SDL_strlen(hint), priority);
}

for (name = hint; name; name = next) {
const char *sep = SDL_strchr(name, '=');
if (!sep) {
break;
}
next = SDL_strchr(sep, ',');
if (next) {
++next;
}

if (SDL_ParseLogCategory(name, (sep - name), &current_category)) {
if (current_category == category) {
const char *value = sep + 1;
size_t len;
if (next) {
len = (next - value - 1);
} else {
len = SDL_strlen(value);
}
return SDL_ParseLogPriority(value, len, priority);
}
}
}
return SDL_FALSE;
}

static SDL_LogPriority SDL_GetDefaultLogPriority(int category)
{
const char *hint = SDL_GetHint(SDL_HINT_LOGGING);
if (hint) {
SDL_LogPriority priority;

if (SDL_ParseLogCategoryPriority(hint, category, &priority)) {
return priority;
}
if (SDL_ParseLogCategoryPriority(hint, DEFAULT_CATEGORY, &priority)) {
return priority;
}
}

switch (category) {
case SDL_LOG_CATEGORY_APPLICATION:
return SDL_LOG_PRIORITY_INFO;
case SDL_LOG_CATEGORY_ASSERT:
return SDL_LOG_PRIORITY_WARN;
case SDL_LOG_CATEGORY_TEST:
return SDL_LOG_PRIORITY_VERBOSE;
default:
return SDL_LOG_PRIORITY_ERROR;
}
}

SDL_LogPriority SDL_LogGetPriority(int category)
{
SDL_LogLevel *entry;
Expand All @@ -168,15 +282,11 @@ SDL_LogPriority SDL_LogGetPriority(int category)
}
}

if (category == SDL_LOG_CATEGORY_TEST) {
return SDL_test_priority;
} else if (category == SDL_LOG_CATEGORY_APPLICATION) {
return SDL_application_priority;
} else if (category == SDL_LOG_CATEGORY_ASSERT) {
return SDL_assert_priority;
} else {
return SDL_default_priority;
if (SDL_forced_priority) {
return SDL_forced_priority_level;
}

return SDL_GetDefaultLogPriority(category);
}

void SDL_LogResetPriorities(void)
Expand All @@ -188,11 +298,7 @@ void SDL_LogResetPriorities(void)
SDL_loglevels = entry->next;
SDL_free(entry);
}

SDL_default_priority = DEFAULT_PRIORITY;
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
SDL_test_priority = DEFAULT_TEST_PRIORITY;
SDL_forced_priority = SDL_FALSE;
}

void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
Expand Down
Loading

0 comments on commit 07c35e1

Please sign in to comment.