summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2010-05-18 17:56:23 -0700
committerDianne Hackborn <hackbod@google.com>2010-05-18 18:16:35 -0700
commit74323fd1ab8eb11beea286d5c213c63e4b803141 (patch)
tree6c3108b7da5b5fb32d2b05ff3126b102a138b6d8 /core
parent4ec730cabb68ee8347c6aa5dc929b09651275aca (diff)
downloadframeworks_base-74323fd1ab8eb11beea286d5c213c63e4b803141.zip
frameworks_base-74323fd1ab8eb11beea286d5c213c63e4b803141.tar.gz
frameworks_base-74323fd1ab8eb11beea286d5c213c63e4b803141.tar.bz2
Update NativeActivity to allow direct surface access.
No actual native API for using a surface, but it's a step. Change-Id: I627f26b705abc7a05edf9117411abfacf0fae64a
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/NativeActivity.java33
-rw-r--r--core/jni/android_app_NativeActivity.cpp87
2 files changed, 100 insertions, 20 deletions
diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java
index 6318378..fd20b71 100644
--- a/core/java/android/app/NativeActivity.java
+++ b/core/java/android/app/NativeActivity.java
@@ -6,6 +6,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.view.SurfaceHolder;
import java.io.File;
@@ -13,7 +14,7 @@ import java.io.File;
* Convenience for implementing an activity that will be implemented
* purely in native code. That is, a game (or game-like thing).
*/
-public class NativeActivity extends Activity {
+public class NativeActivity extends Activity implements SurfaceHolder.Callback {
public static final String META_DATA_LIB_NAME = "android.app.lib_name";
private int mNativeHandle;
@@ -28,12 +29,18 @@ public class NativeActivity extends Activity {
private native void onStopNative(int handle);
private native void onLowMemoryNative(int handle);
private native void onWindowFocusChangedNative(int handle, boolean focused);
+ private native void onSurfaceCreatedNative(int handle, SurfaceHolder holder);
+ private native void onSurfaceChangedNative(int handle, SurfaceHolder holder,
+ int format, int width, int height);
+ private native void onSurfaceDestroyedNative(int handle, SurfaceHolder holder);
@Override
protected void onCreate(Bundle savedInstanceState) {
String libname = "main";
ActivityInfo ai;
+ getWindow().takeSurface(this);
+
try {
ai = getPackageManager().getActivityInfo(
getIntent().getComponent(), PackageManager.GET_META_DATA);
@@ -79,12 +86,6 @@ public class NativeActivity extends Activity {
}
@Override
- public void onLowMemory() {
- super.onLowMemory();
- onLowMemoryNative(mNativeHandle);
- }
-
- @Override
protected void onPause() {
super.onPause();
onPauseNative(mNativeHandle);
@@ -115,8 +116,26 @@ public class NativeActivity extends Activity {
}
@Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ onLowMemoryNative(mNativeHandle);
+ }
+
+ @Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
onWindowFocusChangedNative(mNativeHandle, hasFocus);
}
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ onSurfaceCreatedNative(mNativeHandle, holder);
+ }
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ onSurfaceChangedNative(mNativeHandle, holder, format, width, height);
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ onSurfaceDestroyedNative(mNativeHandle, holder);
+ }
}
diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp
index 1810fd5..f2ab134 100644
--- a/core/jni/android_app_NativeActivity.cpp
+++ b/core/jni/android_app_NativeActivity.cpp
@@ -27,13 +27,41 @@ namespace android
{
struct NativeCode {
+ NativeCode(void* _dlhandle, android_activity_create_t* _createFunc) {
+ memset(&activity, sizeof(activity), 0);
+ memset(&callbacks, sizeof(callbacks), 0);
+ dlhandle = _dlhandle;
+ createActivityFunc = _createFunc;
+ surface = NULL;
+ }
+
+ ~NativeCode() {
+ if (callbacks.onDestroy != NULL) {
+ callbacks.onDestroy(&activity);
+ }
+ if (dlhandle != NULL) {
+ dlclose(dlhandle);
+ }
+ }
+
+ void setSurface(jobject _surface) {
+ if (surface != NULL) {
+ activity.env->DeleteGlobalRef(surface);
+ }
+ if (_surface != NULL) {
+ surface = activity.env->NewGlobalRef(_surface);
+ } else {
+ surface = NULL;
+ }
+ }
+
android_activity_t activity;
android_activity_callbacks_t callbacks;
void* dlhandle;
-
android_activity_create_t* createActivityFunc;
- void* clientContext;
+
+ jobject surface;
};
static jint
@@ -47,18 +75,13 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path)
env->ReleaseStringUTFChars(path, pathStr);
if (handle != NULL) {
- code = new NativeCode();
- code->dlhandle = handle;
- code->createActivityFunc = (android_activity_create_t*)
- dlsym(handle, "android_onCreateActivity");
+ code = new NativeCode(handle, (android_activity_create_t*)
+ dlsym(handle, "android_onCreateActivity"));
if (code->createActivityFunc == NULL) {
LOGW("android_onCreateActivity not found");
delete code;
- dlclose(handle);
return 0;
}
- memset(&code->activity, sizeof(code->activity), 0);
- memset(&code->callbacks, sizeof(code->callbacks), 0);
code->activity.callbacks = &code->callbacks;
code->activity.env = env;
code->activity.clazz = clazz;
@@ -73,10 +96,6 @@ unloadNativeCode_native(JNIEnv* env, jobject clazz, jint handle)
{
if (handle != 0) {
NativeCode* code = (NativeCode*)handle;
- if (code->callbacks.onDestroy != NULL) {
- code->callbacks.onDestroy(&code->activity);
- }
- dlclose(code->dlhandle);
delete code;
}
}
@@ -159,6 +178,45 @@ onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jint handle, jboolean fo
}
}
+static void
+onSurfaceCreated_native(JNIEnv* env, jobject clazz, jint handle, jobject surface)
+{
+ if (handle != 0) {
+ NativeCode* code = (NativeCode*)handle;
+ code->setSurface(surface);
+ if (code->callbacks.onSurfaceCreated != NULL) {
+ code->callbacks.onSurfaceCreated(&code->activity,
+ (android_surface_t*)code->surface);
+ }
+ }
+}
+
+static void
+onSurfaceChanged_native(JNIEnv* env, jobject clazz, jint handle, jobject surface,
+ jint format, jint width, jint height)
+{
+ if (handle != 0) {
+ NativeCode* code = (NativeCode*)handle;
+ if (code->surface != NULL && code->callbacks.onSurfaceChanged != NULL) {
+ code->callbacks.onSurfaceChanged(&code->activity,
+ (android_surface_t*)code->surface, format, width, height);
+ }
+ }
+}
+
+static void
+onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jint handle, jobject surface)
+{
+ if (handle != 0) {
+ NativeCode* code = (NativeCode*)handle;
+ if (code->surface != NULL && code->callbacks.onSurfaceDestroyed != NULL) {
+ code->callbacks.onSurfaceDestroyed(&code->activity,
+ (android_surface_t*)code->surface);
+ }
+ code->setSurface(NULL);
+ }
+}
+
static const JNINativeMethod g_methods[] = {
{ "loadNativeCode", "(Ljava/lang/String;)I", (void*)loadNativeCode_native },
{ "unloadNativeCode", "(I)V", (void*)unloadNativeCode_native },
@@ -169,6 +227,9 @@ static const JNINativeMethod g_methods[] = {
{ "onStopNative", "(I)V", (void*)onStop_native },
{ "onLowMemoryNative", "(I)V", (void*)onLowMemory_native },
{ "onWindowFocusChangedNative", "(IZ)V", (void*)onWindowFocusChanged_native },
+ { "onSurfaceCreatedNative", "(ILandroid/view/SurfaceHolder;)V", (void*)onSurfaceCreated_native },
+ { "onSurfaceChangedNative", "(ILandroid/view/SurfaceHolder;III)V", (void*)onSurfaceChanged_native },
+ { "onSurfaceDestroyedNative", "(ILandroid/view/SurfaceHolder;)V", (void*)onSurfaceDestroyed_native },
};
static const char* const kNativeActivityPathName = "android/app/NativeActivity";