aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/android_output.gyp16
-rw-r--r--gyp/apptype_console.gypi13
-rw-r--r--platform_tools/android/launcher/skia_launcher.cpp11
-rw-r--r--src/ports/SkDebug_android.cpp20
-rw-r--r--tools/AndroidSkDebugToStdOut.cpp24
5 files changed, 58 insertions, 26 deletions
diff --git a/gyp/android_output.gyp b/gyp/android_output.gyp
new file mode 100644
index 0000000000..b22ac9d4a7
--- /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 906bea814d..d3759419a1 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 746d470a3c..6cd900cbe0 100644
--- a/platform_tools/android/launcher/skia_launcher.cpp
+++ b/platform_tools/android/launcher/skia_launcher.cpp
@@ -98,17 +98,6 @@ int main(int argc, const char** argv) {
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 2795c0444a..4ab9ad24d3 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 0000000000..9dc991164d
--- /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