merge from open-source master
Change-Id: I7ef151320d924b2b258163d8aabf5eeebffecd39
diff --git a/ndk/apps/hello-gl2/project/AndroidManifest.xml b/ndk/apps/hello-gl2/project/AndroidManifest.xml
index 0ef6fb0..5a4d5f2 100644
--- a/ndk/apps/hello-gl2/project/AndroidManifest.xml
+++ b/ndk/apps/hello-gl2/project/AndroidManifest.xml
@@ -32,5 +32,6 @@
</intent-filter>
</activity>
</application>
+ <uses-feature android:glEsVersion="0x00020000"/>
<uses-sdk android:minSdkVersion="5"/>
</manifest>
diff --git a/ndk/apps/hello-gl2/project/jni/gl_code.cpp b/ndk/apps/hello-gl2/project/jni/gl_code.cpp
index e1e30ce..42d99d3 100644
--- a/ndk/apps/hello-gl2/project/jni/gl_code.cpp
+++ b/ndk/apps/hello-gl2/project/jni/gl_code.cpp
@@ -42,12 +42,14 @@
}
}
-static const char gVertexShader[] = "attribute vec4 vPosition;\n"
+static const char gVertexShader[] =
+ "attribute vec4 vPosition;\n"
"void main() {\n"
" gl_Position = vPosition;\n"
"}\n";
-static const char gFragmentShader[] = "precision mediump float;\n"
+static const char gFragmentShader[] =
+ "precision mediump float;\n"
"void main() {\n"
" gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
"}\n";
diff --git a/ndk/apps/hello-gl2/project/src/com/android/gl2jni/GL2JNIView.java b/ndk/apps/hello-gl2/project/src/com/android/gl2jni/GL2JNIView.java
index 72b1dfb..060290a 100644
--- a/ndk/apps/hello-gl2/project/src/com/android/gl2jni/GL2JNIView.java
+++ b/ndk/apps/hello-gl2/project/src/com/android/gl2jni/GL2JNIView.java
@@ -33,6 +33,7 @@
import android.content.Context;
+import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
@@ -46,16 +47,26 @@
import javax.microedition.khronos.opengles.GL10;
/**
- * An implementation of SurfaceView that uses the dedicated surface for
- * displaying an OpenGL animation. This allows the animation to run in a
- * separate thread, without requiring that it be driven by the update mechanism
- * of the view hierarchy.
+ * A simple GLSurfaceView sub-class that demonstrate how to perform
+ * OpenGL ES 2.0 rendering into a GL Surface. Note the following important
+ * details:
*
- * The application-specific rendering code is delegated to a GLView.Renderer
- * instance.
+ * - The class must use a custom context factory to enable 2.0 rendering.
+ * See ContextFactory class definition below.
+ *
+ * - The class must use a custom EGLConfigChooser to be able to select
+ * an EGLConfig that supports 2.0. This is done by providing a config
+ * specification to eglChooseConfig() that has the attribute
+ * EGL10.ELG_RENDERABLE_TYPE containing the EGL_OPENGL_ES2_BIT flag
+ * set. See ConfigChooser class definition below.
+ *
+ * - The class must select the surface's format, then choose an EGLConfig
+ * that matches it exactly (with regards to red/green/blue/alpha channels
+ * bit depths). Failure to do so would result in an EGL_BAD_MATCH error.
*/
class GL2JNIView extends GLSurfaceView {
private static String TAG = "GL2JNIView";
+ private static final boolean DEBUG = false;
public GL2JNIView(Context context) {
super(context);
@@ -68,10 +79,31 @@
}
private void init(boolean translucent, int depth, int stencil) {
+
+ /* By default, GLSurfaceView() creates a RGB_565 opaque surface.
+ * If we want a translucent one, we should change the surface's
+ * format here, using PixelFormat.TRANSLUCENT for GL Surfaces
+ * is interpreted as any 32-bit surface with alpha by SurfaceFlinger.
+ */
+ if (translucent) {
+ this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
+ }
+
+ /* Setup the context factory for 2.0 rendering.
+ * See ContextFactory class definition below
+ */
setEGLContextFactory(new ContextFactory());
+
+ /* We need to choose an EGLConfig that matches the format of
+ * our surface exactly. This is going to be done in our
+ * custom config chooser. See ConfigChooser class definition
+ * below.
+ */
setEGLConfigChooser( translucent ?
- new ConfigChooser(8,8,8,8, depth, stencil) :
- new ConfigChooser(5,6,5,0, depth, stencil));
+ new ConfigChooser(8, 8, 8, 8, depth, stencil) :
+ new ConfigChooser(5, 6, 5, 0, depth, stencil) );
+
+ /* Set the renderer responsible for frame rendering */
setRenderer(new Renderer());
}
@@ -99,15 +131,6 @@
}
private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser {
- private static int EGL_OPENGL_ES2_BIT = 4;
- private static int[] s_configAttribs2 =
- {
- EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL10.EGL_NONE
- };
public ConfigChooser(int r, int g, int b, int a, int depth, int stencil) {
mRedSize = r;
@@ -118,8 +141,24 @@
mStencilSize = stencil;
}
+ /* This EGL config specification is used to specify 2.0 rendering.
+ * We use a minimum size of 4 bits for red/green/blue, but will
+ * perform actual matching in chooseConfig() below.
+ */
+ private static int EGL_OPENGL_ES2_BIT = 4;
+ private static int[] s_configAttribs2 =
+ {
+ EGL10.EGL_RED_SIZE, 4,
+ EGL10.EGL_GREEN_SIZE, 4,
+ EGL10.EGL_BLUE_SIZE, 4,
+ EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL10.EGL_NONE
+ };
+
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
+ /* Get the number of minimally matching EGL configurations
+ */
int[] num_config = new int[1];
egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
@@ -128,41 +167,46 @@
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
+
+ /* Allocate then read the array of minimally matching EGL configs
+ */
EGLConfig[] configs = new EGLConfig[numConfigs];
egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
- // printConfigs(egl, display, configs);
+
+ if (DEBUG) {
+ printConfigs(egl, display, configs);
+ }
+ /* Now return the "best" one
+ */
return chooseConfig(egl, display, configs);
}
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs) {
- EGLConfig closestConfig = null;
- int closestDistance = 1000;
for(EGLConfig config : configs) {
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
- if (d >= mDepthSize && s>= mStencilSize) {
- int r = findConfigAttrib(egl, display, config,
- EGL10.EGL_RED_SIZE, 0);
- int g = findConfigAttrib(egl, display, config,
- EGL10.EGL_GREEN_SIZE, 0);
- int b = findConfigAttrib(egl, display, config,
- EGL10.EGL_BLUE_SIZE, 0);
- int a = findConfigAttrib(egl, display, config,
- EGL10.EGL_ALPHA_SIZE, 0);
- int distance = Math.abs(r - mRedSize)
- + Math.abs(g - mGreenSize)
- + Math.abs(b - mBlueSize)
- + Math.abs(a - mAlphaSize);
- if (distance < closestDistance) {
- closestDistance = distance;
- closestConfig = config;
- }
- }
+
+ // We need at least mDepthSize and mStencilSize bits
+ if (d < mDepthSize || s < mStencilSize)
+ continue;
+
+ // We want an *exact* match for red/green/blue/alpha
+ int r = findConfigAttrib(egl, display, config,
+ EGL10.EGL_RED_SIZE, 0);
+ int g = findConfigAttrib(egl, display, config,
+ EGL10.EGL_GREEN_SIZE, 0);
+ int b = findConfigAttrib(egl, display, config,
+ EGL10.EGL_BLUE_SIZE, 0);
+ int a = findConfigAttrib(egl, display, config,
+ EGL10.EGL_ALPHA_SIZE, 0);
+
+ if (r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize)
+ return config;
}
- return closestConfig;
+ return null;
}
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
@@ -293,4 +337,3 @@
}
}
}
-
diff --git a/ndk/apps/hello-neon/Application.mk b/ndk/apps/hello-neon/Application.mk
new file mode 100644
index 0000000..7325bb9
--- /dev/null
+++ b/ndk/apps/hello-neon/Application.mk
@@ -0,0 +1,3 @@
+APP_PROJECT_PATH := $(call my-dir)/project
+APP_MODULES := helloneon cpufeatures
+APP_ABI := armeabi armeabi-v7a
diff --git a/ndk/apps/hello-neon/project/AndroidManifest.xml b/ndk/apps/hello-neon/project/AndroidManifest.xml
new file mode 100644
index 0000000..2d362d6
--- /dev/null
+++ b/ndk/apps/hello-neon/project/AndroidManifest.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.neon"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:label="@string/app_name">
+ <activity android:name=".HelloNeon"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/ndk/apps/hello-neon/project/build.properties b/ndk/apps/hello-neon/project/build.properties
new file mode 100644
index 0000000..8167464
--- /dev/null
+++ b/ndk/apps/hello-neon/project/build.properties
@@ -0,0 +1,20 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+# 'source.dir' for the location of your java source folder and
+# 'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+# 'key.store' for the location of your keystore and
+# 'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+
+# The name of your application package as defined in the manifest.
+# Used by the 'uninstall' rule.
+application.package=com.example.neon
diff --git a/ndk/apps/hello-neon/project/default.properties b/ndk/apps/hello-neon/project/default.properties
new file mode 100644
index 0000000..4513a1e
--- /dev/null
+++ b/ndk/apps/hello-neon/project/default.properties
@@ -0,0 +1,11 @@
+# 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 use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-3
diff --git a/ndk/apps/hello-neon/project/jni/Android.mk b/ndk/apps/hello-neon/project/jni/Android.mk
new file mode 100644
index 0000000..5c7cb25
--- /dev/null
+++ b/ndk/apps/hello-neon/project/jni/Android.mk
@@ -0,0 +1,22 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := helloneon
+
+LOCAL_SRC_FILES := helloneon.c
+
+ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
+ LOCAL_CFLAGS := -DHAVE_NEON=1
+ LOCAL_SRC_FILES += helloneon-intrinsics.c.neon
+endif
+
+LOCAL_C_INCLUDES := sources/cpufeatures
+
+LOCAL_STATIC_LIBRARIES := cpufeatures
+
+LOCAL_LDLIBS := -llog
+
+include $(BUILD_SHARED_LIBRARY)
+
+include sources/cpufeatures/Android.mk
diff --git a/ndk/apps/hello-neon/project/jni/helloneon-intrinsics.c b/ndk/apps/hello-neon/project/jni/helloneon-intrinsics.c
new file mode 100644
index 0000000..35367c1
--- /dev/null
+++ b/ndk/apps/hello-neon/project/jni/helloneon-intrinsics.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "helloneon-intrinsics.h"
+#include <arm_neon.h>
+
+/* this source file should only be compiled by Android.mk when targeting
+ * the armeabi-v7a ABI, and should be built in NEON mode
+ */
+void
+fir_filter_neon_intrinsics(short *output, const short* input, const short* kernel, int width, int kernelSize)
+{
+#if 1
+ int nn, offset = -kernelSize/2;
+
+ for (nn = 0; nn < width; nn++)
+ {
+ int mm, sum = 0;
+ int32x4_t sum_vec = vdupq_n_s32(0);
+ for(mm = 0; mm < kernelSize/4; mm++)
+ {
+ int16x4_t kernel_vec = vld1_s16(kernel + mm*4);
+ int16x4_t input_vec = vld1_s16(input + (nn+offset+mm*4));
+ sum_vec = vmlal_s16(sum_vec, kernel_vec, input_vec);
+ }
+
+ sum += vgetq_lane_s32(sum_vec, 0);
+ sum += vgetq_lane_s32(sum_vec, 1);
+ sum += vgetq_lane_s32(sum_vec, 2);
+ sum += vgetq_lane_s32(sum_vec, 3);
+
+ if(kernelSize & 3)
+ {
+ for(mm = kernelSize - (kernelSize & 3); mm < kernelSize; mm++)
+ sum += kernel[mm] * input[nn+offset+mm];
+ }
+
+ output[nn] = (short)((sum + 0x8000) >> 16);
+ }
+#else /* for comparison purposes only */
+ int nn, offset = -kernelSize/2;
+ for (nn = 0; nn < width; nn++) {
+ int sum = 0;
+ int mm;
+ for (mm = 0; mm < kernelSize; mm++) {
+ sum += kernel[mm]*input[nn+offset+mm];
+ }
+ output[n] = (short)((sum + 0x8000) >> 16);
+ }
+#endif
+}
diff --git a/ndk/apps/hello-neon/project/jni/helloneon-intrinsics.h b/ndk/apps/hello-neon/project/jni/helloneon-intrinsics.h
new file mode 100644
index 0000000..ad4c8db
--- /dev/null
+++ b/ndk/apps/hello-neon/project/jni/helloneon-intrinsics.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef HELLONEON_INTRINSICS_H
+#define HELLONEON_INTRINSICS_H
+
+void fir_filter_neon_intrinsics(short *output, const short* input, const short* kernel, int width, int kernelSize);
+
+#endif /* HELLONEON_INTRINSICS_H */
diff --git a/ndk/apps/hello-neon/project/jni/helloneon.c b/ndk/apps/hello-neon/project/jni/helloneon.c
new file mode 100644
index 0000000..ee19e08
--- /dev/null
+++ b/ndk/apps/hello-neon/project/jni/helloneon.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <jni.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <cpu-features.h>
+#include "helloneon-intrinsics.h"
+
+#define DEBUG 0
+
+#if DEBUG
+#include <android/log.h>
+# define D(x...) __android_log_print(ANDROID_LOG_INFO,"helloneon",x)
+#else
+# define D(...) do {} while (0)
+#endif
+
+/* return current time in milliseconds */
+static double
+now_ms(void)
+{
+ struct timespec res;
+ clock_gettime(CLOCK_REALTIME, &res);
+ return 1000.0*res.tv_sec + (double)res.tv_nsec/1e6;
+}
+
+
+/* this is a FIR filter implemented in C */
+static void
+fir_filter_c(short *output, const short* input, const short* kernel, int width, int kernelSize)
+{
+ int offset = -kernelSize/2;
+ int nn;
+ for (nn = 0; nn < width; nn++) {
+ int sum = 0;
+ int mm;
+ for (mm = 0; mm < kernelSize; mm++) {
+ sum += kernel[mm]*input[nn+offset+mm];
+ }
+ output[nn] = (short)((sum + 0x8000) >> 16);
+ }
+}
+
+#define FIR_KERNEL_SIZE 32
+#define FIR_OUTPUT_SIZE 2560
+#define FIR_INPUT_SIZE (FIR_OUTPUT_SIZE + FIR_KERNEL_SIZE)
+#define FIR_ITERATIONS 600
+
+static const short fir_kernel[FIR_KERNEL_SIZE] = {
+ 0x10, 0x20, 0x40, 0x70, 0x8c, 0xa2, 0xce, 0xf0, 0xe9, 0xce, 0xa2, 0x8c, 070, 0x40, 0x20, 0x10,
+ 0x10, 0x20, 0x40, 0x70, 0x8c, 0xa2, 0xce, 0xf0, 0xe9, 0xce, 0xa2, 0x8c, 070, 0x40, 0x20, 0x10 };
+
+static short fir_output[FIR_OUTPUT_SIZE];
+static short fir_input_0[FIR_INPUT_SIZE];
+static const short* fir_input = fir_input_0 + (FIR_KERNEL_SIZE/2);
+static short fir_output_expected[FIR_OUTPUT_SIZE];
+
+/* This is a trivial JNI example where we use a native method
+ * to return a new VM String. See the corresponding Java source
+ * file located at:
+ *
+ * apps/samples/hello-neon/project/src/com/example/neon/HelloNeon.java
+ */
+jstring
+Java_com_example_neon_HelloNeon_stringFromJNI( JNIEnv* env,
+ jobject thiz )
+{
+ char* str;
+ uint64_t features;
+ char buffer[512];
+ char tryNeon = 0;
+ double t0, t1, time_c, time_neon;
+
+ /* setup FIR input - whatever */
+ {
+ int nn;
+ for (nn = 0; nn < FIR_INPUT_SIZE; nn++) {
+ fir_input_0[nn] = (5*nn) & 255;
+ }
+ fir_filter_c(fir_output_expected, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
+ }
+
+ /* Benchmark small FIR filter loop - C version */
+ t0 = now_ms();
+ {
+ int count = FIR_ITERATIONS;
+ for (; count > 0; count--) {
+ fir_filter_c(fir_output, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
+ }
+ }
+ t1 = now_ms();
+ time_c = t1 - t0;
+
+ asprintf(&str, "FIR Filter benchmark:\nC version : %g ms\n", time_c);
+ strlcpy(buffer, str, sizeof buffer);
+ free(str);
+
+ strlcat(buffer, "Neon version : ", sizeof buffer);
+
+ if (android_getCpuFamily() != ANDROID_CPU_FAMILY_ARM) {
+ strlcat(buffer, "Not an ARM CPU !\n", sizeof buffer);
+ goto EXIT;
+ }
+
+ features = android_getCpuFeatures();
+ if ((features & ANDROID_CPU_ARM_FEATURE_ARMv7) == 0) {
+ strlcat(buffer, "Not an ARMv7 CPU !\n", sizeof buffer);
+ goto EXIT;
+ }
+
+ /* HAVE_NEON is defined in Android.mk ! */
+#ifdef HAVE_NEON
+ if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0) {
+ strlcat(buffer, "CPU doesn't support NEON !\n", sizeof buffer);
+ goto EXIT;
+ }
+
+ /* Benchmark small FIR filter loop - Neon version */
+ t0 = now_ms();
+ {
+ int count = FIR_ITERATIONS;
+ for (; count > 0; count--) {
+ fir_filter_neon_intrinsics(fir_output, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
+ }
+ }
+ t1 = now_ms();
+ time_neon = t1 - t0;
+ asprintf(&str, "%g ms (x%g faster)\n", time_neon, time_c / (time_neon < 1e-6 ? 1. : time_neon));
+ strlcat(buffer, str, sizeof buffer);
+ free(str);
+
+ /* check the result, just in case */
+ {
+ int nn, fails = 0;
+ for (nn = 0; nn < FIR_OUTPUT_SIZE; nn++) {
+ if (fir_output[nn] != fir_output_expected[nn]) {
+ if (++fails < 16)
+ D("neon[%d] = %d expected %d", nn, fir_output[nn], fir_output_expected[nn]);
+ }
+ }
+ D("%d fails\n", fails);
+ }
+#else /* !HAVE_NEON */
+ strlcat(buffer, "Program not compiled with ARMv7 support !\n", sizeof buffer);
+#endif /* !HAVE_NEON */
+EXIT:
+ return (*env)->NewStringUTF(env, buffer);
+}
diff --git a/ndk/apps/hello-neon/project/res/values/strings.xml b/ndk/apps/hello-neon/project/res/values/strings.xml
new file mode 100644
index 0000000..8d8f980
--- /dev/null
+++ b/ndk/apps/hello-neon/project/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">HelloNeon</string>
+</resources>
diff --git a/ndk/apps/hello-neon/project/src/com/example/neon/HelloNeon.java b/ndk/apps/hello-neon/project/src/com/example/neon/HelloNeon.java
new file mode 100644
index 0000000..b2f5e88
--- /dev/null
+++ b/ndk/apps/hello-neon/project/src/com/example/neon/HelloNeon.java
@@ -0,0 +1,37 @@
+package com.example.neon;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class HelloNeon extends Activity
+{
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ /* Create a TextView and set its content.
+ * the text is retrieved by calling a native
+ * function.
+ */
+ TextView tv = new TextView(this);
+ tv.setText( stringFromJNI() );
+ setContentView(tv);
+ }
+
+ /* A native method that is implemented by the
+ * 'helloneon' native library, which is packaged
+ * with this application.
+ */
+ public native String stringFromJNI();
+
+ /* this is used to load the 'helloneon' library on application
+ * startup. The library has already been unpacked into
+ * /data/data/com.example.neon/lib/libhelloneon.so at
+ * installation time by the package manager.
+ */
+ static {
+ System.loadLibrary("helloneon");
+ }
+}
diff --git a/ndk/build/tools/cleanup-apps.sh b/ndk/build/tools/cleanup-apps.sh
new file mode 100755
index 0000000..21a0df0
--- /dev/null
+++ b/ndk/build/tools/cleanup-apps.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# This is used to cleanup the project directories before making a commit or
+# a clean release. This will get rid of auto-generated files in the
+# apps/<name>/project directories.
+#
+for projectPath in `find apps/*/project` ; do
+ rm -rf $projectPath/bin
+ rm -rf $projectPath/gen
+ rm -f $projectPath/build.xml
+ rm -f $projectPath/local.properties
+done
diff --git a/ndk/build/tools/make-release.sh b/ndk/build/tools/make-release.sh
index 8b9ab0b..a74cfb3 100755
--- a/ndk/build/tools/make-release.sh
+++ b/ndk/build/tools/make-release.sh
@@ -31,11 +31,8 @@
# the package prefix
PREFIX=android-ndk
-# the directory containing the prebuilt toolchain tarballs
-PREBUILT_DIR=
-
-# the prefix of prebuilt toolchain tarballs in $PREBUILT_DIR
-PREBUILT_PREFIX=android-ndk-prebuilt-20090323
+# the prefix of prebuilt toolchain tarballs
+PREBUILT_PREFIX=
# the list of supported host development systems
PREBUILT_SYSTEMS="linux-x86 darwin-x86 windows"
@@ -69,8 +66,6 @@
;;
--prebuilt-prefix=*) PREBUILT_PREFIX=$optarg
;;
- --prebuilt-path=*) PREBUILT_DIR=$optarg
- ;;
--systems=*) PREBUILT_SYSTEMS=$optarg
;;
--no-git) USE_GIT_FILES=no
@@ -85,21 +80,31 @@
echo "Usage: make-release.sh [options]"
echo ""
echo "Package a new set of release packages for the Android NDK."
- echo "You will need to specify the path of a directory containing"
- echo "prebuilt toolchain tarballs with the --prebuilt-path option."
echo ""
- echo "Alternatively, you can specify an existing NDK release package"
- echo "with the --prebuilt-ndk option."
+ echo "You will need to have generated one or more prebuilt toolchain tarballs"
+ echo "with the build/tools/build-toolchain.sh script. These files should be"
+ echo "named like <prefix>-<system>.tar.bz2, where <prefix> is an arbitrary"
+ echo "prefix and <system> is one of: $PREBUILT_SYSTEMS"
+ echo ""
+ echo "Use the --prebuilt-prefix=<path>/<prefix> option to build release"
+ echo "packages from these tarballs."
+ echo ""
+ echo "Alternatively, you can use --prebuilt-ndk=<file> where <file> is the"
+ echo "path to a previous official NDK release package. It will be used to"
+ echo "extract the toolchain binaries and copy them to your new release."
+ echo "Only use this for experimental release packages !"
+ echo ""
+ echo "The generated release packages will be stored in a temporary directory"
+ echo "that will be printed at the end of the generation process."
echo ""
echo "Options: [defaults in brackets after descriptions]"
echo ""
echo " --help Print this help message"
- echo " --prefix=PREFIX Package prefix name [$PREFIX]"
+ echo " --prefix=PREFIX Release package prefix name [$PREFIX]"
echo " --release=NAME Specify release name [$RELEASE]"
- echo " --systems=SYSTEMS List of host system packages [$PREBUILT_SYSTEMS]"
- echo " --prebuilt-ndk=FILE Specify a previous NDK package [$PREBUILT_NDK]"
- echo " --prebuilt-path=PATH Location of prebuilt binary tarballs [$PREBUILT_DIR]"
echo " --prebuilt-prefix=PREFIX Prefix of prebuilt binary tarballs [$PREBUILT_PREFIX]"
+ echo " --prebuilt-ndk=FILE Specify a previous NDK package [$PREBUILT_NDK]"
+ echo " --systems=SYSTEMS List of host system packages [$PREBUILT_SYSTEMS]"
echo " --no-git Don't use git to list input files, take all of them."
echo ""
exit 1
@@ -107,24 +112,24 @@
# Check the prebuilt path
#
-if [ -n "$PREBUILD_NDK" -a -n "$PREBUILT_DIR" ] ; then
- echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-path at the same time."
+if [ -n "$PREBUILD_NDK" -a -n "$PREBUILT_PREFIX" ] ; then
+ echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-prefix at the same time."
exit 1
fi
-if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then
- echo "ERROR: You must use --prebuilt-path=PATH to specify the path of prebuilt binary tarballs."
- echo " Or --prebuilt-ndk=FILE to specify an existing NDK release archive."
+if [ -z "$PREBUILT_PREFIX" -a -z "$PREBUILT_NDK" ] ; then
+ echo "ERROR: You must use one of --prebuilt-prefix or --prebuilt-ndk. See --help for details."
exit 1
fi
-if [ -n "$PREBUILT_DIR" ] ; then
- if [ ! -d "$PREBUILT_DIR" ] ; then
- echo "ERROR: the --prebuilt-path argument is not a directory path: $PREBUILT_DIR"
+if [ -n "$PREBUILT_PREFIX" ] ; then
+ if [ -d "$PREBUILT_PREFIX" ] ; then
+ echo "ERROR: the --prebuilt-prefix argument must not be a direct directory path: $PREBUILT_PREFIX."
exit 1
fi
- if [ -z "$PREBUILT_PREFIX" ] ; then
- echo "ERROR: Your prebuilt prefix is empty; use --prebuilt-prefix=PREFIX."
+ PREBUILT_DIR=`dirname $PREBUILT_PREFIX`
+ if [ ! -d "$PREBUILT_DIR" ] ; then
+ echo "ERROR: the --prebuilt-prefix argument does not point to a directory: $PREBUILT_DIR"
exit 1
fi
if [ -z "$PREBUILT_SYSTEMS" ] ; then
@@ -134,7 +139,7 @@
# Check the systems
#
for SYS in $PREBUILT_SYSTEMS; do
- if [ ! -f $PREBUILT_DIR/$PREBUILT_PREFIX-$SYS.tar.bz2 ] ; then
+ if [ ! -f $PREBUILT_PREFIX-$SYS.tar.bz2 ] ; then
echo "ERROR: It seems there is no prebuilt binary tarball for the '$SYS' system"
echo "Please check the content of $PREBUILT_DIR for a file named $PREBUILT_PREFIX-$SYS.tar.bz2."
exit 1
@@ -165,6 +170,7 @@
# i.e. generated files...
rm -rf $NDK_ROOT_DIR/out
rm -rf $NDK_ROOT_DIR/apps/*/project/libs/armeabi
+ rm -rf $NDK_ROOT_DIR/apps/*/project/libs/armeabi-v7a
rm -rf $NDK_ROOT_DIR/apps/*/project/libs/x86
# Get all files under the NDK root
GIT_FILES=`cd $NDK_ROOT_DIR && find .`
@@ -194,7 +200,7 @@
for SYSTEM in $PREBUILT_SYSTEMS; do
echo "Preparing package for system $SYSTEM."
BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM
- PREBUILT=$PREBUILT_DIR/$PREBUILT_PREFIX-$SYSTEM
+ PREBUILT=$PREBUILT_PREFIX-$SYSTEM
DSTDIR=$TMPDIR/$RELEASE_PREFIX
rm -rf $DSTDIR && mkdir -p $DSTDIR &&
cp -rp $REFERENCE/* $DSTDIR
diff --git a/ndk/docs/CHANGES.TXT b/ndk/docs/CHANGES.TXT
index 6832546..9701b8c 100644
--- a/ndk/docs/CHANGES.TXT
+++ b/ndk/docs/CHANGES.TXT
@@ -61,6 +61,9 @@
For more information, see docs/CPU-ARM-NEON.TXT
+- Added a new sample (hello-neon) to demonstrate usage of 'cpufeatures'
+ and NEON intrinsics & build support.
+
- GCC 4.4.0 is now used by default by the NDK. It generates better code than
GCC 4.2.1, which was used in previous releases. However, the compiler's C++
frontend is also a lot more pedantic regarding certain template constructs
@@ -116,6 +119,10 @@
to 'true', just like the documentation says it works. Also fix a typo
in CLEAR_VARS that prevented this variable from being cleared properly.
+- Simplified build/tools/make-release.sh, the --prebuilt-dir option is
+ gone, and --help will dump a clearer description of expected options
+ and input files.
+
- Added --prebuilt-ndk=FILE option to build/tools/make-release.sh script to
package a new experimental NDK package archive from the current source tree
plus the toolchain binaries of an existing NDK release package. E.g.:
diff --git a/ndk/docs/CPU-ARM-NEON.TXT b/ndk/docs/CPU-ARM-NEON.TXT
index f023cea..61a8331 100644
--- a/ndk/docs/CPU-ARM-NEON.TXT
+++ b/ndk/docs/CPU-ARM-NEON.TXT
@@ -116,3 +116,12 @@
}
...
+
+Sample code:
+------------
+
+Look at the source code for the "hello-neon" sample in this NDK for an example
+on how to use the 'cpufeatures' library and Neon intrinsics at the same time.
+
+This implements a tiny benchmark for a FIR filter loop using a C version, and
+a NEON-optimized one for devices that support it.
diff --git a/ndk/sources/cpufeatures/cpu-features.c b/ndk/sources/cpufeatures/cpu-features.c
index d165635..c46b884 100644
--- a/ndk/sources/cpufeatures/cpu-features.c
+++ b/ndk/sources/cpufeatures/cpu-features.c
@@ -1,3 +1,30 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
#include <sys/system_properties.h>
#include <machine/cpu-features.h>
#include <pthread.h>
diff --git a/ndk/sources/cpufeatures/cpu-features.h b/ndk/sources/cpufeatures/cpu-features.h
index d5fa876..e1cafd6 100644
--- a/ndk/sources/cpufeatures/cpu-features.h
+++ b/ndk/sources/cpufeatures/cpu-features.h
@@ -1,3 +1,30 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
#ifndef CPU_FEATURES_H
#define CPU_FEATURES_H