summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2011-01-16 18:15:36 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-16 18:15:36 -0800
commitcf18c4788af740773c9b2720a1c4ed5f45454b8e (patch)
treecedb4dece79a0f609bf38744e2fbceabcf786957 /graphics
parent41424adec8382af9064baf1d8bde29d7349a6155 (diff)
parent376590d668e22a918439877b55faf075427b13f3 (diff)
downloadframeworks_base-cf18c4788af740773c9b2720a1c4ed5f45454b8e.zip
frameworks_base-cf18c4788af740773c9b2720a1c4ed5f45454b8e.tar.gz
frameworks_base-cf18c4788af740773c9b2720a1c4ed5f45454b8e.tar.bz2
Merge "Implement SurfaceTexture frame-available callback." into honeycomb
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/SurfaceTexture.java67
1 files changed, 60 insertions, 7 deletions
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index 3eb0b03..64c209a 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -16,6 +16,11 @@
package android.graphics;
+import java.lang.ref.WeakReference;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+
/**
* Captures frames from an image stream as an OpenGL ES texture.
*
@@ -32,6 +37,9 @@ package android.graphics;
*/
public class SurfaceTexture {
+ private EventHandler mEventHandler;
+ private OnFrameAvailableListener mOnFrameAvailableListener;
+
@SuppressWarnings("unused")
private int mSurfaceTexture;
@@ -59,7 +67,15 @@ public class SurfaceTexture {
* @param texName the OpenGL texture object name (e.g. generated via glGenTextures)
*/
public SurfaceTexture(int texName) {
- init(texName);
+ Looper looper;
+ if ((looper = Looper.myLooper()) != null) {
+ mEventHandler = new EventHandler(looper);
+ } else if ((looper = Looper.getMainLooper()) != null) {
+ mEventHandler = new EventHandler(looper);
+ } else {
+ mEventHandler = null;
+ }
+ nativeInit(texName, new WeakReference<SurfaceTexture>(this));
}
/**
@@ -69,7 +85,7 @@ public class SurfaceTexture {
* thread invoking the callback.
*/
public void setOnFrameAvailableListener(OnFrameAvailableListener l) {
- // TODO: Implement this!
+ mOnFrameAvailableListener = l;
}
/**
@@ -77,8 +93,9 @@ public class SurfaceTexture {
* called while the OpenGL ES context that owns the texture is bound to the thread. It will
* implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
*/
- public native void updateTexImage();
-
+ public void updateTexImage() {
+ nativeUpdateTexImage();
+ }
/**
* Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by
@@ -99,12 +116,48 @@ public class SurfaceTexture {
if (mtx.length != 16) {
throw new IllegalArgumentException();
}
- getTransformMatrixImpl(mtx);
+ nativeGetTransformMatrix(mtx);
}
- private native void getTransformMatrixImpl(float[] mtx);
+ protected void finalize() throws Throwable {
+ try {
+ nativeFinalize();
+ } finally {
+ super.finalize();
+ }
+ }
+
+ private class EventHandler extends Handler {
+ public EventHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ if (mOnFrameAvailableListener != null) {
+ mOnFrameAvailableListener.onFrameAvailable(SurfaceTexture.this);
+ }
+ return;
+ }
+ }
+
+ private static void postEventFromNative(Object selfRef) {
+ WeakReference weakSelf = (WeakReference)selfRef;
+ SurfaceTexture st = (SurfaceTexture)weakSelf.get();
+ if (st == null) {
+ return;
+ }
+
+ if (st.mEventHandler != null) {
+ Message m = st.mEventHandler.obtainMessage();
+ st.mEventHandler.sendMessage(m);
+ }
+ }
- private native void init(int texName);
+ private native void nativeInit(int texName, Object weakSelf);
+ private native void nativeFinalize();
+ private native void nativeGetTransformMatrix(float[] mtx);
+ private native void nativeUpdateTexImage();
/*
* We use a class initializer to allow the native code to cache some