#include <string.h>
#include <strings.h>
#include "c11/threads.h"
+#include "util/macros.h"
#include "egllog.h"
#ifdef HAVE_ANDROID_PLATFORM
#define LOG_TAG "EGL-MAIN"
+#if ANDROID_API_LEVEL >= 26
+#include <log/log.h>
+#else
#include <cutils/log.h>
-
-/* support versions < JellyBean */
-#ifndef ALOGW
-#define ALOGW LOGW
-#endif
-#ifndef ALOGD
-#define ALOGD LOGD
-#endif
-#ifndef ALOGI
-#define ALOGI LOGI
-#endif
+#endif /* use log/log.h start from android 8 major version */
#endif /* HAVE_ANDROID_PLATFORM */
EGLBoolean initialized;
EGLint level;
} logging = {
- _MTX_INITIALIZER_NP,
- EGL_FALSE,
- FALLBACK_LOG_LEVEL,
+ .mutex = _MTX_INITIALIZER_NP,
+ .initialized = EGL_FALSE,
+ .level = FALLBACK_LOG_LEVEL,
};
static const char *level_strings[] = {
- /* the order is important */
- "fatal",
- "warning",
- "info",
- "debug",
- NULL
+ [_EGL_FATAL] = "fatal",
+ [_EGL_WARNING] = "warning",
+ [_EGL_INFO] = "info",
+ [_EGL_DEBUG] = "debug",
};
_eglDefaultLogger(EGLint level, const char *msg)
{
#ifdef HAVE_ANDROID_PLATFORM
- switch (level) {
- case _EGL_DEBUG:
- ALOGD("%s", msg);
- break;
- case _EGL_INFO:
- ALOGI("%s", msg);
- break;
- case _EGL_WARNING:
- ALOGW("%s", msg);
- break;
- case _EGL_FATAL:
- LOG_FATAL("%s", msg);
- break;
- default:
- break;
- }
+ static const int egl2alog[] = {
+ [_EGL_FATAL] = ANDROID_LOG_ERROR,
+ [_EGL_WARNING] = ANDROID_LOG_WARN,
+ [_EGL_INFO] = ANDROID_LOG_INFO,
+ [_EGL_DEBUG] = ANDROID_LOG_DEBUG,
+ };
+ LOG_PRI(egl2alog[level], LOG_TAG, "%s", msg);
#else
fprintf(stderr, "libEGL %s: %s\n", level_strings[level], msg);
#endif /* HAVE_ANDROID_PLATFORM */
log_env = getenv("EGL_LOG_LEVEL");
if (log_env) {
- for (i = 0; level_strings[i]; i++) {
+ for (i = 0; i < ARRAY_SIZE(level_strings); i++) {
if (strcasecmp(log_env, level_strings[i]) == 0) {
level = i;
break;