libviewer.so on Android, delete hello_skia_app

This spins off parts of 5620 to bake while we work through how to do the rest of libviewer.so -> viewer.apk.

Change-Id: I1cbf135cc952eeb7593e80a5a752dcadaa2dbb00
Reviewed-on: https://skia-review.googlesource.com/5656
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2016-12-08 09:49:39 -05:00 committed by Skia Commit-Bot
parent 9f549358b3
commit a92c383e2f
10 changed files with 18 additions and 361 deletions

View File

@ -1311,8 +1311,8 @@ if (skia_enable_tools) {
testonly = true
}
if (skia_enable_gpu && (is_linux || is_win || is_mac)) {
executable("viewer") {
if (skia_enable_gpu && (is_android || is_linux || is_win || is_mac)) {
source_set("viewer_sources") {
sources = [
"tools/viewer/GMSlide.cpp",
"tools/viewer/ImageSlide.cpp",
@ -1389,6 +1389,22 @@ if (skia_enable_tools) {
}
testonly = true
}
if (is_android) {
shared_library("libviewer") {
deps = [
":viewer_sources",
]
testonly = true
}
} else {
executable("viewer") {
deps = [
":viewer_sources",
]
testonly = true
}
}
}
if (skia_enable_gpu) {

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="15" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:debuggable="true">
<activity android:name="HelloSkiaActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -1,39 +0,0 @@
HelloSkia
=========
Intro
-----
This is a minimal Android app that uses JNI and Skia to do rendering.
Setup
-----
These instructions need to be followed only once to setup your copy of HelloSkia. Path parts that
are surrounded with curly braces should be replaced with the paths that are described.
1. Follow the quick start guide on building Skia for Android.
2. Copy {Skia root directory}/trunk/out/config/android-{your architecture}/{Relase or
Debug}/lib.target/libskia_android.so into {HellSkia root directory}/jni/skia/libskia_android.so
3. Copy {Skia root directory}/trunk/include into {HellSkia root directory}/jni/skia. This should be
done so that the path {HellSkia root directory}/jni/skia/include is a folder that contains, to name
just a few, the folders config and core.
Building
--------
The following assumes that the platform-tools directory of the Android SDK and the Android NDK
directory are both on the system path. This also assumes that adb is working and connected with some
device or virtual device.
1. Open a terminal to the HelloSkia root directory and enter these commands:
$ ndk-build # Builds the modules inside of jni/
$ ant debug # Builds the Activity and packages it with all resources and modules of jni/
$ adb install -r bin/HelloSkia-debug.apk # Installs the app onto a device
2. To run the app, open your Android device's launcher and start the application labeled
HelloSkiaActivity.

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloSkia" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,42 +0,0 @@
LOCAL_PATH := $(call my-dir)
##
# Sets up a module for the skia shared object to be copied into the apk.
##
include $(CLEAR_VARS)
# Name for referencing this module in other modules
LOCAL_MODULE := skia_android
# Local filename of the skia shared object
LOCAL_SRC_FILES := skia/libskia_android.so
# Makes this module into shared object that is simply copied into the apk
include $(PREBUILT_SHARED_LIBRARY)
##
# Sets up the JNI module that our app calls into to draw things with skia.
##
include $(CLEAR_VARS) # clear out the variables of the previous module
# Name of the module that the app will reference with System.loadLibrary
LOCAL_MODULE := hello_skia_ndk
# List of the source files compiled for this module
LOCAL_SRC_FILES := helloskia.cpp
# Makes the skia shared object get pulled in as a reference
LOCAL_SHARED_LIBRARIES := skia_android
# jnigraphics defines the function AndroidBitmap_lockPixels, which we need in order to draw into
# android.graphics.Bitmap
LOCAL_LDLIBS := -ljnigraphics
# Allows the compiler to find the Skia header files
LOCAL_C_INCLUDES := $(LOCAL_PATH)/skia/include/config \
$(LOCAL_PATH)/skia/include/core
include $(BUILD_SHARED_LIBRARY)

View File

@ -1,77 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <math.h>
#include <jni.h>
#include <android/bitmap.h>
#include "SkCanvas.h"
#include "SkGraphics.h"
#include "SkSurface.h"
#include "SkString.h"
#include "SkTime.h"
/**
* Draws something into the given bitmap
* @param env
* @param thiz
* @param dstBitmap The bitmap to place the results of skia into
* @param elapsedTime The number of milliseconds since the app was started
*/
extern "C"
JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv* env,
jobject thiz, jobject dstBitmap, jlong elapsedTime)
{
// Grab the dst bitmap info and pixels
AndroidBitmapInfo dstInfo;
void* dstPixels;
AndroidBitmap_getInfo(env, dstBitmap, &dstInfo);
AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels);
SkImageInfo info = SkImageInfo::MakeN32Premul(dstInfo.width, dstInfo.height);
// Create a surface from the given bitmap
sk_sp<SkSurface> surface(SkSurface::MakeRasterDirect(info, dstPixels, dstInfo.stride));
SkCanvas* canvas = surface->getCanvas();
// Draw something "interesting"
// Clear the canvas with a white color
canvas->drawColor(SK_ColorWHITE);
// Setup a SkPaint for drawing our text
SkPaint paint;
paint.setColor(SK_ColorBLACK); // This is a solid black color for our text
paint.setTextSize(SkIntToScalar(30)); // Sets the text size to 30 pixels
paint.setAntiAlias(true); // We turn on anti-aliasing so that the text to looks good.
// Draw some text
SkString text("Skia is Best!");
SkScalar fontHeight = paint.getFontSpacing();
canvas->drawText(text.c_str(), text.size(), // text's data and length
10, fontHeight, // X and Y coordinates to place the text
paint); // SkPaint to tell how to draw the text
// Adapt the SkPaint for drawing blue lines
paint.setAntiAlias(false); // Turning off anti-aliasing speeds up the line drawing
paint.setColor(0xFF0000FF); // This is a solid blue color for our lines
paint.setStrokeWidth(SkIntToScalar(2)); // This makes the lines have a thickness of 2 pixels
// Draw some interesting lines using trig functions
for (int i = 0; i < 100; i++)
{
float x = (float)i / 99.0f;
float offset = elapsedTime / 1000.0f;
canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint
cos(x * M_PI + offset) * 800.0f, 800, // second endpoint
paint); // SkPapint to tell how to draw the line
}
// Unlock the dst's pixels
AndroidBitmap_unlockPixels(env, dstBitmap);
}

View File

@ -1,14 +0,0 @@
# 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=Google Inc.:Google APIs:15

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloSkiaActivity</string>
</resources>

View File

@ -1,74 +0,0 @@
package com.example;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
public class HelloSkiaActivity extends Activity
{
private SkiaDrawView fMainView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Makes and sets a SkiaDrawView as the only thing seen in this activity
fMainView = new SkiaDrawView(this);
setContentView(fMainView);
try {
// Load Skia and then the app shared object in this order
System.loadLibrary("skia_android");
System.loadLibrary("hello_skia_ndk");
} catch (UnsatisfiedLinkError e) {
Log.d("HelloSkia", "Link Error: " + e);
return;
}
// Set a timer that will periodically request an update of the SkiaDrawView
Timer fAnimationTimer = new Timer();
fAnimationTimer.schedule(new TimerTask() {
public void run()
{
// This will request an update of the SkiaDrawView, even from other threads
fMainView.postInvalidate();
}
}, 0, 5); // 0 means no delay before the timer starts; 5 means repeat every 5 milliseconds
}
private class SkiaDrawView extends View {
Bitmap fSkiaBitmap;
public SkiaDrawView(Context ctx) {
super(ctx);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
// Create a bitmap for skia to draw into
fSkiaBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
}
@Override
protected void onDraw(Canvas canvas) {
// Call into our C++ code that renders to the bitmap using Skia
drawIntoBitmap(fSkiaBitmap, SystemClock.elapsedRealtime());
// Present the bitmap on the screen
canvas.drawBitmap(fSkiaBitmap, 0, 0, null);
}
}
private native void drawIntoBitmap(Bitmap image, long elapsedTime);
}