From 9efef7b56fef1c43c018f75c04b2b9e720f5bc2b Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 23 Jul 2015 08:00:33 -0700 Subject: Revert "Update Android Apps to use gradle" This reverts commit 425535f1626932e4e22f61a2571f9c3c2b1c5977. NOTRY=true NOTREECHECKS=true TBR=djsollen@google.com BUG=skia: DOCS_PREVIEW= https://skia.org/?cl=1250233002 Review URL: https://codereview.chromium.org/1250233002 --- .gitignore | 7 - platform_tools/android/app/AndroidManifest.xml | 22 ++ platform_tools/android/app/build.xml | 61 ++++ platform_tools/android/app/jni/AndroidKeyToSkKey.h | 35 ++ .../app/jni/com_skia_SkiaSampleRenderer.cpp | 384 +++++++++++++++++++++ .../android/app/jni/com_skia_SkiaSampleRenderer.h | 164 +++++++++ platform_tools/android/app/project.properties | 14 + .../app/res/drawable-hdpi/ic_btn_find_next.png | Bin 0 -> 1099 bytes .../app/res/drawable-hdpi/ic_btn_find_prev.png | Bin 0 -> 912 bytes platform_tools/android/app/res/layout/layout.xml | 17 + platform_tools/android/app/res/menu/action_bar.xml | 75 ++++ platform_tools/android/app/res/values/strings.xml | 18 + .../app/src/com/skia/SkiaSampleActivity.java | 279 +++++++++++++++ .../app/src/com/skia/SkiaSampleRenderer.java | 113 ++++++ .../android/app/src/com/skia/SkiaSampleView.java | 306 ++++++++++++++++ platform_tools/android/apps/build.gradle | 86 ----- .../android/apps/sample_app/build.gradle | 46 --- .../apps/sample_app/src/main/AndroidManifest.xml | 22 -- .../src/main/java/com/skia/SkiaSampleActivity.java | 279 --------------- .../src/main/java/com/skia/SkiaSampleRenderer.java | 113 ------ .../src/main/java/com/skia/SkiaSampleView.java | 306 ---------------- .../sample_app/src/main/jni/AndroidKeyToSkKey.h | 35 -- .../src/main/jni/com_skia_SkiaSampleRenderer.cpp | 384 --------------------- .../src/main/jni/com_skia_SkiaSampleRenderer.h | 164 --------- .../main/res/drawable-hdpi/ic_btn_find_next.png | Bin 1099 -> 0 bytes .../main/res/drawable-hdpi/ic_btn_find_prev.png | Bin 912 -> 0 bytes .../apps/sample_app/src/main/res/layout/layout.xml | 17 - .../sample_app/src/main/res/menu/action_bar.xml | 75 ---- .../sample_app/src/main/res/values/strings.xml | 18 - platform_tools/android/apps/settings.gradle | 2 - .../android/apps/visualbench/build.gradle | 46 --- .../apps/visualbench/src/main/AndroidManifest.xml | 29 -- .../main/java/com/skia/VisualBenchActivity.java | 49 --- .../src/main/jni/SkOSWindow_AndroidNative.cpp | 187 ---------- .../android/apps/visualbench/src/main/jni/main.cpp | 134 ------- platform_tools/android/bin/android_install_app | 14 +- platform_tools/android/bin/android_setup.sh | 5 - platform_tools/android/gyp/dependencies.gypi | 6 +- platform_tools/android/gyp/skia_android.gypi | 77 +++-- .../android/visualbench/AndroidManifest.xml | 29 ++ platform_tools/android/visualbench/build.xml | 61 ++++ .../visualbench/jni/SkOSWindow_AndroidNative.cpp | 187 ++++++++++ platform_tools/android/visualbench/jni/main.cpp | 134 +++++++ .../android/visualbench/project.properties | 14 + .../src/com/skia/VisualBenchActivity.java | 49 +++ site/user/quick/android.md | 35 +- 46 files changed, 2032 insertions(+), 2066 deletions(-) create mode 100644 platform_tools/android/app/AndroidManifest.xml create mode 100644 platform_tools/android/app/build.xml create mode 100644 platform_tools/android/app/jni/AndroidKeyToSkKey.h create mode 100644 platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.cpp create mode 100644 platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.h create mode 100644 platform_tools/android/app/project.properties create mode 100644 platform_tools/android/app/res/drawable-hdpi/ic_btn_find_next.png create mode 100644 platform_tools/android/app/res/drawable-hdpi/ic_btn_find_prev.png create mode 100644 platform_tools/android/app/res/layout/layout.xml create mode 100644 platform_tools/android/app/res/menu/action_bar.xml create mode 100644 platform_tools/android/app/res/values/strings.xml create mode 100644 platform_tools/android/app/src/com/skia/SkiaSampleActivity.java create mode 100644 platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java create mode 100644 platform_tools/android/app/src/com/skia/SkiaSampleView.java delete mode 100644 platform_tools/android/apps/build.gradle delete mode 100644 platform_tools/android/apps/sample_app/build.gradle delete mode 100644 platform_tools/android/apps/sample_app/src/main/AndroidManifest.xml delete mode 100644 platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java delete mode 100644 platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java delete mode 100644 platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java delete mode 100644 platform_tools/android/apps/sample_app/src/main/jni/AndroidKeyToSkKey.h delete mode 100644 platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp delete mode 100644 platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h delete mode 100644 platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_next.png delete mode 100644 platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_prev.png delete mode 100644 platform_tools/android/apps/sample_app/src/main/res/layout/layout.xml delete mode 100644 platform_tools/android/apps/sample_app/src/main/res/menu/action_bar.xml delete mode 100644 platform_tools/android/apps/sample_app/src/main/res/values/strings.xml delete mode 100644 platform_tools/android/apps/settings.gradle delete mode 100644 platform_tools/android/apps/visualbench/build.gradle delete mode 100644 platform_tools/android/apps/visualbench/src/main/AndroidManifest.xml delete mode 100644 platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java delete mode 100644 platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp delete mode 100644 platform_tools/android/apps/visualbench/src/main/jni/main.cpp create mode 100644 platform_tools/android/visualbench/AndroidManifest.xml create mode 100644 platform_tools/android/visualbench/build.xml create mode 100644 platform_tools/android/visualbench/jni/SkOSWindow_AndroidNative.cpp create mode 100644 platform_tools/android/visualbench/jni/main.cpp create mode 100644 platform_tools/android/visualbench/project.properties create mode 100644 platform_tools/android/visualbench/src/com/skia/VisualBenchActivity.java diff --git a/.gitignore b/.gitignore index 7ea825655a..44d423f269 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,9 @@ *.pyc *.swp -*.iml .DS_Store .android_config .gclient* .gm-actuals -.gradle -.idea .cproject .project .settings/ @@ -15,10 +12,6 @@ bower_components common gyp/build out -platform_tools/android/apps/build -platform_tools/android/apps/*.properties -platform_tools/android/apps/*/build -platform_tools/android/apps/*/src/main/libs platform_tools/chromeos/third_party/externals platform_tools/chromeos/toolchain skps diff --git a/platform_tools/android/app/AndroidManifest.xml b/platform_tools/android/app/AndroidManifest.xml new file mode 100644 index 0000000000..edb0424ba8 --- /dev/null +++ b/platform_tools/android/app/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + diff --git a/platform_tools/android/app/build.xml b/platform_tools/android/app/build.xml new file mode 100644 index 0000000000..fbba716abb --- /dev/null +++ b/platform_tools/android/app/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/platform_tools/android/app/jni/AndroidKeyToSkKey.h b/platform_tools/android/app/jni/AndroidKeyToSkKey.h new file mode 100644 index 0000000000..6bcb148b46 --- /dev/null +++ b/platform_tools/android/app/jni/AndroidKeyToSkKey.h @@ -0,0 +1,35 @@ + +/* + * Copyright 2011 Skia + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef _ANDROID_TO_SKIA_KEYCODES_H +#define _ANDROID_TO_SKIA_KEYCODES_H + +#include "android/keycodes.h" +#include "SkKey.h" + +// Convert an Android keycode to an SkKey. This is an incomplete list, only +// including keys used by the sample app. +SkKey AndroidKeycodeToSkKey(int keycode) { + switch (keycode) { + case AKEYCODE_DPAD_LEFT: + return kLeft_SkKey; + case AKEYCODE_DPAD_RIGHT: + return kRight_SkKey; + case AKEYCODE_DPAD_UP: + return kUp_SkKey; + case AKEYCODE_DPAD_DOWN: + return kDown_SkKey; + case AKEYCODE_BACK: + return kBack_SkKey; + default: + return kNONE_SkKey; + } +} + +#endif diff --git a/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.cpp b/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.cpp new file mode 100644 index 0000000000..d66221a01c --- /dev/null +++ b/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.cpp @@ -0,0 +1,384 @@ + +/* + * Copyright 2011 Skia + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "com_skia_SkiaSampleRenderer.h" + +#include "SampleApp.h" +#include "SkApplication.h" +#include "SkCanvas.h" +#include "SkDevice.h" +#include "SkEvent.h" +#include "SkWindow.h" + +#include +#include "AndroidKeyToSkKey.h" + + +/////////////////////////////////////////// +///////////////// Globals ///////////////// +/////////////////////////////////////////// + +struct ActivityGlue { + JNIEnv* m_env; + jweak m_obj; + jmethodID m_setTitle; + jmethodID m_setSlideList; + jmethodID m_addToDownloads; + ActivityGlue() { + m_env = NULL; + m_obj = NULL; + m_setTitle = NULL; + m_setSlideList = NULL; + m_addToDownloads = NULL; + } +} gActivityGlue; + +struct WindowGlue { + jweak m_obj; + jmethodID m_inval; + jmethodID m_queueSkEvent; + jmethodID m_startTimer; + jmethodID m_getMSAASampleCount; + WindowGlue() { + m_obj = NULL; + m_inval = NULL; + m_queueSkEvent = NULL; + m_startTimer = NULL; + m_getMSAASampleCount = NULL; + } +} gWindowGlue; + +SampleWindow* gWindow; + +/////////////////////////////////////////// +///////////// SkOSWindow impl ///////////// +/////////////////////////////////////////// + +SkOSWindow::SkOSWindow(void*) : fDestroyRequested(false) { +} + +SkOSWindow::~SkOSWindow() { +} + +bool SkOSWindow::attach(SkBackEndTypes /* attachType */, int /*msaaSampleCount*/, AttachmentInfo* info) +{ + JNIEnv* env = gActivityGlue.m_env; + if (!env || !gWindowGlue.m_getMSAASampleCount || !gWindowGlue.m_obj) { + return false; + } + if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { + SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); + return false; + } + info->fSampleCount = env->CallIntMethod(gWindowGlue.m_obj, gWindowGlue.m_getMSAASampleCount); + + // This is the value requested in SkiaSampleView.java. + info->fStencilBits = 8; + return true; +} + +void SkOSWindow::detach() { +} + +void SkOSWindow::present() { +} + +void SkOSWindow::closeWindow() { +} + +void SkOSWindow::setVsync(bool) { +} + +void SkOSWindow::onSetTitle(const char title[]) +{ + JNIEnv* env = gActivityGlue.m_env; + if (!env) { + return; + } + if (env->IsSameObject(gActivityGlue.m_obj, NULL)) { + SkDebugf("ERROR: The JNI WeakRef to the Activity is invalid"); + return; + } + + jstring string = env->NewStringUTF(title); + env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_setTitle, string); + env->DeleteLocalRef(string); +} + +void SkOSWindow::onHandleInval(const SkIRect& rect) +{ + JNIEnv* env = gActivityGlue.m_env; + if (!env || !gWindowGlue.m_inval || !gWindowGlue.m_obj) { + return; + } + if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { + SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); + return; + } + env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_inval); +} + +void SkOSWindow::onPDFSaved(const char title[], const char desc[], + const char path[]) +{ + JNIEnv* env = gActivityGlue.m_env; + if (!env || !gActivityGlue.m_addToDownloads || !gActivityGlue.m_obj) { + return; + } + if (env->IsSameObject(gActivityGlue.m_obj, NULL)) { + SkDebugf("ERROR: The JNI WeakRef to the Activity is invalid"); + return; + } + + jstring jtitle = env->NewStringUTF(title); + jstring jdesc = env->NewStringUTF(desc); + jstring jpath = env->NewStringUTF(path); + + env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_addToDownloads, + jtitle, jdesc, jpath); + + env->DeleteLocalRef(jtitle); + env->DeleteLocalRef(jdesc); + env->DeleteLocalRef(jpath); +} + +/////////////////////////////////////////// +/////////////// SkEvent impl ////////////// +/////////////////////////////////////////// + +void SkEvent::SignalQueueTimer(SkMSec ms) +{ + JNIEnv* env = gActivityGlue.m_env; + if (!env || !gWindowGlue.m_startTimer || !gWindowGlue.m_obj || !ms) { + return; + } + if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { + SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); + return; + } + env->CallVoidMethod(gWindowGlue.m_obj, + gWindowGlue.m_startTimer, ms); +} + +void SkEvent::SignalNonEmptyQueue() +{ + JNIEnv* env = gActivityGlue.m_env; + if (!env || !gWindowGlue.m_queueSkEvent || !gWindowGlue.m_obj) { + return; + } + if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { + SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); + return; + } + env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_queueSkEvent); +} + +/////////////////////////////////////////// +////////////////// JNI //////////////////// +/////////////////////////////////////////// + +static jmethodID GetJMethod(JNIEnv* env, jclass clazz, const char name[], + const char signature[]) +{ + jmethodID m = env->GetMethodID(clazz, name, signature); + if (!m) SkDebugf("Could not find Java method %s\n", name); + return m; +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env, + jobject thiz, jobject jsampleActivity, jstring cmdLineFlags, jint msaaSampleCount) +{ + // setup jni hooks to the java activity + gActivityGlue.m_env = env; + jclass clazz = env->FindClass("com/skia/SkiaSampleActivity"); + gActivityGlue.m_obj = env->NewWeakGlobalRef(jsampleActivity); + gActivityGlue.m_setTitle = GetJMethod(env, clazz, "setTitle", "(Ljava/lang/CharSequence;)V"); + gActivityGlue.m_setSlideList = GetJMethod(env, clazz, "setSlideList", "([Ljava/lang/String;)V"); + gActivityGlue.m_addToDownloads = GetJMethod(env, clazz, "addToDownloads", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + env->DeleteLocalRef(clazz); + + // setup jni hooks to the java renderer + clazz = env->FindClass("com/skia/SkiaSampleRenderer"); + gWindowGlue.m_obj = env->NewWeakGlobalRef(thiz); + gWindowGlue.m_inval = GetJMethod(env, clazz, "requestRender", "()V"); + gWindowGlue.m_queueSkEvent = GetJMethod(env, clazz, "queueSkEvent", "()V"); + gWindowGlue.m_startTimer = GetJMethod(env, clazz, "startTimer", "(I)V"); + gWindowGlue.m_getMSAASampleCount = GetJMethod(env, clazz, "getMSAASampleCount", "()I"); + env->DeleteLocalRef(clazz); + + application_init(); + + const char* flags = env->GetStringUTFChars(cmdLineFlags, JNI_FALSE); + SkTArray flagEntries; + SkStrSplit(flags, " ", &flagEntries); + + SkTArray args; + args.push_back("SampleApp"); + 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) { + args.push_back("--msaa"); + msaaSampleCountString.appendS32(static_cast(msaaSampleCount)); + args.push_back(msaaSampleCountString.c_str()); + } + + if (gWindow) { + SkDebugf("The sample window already exists."); + } else { + gWindow = new SampleWindow(NULL, args.count(), const_cast(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(); + jobjectArray slideList = env->NewObjectArray(slideCount, env->FindClass("java/lang/String"), env->NewStringUTF("")); + for (int i = 0; i < slideCount; i++) { + jstring slideTitle = env->NewStringUTF(gWindow->getSampleTitle(i).c_str()); + env->SetObjectArrayElement(slideList, i, slideTitle); + env->DeleteLocalRef(slideTitle); + } + env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_setSlideList, slideList); + env->DeleteLocalRef(slideList); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_term(JNIEnv* env, + jobject thiz) +{ + delete gWindow; + gWindow = NULL; + application_term(); + if (gWindowGlue.m_obj) { + env->DeleteWeakGlobalRef(gWindowGlue.m_obj); + gWindowGlue.m_obj = NULL; + } + if (gActivityGlue.m_obj) { + env->DeleteWeakGlobalRef(gActivityGlue.m_obj); + gActivityGlue.m_obj = NULL; + } +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_draw( + JNIEnv* env, jobject thiz) +{ + if (!gWindow) return; + gWindow->update(NULL); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_updateSize(JNIEnv* env, + jobject thiz, jint w, jint h) +{ + gWindow->resize(w, h); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_handleClick(JNIEnv* env, + jobject thiz, jint owner, jfloat x, jfloat y, jint jstate) +{ + SkView::Click::State state; + switch(jstate) { + case 0: // MotionEvent.ACTION_DOWN + state = SkView::Click::kDown_State; + break; + case 1: // MotionEvent.ACTION_UP + case 3: // MotionEvent.ACTION_CANCEL + state = SkView::Click::kUp_State; + break; + case 2: // MotionEvent.ACTION_MOVE + state = SkView::Click::kMoved_State; + break; + default: + SkDebugf("motion event ignored\n"); + return; + } + gWindow->handleClick(x, y, state, reinterpret_cast(owner)); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_nextSample( + JNIEnv* env, jobject thiz) +{ + gWindow->nextSample(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_previousSample( + JNIEnv* env, jobject thiz) +{ + gWindow->previousSample(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_goToSample( + JNIEnv* env, jobject thiz, jint position) +{ + gWindow->goToSample(position); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleRenderingMode( + JNIEnv* env, jobject thiz) +{ + gWindow->toggleRendering(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_showOverview( + JNIEnv* env, jobject thiz) +{ + gWindow->showOverview(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleSlideshow( + JNIEnv* env, jobject thiz) +{ + gWindow->toggleSlideshow(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleFPS( + JNIEnv* env, jobject thiz) +{ + gWindow->toggleFPS(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleTiling( + JNIEnv* env, jobject thiz) +{ + gWindow->handleChar('t'); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleBBox( + JNIEnv* env, jobject thiz) +{ + gWindow->handleChar('b'); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_processSkEvent( + JNIEnv* env, jobject thiz) +{ + if (SkEvent::ProcessEvent()) { + SkEvent::SignalNonEmptyQueue(); + } +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_serviceQueueTimer( + JNIEnv* env, jobject thiz) +{ + SkEvent::ServiceQueueTimer(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_saveToPDF( + JNIEnv* env, jobject thiz) +{ + gWindow->saveToPdf(); +} + +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_postInval( + JNIEnv* env, jobject thiz) +{ + gWindow->postInvalDelay(); +} diff --git a/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.h b/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.h new file mode 100644 index 0000000000..8883a3a9f0 --- /dev/null +++ b/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.h @@ -0,0 +1,164 @@ +/* + * Copyright 2015 Skia + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_skia_SkiaSampleRenderer */ + +#ifndef _Included_com_skia_SkiaSampleRenderer +#define _Included_com_skia_SkiaSampleRenderer +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_skia_SkiaSampleRenderer + * Method: init + * Signature: (Lcom/skia/SkiaSampleActivity;Ljava/lang/String;I)V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init + (JNIEnv *, jobject, jobject, jstring, jint); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: term + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_term + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: draw + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_draw + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: updateSize + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_updateSize + (JNIEnv *, jobject, jint, jint); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: handleClick + * Signature: (IFFI)V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_handleClick + (JNIEnv *, jobject, jint, jfloat, jfloat, jint); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: showOverview + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_showOverview + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: nextSample + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_nextSample + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: previousSample + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_previousSample + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: goToSample + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_goToSample + (JNIEnv *, jobject, jint); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: toggleRenderingMode + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleRenderingMode + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: toggleSlideshow + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleSlideshow + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: toggleFPS + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleFPS + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: toggleTiling + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleTiling + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: toggleBBox + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleBBox + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: processSkEvent + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_processSkEvent + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: serviceQueueTimer + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_serviceQueueTimer + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: saveToPdf + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_saveToPDF + (JNIEnv *, jobject); + +/* + * Class: com_skia_SkiaSampleRenderer + * Method: postInval + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_postInval + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/platform_tools/android/app/project.properties b/platform_tools/android/app/project.properties new file mode 100644 index 0000000000..4ab125693c --- /dev/null +++ b/platform_tools/android/app/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_next.png b/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_next.png new file mode 100644 index 0000000000..b696a6bb22 Binary files /dev/null and b/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_next.png differ diff --git a/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_prev.png b/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_prev.png new file mode 100644 index 0000000000..5550c5a6ff Binary files /dev/null and b/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_prev.png differ diff --git a/platform_tools/android/app/res/layout/layout.xml b/platform_tools/android/app/res/layout/layout.xml new file mode 100644 index 0000000000..cdb90e9961 --- /dev/null +++ b/platform_tools/android/app/res/layout/layout.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/platform_tools/android/app/res/menu/action_bar.xml b/platform_tools/android/app/res/menu/action_bar.xml new file mode 100644 index 0000000000..72e135e43b --- /dev/null +++ b/platform_tools/android/app/res/menu/action_bar.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform_tools/android/app/res/values/strings.xml b/platform_tools/android/app/res/values/strings.xml new file mode 100644 index 0000000000..b0b4e7b74b --- /dev/null +++ b/platform_tools/android/app/res/values/strings.xml @@ -0,0 +1,18 @@ + + + Skia Samples + Overview + Toggle Rendering + Slideshow + FPS + Toggle Tiling + Toggle SKP BBox + Save to PDF + Save Failed + %s saved! + Set OpenGL Context Type + OpenGL ES + OpenGL ES, MSAA4 + OpenGL + OpenGL, MSAA4 + \ No newline at end of file diff --git a/platform_tools/android/app/src/com/skia/SkiaSampleActivity.java b/platform_tools/android/app/src/com/skia/SkiaSampleActivity.java new file mode 100644 index 0000000000..d9cd9f887d --- /dev/null +++ b/platform_tools/android/app/src/com/skia/SkiaSampleActivity.java @@ -0,0 +1,279 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +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; +import android.os.Handler; +import android.os.Message; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.File; + +public class SkiaSampleActivity extends Activity +{ + private TextView mTitle; + private SkiaSampleView mSampleView; + + private ArrayAdapter mSlideList; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.layout); + mTitle = (TextView) findViewById(R.id.title_view); + mSlideList = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1); + + try { + System.loadLibrary("skia_android"); + } catch (UnsatisfiedLinkError e) { + // This might be because skia was linked to SampleApp statically. + } + + try { + System.loadLibrary("SampleApp"); + + createSampleView(false, 0); + + setupActionBar(); + } catch (UnsatisfiedLinkError e) { + mTitle.setText("ERROR: native library could not be loaded"); + } + } + + private void createSampleView(boolean useOpenGLAPI, int msaaSampleCount) { + if (mSampleView != null) { + ViewGroup viewGroup = (ViewGroup) mSampleView.getParent(); + viewGroup.removeView(mSampleView); + mSampleView.terminate(); + } + + // 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, + ViewGroup.LayoutParams.MATCH_PARENT)); + } + + private void setupActionBar() { + ActionBar.OnNavigationListener navigationCallback = new ActionBar.OnNavigationListener() { + @Override + public boolean onNavigationItemSelected(int position, long itemId) { + mSampleView.goToSample(position); + return true; + } + }; + + ActionBar actionBar = getActionBar(); + actionBar.setDisplayShowHomeEnabled(false); + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + actionBar.setListNavigationCallbacks(mSlideList, navigationCallback); + } + + @Override + protected void onResume () { + super.onResume(); + if (mSampleView != null && mSampleView.getWidth() > 0 && mSampleView.getHeight() > 0) { + //TODO try mSampleView.requestRender() instead + mSampleView.inval(); + } + } + + @Override + public void onDestroy() { + if (mSampleView != null) { + mSampleView.terminate(); + } + super.onDestroy(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.action_bar, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + if (mSampleView != null) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + ((MenuItem) menu.findItem(R.id.glcontext_menu)) + .setEnabled(false); + + } else { + boolean usesOpenGLAPI = mSampleView.getUsesOpenGLAPI(); + boolean isMSAA4 = mSampleView.getMSAASampleCount() == 4; + + ((MenuItem) menu.findItem(R.id.glcontext_opengles)) + .setChecked(!usesOpenGLAPI && !isMSAA4); + + ((MenuItem) menu.findItem(R.id.glcontext_msaa4_opengles)) + .setChecked(!usesOpenGLAPI && isMSAA4); + + ((MenuItem) menu.findItem(R.id.glcontext_opengl)) + .setChecked(usesOpenGLAPI && !isMSAA4); + + ((MenuItem) menu.findItem(R.id.glcontext_msaa4_opengl)) + .setChecked(usesOpenGLAPI && isMSAA4); + } + } + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mSampleView == null) { + return false; + } + + switch (item.getItemId()) { + case R.id.overview: + mSampleView.showOverview(); + return true; + case R.id.prev: + mSampleView.previousSample(); + return true; + case R.id.next: + mSampleView.nextSample(); + return true; + case R.id.toggle_rendering: + mSampleView.toggleRenderingMode(); + return true; + case R.id.slideshow: + mSampleView.toggleSlideshow(); + return true; + case R.id.fps: + mSampleView.toggleFPS(); + return true; + case R.id.tiling: + mSampleView.toggleTiling(); + return true; + case R.id.bbox: + mSampleView.toggleBBox(); + return true; + case R.id.save_to_pdf: + mSampleView.saveToPDF(); + return true; + case R.id.glcontext_opengles: + return setOpenGLContextSettings(false, 0); + case R.id.glcontext_msaa4_opengles: + return setOpenGLContextSettings(false, 4); + case R.id.glcontext_opengl: + return setOpenGLContextSettings(true, 0); + case R.id.glcontext_msaa4_opengl: + return setOpenGLContextSettings(true, 4); + default: + return false; + } + } + + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + final int keycode = event.getKeyCode(); + if (keycode == KeyEvent.KEYCODE_BACK) { + if (event.getAction() == KeyEvent.ACTION_UP) { + finish(); + } + return true; + } + return false; + } + + private static final int SET_TITLE = 1; + private static final int SET_SLIDES = 2; + private static final int TOAST_DOWNLOAD = 3; + + private Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case SET_TITLE: + mTitle.setText((String) msg.obj); + SkiaSampleActivity.this.getActionBar().setSubtitle((String) msg.obj); + break; + case SET_SLIDES: + mSlideList.addAll((String[]) msg.obj); + break; + case TOAST_DOWNLOAD: + Toast.makeText(SkiaSampleActivity.this, (String) msg.obj, + Toast.LENGTH_SHORT).show(); + break; + default: + break; + } + } + }; + + // Called by JNI + @Override + public void setTitle(CharSequence title) { + mHandler.obtainMessage(SET_TITLE, title).sendToTarget(); + } + + // Called by JNI + public void setSlideList(String[] slideList) { + mHandler.obtainMessage(SET_SLIDES, slideList).sendToTarget(); + } + + // Called by JNI + public void addToDownloads(final String title, final String desc, final String path) { + File file = new File(path); + final long length = file.exists() ? file.length() : 0; + if (length == 0) { + String failed = getString(R.string.save_failed); + mHandler.obtainMessage(TOAST_DOWNLOAD, failed).sendToTarget(); + return; + } + String toast = getString(R.string.file_saved).replace("%s", title); + mHandler.obtainMessage(TOAST_DOWNLOAD, toast).sendToTarget(); + final DownloadManager manager = + (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); + new Thread("Add PDF to downloads") { + @Override + public void run() { + final String mimeType = "application/pdf"; + manager.addCompletedDownload(title, desc, true, mimeType, path, length, true); + } + }.start(); + } + + private boolean setOpenGLContextSettings(boolean requestedOpenGLAPI, int requestedSampleCount) { + if (mSampleView != null && + mSampleView.getMSAASampleCount() == requestedSampleCount && + mSampleView.getUsesOpenGLAPI() == requestedOpenGLAPI) { + return true; + } + + createSampleView(requestedOpenGLAPI, requestedSampleCount); + + return true; + } +} diff --git a/platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java b/platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java new file mode 100644 index 0000000000..55257094cd --- /dev/null +++ b/platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java @@ -0,0 +1,113 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +package com.skia; + +import android.opengl.GLSurfaceView; +import android.os.Handler; +import android.util.Log; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; +import javax.microedition.khronos.opengles.GL11; + +public class SkiaSampleRenderer implements GLSurfaceView.Renderer { + + private final SkiaSampleView mSampleView; + private Handler mHandler = new Handler(); + private int mMSAASampleCount; + private String mCmdLineFlags; + + SkiaSampleRenderer(SkiaSampleView view, String cmdLineFlags) { + mSampleView = view; + mCmdLineFlags = cmdLineFlags; + } + + @Override + public void onDrawFrame(GL10 gl) { + draw(); + } + + @Override + public void onSurfaceChanged(GL10 gl, int width, int height) { + updateSize(width, height); + } + + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + if (gl instanceof GL11) { + int value[] = new int[1]; + ((GL11) gl).glGetIntegerv(GL11.GL_SAMPLES, value, 0); + if (value[0] == 1) { + mMSAASampleCount = 0; + } else { + mMSAASampleCount = value[0]; + } + } + + gl.glClearStencil(0); + gl.glClear(GL10.GL_STENCIL_BUFFER_BIT); + + init((SkiaSampleActivity)mSampleView.getContext(), mCmdLineFlags, mMSAASampleCount); + } + + // Called by JNI and the view. + synchronized public int getMSAASampleCount() { + return mMSAASampleCount; + } + + // Called by JNI + private void startTimer(int ms) { + // After the delay, queue an event to the Renderer's thread + // to handle the event on the timer queue + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + mSampleView.queueEvent(new Runnable() { + @Override + public void run() { + serviceQueueTimer(); + } + }); + } + }, ms); + } + + // Called by JNI + private void queueSkEvent() { + mSampleView.queueEvent(new Runnable() { + @Override + public void run() { + processSkEvent(); + } + }); + } + + // Called by JNI + private void requestRender() { + mSampleView.requestRender(); + } + + native void init(SkiaSampleActivity activity, String flags, int msaaSampleCount); + native void term(); + native void draw(); + native void updateSize(int w, int h); + native void handleClick(int owner, float x, float y, int state); + native void showOverview(); + native void nextSample(); + native void previousSample(); + native void goToSample(int position); + native void toggleRenderingMode(); + native void toggleSlideshow(); + native void toggleFPS(); + native void toggleTiling(); + native void toggleBBox(); + native void processSkEvent(); + native void serviceQueueTimer(); + native void saveToPDF(); + native void postInval(); +} \ No newline at end of file diff --git a/platform_tools/android/app/src/com/skia/SkiaSampleView.java b/platform_tools/android/app/src/com/skia/SkiaSampleView.java new file mode 100644 index 0000000000..c33f8ae8ac --- /dev/null +++ b/platform_tools/android/app/src/com/skia/SkiaSampleView.java @@ -0,0 +1,306 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +package com.skia; + +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.egl.EGLDisplay; +import javax.microedition.khronos.opengles.GL10; + +import android.content.Context; +import android.opengl.EGL14; +import android.opengl.GLSurfaceView; +import android.os.Build; +import android.util.Log; +import android.view.MotionEvent; + +public class SkiaSampleView extends GLSurfaceView { + + private final SkiaSampleRenderer mSampleRenderer; + private boolean mRequestedOpenGLAPI; // true == use (desktop) OpenGL. false == use OpenGL ES. + private int mRequestedMSAASampleCount; + + public SkiaSampleView(Context ctx, String cmdLineFlags, boolean useOpenGL, int msaaSampleCount) { + super(ctx); + + mSampleRenderer = new SkiaSampleRenderer(this, cmdLineFlags); + mRequestedMSAASampleCount = msaaSampleCount; + + setEGLContextClientVersion(2); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + setEGLConfigChooser(8, 8, 8, 8, 0, 8); + } else { + mRequestedOpenGLAPI = useOpenGL; + setEGLConfigChooser(new SampleViewEGLConfigChooser()); + } + setRenderer(mSampleRenderer); + setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + int count = event.getPointerCount(); + for (int i = 0; i < count; i++) { + final float x = event.getX(i); + final float y = event.getY(i); + final int owner = event.getPointerId(i); + int action = event.getAction() & MotionEvent.ACTION_MASK; + switch (action) { + case MotionEvent.ACTION_POINTER_UP: + action = MotionEvent.ACTION_UP; + break; + case MotionEvent.ACTION_POINTER_DOWN: + action = MotionEvent.ACTION_DOWN; + break; + default: + break; + } + final int finalAction = action; + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.handleClick(owner, x, y, finalAction); + } + }); + } + return true; + } + + public void inval() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.postInval(); + } + }); + } + + public void terminate() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.term(); + } + }); + } + + public void showOverview() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.showOverview(); + } + }); + } + + public void nextSample() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.nextSample(); + } + }); + } + + public void previousSample() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.previousSample(); + } + }); + } + + public void goToSample(final int position) { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.goToSample(position); + } + }); + } + + public void toggleRenderingMode() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.toggleRenderingMode(); + } + }); + } + + public void toggleSlideshow() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.toggleSlideshow(); + } + }); + } + + public void toggleFPS() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.toggleFPS(); + } + }); + } + + public void toggleTiling() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.toggleTiling(); + } + }); + } + + public void toggleBBox() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.toggleBBox(); + } + }); + } + + public void saveToPDF() { + queueEvent(new Runnable() { + @Override + public void run() { + mSampleRenderer.saveToPDF(); + } + }); + } + + public boolean getUsesOpenGLAPI() { + return mRequestedOpenGLAPI; + } + + public int getMSAASampleCount() { + return mSampleRenderer.getMSAASampleCount(); + } + + private class SampleViewEGLConfigChooser implements GLSurfaceView.EGLConfigChooser { + + @Override + public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { + int numConfigs = 0; + int[] configSpec = null; + int[] value = new int[1]; + + int[] validAPIs = new int[] { + EGL14.EGL_OPENGL_API, + EGL14.EGL_OPENGL_ES_API + }; + int initialAPI = mRequestedOpenGLAPI ? 0 : 1; + + for (int i = initialAPI; i < validAPIs.length && numConfigs == 0; i++) { + int currentAPI = validAPIs[i]; + EGL14.eglBindAPI(currentAPI); + + // setup the renderableType which will only be included in the + // spec if we are attempting to get access to the OpenGL APIs. + int renderableType = EGL14.EGL_OPENGL_BIT; + if (currentAPI == EGL14.EGL_OPENGL_API) { + renderableType = EGL14.EGL_OPENGL_ES2_BIT; + } + + if (mRequestedMSAASampleCount > 0) { + configSpec = new int[] { + EGL10.EGL_RED_SIZE, 8, + EGL10.EGL_GREEN_SIZE, 8, + EGL10.EGL_BLUE_SIZE, 8, + EGL10.EGL_ALPHA_SIZE, 8, + EGL10.EGL_DEPTH_SIZE, 0, + EGL10.EGL_STENCIL_SIZE, 8, + EGL10.EGL_SAMPLE_BUFFERS, 1, + EGL10.EGL_SAMPLES, mRequestedMSAASampleCount, + EGL10.EGL_RENDERABLE_TYPE, renderableType, + EGL10.EGL_NONE + }; + + // EGL_RENDERABLE_TYPE is only needed when attempting to use + // the OpenGL API (not ES) and causes many EGL drivers to fail + // with a BAD_ATTRIBUTE error. + if (!mRequestedOpenGLAPI) { + configSpec[16] = EGL10.EGL_NONE; + Log.i("Skia", "spec: " + configSpec); + } + + if (!egl.eglChooseConfig(display, configSpec, null, 0, value)) { + Log.i("Skia", "Could not get MSAA context count: " + mRequestedMSAASampleCount); + } + + numConfigs = value[0]; + } + + if (numConfigs <= 0) { + // Try without multisampling. + configSpec = new int[] { + EGL10.EGL_RED_SIZE, 8, + EGL10.EGL_GREEN_SIZE, 8, + EGL10.EGL_BLUE_SIZE, 8, + EGL10.EGL_ALPHA_SIZE, 8, + EGL10.EGL_DEPTH_SIZE, 0, + EGL10.EGL_STENCIL_SIZE, 8, + EGL10.EGL_RENDERABLE_TYPE, renderableType, + EGL10.EGL_NONE + }; + + // EGL_RENDERABLE_TYPE is only needed when attempting to use + // the OpenGL API (not ES) and causes many EGL drivers to fail + // with a BAD_ATTRIBUTE error. + if (!mRequestedOpenGLAPI) { + configSpec[12] = EGL10.EGL_NONE; + Log.i("Skia", "spec: " + configSpec); + } + + if (!egl.eglChooseConfig(display, configSpec, null, 0, value)) { + Log.i("Skia", "Could not get non-MSAA context count"); + } + numConfigs = value[0]; + } + } + + if (numConfigs <= 0) { + throw new IllegalArgumentException("No configs match configSpec"); + } + + // Get all matching configurations. + EGLConfig[] configs = new EGLConfig[numConfigs]; + if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, value)) { + throw new IllegalArgumentException("Could not get config data"); + } + + for (int i = 0; i < configs.length; ++i) { + EGLConfig config = configs[i]; + if (findConfigAttrib(egl, display, config , EGL10.EGL_RED_SIZE, 0) == 8 && + findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0) == 8 && + findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0) == 8 && + findConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0) == 8 && + findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0) == 8) { + return config; + } + } + + throw new IllegalArgumentException("Could not find suitable EGL config"); + } + + private int findConfigAttrib(EGL10 egl, EGLDisplay display, + EGLConfig config, int attribute, int defaultValue) { + int[] value = new int[1]; + if (egl.eglGetConfigAttrib(display, config, attribute, value)) { + return value[0]; + } + return defaultValue; + } + + } +} diff --git a/platform_tools/android/apps/build.gradle b/platform_tools/android/apps/build.gradle deleted file mode 100644 index b20334b887..0000000000 --- a/platform_tools/android/apps/build.gradle +++ /dev/null @@ -1,86 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} - -def getLocalProperties() { - Properties properties = new Properties() - File propFile = project.rootProject.file('local.properties') - if (propFile.canRead()) { - properties.load(propFile.newDataInputStream()) - } - propFile = project.rootProject.file('gradle.properties') - if (propFile.canRead()) { - properties.load(propFile.newDataInputStream()) - } - return properties -} - -def getSDKPath() { - String path = System.getenv("ANDROID_SDK_ROOT") - if (path == null) { - path = getLocalProperties().getProperty('sdk.dir', null) - } - - if (path == null) { - throw new GradleScriptException("Android SDK not found! Please set ANDROID_SDK_ROOT to" + - " your path or define sdk.dir in gradle.properties") - } - return path -} - -def getPathWithDepotTools() { - System.getenv("PATH") + ":" + getLocalProperties().getProperty('depot_tools.dir', null) - String path = System.getenv("PATH") - if (!path.contains("depot_tools")) { - path += ":" + getLocalProperties().getProperty('depot_tools.dir', null) - } - - if (!path.contains("depot_tools")) { - throw GradleScriptException("Depot Tools not found! Please update your path to include" + - " depot_tools or define depot_tools.dir in gradle.properties") - } - return path -} - -def constructBuildCommand(variant, buildTarget) { - String cmdLine = "./platform_tools/android/bin/android_ninja $buildTarget" - String deviceType = null - if (variant.name.startsWith("arm64")) { - deviceType = "arm64" - } else if (variant.name.startsWith("arm")) { - deviceType = "arm_v7_neon" - } else if (variant.name.startsWith("x86_64")) { - deviceType = "x86_64" - } else if (variant.name.startsWith("x86")) { - deviceType = "x86" - } else if (variant.name.startsWith("mips")) { - deviceType = "mips" - } else if (variant.name.startsWith("mips64")) { - deviceType = "mips64" - } - - if (deviceType != null) { - cmdLine += " -d " + deviceType - } - - if (variant.name.endsWith("Release")) { - cmdLine += " --release" - } - return cmdLine -} \ No newline at end of file diff --git a/platform_tools/android/apps/sample_app/build.gradle b/platform_tools/android/apps/sample_app/build.gradle deleted file mode 100644 index e27a77ae24..0000000000 --- a/platform_tools/android/apps/sample_app/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 19 - buildToolsVersion "22.0.1" - - defaultConfig { - applicationId "com.skia.sample_app" - minSdkVersion 9 - targetSdkVersion 19 - versionCode 1 - versionName "1.0" - } - - sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call - sourceSets.main.jniLibs.srcDir "src/main/libs" - - productFlavors { - arm {} - arm64 {} - x86 {} - x86_64 {} - mips {} - mips64 {} - } - - // make sure that app is built and shared libraries are copied to correct directories - applicationVariants.all{ variant -> - - def buildNativeLib = task("${variant.name}_NativeLib", type:Exec) { - workingDir '../../../..' // top-level skia directory - commandLine constructBuildCommand(variant, "CopySampleAppDeps").split() - environment PATH: getPathWithDepotTools() - environment ANDROID_SDK_ROOT: getSDKPath() - } - - if (!hasProperty("suppressNativeBuild")) { - TaskCollection assembleTask - assembleTask = project.tasks.matching { - it.name.contains("assemble") && - it.name.toLowerCase().endsWith(variant.name.toLowerCase()) - } - assembleTask.getAt(0).dependsOn buildNativeLib - } - } -} \ No newline at end of file diff --git a/platform_tools/android/apps/sample_app/src/main/AndroidManifest.xml b/platform_tools/android/apps/sample_app/src/main/AndroidManifest.xml deleted file mode 100644 index edb0424ba8..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java deleted file mode 100644 index d9cd9f887d..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -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; -import android.os.Handler; -import android.os.Message; -import android.view.KeyEvent; -import android.view.Menu; -import android.view.MenuItem; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.File; - -public class SkiaSampleActivity extends Activity -{ - private TextView mTitle; - private SkiaSampleView mSampleView; - - private ArrayAdapter mSlideList; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.layout); - mTitle = (TextView) findViewById(R.id.title_view); - mSlideList = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1); - - try { - System.loadLibrary("skia_android"); - } catch (UnsatisfiedLinkError e) { - // This might be because skia was linked to SampleApp statically. - } - - try { - System.loadLibrary("SampleApp"); - - createSampleView(false, 0); - - setupActionBar(); - } catch (UnsatisfiedLinkError e) { - mTitle.setText("ERROR: native library could not be loaded"); - } - } - - private void createSampleView(boolean useOpenGLAPI, int msaaSampleCount) { - if (mSampleView != null) { - ViewGroup viewGroup = (ViewGroup) mSampleView.getParent(); - viewGroup.removeView(mSampleView); - mSampleView.terminate(); - } - - // 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, - ViewGroup.LayoutParams.MATCH_PARENT)); - } - - private void setupActionBar() { - ActionBar.OnNavigationListener navigationCallback = new ActionBar.OnNavigationListener() { - @Override - public boolean onNavigationItemSelected(int position, long itemId) { - mSampleView.goToSample(position); - return true; - } - }; - - ActionBar actionBar = getActionBar(); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - actionBar.setListNavigationCallbacks(mSlideList, navigationCallback); - } - - @Override - protected void onResume () { - super.onResume(); - if (mSampleView != null && mSampleView.getWidth() > 0 && mSampleView.getHeight() > 0) { - //TODO try mSampleView.requestRender() instead - mSampleView.inval(); - } - } - - @Override - public void onDestroy() { - if (mSampleView != null) { - mSampleView.terminate(); - } - super.onDestroy(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.action_bar, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - if (mSampleView != null) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { - ((MenuItem) menu.findItem(R.id.glcontext_menu)) - .setEnabled(false); - - } else { - boolean usesOpenGLAPI = mSampleView.getUsesOpenGLAPI(); - boolean isMSAA4 = mSampleView.getMSAASampleCount() == 4; - - ((MenuItem) menu.findItem(R.id.glcontext_opengles)) - .setChecked(!usesOpenGLAPI && !isMSAA4); - - ((MenuItem) menu.findItem(R.id.glcontext_msaa4_opengles)) - .setChecked(!usesOpenGLAPI && isMSAA4); - - ((MenuItem) menu.findItem(R.id.glcontext_opengl)) - .setChecked(usesOpenGLAPI && !isMSAA4); - - ((MenuItem) menu.findItem(R.id.glcontext_msaa4_opengl)) - .setChecked(usesOpenGLAPI && isMSAA4); - } - } - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (mSampleView == null) { - return false; - } - - switch (item.getItemId()) { - case R.id.overview: - mSampleView.showOverview(); - return true; - case R.id.prev: - mSampleView.previousSample(); - return true; - case R.id.next: - mSampleView.nextSample(); - return true; - case R.id.toggle_rendering: - mSampleView.toggleRenderingMode(); - return true; - case R.id.slideshow: - mSampleView.toggleSlideshow(); - return true; - case R.id.fps: - mSampleView.toggleFPS(); - return true; - case R.id.tiling: - mSampleView.toggleTiling(); - return true; - case R.id.bbox: - mSampleView.toggleBBox(); - return true; - case R.id.save_to_pdf: - mSampleView.saveToPDF(); - return true; - case R.id.glcontext_opengles: - return setOpenGLContextSettings(false, 0); - case R.id.glcontext_msaa4_opengles: - return setOpenGLContextSettings(false, 4); - case R.id.glcontext_opengl: - return setOpenGLContextSettings(true, 0); - case R.id.glcontext_msaa4_opengl: - return setOpenGLContextSettings(true, 4); - default: - return false; - } - } - - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - final int keycode = event.getKeyCode(); - if (keycode == KeyEvent.KEYCODE_BACK) { - if (event.getAction() == KeyEvent.ACTION_UP) { - finish(); - } - return true; - } - return false; - } - - private static final int SET_TITLE = 1; - private static final int SET_SLIDES = 2; - private static final int TOAST_DOWNLOAD = 3; - - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case SET_TITLE: - mTitle.setText((String) msg.obj); - SkiaSampleActivity.this.getActionBar().setSubtitle((String) msg.obj); - break; - case SET_SLIDES: - mSlideList.addAll((String[]) msg.obj); - break; - case TOAST_DOWNLOAD: - Toast.makeText(SkiaSampleActivity.this, (String) msg.obj, - Toast.LENGTH_SHORT).show(); - break; - default: - break; - } - } - }; - - // Called by JNI - @Override - public void setTitle(CharSequence title) { - mHandler.obtainMessage(SET_TITLE, title).sendToTarget(); - } - - // Called by JNI - public void setSlideList(String[] slideList) { - mHandler.obtainMessage(SET_SLIDES, slideList).sendToTarget(); - } - - // Called by JNI - public void addToDownloads(final String title, final String desc, final String path) { - File file = new File(path); - final long length = file.exists() ? file.length() : 0; - if (length == 0) { - String failed = getString(R.string.save_failed); - mHandler.obtainMessage(TOAST_DOWNLOAD, failed).sendToTarget(); - return; - } - String toast = getString(R.string.file_saved).replace("%s", title); - mHandler.obtainMessage(TOAST_DOWNLOAD, toast).sendToTarget(); - final DownloadManager manager = - (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - new Thread("Add PDF to downloads") { - @Override - public void run() { - final String mimeType = "application/pdf"; - manager.addCompletedDownload(title, desc, true, mimeType, path, length, true); - } - }.start(); - } - - private boolean setOpenGLContextSettings(boolean requestedOpenGLAPI, int requestedSampleCount) { - if (mSampleView != null && - mSampleView.getMSAASampleCount() == requestedSampleCount && - mSampleView.getUsesOpenGLAPI() == requestedOpenGLAPI) { - return true; - } - - createSampleView(requestedOpenGLAPI, requestedSampleCount); - - return true; - } -} diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java deleted file mode 100644 index 55257094cd..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -package com.skia; - -import android.opengl.GLSurfaceView; -import android.os.Handler; -import android.util.Log; - -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; -import javax.microedition.khronos.opengles.GL11; - -public class SkiaSampleRenderer implements GLSurfaceView.Renderer { - - private final SkiaSampleView mSampleView; - private Handler mHandler = new Handler(); - private int mMSAASampleCount; - private String mCmdLineFlags; - - SkiaSampleRenderer(SkiaSampleView view, String cmdLineFlags) { - mSampleView = view; - mCmdLineFlags = cmdLineFlags; - } - - @Override - public void onDrawFrame(GL10 gl) { - draw(); - } - - @Override - public void onSurfaceChanged(GL10 gl, int width, int height) { - updateSize(width, height); - } - - @Override - public void onSurfaceCreated(GL10 gl, EGLConfig config) { - if (gl instanceof GL11) { - int value[] = new int[1]; - ((GL11) gl).glGetIntegerv(GL11.GL_SAMPLES, value, 0); - if (value[0] == 1) { - mMSAASampleCount = 0; - } else { - mMSAASampleCount = value[0]; - } - } - - gl.glClearStencil(0); - gl.glClear(GL10.GL_STENCIL_BUFFER_BIT); - - init((SkiaSampleActivity)mSampleView.getContext(), mCmdLineFlags, mMSAASampleCount); - } - - // Called by JNI and the view. - synchronized public int getMSAASampleCount() { - return mMSAASampleCount; - } - - // Called by JNI - private void startTimer(int ms) { - // After the delay, queue an event to the Renderer's thread - // to handle the event on the timer queue - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - mSampleView.queueEvent(new Runnable() { - @Override - public void run() { - serviceQueueTimer(); - } - }); - } - }, ms); - } - - // Called by JNI - private void queueSkEvent() { - mSampleView.queueEvent(new Runnable() { - @Override - public void run() { - processSkEvent(); - } - }); - } - - // Called by JNI - private void requestRender() { - mSampleView.requestRender(); - } - - native void init(SkiaSampleActivity activity, String flags, int msaaSampleCount); - native void term(); - native void draw(); - native void updateSize(int w, int h); - native void handleClick(int owner, float x, float y, int state); - native void showOverview(); - native void nextSample(); - native void previousSample(); - native void goToSample(int position); - native void toggleRenderingMode(); - native void toggleSlideshow(); - native void toggleFPS(); - native void toggleTiling(); - native void toggleBBox(); - native void processSkEvent(); - native void serviceQueueTimer(); - native void saveToPDF(); - native void postInval(); -} \ No newline at end of file diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java deleted file mode 100644 index c33f8ae8ac..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -package com.skia; - -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLDisplay; -import javax.microedition.khronos.opengles.GL10; - -import android.content.Context; -import android.opengl.EGL14; -import android.opengl.GLSurfaceView; -import android.os.Build; -import android.util.Log; -import android.view.MotionEvent; - -public class SkiaSampleView extends GLSurfaceView { - - private final SkiaSampleRenderer mSampleRenderer; - private boolean mRequestedOpenGLAPI; // true == use (desktop) OpenGL. false == use OpenGL ES. - private int mRequestedMSAASampleCount; - - public SkiaSampleView(Context ctx, String cmdLineFlags, boolean useOpenGL, int msaaSampleCount) { - super(ctx); - - mSampleRenderer = new SkiaSampleRenderer(this, cmdLineFlags); - mRequestedMSAASampleCount = msaaSampleCount; - - setEGLContextClientVersion(2); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { - setEGLConfigChooser(8, 8, 8, 8, 0, 8); - } else { - mRequestedOpenGLAPI = useOpenGL; - setEGLConfigChooser(new SampleViewEGLConfigChooser()); - } - setRenderer(mSampleRenderer); - setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - int count = event.getPointerCount(); - for (int i = 0; i < count; i++) { - final float x = event.getX(i); - final float y = event.getY(i); - final int owner = event.getPointerId(i); - int action = event.getAction() & MotionEvent.ACTION_MASK; - switch (action) { - case MotionEvent.ACTION_POINTER_UP: - action = MotionEvent.ACTION_UP; - break; - case MotionEvent.ACTION_POINTER_DOWN: - action = MotionEvent.ACTION_DOWN; - break; - default: - break; - } - final int finalAction = action; - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.handleClick(owner, x, y, finalAction); - } - }); - } - return true; - } - - public void inval() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.postInval(); - } - }); - } - - public void terminate() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.term(); - } - }); - } - - public void showOverview() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.showOverview(); - } - }); - } - - public void nextSample() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.nextSample(); - } - }); - } - - public void previousSample() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.previousSample(); - } - }); - } - - public void goToSample(final int position) { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.goToSample(position); - } - }); - } - - public void toggleRenderingMode() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.toggleRenderingMode(); - } - }); - } - - public void toggleSlideshow() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.toggleSlideshow(); - } - }); - } - - public void toggleFPS() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.toggleFPS(); - } - }); - } - - public void toggleTiling() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.toggleTiling(); - } - }); - } - - public void toggleBBox() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.toggleBBox(); - } - }); - } - - public void saveToPDF() { - queueEvent(new Runnable() { - @Override - public void run() { - mSampleRenderer.saveToPDF(); - } - }); - } - - public boolean getUsesOpenGLAPI() { - return mRequestedOpenGLAPI; - } - - public int getMSAASampleCount() { - return mSampleRenderer.getMSAASampleCount(); - } - - private class SampleViewEGLConfigChooser implements GLSurfaceView.EGLConfigChooser { - - @Override - public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { - int numConfigs = 0; - int[] configSpec = null; - int[] value = new int[1]; - - int[] validAPIs = new int[] { - EGL14.EGL_OPENGL_API, - EGL14.EGL_OPENGL_ES_API - }; - int initialAPI = mRequestedOpenGLAPI ? 0 : 1; - - for (int i = initialAPI; i < validAPIs.length && numConfigs == 0; i++) { - int currentAPI = validAPIs[i]; - EGL14.eglBindAPI(currentAPI); - - // setup the renderableType which will only be included in the - // spec if we are attempting to get access to the OpenGL APIs. - int renderableType = EGL14.EGL_OPENGL_BIT; - if (currentAPI == EGL14.EGL_OPENGL_API) { - renderableType = EGL14.EGL_OPENGL_ES2_BIT; - } - - if (mRequestedMSAASampleCount > 0) { - configSpec = new int[] { - EGL10.EGL_RED_SIZE, 8, - EGL10.EGL_GREEN_SIZE, 8, - EGL10.EGL_BLUE_SIZE, 8, - EGL10.EGL_ALPHA_SIZE, 8, - EGL10.EGL_DEPTH_SIZE, 0, - EGL10.EGL_STENCIL_SIZE, 8, - EGL10.EGL_SAMPLE_BUFFERS, 1, - EGL10.EGL_SAMPLES, mRequestedMSAASampleCount, - EGL10.EGL_RENDERABLE_TYPE, renderableType, - EGL10.EGL_NONE - }; - - // EGL_RENDERABLE_TYPE is only needed when attempting to use - // the OpenGL API (not ES) and causes many EGL drivers to fail - // with a BAD_ATTRIBUTE error. - if (!mRequestedOpenGLAPI) { - configSpec[16] = EGL10.EGL_NONE; - Log.i("Skia", "spec: " + configSpec); - } - - if (!egl.eglChooseConfig(display, configSpec, null, 0, value)) { - Log.i("Skia", "Could not get MSAA context count: " + mRequestedMSAASampleCount); - } - - numConfigs = value[0]; - } - - if (numConfigs <= 0) { - // Try without multisampling. - configSpec = new int[] { - EGL10.EGL_RED_SIZE, 8, - EGL10.EGL_GREEN_SIZE, 8, - EGL10.EGL_BLUE_SIZE, 8, - EGL10.EGL_ALPHA_SIZE, 8, - EGL10.EGL_DEPTH_SIZE, 0, - EGL10.EGL_STENCIL_SIZE, 8, - EGL10.EGL_RENDERABLE_TYPE, renderableType, - EGL10.EGL_NONE - }; - - // EGL_RENDERABLE_TYPE is only needed when attempting to use - // the OpenGL API (not ES) and causes many EGL drivers to fail - // with a BAD_ATTRIBUTE error. - if (!mRequestedOpenGLAPI) { - configSpec[12] = EGL10.EGL_NONE; - Log.i("Skia", "spec: " + configSpec); - } - - if (!egl.eglChooseConfig(display, configSpec, null, 0, value)) { - Log.i("Skia", "Could not get non-MSAA context count"); - } - numConfigs = value[0]; - } - } - - if (numConfigs <= 0) { - throw new IllegalArgumentException("No configs match configSpec"); - } - - // Get all matching configurations. - EGLConfig[] configs = new EGLConfig[numConfigs]; - if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, value)) { - throw new IllegalArgumentException("Could not get config data"); - } - - for (int i = 0; i < configs.length; ++i) { - EGLConfig config = configs[i]; - if (findConfigAttrib(egl, display, config , EGL10.EGL_RED_SIZE, 0) == 8 && - findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0) == 8 && - findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0) == 8 && - findConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0) == 8 && - findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0) == 8) { - return config; - } - } - - throw new IllegalArgumentException("Could not find suitable EGL config"); - } - - private int findConfigAttrib(EGL10 egl, EGLDisplay display, - EGLConfig config, int attribute, int defaultValue) { - int[] value = new int[1]; - if (egl.eglGetConfigAttrib(display, config, attribute, value)) { - return value[0]; - } - return defaultValue; - } - - } -} diff --git a/platform_tools/android/apps/sample_app/src/main/jni/AndroidKeyToSkKey.h b/platform_tools/android/apps/sample_app/src/main/jni/AndroidKeyToSkKey.h deleted file mode 100644 index 6bcb148b46..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/jni/AndroidKeyToSkKey.h +++ /dev/null @@ -1,35 +0,0 @@ - -/* - * Copyright 2011 Skia - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#ifndef _ANDROID_TO_SKIA_KEYCODES_H -#define _ANDROID_TO_SKIA_KEYCODES_H - -#include "android/keycodes.h" -#include "SkKey.h" - -// Convert an Android keycode to an SkKey. This is an incomplete list, only -// including keys used by the sample app. -SkKey AndroidKeycodeToSkKey(int keycode) { - switch (keycode) { - case AKEYCODE_DPAD_LEFT: - return kLeft_SkKey; - case AKEYCODE_DPAD_RIGHT: - return kRight_SkKey; - case AKEYCODE_DPAD_UP: - return kUp_SkKey; - case AKEYCODE_DPAD_DOWN: - return kDown_SkKey; - case AKEYCODE_BACK: - return kBack_SkKey; - default: - return kNONE_SkKey; - } -} - -#endif diff --git a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp b/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp deleted file mode 100644 index d66221a01c..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp +++ /dev/null @@ -1,384 +0,0 @@ - -/* - * Copyright 2011 Skia - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#include "com_skia_SkiaSampleRenderer.h" - -#include "SampleApp.h" -#include "SkApplication.h" -#include "SkCanvas.h" -#include "SkDevice.h" -#include "SkEvent.h" -#include "SkWindow.h" - -#include -#include "AndroidKeyToSkKey.h" - - -/////////////////////////////////////////// -///////////////// Globals ///////////////// -/////////////////////////////////////////// - -struct ActivityGlue { - JNIEnv* m_env; - jweak m_obj; - jmethodID m_setTitle; - jmethodID m_setSlideList; - jmethodID m_addToDownloads; - ActivityGlue() { - m_env = NULL; - m_obj = NULL; - m_setTitle = NULL; - m_setSlideList = NULL; - m_addToDownloads = NULL; - } -} gActivityGlue; - -struct WindowGlue { - jweak m_obj; - jmethodID m_inval; - jmethodID m_queueSkEvent; - jmethodID m_startTimer; - jmethodID m_getMSAASampleCount; - WindowGlue() { - m_obj = NULL; - m_inval = NULL; - m_queueSkEvent = NULL; - m_startTimer = NULL; - m_getMSAASampleCount = NULL; - } -} gWindowGlue; - -SampleWindow* gWindow; - -/////////////////////////////////////////// -///////////// SkOSWindow impl ///////////// -/////////////////////////////////////////// - -SkOSWindow::SkOSWindow(void*) : fDestroyRequested(false) { -} - -SkOSWindow::~SkOSWindow() { -} - -bool SkOSWindow::attach(SkBackEndTypes /* attachType */, int /*msaaSampleCount*/, AttachmentInfo* info) -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env || !gWindowGlue.m_getMSAASampleCount || !gWindowGlue.m_obj) { - return false; - } - if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { - SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); - return false; - } - info->fSampleCount = env->CallIntMethod(gWindowGlue.m_obj, gWindowGlue.m_getMSAASampleCount); - - // This is the value requested in SkiaSampleView.java. - info->fStencilBits = 8; - return true; -} - -void SkOSWindow::detach() { -} - -void SkOSWindow::present() { -} - -void SkOSWindow::closeWindow() { -} - -void SkOSWindow::setVsync(bool) { -} - -void SkOSWindow::onSetTitle(const char title[]) -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env) { - return; - } - if (env->IsSameObject(gActivityGlue.m_obj, NULL)) { - SkDebugf("ERROR: The JNI WeakRef to the Activity is invalid"); - return; - } - - jstring string = env->NewStringUTF(title); - env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_setTitle, string); - env->DeleteLocalRef(string); -} - -void SkOSWindow::onHandleInval(const SkIRect& rect) -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env || !gWindowGlue.m_inval || !gWindowGlue.m_obj) { - return; - } - if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { - SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); - return; - } - env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_inval); -} - -void SkOSWindow::onPDFSaved(const char title[], const char desc[], - const char path[]) -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env || !gActivityGlue.m_addToDownloads || !gActivityGlue.m_obj) { - return; - } - if (env->IsSameObject(gActivityGlue.m_obj, NULL)) { - SkDebugf("ERROR: The JNI WeakRef to the Activity is invalid"); - return; - } - - jstring jtitle = env->NewStringUTF(title); - jstring jdesc = env->NewStringUTF(desc); - jstring jpath = env->NewStringUTF(path); - - env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_addToDownloads, - jtitle, jdesc, jpath); - - env->DeleteLocalRef(jtitle); - env->DeleteLocalRef(jdesc); - env->DeleteLocalRef(jpath); -} - -/////////////////////////////////////////// -/////////////// SkEvent impl ////////////// -/////////////////////////////////////////// - -void SkEvent::SignalQueueTimer(SkMSec ms) -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env || !gWindowGlue.m_startTimer || !gWindowGlue.m_obj || !ms) { - return; - } - if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { - SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); - return; - } - env->CallVoidMethod(gWindowGlue.m_obj, - gWindowGlue.m_startTimer, ms); -} - -void SkEvent::SignalNonEmptyQueue() -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env || !gWindowGlue.m_queueSkEvent || !gWindowGlue.m_obj) { - return; - } - if (env->IsSameObject(gWindowGlue.m_obj, NULL)) { - SkDebugf("ERROR: The JNI WeakRef to the Window is invalid"); - return; - } - env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_queueSkEvent); -} - -/////////////////////////////////////////// -////////////////// JNI //////////////////// -/////////////////////////////////////////// - -static jmethodID GetJMethod(JNIEnv* env, jclass clazz, const char name[], - const char signature[]) -{ - jmethodID m = env->GetMethodID(clazz, name, signature); - if (!m) SkDebugf("Could not find Java method %s\n", name); - return m; -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env, - jobject thiz, jobject jsampleActivity, jstring cmdLineFlags, jint msaaSampleCount) -{ - // setup jni hooks to the java activity - gActivityGlue.m_env = env; - jclass clazz = env->FindClass("com/skia/SkiaSampleActivity"); - gActivityGlue.m_obj = env->NewWeakGlobalRef(jsampleActivity); - gActivityGlue.m_setTitle = GetJMethod(env, clazz, "setTitle", "(Ljava/lang/CharSequence;)V"); - gActivityGlue.m_setSlideList = GetJMethod(env, clazz, "setSlideList", "([Ljava/lang/String;)V"); - gActivityGlue.m_addToDownloads = GetJMethod(env, clazz, "addToDownloads", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); - env->DeleteLocalRef(clazz); - - // setup jni hooks to the java renderer - clazz = env->FindClass("com/skia/SkiaSampleRenderer"); - gWindowGlue.m_obj = env->NewWeakGlobalRef(thiz); - gWindowGlue.m_inval = GetJMethod(env, clazz, "requestRender", "()V"); - gWindowGlue.m_queueSkEvent = GetJMethod(env, clazz, "queueSkEvent", "()V"); - gWindowGlue.m_startTimer = GetJMethod(env, clazz, "startTimer", "(I)V"); - gWindowGlue.m_getMSAASampleCount = GetJMethod(env, clazz, "getMSAASampleCount", "()I"); - env->DeleteLocalRef(clazz); - - application_init(); - - const char* flags = env->GetStringUTFChars(cmdLineFlags, JNI_FALSE); - SkTArray flagEntries; - SkStrSplit(flags, " ", &flagEntries); - - SkTArray args; - args.push_back("SampleApp"); - 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) { - args.push_back("--msaa"); - msaaSampleCountString.appendS32(static_cast(msaaSampleCount)); - args.push_back(msaaSampleCountString.c_str()); - } - - if (gWindow) { - SkDebugf("The sample window already exists."); - } else { - gWindow = new SampleWindow(NULL, args.count(), const_cast(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(); - jobjectArray slideList = env->NewObjectArray(slideCount, env->FindClass("java/lang/String"), env->NewStringUTF("")); - for (int i = 0; i < slideCount; i++) { - jstring slideTitle = env->NewStringUTF(gWindow->getSampleTitle(i).c_str()); - env->SetObjectArrayElement(slideList, i, slideTitle); - env->DeleteLocalRef(slideTitle); - } - env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_setSlideList, slideList); - env->DeleteLocalRef(slideList); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_term(JNIEnv* env, - jobject thiz) -{ - delete gWindow; - gWindow = NULL; - application_term(); - if (gWindowGlue.m_obj) { - env->DeleteWeakGlobalRef(gWindowGlue.m_obj); - gWindowGlue.m_obj = NULL; - } - if (gActivityGlue.m_obj) { - env->DeleteWeakGlobalRef(gActivityGlue.m_obj); - gActivityGlue.m_obj = NULL; - } -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_draw( - JNIEnv* env, jobject thiz) -{ - if (!gWindow) return; - gWindow->update(NULL); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_updateSize(JNIEnv* env, - jobject thiz, jint w, jint h) -{ - gWindow->resize(w, h); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_handleClick(JNIEnv* env, - jobject thiz, jint owner, jfloat x, jfloat y, jint jstate) -{ - SkView::Click::State state; - switch(jstate) { - case 0: // MotionEvent.ACTION_DOWN - state = SkView::Click::kDown_State; - break; - case 1: // MotionEvent.ACTION_UP - case 3: // MotionEvent.ACTION_CANCEL - state = SkView::Click::kUp_State; - break; - case 2: // MotionEvent.ACTION_MOVE - state = SkView::Click::kMoved_State; - break; - default: - SkDebugf("motion event ignored\n"); - return; - } - gWindow->handleClick(x, y, state, reinterpret_cast(owner)); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_nextSample( - JNIEnv* env, jobject thiz) -{ - gWindow->nextSample(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_previousSample( - JNIEnv* env, jobject thiz) -{ - gWindow->previousSample(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_goToSample( - JNIEnv* env, jobject thiz, jint position) -{ - gWindow->goToSample(position); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleRenderingMode( - JNIEnv* env, jobject thiz) -{ - gWindow->toggleRendering(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_showOverview( - JNIEnv* env, jobject thiz) -{ - gWindow->showOverview(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleSlideshow( - JNIEnv* env, jobject thiz) -{ - gWindow->toggleSlideshow(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleFPS( - JNIEnv* env, jobject thiz) -{ - gWindow->toggleFPS(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleTiling( - JNIEnv* env, jobject thiz) -{ - gWindow->handleChar('t'); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleBBox( - JNIEnv* env, jobject thiz) -{ - gWindow->handleChar('b'); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_processSkEvent( - JNIEnv* env, jobject thiz) -{ - if (SkEvent::ProcessEvent()) { - SkEvent::SignalNonEmptyQueue(); - } -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_serviceQueueTimer( - JNIEnv* env, jobject thiz) -{ - SkEvent::ServiceQueueTimer(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_saveToPDF( - JNIEnv* env, jobject thiz) -{ - gWindow->saveToPdf(); -} - -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_postInval( - JNIEnv* env, jobject thiz) -{ - gWindow->postInvalDelay(); -} diff --git a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h b/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h deleted file mode 100644 index 8883a3a9f0..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2015 Skia - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_skia_SkiaSampleRenderer */ - -#ifndef _Included_com_skia_SkiaSampleRenderer -#define _Included_com_skia_SkiaSampleRenderer -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_skia_SkiaSampleRenderer - * Method: init - * Signature: (Lcom/skia/SkiaSampleActivity;Ljava/lang/String;I)V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init - (JNIEnv *, jobject, jobject, jstring, jint); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: term - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_term - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: draw - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_draw - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: updateSize - * Signature: (II)V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_updateSize - (JNIEnv *, jobject, jint, jint); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: handleClick - * Signature: (IFFI)V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_handleClick - (JNIEnv *, jobject, jint, jfloat, jfloat, jint); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: showOverview - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_showOverview - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: nextSample - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_nextSample - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: previousSample - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_previousSample - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: goToSample - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_goToSample - (JNIEnv *, jobject, jint); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: toggleRenderingMode - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleRenderingMode - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: toggleSlideshow - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleSlideshow - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: toggleFPS - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleFPS - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: toggleTiling - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleTiling - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: toggleBBox - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_toggleBBox - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: processSkEvent - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_processSkEvent - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: serviceQueueTimer - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_serviceQueueTimer - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: saveToPdf - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_saveToPDF - (JNIEnv *, jobject); - -/* - * Class: com_skia_SkiaSampleRenderer - * Method: postInval - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_postInval - (JNIEnv *, jobject); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_next.png b/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_next.png deleted file mode 100644 index b696a6bb22..0000000000 Binary files a/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_next.png and /dev/null differ diff --git a/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_prev.png b/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_prev.png deleted file mode 100644 index 5550c5a6ff..0000000000 Binary files a/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_prev.png and /dev/null differ diff --git a/platform_tools/android/apps/sample_app/src/main/res/layout/layout.xml b/platform_tools/android/apps/sample_app/src/main/res/layout/layout.xml deleted file mode 100644 index cdb90e9961..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/res/layout/layout.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - diff --git a/platform_tools/android/apps/sample_app/src/main/res/menu/action_bar.xml b/platform_tools/android/apps/sample_app/src/main/res/menu/action_bar.xml deleted file mode 100644 index 72e135e43b..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/res/menu/action_bar.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml b/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml deleted file mode 100644 index b0b4e7b74b..0000000000 --- a/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - Skia Samples - Overview - Toggle Rendering - Slideshow - FPS - Toggle Tiling - Toggle SKP BBox - Save to PDF - Save Failed - %s saved! - Set OpenGL Context Type - OpenGL ES - OpenGL ES, MSAA4 - OpenGL - OpenGL, MSAA4 - \ No newline at end of file diff --git a/platform_tools/android/apps/settings.gradle b/platform_tools/android/apps/settings.gradle deleted file mode 100644 index 89cc95447b..0000000000 --- a/platform_tools/android/apps/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':sample_app' -include ':visualbench' diff --git a/platform_tools/android/apps/visualbench/build.gradle b/platform_tools/android/apps/visualbench/build.gradle deleted file mode 100644 index 81322b026e..0000000000 --- a/platform_tools/android/apps/visualbench/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 19 - buildToolsVersion "22.0.1" - - defaultConfig { - applicationId "com.skia.visualbench" - minSdkVersion 9 - targetSdkVersion 19 - versionCode 1 - versionName "1.0" - } - - sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call - sourceSets.main.jniLibs.srcDir "src/main/libs" - - productFlavors { - arm {} - arm64 {} - x86 {} - x86_64 {} - mips {} - mips64 {} - } - - // make sure that app is built and shared libraries are copied to correct directories - applicationVariants.all{ variant -> - - def buildNativeLib = task("${variant.name}_NativeLib", type:Exec) { - workingDir '../../../..' // top-level skia directory - commandLine constructBuildCommand(variant, "CopyVisualBenchDeps").split() - environment PATH: getPathWithDepotTools() - environment ANDROID_SDK_ROOT: getSDKPath() - } - - if (!hasProperty("suppressNativeBuild")) { - TaskCollection assembleTask - assembleTask = project.tasks.matching { - it.name.contains("assemble") && - it.name.toLowerCase().endsWith(variant.name.toLowerCase()) - } - assembleTask.getAt(0).dependsOn buildNativeLib - } - } -} \ No newline at end of file diff --git a/platform_tools/android/apps/visualbench/src/main/AndroidManifest.xml b/platform_tools/android/apps/visualbench/src/main/AndroidManifest.xml deleted file mode 100644 index c15dee6e16..0000000000 --- a/platform_tools/android/apps/visualbench/src/main/AndroidManifest.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java b/platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java deleted file mode 100644 index 90f70bfe0a..0000000000 --- a/platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -package com.skia; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.provider.Settings; -import android.util.Log; -import android.view.View; -import android.view.WindowManager; - -public class VisualBenchActivity extends android.app.NativeActivity { - static { - System.loadLibrary("skia_android"); - } - - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - - // Setup a bunch of window parameters. We have to do this here to prevent our backend from - // getting spurious term / init messages when we relayout - - // Layout fullscreen and keep screen on - getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | - WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - - getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // hide nav bar - View.SYSTEM_UI_FLAG_FULLSCREEN |// hide status bar - View.SYSTEM_UI_FLAG_IMMERSIVE); - - // Disable backlight to keep the system as cool as possible - // TODO make this configurable - Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, - Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); - - WindowManager.LayoutParams lp = getWindow().getAttributes(); - lp.screenBrightness = 0; // 0f - no backlight - getWindow().setAttributes(lp); - } -} diff --git a/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp b/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp deleted file mode 100644 index e2bc99610f..0000000000 --- a/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkOSWindow_Android.h" - -#include - -SkOSWindow::SkOSWindow(void* hwnd) { - fWindow.fDisplay = EGL_NO_DISPLAY; - fWindow.fContext = EGL_NO_CONTEXT; - fWindow.fSurface = EGL_NO_SURFACE; - fNativeWindow = (ANativeWindow*)hwnd; - fDestroyRequested = false; -} - -SkOSWindow::~SkOSWindow() { - if (fWindow.fDisplay != EGL_NO_DISPLAY) { - eglMakeCurrent(fWindow.fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (fWindow.fContext != EGL_NO_CONTEXT) { - eglDestroyContext(fWindow.fDisplay, fWindow.fContext); - } - if (fWindow.fSurface != EGL_NO_SURFACE) { - eglDestroySurface(fWindow.fDisplay, fWindow.fSurface); - } - eglTerminate(fWindow.fDisplay); - } - fWindow.fDisplay = EGL_NO_DISPLAY; - fWindow.fContext = EGL_NO_CONTEXT; - fWindow.fSurface = EGL_NO_SURFACE; -} - -bool SkOSWindow::attach(SkBackEndTypes attachType, - int /*msaaSampleCount*/, - AttachmentInfo* info) { - static const EGLint kEGLContextAttribsForOpenGL[] = { - EGL_NONE - }; - - static const EGLint kEGLContextAttribsForOpenGLES[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - - static const struct { - const EGLint* fContextAttribs; - EGLenum fAPI; - EGLint fRenderableTypeBit; - } kAPIs[] = { - { // OpenGL - kEGLContextAttribsForOpenGL, - EGL_OPENGL_API, - EGL_OPENGL_BIT, - }, - { // OpenGL ES. This seems to work for both ES2 and 3 (when available). - kEGLContextAttribsForOpenGLES, - EGL_OPENGL_ES_API, - EGL_OPENGL_ES2_BIT, - }, - }; - - size_t apiLimit = SK_ARRAY_COUNT(kAPIs); - - for (size_t api = 0; api < apiLimit; ++api) { - EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - - EGLint majorVersion; - EGLint minorVersion; - eglInitialize(display, &majorVersion, &minorVersion); - -#if 0 - SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); - SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); - SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); - SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS)); -#endif - - if (!eglBindAPI(kAPIs[api].fAPI)) { - continue; - } - - const EGLint configAttribs[] = { - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, - EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_NONE - }; - - EGLint format; - EGLint numConfigs; - EGLConfig config; - EGLSurface surface; - EGLContext context; - - /* Here, the application chooses the configuration it desires. In this - * sample, we have a very simplified selection process, where we pick - * the first EGLConfig that matches our criteria */ - eglChooseConfig(display, configAttribs, &config, 1, &numConfigs); - - /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is - * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). - * As soon as we picked a EGLConfig, we can safely reconfigure the - * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ - eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); - - ANativeWindow_setBuffersGeometry(fNativeWindow, 0, 0, format); - - surface = eglCreateWindowSurface(display, config, fNativeWindow, NULL); - context = eglCreateContext(display, config, NULL, kAPIs[api].fContextAttribs); - if (EGL_NO_CONTEXT == context) { - SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetError()); - continue; - } - - if (!eglMakeCurrent(display, surface, surface, context)) { - SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError()); - continue; - } - - fWindow.fDisplay = display; - fWindow.fContext = context; - fWindow.fSurface = surface; - } - - if (fWindow.fDisplay && fWindow.fContext && fWindow.fSurface) { - EGLint w, h; - eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_WIDTH, &w); - eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_HEIGHT, &h); - - glViewport(0, 0, w, h); - glClearColor(0.0, 0, 0, 0.0); - glClearStencil(0); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - - // We retrieve the fullscreen width and height - this->setSize((SkScalar)w, (SkScalar)h); - return true; - } else { - return false; - } -} - -void SkOSWindow::detach() { - fDestroyRequested = true; -} - -void SkOSWindow::present() { - if (fWindow.fDisplay != EGL_NO_DISPLAY && fWindow.fContext != EGL_NO_CONTEXT) { - eglSwapBuffers(fWindow.fDisplay, fWindow.fSurface); - } -} - -void SkOSWindow::closeWindow() { - fDestroyRequested = true; -} - -void SkOSWindow::setVsync(bool vsync) { - if (fWindow.fDisplay != EGL_NO_DISPLAY) { - int swapInterval = vsync ? 1 : 0; - eglSwapInterval(fWindow.fDisplay, swapInterval); - } -} - -void SkOSWindow::onSetTitle(const char title[]) { -} - -void SkOSWindow::onHandleInval(const SkIRect& rect) { -} - -void SkOSWindow::onPDFSaved(const char title[], const char desc[], const char path[]) { -} - -/////////////////////////////////////////// -/////////////// SkEvent impl ////////////// -/////////////////////////////////////////// - -void SkEvent::SignalQueueTimer(SkMSec ms) { -} - -void SkEvent::SignalNonEmptyQueue() { -} diff --git a/platform_tools/android/apps/visualbench/src/main/jni/main.cpp b/platform_tools/android/apps/visualbench/src/main/jni/main.cpp deleted file mode 100644 index 2ea6b76b39..0000000000 --- a/platform_tools/android/apps/visualbench/src/main/jni/main.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - */ - -#include - -#include "SkApplication.h" -#include "VisualBench.h" - -/** - * Shared state for our app. - */ -enum State { - kInit_State, - kAnimate_State, - kDestroyRequested_State, - kFinished_State, -}; - -struct VisualBenchState { - VisualBenchState() : fApp(NULL), fWindow(NULL), fState(kInit_State) {} - struct android_app* fApp; - SkOSWindow* fWindow; - SkTArray fFlags; - State fState; -}; - -static void handle_cmd(struct android_app* app, int32_t cmd) { - struct VisualBenchState* state = (struct VisualBenchState*)app->userData; - switch (cmd) { - case APP_CMD_INIT_WINDOW: - // The window is being shown, get it ready. - if (state->fApp->window != NULL && kInit_State == state->fState) { - // drain any events that occurred before |window| was assigned. - while (SkEvent::ProcessEvent()); - - // Start normal Skia sequence - application_init(); - - SkTArray args; - args.push_back("VisualBench"); - for (int i = 0; i < state->fFlags.count(); i++) { - SkDebugf(state->fFlags[i].c_str()); - args.push_back(state->fFlags[i].c_str()); - } - - state->fWindow = create_sk_window((void*)state->fApp->window, - args.count(), - const_cast(args.begin())); - state->fWindow->forceInvalAll(); - state->fState = kAnimate_State; - } - break; - case APP_CMD_TERM_WINDOW: - state->fState = kDestroyRequested_State; - break; - } -} - -void android_main(struct android_app* state) { - struct VisualBenchState visualBenchState; - - // Make sure glue isn't stripped. - app_dummy(); - - state->userData = &visualBenchState; - state->onAppCmd = handle_cmd; - visualBenchState.fApp = state; - - // Get command line arguments - JavaVM* jvm = state->activity->vm; - JNIEnv *env; - jvm->AttachCurrentThread(&env, 0); - - jobject me = state->activity->clazz; - - jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity - jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;"); - jobject intent = env->CallObjectMethod(me, giid); //Got our intent - - jclass icl = env->GetObjectClass(intent); //class pointer of Intent - jmethodID gseid = env->GetMethodID(icl, "getStringExtra", - "(Ljava/lang/String;)Ljava/lang/String;"); - - jstring jsParam1 = (jstring)env->CallObjectMethod(intent, gseid, - env->NewStringUTF("cmdLineFlags")); - if (jsParam1) { - const char* flags = env->GetStringUTFChars(jsParam1, 0); - SkStrSplit(flags, " ", &visualBenchState.fFlags); - env->ReleaseStringUTFChars(jsParam1, flags); - } - jvm->DetachCurrentThread(); - - while (1) { - // Read all pending events. - int ident; - int events; - struct android_poll_source* source; - - // We loop until all events are read, then continue to draw the next frame of animation. - while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { - // Process this event. - if (source != NULL) { - source->process(state, source); - } - - // Check if we are exiting. - if (state->destroyRequested != 0) { - return; - } - - } - - if (visualBenchState.fWindow) { - if (visualBenchState.fWindow->destroyRequested()) { - visualBenchState.fState = kDestroyRequested_State; - } else { - visualBenchState.fWindow->update(NULL); - } - } - - if (kDestroyRequested_State == visualBenchState.fState) { - SkDELETE(visualBenchState.fWindow); - visualBenchState.fWindow = NULL; - application_term(); - ANativeActivity_finish(state->activity); - visualBenchState.fState = kFinished_State; - } - } -} diff --git a/platform_tools/android/bin/android_install_app b/platform_tools/android/bin/android_install_app index ed5ed61318..a8c1a12b2b 100755 --- a/platform_tools/android/bin/android_install_app +++ b/platform_tools/android/bin/android_install_app @@ -9,7 +9,7 @@ function print_usage { echo " -h Prints this help message" echo " --release Install the release build of Skia" echo " -s [device_s/n] Serial number of the device to be used" - echo " AppName Can be either sample_app or VisualBench" + echo " AppName Can be either SampleApp or VisualBench" } SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" @@ -18,6 +18,8 @@ source $SCRIPT_DIR/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh forceRemoval="false" +installLauncher="false" +installOptions="-r" app="" for arg in ${APP_ARGS[@]}; do @@ -43,8 +45,8 @@ for arg in ${APP_ARGS[@]}; do done if [[ ${app} == "" ]]; then - echo "defaulting to installing sample_app." - app="sample_app" + echo "defaulting to installing SampleApp." + app="SampleApp" fi @@ -54,8 +56,6 @@ then $ADB ${DEVICE_SERIAL} uninstall com.skia > /dev/null fi -BUILD_TYPE_LC=$(echo $BUILDTYPE | tr "[:upper:]" "[:lower:]") - -echo "Installing ${app} from ${app}/build/outputs/apk/${app}-${ANDROID_ARCH}-${BUILD_TYPE_LC}.apk" -$ADB ${DEVICE_SERIAL} install -r ${SCRIPT_DIR}/../apps/${app}/build/outputs/apk/${app}-${ANDROID_ARCH}-${BUILD_TYPE_LC}.apk +echo "Installing ${app} from ${SKIA_OUT}/${BUILDTYPE}" +$ADB ${DEVICE_SERIAL} install ${installOptions} ${SKIA_OUT}/${BUILDTYPE}/android/${app}/bin/${app}.apk diff --git a/platform_tools/android/bin/android_setup.sh b/platform_tools/android/bin/android_setup.sh index 5396294c7f..94ae87f9a1 100755 --- a/platform_tools/android/bin/android_setup.sh +++ b/platform_tools/android/bin/android_setup.sh @@ -70,11 +70,6 @@ if [ -z "$ANDROID_SDK_ROOT" ]; then fi fi -if [ -z "$ANDROID_HOME" ]; then - echo "ANDROID_HOME not set so we are setting it to a default value of ANDROID_SDK_ROOT" - exportVar ANDROID_HOME $ANDROID_SDK_ROOT -fi - # check to see that gclient sync ran successfully THIRD_PARTY_EXTERNAL_DIR=${SCRIPT_DIR}/../third_party/externals if [ ! -d "$THIRD_PARTY_EXTERNAL_DIR" ]; then diff --git a/platform_tools/android/gyp/dependencies.gypi b/platform_tools/android/gyp/dependencies.gypi index 036abf2cc5..8be6836f37 100644 --- a/platform_tools/android/gyp/dependencies.gypi +++ b/platform_tools/android/gyp/dependencies.gypi @@ -287,7 +287,7 @@ }], ], 'sources': [ - '../apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp', + '../app/jni/com_skia_SkiaSampleRenderer.cpp', ], }, }, @@ -320,8 +320,8 @@ '../../../tools/VisualBench/', ], 'sources': [ - '../apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp', - '../apps/visualbench/src/main/jni/main.cpp', + '../visualbench/jni/SkOSWindow_AndroidNative.cpp', + '../visualbench/jni/main.cpp', ], }, }, diff --git a/platform_tools/android/gyp/skia_android.gypi b/platform_tools/android/gyp/skia_android.gypi index 6ffb49cd93..e8bf1c3150 100644 --- a/platform_tools/android/gyp/skia_android.gypi +++ b/platform_tools/android/gyp/skia_android.gypi @@ -12,31 +12,24 @@ 'conditions': [ [ 'skia_arch_type == "arm" and arm_version != 7', { 'android_arch%': "armeabi", - 'android_variant%': "arm", }], [ 'skia_arch_type == "arm" and arm_version == 7', { 'android_arch%': "armeabi-v7a", - 'android_variant%': "arm", }], [ 'skia_arch_type == "arm64"', { 'android_arch%': "arm64-v8a", - 'android_variant%': "arm64", }], [ 'skia_arch_type == "x86"', { 'android_arch%': "x86", - 'android_variant%': "x86", }], [ 'skia_arch_type == "x86_64"', { 'android_arch%': "x86_64", - 'android_variant%': "x86_64", }], [ 'skia_arch_type == "mips" and skia_arch_width == 32', { 'android_arch%': "mips", - 'android_variant%': "mips", }], [ 'skia_arch_type == "mips" and skia_arch_width == 64', { 'android_arch%': "mips64", - 'android_variant%': "mips64", }], ], }, @@ -55,7 +48,7 @@ # libraries to copy, this will cause an error in Make, but the app will # still build. { - 'destination': '<(android_base)/apps/sample_app/src/main/libs/<(android_arch)', + 'destination': '<(PRODUCT_DIR)/android/SampleApp/libs/<(android_arch)', 'conditions': [ [ 'skia_shared_lib', { 'files': [ @@ -76,25 +69,40 @@ 'dependencies': [ 'CopySampleAppDeps', ], + 'variables': { + 'ANDROID_SDK_ROOT': ' + + + + + + + + + + + + + + + + + + + + + diff --git a/platform_tools/android/visualbench/build.xml b/platform_tools/android/visualbench/build.xml new file mode 100644 index 0000000000..61df264754 --- /dev/null +++ b/platform_tools/android/visualbench/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/platform_tools/android/visualbench/jni/SkOSWindow_AndroidNative.cpp b/platform_tools/android/visualbench/jni/SkOSWindow_AndroidNative.cpp new file mode 100644 index 0000000000..e2bc99610f --- /dev/null +++ b/platform_tools/android/visualbench/jni/SkOSWindow_AndroidNative.cpp @@ -0,0 +1,187 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkOSWindow_Android.h" + +#include + +SkOSWindow::SkOSWindow(void* hwnd) { + fWindow.fDisplay = EGL_NO_DISPLAY; + fWindow.fContext = EGL_NO_CONTEXT; + fWindow.fSurface = EGL_NO_SURFACE; + fNativeWindow = (ANativeWindow*)hwnd; + fDestroyRequested = false; +} + +SkOSWindow::~SkOSWindow() { + if (fWindow.fDisplay != EGL_NO_DISPLAY) { + eglMakeCurrent(fWindow.fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (fWindow.fContext != EGL_NO_CONTEXT) { + eglDestroyContext(fWindow.fDisplay, fWindow.fContext); + } + if (fWindow.fSurface != EGL_NO_SURFACE) { + eglDestroySurface(fWindow.fDisplay, fWindow.fSurface); + } + eglTerminate(fWindow.fDisplay); + } + fWindow.fDisplay = EGL_NO_DISPLAY; + fWindow.fContext = EGL_NO_CONTEXT; + fWindow.fSurface = EGL_NO_SURFACE; +} + +bool SkOSWindow::attach(SkBackEndTypes attachType, + int /*msaaSampleCount*/, + AttachmentInfo* info) { + static const EGLint kEGLContextAttribsForOpenGL[] = { + EGL_NONE + }; + + static const EGLint kEGLContextAttribsForOpenGLES[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + static const struct { + const EGLint* fContextAttribs; + EGLenum fAPI; + EGLint fRenderableTypeBit; + } kAPIs[] = { + { // OpenGL + kEGLContextAttribsForOpenGL, + EGL_OPENGL_API, + EGL_OPENGL_BIT, + }, + { // OpenGL ES. This seems to work for both ES2 and 3 (when available). + kEGLContextAttribsForOpenGLES, + EGL_OPENGL_ES_API, + EGL_OPENGL_ES2_BIT, + }, + }; + + size_t apiLimit = SK_ARRAY_COUNT(kAPIs); + + for (size_t api = 0; api < apiLimit; ++api) { + EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + + EGLint majorVersion; + EGLint minorVersion; + eglInitialize(display, &majorVersion, &minorVersion); + +#if 0 + SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); + SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); + SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); + SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS)); +#endif + + if (!eglBindAPI(kAPIs[api].fAPI)) { + continue; + } + + const EGLint configAttribs[] = { + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_NONE + }; + + EGLint format; + EGLint numConfigs; + EGLConfig config; + EGLSurface surface; + EGLContext context; + + /* Here, the application chooses the configuration it desires. In this + * sample, we have a very simplified selection process, where we pick + * the first EGLConfig that matches our criteria */ + eglChooseConfig(display, configAttribs, &config, 1, &numConfigs); + + /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is + * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). + * As soon as we picked a EGLConfig, we can safely reconfigure the + * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ + eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); + + ANativeWindow_setBuffersGeometry(fNativeWindow, 0, 0, format); + + surface = eglCreateWindowSurface(display, config, fNativeWindow, NULL); + context = eglCreateContext(display, config, NULL, kAPIs[api].fContextAttribs); + if (EGL_NO_CONTEXT == context) { + SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetError()); + continue; + } + + if (!eglMakeCurrent(display, surface, surface, context)) { + SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError()); + continue; + } + + fWindow.fDisplay = display; + fWindow.fContext = context; + fWindow.fSurface = surface; + } + + if (fWindow.fDisplay && fWindow.fContext && fWindow.fSurface) { + EGLint w, h; + eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_WIDTH, &w); + eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_HEIGHT, &h); + + glViewport(0, 0, w, h); + glClearColor(0.0, 0, 0, 0.0); + glClearStencil(0); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + // We retrieve the fullscreen width and height + this->setSize((SkScalar)w, (SkScalar)h); + return true; + } else { + return false; + } +} + +void SkOSWindow::detach() { + fDestroyRequested = true; +} + +void SkOSWindow::present() { + if (fWindow.fDisplay != EGL_NO_DISPLAY && fWindow.fContext != EGL_NO_CONTEXT) { + eglSwapBuffers(fWindow.fDisplay, fWindow.fSurface); + } +} + +void SkOSWindow::closeWindow() { + fDestroyRequested = true; +} + +void SkOSWindow::setVsync(bool vsync) { + if (fWindow.fDisplay != EGL_NO_DISPLAY) { + int swapInterval = vsync ? 1 : 0; + eglSwapInterval(fWindow.fDisplay, swapInterval); + } +} + +void SkOSWindow::onSetTitle(const char title[]) { +} + +void SkOSWindow::onHandleInval(const SkIRect& rect) { +} + +void SkOSWindow::onPDFSaved(const char title[], const char desc[], const char path[]) { +} + +/////////////////////////////////////////// +/////////////// SkEvent impl ////////////// +/////////////////////////////////////////// + +void SkEvent::SignalQueueTimer(SkMSec ms) { +} + +void SkEvent::SignalNonEmptyQueue() { +} diff --git a/platform_tools/android/visualbench/jni/main.cpp b/platform_tools/android/visualbench/jni/main.cpp new file mode 100644 index 0000000000..2ea6b76b39 --- /dev/null +++ b/platform_tools/android/visualbench/jni/main.cpp @@ -0,0 +1,134 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + */ + +#include + +#include "SkApplication.h" +#include "VisualBench.h" + +/** + * Shared state for our app. + */ +enum State { + kInit_State, + kAnimate_State, + kDestroyRequested_State, + kFinished_State, +}; + +struct VisualBenchState { + VisualBenchState() : fApp(NULL), fWindow(NULL), fState(kInit_State) {} + struct android_app* fApp; + SkOSWindow* fWindow; + SkTArray fFlags; + State fState; +}; + +static void handle_cmd(struct android_app* app, int32_t cmd) { + struct VisualBenchState* state = (struct VisualBenchState*)app->userData; + switch (cmd) { + case APP_CMD_INIT_WINDOW: + // The window is being shown, get it ready. + if (state->fApp->window != NULL && kInit_State == state->fState) { + // drain any events that occurred before |window| was assigned. + while (SkEvent::ProcessEvent()); + + // Start normal Skia sequence + application_init(); + + SkTArray args; + args.push_back("VisualBench"); + for (int i = 0; i < state->fFlags.count(); i++) { + SkDebugf(state->fFlags[i].c_str()); + args.push_back(state->fFlags[i].c_str()); + } + + state->fWindow = create_sk_window((void*)state->fApp->window, + args.count(), + const_cast(args.begin())); + state->fWindow->forceInvalAll(); + state->fState = kAnimate_State; + } + break; + case APP_CMD_TERM_WINDOW: + state->fState = kDestroyRequested_State; + break; + } +} + +void android_main(struct android_app* state) { + struct VisualBenchState visualBenchState; + + // Make sure glue isn't stripped. + app_dummy(); + + state->userData = &visualBenchState; + state->onAppCmd = handle_cmd; + visualBenchState.fApp = state; + + // Get command line arguments + JavaVM* jvm = state->activity->vm; + JNIEnv *env; + jvm->AttachCurrentThread(&env, 0); + + jobject me = state->activity->clazz; + + jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity + jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;"); + jobject intent = env->CallObjectMethod(me, giid); //Got our intent + + jclass icl = env->GetObjectClass(intent); //class pointer of Intent + jmethodID gseid = env->GetMethodID(icl, "getStringExtra", + "(Ljava/lang/String;)Ljava/lang/String;"); + + jstring jsParam1 = (jstring)env->CallObjectMethod(intent, gseid, + env->NewStringUTF("cmdLineFlags")); + if (jsParam1) { + const char* flags = env->GetStringUTFChars(jsParam1, 0); + SkStrSplit(flags, " ", &visualBenchState.fFlags); + env->ReleaseStringUTFChars(jsParam1, flags); + } + jvm->DetachCurrentThread(); + + while (1) { + // Read all pending events. + int ident; + int events; + struct android_poll_source* source; + + // We loop until all events are read, then continue to draw the next frame of animation. + while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { + // Process this event. + if (source != NULL) { + source->process(state, source); + } + + // Check if we are exiting. + if (state->destroyRequested != 0) { + return; + } + + } + + if (visualBenchState.fWindow) { + if (visualBenchState.fWindow->destroyRequested()) { + visualBenchState.fState = kDestroyRequested_State; + } else { + visualBenchState.fWindow->update(NULL); + } + } + + if (kDestroyRequested_State == visualBenchState.fState) { + SkDELETE(visualBenchState.fWindow); + visualBenchState.fWindow = NULL; + application_term(); + ANativeActivity_finish(state->activity); + visualBenchState.fState = kFinished_State; + } + } +} diff --git a/platform_tools/android/visualbench/project.properties b/platform_tools/android/visualbench/project.properties new file mode 100644 index 0000000000..4ab125693c --- /dev/null +++ b/platform_tools/android/visualbench/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/platform_tools/android/visualbench/src/com/skia/VisualBenchActivity.java b/platform_tools/android/visualbench/src/com/skia/VisualBenchActivity.java new file mode 100644 index 0000000000..90f70bfe0a --- /dev/null +++ b/platform_tools/android/visualbench/src/com/skia/VisualBenchActivity.java @@ -0,0 +1,49 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +package com.skia; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.provider.Settings; +import android.util.Log; +import android.view.View; +import android.view.WindowManager; + +public class VisualBenchActivity extends android.app.NativeActivity { + static { + System.loadLibrary("skia_android"); + } + + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + // Setup a bunch of window parameters. We have to do this here to prevent our backend from + // getting spurious term / init messages when we relayout + + // Layout fullscreen and keep screen on + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // hide nav bar + View.SYSTEM_UI_FLAG_FULLSCREEN |// hide status bar + View.SYSTEM_UI_FLAG_IMMERSIVE); + + // Disable backlight to keep the system as cool as possible + // TODO make this configurable + Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, + Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); + + WindowManager.LayoutParams lp = getWindow().getAttributes(); + lp.screenBrightness = 0; // 0f - no backlight + getWindow().setAttributes(lp); + } +} diff --git a/site/user/quick/android.md b/site/user/quick/android.md index 57d45d5259..44e3161c40 100644 --- a/site/user/quick/android.md +++ b/site/user/quick/android.md @@ -10,12 +10,20 @@ _Currently we only support building Skia for Android on a Linux or Mac host! In The following libraries/utilities are required in addition to those needed for a standard skia checkout: + * Apache Ant * The Android SDK: http://developer.android.com/sdk/ +~~~~ +$ sudo apt-get install ant git +~~~~ + Check out the source code ------------------------- -Follow the instructions [here](../download) for downloading the Skia source. +Follow the instructions [here](../download) for downloading the Skia source. Modify .gclient to add the following line to +the bottom, and then run gclient sync again: + + target_os = ["android"] Inside your Skia checkout, `platform_tools/android` contains the Android setup scripts, Android specific dependencies, and the Android Sample App. @@ -55,7 +63,6 @@ the -d option plus any of the options or arguments you would normally pass to ninja (see descriptions of some of the other flags here). export ANDROID_SDK_ROOT=/path/to/android/sdk - export ANDROID_HOME=/path/to/android/sdk export PATH=$PATH:/path/to/depot_tools cd skia @@ -128,7 +135,7 @@ Build and run SampleApp The SampleApp on Android provides a simple UI for viewing sample slides and gm images. - BUILDTYPE=Debug ./platform_tools/android/bin/android_ninja -d $TARGET_DEVICE SampleApp_APK + BUILDTYPE=Debug ./platform_tools/android/bin/android_ninja -d $TARGET_DEVICE Then, install the app onto the device: @@ -148,28 +155,6 @@ params... --resourcePath /data/local/tmp/skia_resoures --pictureDir /data/local/tmp/skia_skp - -Android Studio Support ------------------------ - -You can also build and run SampleApp (and some other experimental apps) using Android -Studio. To create the project either select "import project" from the quickstart -screen or use File -> Open. In both cases you'll need to select ./platform_tools/android/apps -as the root directory of your project. - -Finally to be able to build within Android studio it needs to know the path to -ninja so you will need to add a properties file and populate it with the path -to depot_tools. The syntax and location of that file is... - - # - # file location: ./platform_tools/android/apps/gradle.properties - # - depot_tools.dir= - -That should be all the setup you need. You should now be able to build and deploy -SampleApp on ARM, Intel, and MIPS devices. - - Build tools ----------- -- cgit v1.2.3