diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 67 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 8 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Script.java | 20 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ScriptC.java | 4 |
4 files changed, 62 insertions, 37 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 diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 579f314..852aabf 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -239,15 +239,13 @@ public class Allocation extends BaseObj { } /** - * @hide - * * This is only intended to be used by auto-generate code reflected from the * renderscript script files. * * @param xoff * @param fp */ - public void setOneElement(int xoff, FieldPacker fp) { + public void setFromFieldPacker(int xoff, FieldPacker fp) { int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); @@ -262,8 +260,6 @@ public class Allocation extends BaseObj { /** - * @hide - * * This is only intended to be used by auto-generate code reflected from the * renderscript script files. * @@ -271,7 +267,7 @@ public class Allocation extends BaseObj { * @param component_number * @param fp */ - public void setOneComponent(int xoff, int component_number, FieldPacker fp) { + public void setFromFieldPacker(int xoff, int component_number, FieldPacker fp) { if (component_number >= mType.mElement.mElements.length) { throw new RSIllegalArgumentException("Component_number " + component_number + " out of range."); } diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java index b3ad20a..56abba5 100644 --- a/graphics/java/android/renderscript/Script.java +++ b/graphics/java/android/renderscript/Script.java @@ -21,8 +21,6 @@ package android.renderscript; **/ public class Script extends BaseObj { /** - * @hide - * * Only intended for use by generated reflected code. * * @param slot @@ -32,8 +30,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param slot @@ -54,8 +50,6 @@ public class Script extends BaseObj { /** - * @hide - * * Only intended for use by generated reflected code. * * @param va @@ -71,8 +65,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index @@ -83,8 +75,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index @@ -95,8 +85,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index @@ -107,8 +95,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index @@ -119,8 +105,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index @@ -131,8 +115,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index @@ -143,8 +125,6 @@ public class Script extends BaseObj { } /** - * @hide - * * Only intended for use by generated reflected code. * * @param index diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index 14e4ab5..ff8f093 100644 --- a/graphics/java/android/renderscript/ScriptC.java +++ b/graphics/java/android/renderscript/ScriptC.java @@ -36,8 +36,6 @@ public class ScriptC extends Script { private static final String TAG = "ScriptC"; /** - * @hide - * * Only intended for use by the generated derived classes. * * @param id @@ -48,8 +46,6 @@ public class ScriptC extends Script { } /** - * @hide - * * Only intended for use by the generated derived classes. * * |