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
This commit is contained in:
scroggo 2014-12-10 10:23:04 -08:00 committed by Commit bot
parent 96472deea7
commit 6cfce1b7b4
5 changed files with 58 additions and 26 deletions

16
gyp/android_output.gyp Normal file
View File

@ -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',
],
},
],
}

View File

@ -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"', {

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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