diff options
author | Jamie Gennis <jgennis@google.com> | 2012-04-05 11:34:02 -0700 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2012-04-05 16:11:43 -0700 |
commit | c6d993077761fc737bbb0f4db44b961a4e7b6bbb (patch) | |
tree | d0211f91c3650c5195d146799479b67652c7d01b | |
parent | 9828830611137bb751ab3512082a3bd31f439e38 (diff) | |
download | frameworks_base-c6d993077761fc737bbb0f4db44b961a4e7b6bbb.zip frameworks_base-c6d993077761fc737bbb0f4db44b961a4e7b6bbb.tar.gz frameworks_base-c6d993077761fc737bbb0f4db44b961a4e7b6bbb.tar.bz2 |
SurfaceTexture: add GL context attach & detach
This change adds Java API support for detaching a SurfaceTexture from one GLES
context and then attaching it to a different one.
Change-Id: I8eed4b0d0e339c11598cb0408d9f4f2d99b3aa06
-rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 28 | ||||
-rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 28 |
2 files changed, 48 insertions, 8 deletions
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index 3d350ed..244b166 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -218,6 +218,18 @@ static jint SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz) return surfaceTexture->updateTexImage(); } +static jint SurfaceTexture_detachFromGLContext(JNIEnv* env, jobject thiz) +{ + sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz)); + return surfaceTexture->detachFromContext(); +} + +static jint SurfaceTexture_attachToGLContext(JNIEnv* env, jobject thiz, jint tex) +{ + sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz)); + return surfaceTexture->attachToContext((GLuint)tex); +} + static void SurfaceTexture_getTransformMatrix(JNIEnv* env, jobject thiz, jfloatArray jmtx) { @@ -242,14 +254,16 @@ static void SurfaceTexture_release(JNIEnv* env, jobject thiz) // ---------------------------------------------------------------------------- static JNINativeMethod gSurfaceTextureMethods[] = { - {"nativeClassInit", "()V", (void*)SurfaceTexture_classInit }, - {"nativeInit", "(ILjava/lang/Object;Z)V", (void*)SurfaceTexture_init }, - {"nativeFinalize", "()V", (void*)SurfaceTexture_finalize }, + {"nativeClassInit", "()V", (void*)SurfaceTexture_classInit }, + {"nativeInit", "(ILjava/lang/Object;Z)V", (void*)SurfaceTexture_init }, + {"nativeFinalize", "()V", (void*)SurfaceTexture_finalize }, {"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize }, - {"nativeUpdateTexImage", "()I", (void*)SurfaceTexture_updateTexImage }, - {"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix }, - {"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp }, - {"nativeRelease", "()V", (void*)SurfaceTexture_release }, + {"nativeUpdateTexImage", "()I", (void*)SurfaceTexture_updateTexImage }, + {"nativeDetachFromGLContext", "()I", (void*)SurfaceTexture_detachFromGLContext }, + {"nativeAttachToGLContext", "(I)I", (void*)SurfaceTexture_attachToGLContext }, + {"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix }, + {"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp }, + {"nativeRelease", "()V", (void*)SurfaceTexture_release }, }; int register_android_graphics_SurfaceTexture(JNIEnv* env) diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index 0521e69..e101581 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -161,7 +161,31 @@ public class SurfaceTexture { public void updateTexImage() { int err = nativeUpdateTexImage(); if (err != 0) { - throw new RuntimeException("Error during updateTexImage (see logs)"); + throw new RuntimeException("Error during updateTexImage (see logcat for details)"); + } + } + + /** + * Detach the SurfaceTexture from the OpenGL ES context with which it is currently associated. + * This can be used to change from one OpenGL ES context to another. + * + * @hide + */ + public void detachFromGLContext() { + int err = nativeDetachFromGLContext(); + if (err != 0) { + throw new RuntimeException("Error during detachFromGLContext (see logcat for details)"); + } + } + + /** + * + * @hide + */ + public void attachToGLContext(int texName) { + int err = nativeAttachToGLContext(texName); + if (err != 0) { + throw new RuntimeException("Error during detachFromGLContext (see logcat for details)"); } } @@ -269,6 +293,8 @@ public class SurfaceTexture { private native long nativeGetTimestamp(); private native void nativeSetDefaultBufferSize(int width, int height); private native int nativeUpdateTexImage(); + private native int nativeDetachFromGLContext(); + private native int nativeAttachToGLContext(int texName); private native int nativeGetQueuedCount(); private native void nativeRelease(); |