[Mesa-dev] [PATCH 1/8] android: print debug info to logcat

Wu Zhen wuzhen at jidemail.com
Fri Jan 6 17:35:02 UTC 2017


From: WuZhen <wuzhen at jidemail.com>

Redirect logs printed to stderr to logcat.

Change-Id: I58e3966a608af361b86c54b4c95a92561b711968
Signed-off-by: Chih-Wei Huang <cwhuang at linux.org.tw>
Reviewed-by: Mauro Rossi <issor.oruam at gmail.com>
Reviewed-by: Chih-Wei Huang <cwhuang at linux.org.tw>
---
 src/gallium/auxiliary/os/os_misc.c   | 12 ++++++++++--
 src/gallium/auxiliary/util/u_debug.c |  2 +-
 src/gallium/targets/dri/Android.mk   |  1 +
 src/mesa/main/errors.c               |  8 ++++++++
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
index 09d4400e08..a4d962868a 100644
--- a/src/gallium/auxiliary/os/os_misc.c
+++ b/src/gallium/auxiliary/os/os_misc.c
@@ -46,8 +46,10 @@
 
 #endif
 
-
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS)
+#if defined(PIPE_OS_ANDROID)
+#  define LOG_TAG "gallium"
+#  include <log/log.h>
+#elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS)
 #  include <unistd.h>
 #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
 #  include <sys/sysctl.h>
@@ -100,6 +102,12 @@ os_log_message(const char *message)
       fflush(fout);
    }
 #else /* !PIPE_SUBSYSTEM_WINDOWS */
+#if defined(PIPE_OS_ANDROID)
+   if (fout == stderr) {
+      ALOGD("%s", message);
+      return;
+   }
+#endif
    fflush(stdout);
    fputs(message, fout);
    fflush(fout);
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index dd3e16791d..6ccc4f6ece 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -55,7 +55,7 @@ void
 _debug_vprintf(const char *format, va_list ap)
 {
    static char buf[4096] = {'\0'};
-#if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
+#if defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_ANDROID) || defined(PIPE_SUBSYSTEM_EMBEDDED)
    /* We buffer until we find a newline. */
    size_t len = strlen(buf);
    int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
diff --git a/src/gallium/targets/dri/Android.mk b/src/gallium/targets/dri/Android.mk
index 950a46420c..0333641d97 100644
--- a/src/gallium/targets/dri/Android.mk
+++ b/src/gallium/targets/dri/Android.mk
@@ -40,6 +40,7 @@ LOCAL_CFLAGS :=
 
 LOCAL_SHARED_LIBRARIES := \
 	libdl \
+	liblog \
 	libglapi \
 	libexpat \
 
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 3a40c7457a..d3121746a6 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -36,6 +36,10 @@
 #include "context.h"
 #include "debug_output.h"
 
+#if defined(ANDROID)
+#  define LOG_TAG "mesa"
+#  include <log/log.h>
+#endif
 
 static FILE *LogFile = NULL;
 
@@ -89,6 +93,10 @@ output_if_debug(const char *prefixString, const char *outputString,
          _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
          OutputDebugStringA(buf);
       }
+#elif defined(ANDROID)
+      {
+         ALOGD("%s: %s", prefixString, outputString);
+      }
 #endif
    }
 }
-- 
2.11.0



More information about the mesa-dev mailing list