Skip to content

Commit 2b4bfa5

Browse files
author
Jamie Gennis
committed
SurfaceTexture: update API docs
This change updates the SurfaceTexture API docs and modifies the behavior of the updateTexImage to produce an IllegalStateException when not attached to a GLES context. Change-Id: I5a0875927785108960985c567d571d5f7033256a
1 parent 58ab2bc commit 2b4bfa5

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

core/jni/android/graphics/SurfaceTexture.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace android {
3535

3636
static const char* const OutOfResourcesException =
3737
"android/graphics/SurfaceTexture$OutOfResourcesException";
38+
static const char* const IllegalStateException = "java/lang/IllegalStateException";
3839
const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
3940

4041
struct fields_t {
@@ -212,10 +213,16 @@ static void SurfaceTexture_setDefaultBufferSize(
212213
surfaceTexture->setDefaultBufferSize(width, height);
213214
}
214215

215-
static jint SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
216+
static void SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
216217
{
217218
sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
218-
return surfaceTexture->updateTexImage();
219+
status_t err = surfaceTexture->updateTexImage();
220+
if (err == INVALID_OPERATION) {
221+
jniThrowException(env, IllegalStateException, "Unable to update texture contents (see "
222+
"logcat for details)");
223+
} else {
224+
jniThrowRuntimeException(env, "Error during updateTexImage (see logcat for details)");
225+
}
219226
}
220227

221228
static jint SurfaceTexture_detachFromGLContext(JNIEnv* env, jobject thiz)
@@ -258,7 +265,7 @@ static JNINativeMethod gSurfaceTextureMethods[] = {
258265
{"nativeInit", "(ILjava/lang/Object;Z)V", (void*)SurfaceTexture_init },
259266
{"nativeFinalize", "()V", (void*)SurfaceTexture_finalize },
260267
{"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize },
261-
{"nativeUpdateTexImage", "()I", (void*)SurfaceTexture_updateTexImage },
268+
{"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage },
262269
{"nativeDetachFromGLContext", "()I", (void*)SurfaceTexture_detachFromGLContext },
263270
{"nativeAttachToGLContext", "(I)I", (void*)SurfaceTexture_attachToGLContext },
264271
{"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },

graphics/java/android/graphics/SurfaceTexture.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,23 @@ public void setDefaultBufferSize(int width, int height) {
155155

156156
/**
157157
* Update the texture image to the most recent frame from the image stream. This may only be
158-
* called while the OpenGL ES context that owns the texture is bound to the thread. It will
159-
* implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
158+
* called while the OpenGL ES context that owns the texture is current on the calling thread.
159+
* It will implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
160160
*/
161161
public void updateTexImage() {
162-
int err = nativeUpdateTexImage();
163-
if (err != 0) {
164-
throw new RuntimeException("Error during updateTexImage (see logcat for details)");
165-
}
162+
nativeUpdateTexImage();
166163
}
167164

168165
/**
169-
* Detach the SurfaceTexture from the OpenGL ES context with which it is currently associated.
170-
* This can be used to change from one OpenGL ES context to another.
166+
* Detach the SurfaceTexture from the OpenGL ES context that owns the OpenGL ES texture object.
167+
* This call must be made with the OpenGL ES context current on the calling thread. The OpenGL
168+
* ES texture object will be deleted as a result of this call. After calling this method all
169+
* calls to {@link #updateTexImage} will throw an {@link java.lang.IllegalStateException} until
170+
* a successful call to {@link #attachToGLContext} is made.
171+
*
172+
* This can be used to access the SurfaceTexture image contents from multiple OpenGL ES
173+
* contexts. Note, however, that the image contents are only accessible from one OpenGL ES
174+
* context at a time.
171175
*
172176
* @hide
173177
*/
@@ -179,6 +183,17 @@ public void detachFromGLContext() {
179183
}
180184

181185
/**
186+
* Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread. A
187+
* new OpenGL ES texture object is created and populated with the SurfaceTexture image frame
188+
* that was current at the time of the last call to {@link #detachFromGLContext}. This new
189+
* texture is bound to the GL_TEXTURE_EXTERNAL_OES texture target.
190+
*
191+
* This can be used to access the SurfaceTexture image contents from multiple OpenGL ES
192+
* contexts. Note, however, that the image contents are only accessible from one OpenGL ES
193+
* context at a time.
194+
*
195+
* @param texName The name of the OpenGL ES texture that will be created. This texture name
196+
* must be unusued in the OpenGL ES context that is current on the calling thread.
182197
*
183198
* @hide
184199
*/
@@ -292,7 +307,7 @@ private static void postEventFromNative(Object selfRef) {
292307
private native void nativeGetTransformMatrix(float[] mtx);
293308
private native long nativeGetTimestamp();
294309
private native void nativeSetDefaultBufferSize(int width, int height);
295-
private native int nativeUpdateTexImage();
310+
private native void nativeUpdateTexImage();
296311
private native int nativeDetachFromGLContext();
297312
private native int nativeAttachToGLContext(int texName);
298313
private native int nativeGetQueuedCount();

0 commit comments

Comments
 (0)