egl: drop unused _EGLDriver from QueryBufferAge()
[mesa.git] / src / egl / main / egllog.c
index babab07d8ebc0a234a717ca7ba498e8f19155cab..6a91952577fd313e48eef710974b863efb5861d4 100644 (file)
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "c11/threads.h"
+#include "util/macros.h"
+#include "util/u_string.h"
 
 #include "egllog.h"
-#include "eglstring.h"
-#include "eglmutex.h"
+
+#ifdef HAVE_ANDROID_PLATFORM
+#define LOG_TAG "EGL-MAIN"
+#if ANDROID_API_LEVEL >= 26
+#include <log/log.h>
+#else
+#include <cutils/log.h>
+#endif /* use log/log.h start from android 8 major version */
+
+#endif /* HAVE_ANDROID_PLATFORM */
 
 #define MAXSTRING 1000
 #define FALLBACK_LOG_LEVEL _EGL_WARNING
 
 
 static struct {
-   _EGLMutex mutex;
+   mtx_t mutex;
 
    EGLBoolean initialized;
    EGLint level;
-   _EGLLogProc logger;
-   EGLint num_messages;
 } logging = {
-   _EGL_MUTEX_INITIALIZER,
-   EGL_FALSE,
-   FALLBACK_LOG_LEVEL,
-   NULL,
-   0
+   .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",
 };
 
 
-/**
- * Set the function to be called when there is a message to log.
- * Note that the function will be called with an internal lock held.
- * Recursive logging is not allowed.
- */
-void
-_eglSetLogProc(_EGLLogProc logger)
-{
-   EGLint num_messages = 0;
-
-   _eglLockMutex(&logging.mutex);
-
-   if (logging.logger != logger) {
-      logging.logger = logger;
-
-      num_messages = logging.num_messages;
-      logging.num_messages = 0;
-   }
-
-   _eglUnlockMutex(&logging.mutex);
-
-   if (num_messages)
-      _eglLog(_EGL_DEBUG,
-              "New logger installed. "
-              "Messages before the new logger might not be available.");
-}
-
-
-/**
- * Set the log reporting level.
- */
-void
-_eglSetLogLevel(EGLint level)
-{
-   switch (level) {
-   case _EGL_FATAL:
-   case _EGL_WARNING:
-   case _EGL_INFO:
-   case _EGL_DEBUG:
-      _eglLockMutex(&logging.mutex);
-      logging.level = level;
-      _eglUnlockMutex(&logging.mutex);
-      break;
-   default:
-      break;
-   }
-}
-
-
 /**
  * The default logger.  It prints the message to stderr.
  */
 static void
 _eglDefaultLogger(EGLint level, const char *msg)
 {
+#ifdef HAVE_ANDROID_PLATFORM
+   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 */
 }
 
 
@@ -145,18 +113,14 @@ _eglInitLogger(void)
 
    log_env = getenv("EGL_LOG_LEVEL");
    if (log_env) {
-      for (i = 0; level_strings[i]; i++) {
-         if (_eglstrcasecmp(log_env, level_strings[i]) == 0) {
+      for (i = 0; i < ARRAY_SIZE(level_strings); i++) {
+         if (strcasecmp(log_env, level_strings[i]) == 0) {
             level = i;
             break;
          }
       }
    }
-   else {
-      level = FALLBACK_LOG_LEVEL;
-   }
 
-   logging.logger = _eglDefaultLogger;
    logging.level = (level >= 0) ? level : FALLBACK_LOG_LEVEL;
    logging.initialized = EGL_TRUE;
 
@@ -188,20 +152,17 @@ _eglLog(EGLint level, const char *fmtStr, ...)
    if (level > logging.level || level < 0)
       return;
 
-   _eglLockMutex(&logging.mutex);
+   mtx_lock(&logging.mutex);
 
-   if (logging.logger) {
-      va_start(args, fmtStr);
-      ret = vsnprintf(msg, MAXSTRING, fmtStr, args);
-      if (ret < 0 || ret >= MAXSTRING)
-         strcpy(msg, "<message truncated>");
-      va_end(args);
+   va_start(args, fmtStr);
+   ret = vsnprintf(msg, MAXSTRING, fmtStr, args);
+   if (ret < 0 || ret >= MAXSTRING)
+      strcpy(msg, "<message truncated>");
+   va_end(args);
 
-      logging.logger(level, msg);
-      logging.num_messages++;
-   }
+   _eglDefaultLogger(level, msg);
 
-   _eglUnlockMutex(&logging.mutex);
+   mtx_unlock(&logging.mutex);
 
    if (level == _EGL_FATAL)
       exit(1); /* or abort()? */