Change how SkDebugf is sent to stdout on Android.
Previously, a function was called using dlsym in skia_launcher.
Add a static initializer that changes the setting, and include that for
the tools we automate for testing.
Also only do va_copy if we actually use it.
BUG=skia:2454
Review URL: https://codereview.chromium.org/753543003
diff --git a/gyp/android_output.gyp b/gyp/android_output.gyp
new file mode 100644
index 0000000..b22ac9d
--- /dev/null
+++ b/gyp/android_output.gyp
@@ -0,0 +1,16 @@
+# GYP file to send android SkDebug to stdout in addition to logcat. To enable,
+# include this project as a dependency.
+{
+ 'targets': [
+ {
+ 'target_name': 'android_output',
+ 'type': 'static_library',
+ 'sources': [
+ '../tools/AndroidSkDebugToStdOut.cpp',
+ ],
+ 'dependencies': [
+ 'skia_lib.gyp:skia_lib',
+ ],
+ },
+ ],
+}
diff --git a/gyp/apptype_console.gypi b/gyp/apptype_console.gypi
index 906bea8..d375941 100644
--- a/gyp/apptype_console.gypi
+++ b/gyp/apptype_console.gypi
@@ -12,10 +12,17 @@
},
},
'conditions': [
- [ 'skia_os == "android" and not skia_android_framework', {
+ [ 'skia_os == "android"', {
+ 'conditions': [
+ ['skia_android_framework == 0', {
+ 'dependencies': [
+ 'android_deps.gyp:Android_EntryPoint',
+ 'skia_launcher.gyp:skia_launcher',
+ ],
+ }],
+ ],
'dependencies': [
- 'android_deps.gyp:Android_EntryPoint',
- 'skia_launcher.gyp:skia_launcher',
+ 'android_output.gyp:android_output',
],
}],
[ 'skia_os == "nacl"', {
diff --git a/platform_tools/android/launcher/skia_launcher.cpp b/platform_tools/android/launcher/skia_launcher.cpp
index 746d470..6cd900c 100644
--- a/platform_tools/android/launcher/skia_launcher.cpp
+++ b/platform_tools/android/launcher/skia_launcher.cpp
@@ -98,17 +98,6 @@
return -1;
}
- // find the address of the SkPrintToConsole function
- void (*app_SkDebugToStdOut)(bool);
- *(void **) (&app_SkDebugToStdOut) = dlsym(skiaLibrary, "AndroidSkDebugToStdOut");
-
- if (app_SkDebugToStdOut) {
- (*app_SkDebugToStdOut)(true);
- } else {
- printf("WARNING: Unable to redirect output to the console.\n");
- printf("WARNING: %s\n", dlerror());
- }
-
// pass all additional arguments to the main function
return launch_app(app_main, argc - 1, ++argv);
}
diff --git a/src/ports/SkDebug_android.cpp b/src/ports/SkDebug_android.cpp
index 2795c04..4ab9ad2 100644
--- a/src/ports/SkDebug_android.cpp
+++ b/src/ports/SkDebug_android.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,31 +5,28 @@
* found in the LICENSE file.
*/
-
#include "SkTypes.h"
#include <stdio.h>
#define LOG_TAG "skia"
#include <android/log.h>
-static bool gSkDebugToStdOut = false;
-
-extern "C" void AndroidSkDebugToStdOut(bool debugToStdOut) {
- gSkDebugToStdOut = debugToStdOut;
-}
+// Print debug output to stdout as well. This is useful for command line
+// applications (e.g. skia_launcher). To enable, include android_output as a
+// gyp dependency.
+bool gSkDebugToStdOut = false;
void SkDebugf(const char format[], ...) {
va_list args1, args2;
va_start(args1, format);
- va_copy(args2, args1);
- __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, args1);
- // Print debug output to stdout as well. This is useful for command
- // line applications (e.g. skia_launcher)
if (gSkDebugToStdOut) {
+ va_copy(args2, args1);
vprintf(format, args2);
+ va_end(args2);
}
+ __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, args1);
+
va_end(args1);
- va_end(args2);
}
diff --git a/tools/AndroidSkDebugToStdOut.cpp b/tools/AndroidSkDebugToStdOut.cpp
new file mode 100644
index 0000000..9dc9911
--- /dev/null
+++ b/tools/AndroidSkDebugToStdOut.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// Need to include SkTypes before checking SK_BUILD_FOR_ANDROID, so it will be
+// set in the Android framework build.
+#include "SkTypes.h"
+#ifdef SK_BUILD_FOR_ANDROID
+extern bool gSkDebugToStdOut;
+
+// Use a static initializer to set gSkDebugToStdOut to true, sending SkDebugf
+// to stdout.
+class SendToStdOut {
+public:
+ SendToStdOut() {
+ gSkDebugToStdOut = true;
+ }
+};
+
+static SendToStdOut gSendToStdOut;
+#endif // SK_BUILD_FOR_ANDROID