From 6cfce1b7b4ad546b02823a1a0bbbda2c17b688f5 Mon Sep 17 00:00:00 2001 From: scroggo Date: Wed, 10 Dec 2014 10:23:04 -0800 Subject: [PATCH] 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 --- gyp/android_output.gyp | 16 +++++++++++++ gyp/apptype_console.gypi | 13 +++++++--- .../android/launcher/skia_launcher.cpp | 11 --------- src/ports/SkDebug_android.cpp | 20 +++++++--------- tools/AndroidSkDebugToStdOut.cpp | 24 +++++++++++++++++++ 5 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 gyp/android_output.gyp create mode 100644 tools/AndroidSkDebugToStdOut.cpp 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 #define LOG_TAG "skia" #include -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