Add android_launch_app script to allow command line options to be passed to the sampleApp when starting.

BUG=skia:3815
DOCS_PREVIEW= https://skia.org/?cl=1136753003
R=bungeman@google.com, tomhudson@google.com

Review URL: https://codereview.chromium.org/1136753003
This commit is contained in:
Derek Sollenberger 2015-05-11 08:54:19 -04:00
parent 88f12dbe92
commit 7c722197b3
8 changed files with 83 additions and 23 deletions

View File

@ -172,7 +172,7 @@ static jmethodID GetJMethod(JNIEnv* env, jclass clazz, const char name[],
}
JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env,
jobject thiz, jobject jsampleActivity, jint msaaSampleCount)
jobject thiz, jobject jsampleActivity, jstring cmdLineFlags, jint msaaSampleCount)
{
// setup jni hooks to the java activity
gActivityGlue.m_env = env;
@ -194,15 +194,17 @@ JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env,
env->DeleteLocalRef(clazz);
application_init();
const char* flags = env->GetStringUTFChars(cmdLineFlags, JNI_FALSE);
SkTArray<SkString> flagEntries;
SkStrSplit(flags, " ", &flagEntries);
SkTArray<const char*> args;
args.push_back("SampleApp");
// TODO: push ability to select skp dir into the UI
args.push_back("--pictureDir");
args.push_back("/sdcard/skiabot/skia_skp");
args.push_back("--resourcePath");
args.push_back("/data/local/tmp/skia/resources/");
for (int i = 0; i < flagEntries.count(); i++) {
SkDebugf(flagEntries[i].c_str());
args.push_back(flagEntries[i].c_str());
}
SkString msaaSampleCountString;
if (msaaSampleCount > 0) {
@ -211,7 +213,14 @@ JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env,
args.push_back(msaaSampleCountString.c_str());
}
gWindow = new SampleWindow(NULL, args.count(), const_cast<char**>(args.begin()), NULL);
if (gWindow) {
SkDebugf("The sample window already exists.");
} else {
gWindow = new SampleWindow(NULL, args.count(), const_cast<char**>(args.begin()), NULL);
}
// cleanup the command line flags
env->ReleaseStringUTFChars(cmdLineFlags, flags);
// send the list of slides up to the activity
const int slideCount = gWindow->sampleCount();

View File

@ -10,10 +10,10 @@ extern "C" {
/*
* Class: com_skia_SkiaSampleRenderer
* Method: init
* Signature: (Lcom/skia/SkiaSampleActivity;I)V
* Signature: (Lcom/skia/SkiaSampleActivity;Ljava/lang/String;I)V
*/
JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init
(JNIEnv *, jobject, jobject, jint);
(JNIEnv *, jobject, jobject, jstring, jint);
/*
* Class: com_skia_SkiaSampleRenderer

View File

@ -10,6 +10,7 @@ package com.skia;
import android.app.ActionBar;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Intent;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
@ -65,7 +66,16 @@ public class SkiaSampleActivity extends Activity
mSampleView.terminate();
}
mSampleView = new SkiaSampleView(this, useOpenGLAPI, msaaSampleCount);
// intent get intent extras if triggered from the command line
Intent intent = this.getIntent();
String flags = intent.getStringExtra("cmdLineFlags");
if (flags == null || flags.isEmpty()) {
flags = "--pictureDir /data/local/tmp/skia_skp ";
flags += "--resourcePath /data/local/tmp/skia_resources ";
}
mSampleView = new SkiaSampleView(this, flags, useOpenGLAPI, msaaSampleCount);
LinearLayout holder = (LinearLayout) findViewById(R.id.holder);
holder.addView(mSampleView, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,

View File

@ -20,9 +20,11 @@ public class SkiaSampleRenderer implements GLSurfaceView.Renderer {
private final SkiaSampleView mSampleView;
private Handler mHandler = new Handler();
private int mMSAASampleCount;
private String mCmdLineFlags;
SkiaSampleRenderer(SkiaSampleView view) {
SkiaSampleRenderer(SkiaSampleView view, String cmdLineFlags) {
mSampleView = view;
mCmdLineFlags = cmdLineFlags;
}
@Override
@ -49,7 +51,8 @@ public class SkiaSampleRenderer implements GLSurfaceView.Renderer {
gl.glClearStencil(0);
gl.glClear(GL10.GL_STENCIL_BUFFER_BIT);
init((SkiaSampleActivity)mSampleView.getContext(), mMSAASampleCount);
init((SkiaSampleActivity)mSampleView.getContext(), mCmdLineFlags, mMSAASampleCount);
}
// Called by JNI and the view.
@ -89,7 +92,7 @@ public class SkiaSampleRenderer implements GLSurfaceView.Renderer {
mSampleView.requestRender();
}
native void init(SkiaSampleActivity activity, int msaaSampleCount);
native void init(SkiaSampleActivity activity, String flags, int msaaSampleCount);
native void term();
native void draw();
native void updateSize(int w, int h);

View File

@ -25,10 +25,10 @@ public class SkiaSampleView extends GLSurfaceView {
private boolean mRequestedOpenGLAPI; // true == use (desktop) OpenGL. false == use OpenGL ES.
private int mRequestedMSAASampleCount;
public SkiaSampleView(Context ctx, boolean useOpenGL, int msaaSampleCount) {
public SkiaSampleView(Context ctx, String cmdLineFlags, boolean useOpenGL, int msaaSampleCount) {
super(ctx);
mSampleRenderer = new SkiaSampleRenderer(this);
mSampleRenderer = new SkiaSampleRenderer(this, cmdLineFlags);
mRequestedMSAASampleCount = msaaSampleCount;
setEGLContextClientVersion(2);

View File

@ -0,0 +1,16 @@
#!/bin/bash
#
# android_launch_app: Launches the skia sampleApp on the device.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/android_setup.sh
source $SCRIPT_DIR/utils/setup_adb.sh
# TODO: check to ensure that the app exists on the device and prompt to install
if [[ -n $RESOURCE_PATH ]]; then
adb_push_if_needed "${SKIA_SRC_DIR}/resources" $RESOURCE_PATH
fi
$ADB ${DEVICE_SERIAL} shell am start -S -n "com.skia/.SkiaSampleActivity" --es "cmdLineFlags" "${APP_ARGS[*]}"

View File

@ -182,8 +182,13 @@ adb_pull_if_needed() {
if [ -f $HOST_DST ];
then
#get the MD5 for dst and src
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_SRC`
#get the MD5 for dst and src depending on OS and/or OS revision
ANDROID_MD5_SUPPORT=`$ADB $DEVICE_SERIAL shell ls -ld /system/bin/md5`
if [ "${ANDROID_MD5_SUPPORT:0:15}" != "/system/bin/md5" ]; then
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST`
else
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5sum $ANDROID_DST`
fi
if [ $(uname) == "Darwin" ]; then
HOST_MD5=`md5 -q $HOST_DST`
else
@ -220,8 +225,14 @@ adb_push_if_needed() {
ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST`
if [ "${ANDROID_LS:0:1}" == "-" ]; then
#get the MD5 for dst and src
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST`
#get the MD5 for dst and src depending on OS and/or OS revision
ANDROID_MD5_SUPPORT=`$ADB $DEVICE_SERIAL shell ls -ld /system/bin/md5`
if [ "${ANDROID_MD5_SUPPORT:0:15}" != "/system/bin/md5" ]; then
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST`
else
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5sum $ANDROID_DST`
fi
if [ $(uname) == "Darwin" ]; then
HOST_MD5=`md5 -q $HOST_SRC`
else

View File

@ -139,8 +139,19 @@ Then, install the app onto the device:
./platform_tools/android/bin/android_install_app
Finally to run the application you must navigate to the Skia Samples
application using the application launcher on your device.
Finally to run the application you can either navigate to the Skia Samples
application using the application launcher on your device or from the command
line. The command line option allows you to pass additional details to the
application (similiar to other operating system) that specify where to find
skp files and other resources.
./platform_tools/android/bin/android_launch_app --resourcePath /data/local/tmp/resources
By default if no additional parameters are specified the app will use the default
params...
--resourcePath /data/local/tmp/skia_resoures
--pictureDir /data/local/tmp/skia_skp
Build tools
-----------