diff options
author | Mathias Agopian <mathias@google.com> | 2013-07-24 19:15:00 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2013-07-26 19:33:54 -0700 |
commit | e591b49de038a9942cbcc77540c03e85c96e3dcb (patch) | |
tree | 3bc8b5ae1d6db61c137dac96d77777db2d28032f /graphics | |
parent | d06db894b2b092e95fc19bf993bfc5bab7a486b1 (diff) | |
download | frameworks_base-e591b49de038a9942cbcc77540c03e85c96e3dcb.zip frameworks_base-e591b49de038a9942cbcc77540c03e85c96e3dcb.tar.gz frameworks_base-e591b49de038a9942cbcc77540c03e85c96e3dcb.tar.bz2 |
single buffer mode for SurfaceTexture
Bug: 9891035
Change-Id: Ib9cc2b64f7ff3c084ef1d7db442db8e7a24a923d
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index aaed094..06a8d99 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -95,15 +95,26 @@ public class SurfaceTexture { * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) */ public SurfaceTexture(int 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)); + init(texName, false); + } + + /** + * Construct a new SurfaceTexture to stream images to a given OpenGL texture. + * + * In single buffered mode the application is responsible for serializing access to the image + * content buffer. Each time the image content is to be updated, the + * {@link #releaseTexImage()} method must be called before the image content producer takes + * ownership of the buffer. For example, when producing image content with the NDK + * ANativeWindow_lock and ANativeWindow_unlockAndPost functions, {@link #releaseTexImage()} + * must be called before each ANativeWindow_lock, or that call will fail. When producing + * image content with OpenGL ES, {@link #releaseTexImage()} must be called before the first + * OpenGL ES function call each frame. + * + * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) + * @param singleBufferMode whether the SurfaceTexture will be in single buffered mode. + */ + public SurfaceTexture(int texName, boolean singleBufferMode) { + init(texName, singleBufferMode); } /** @@ -149,6 +160,15 @@ public class SurfaceTexture { } /** + * Releases the the texture content. This is needed in single buffered mode to allow the image + * content producer to take ownership of the image buffer. + * For more information see {@link SurfaceTexture(int, boolean)}. + */ + public void releaseTexImage() { + nativeReleaseTexImage(); + } + + /** * Detach the SurfaceTexture from the OpenGL ES context that owns the OpenGL ES texture object. * This call must be made with the OpenGL ES context current on the calling thread. The OpenGL * ES texture object will be deleted as a result of this call. After calling this method all @@ -284,12 +304,25 @@ public class SurfaceTexture { } } - private native void nativeInit(int texName, Object weakSelf); + private void init(int texName, boolean singleBufferMode) { + 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, singleBufferMode, new WeakReference<SurfaceTexture>(this)); + } + + private native void nativeInit(int texName, boolean singleBufferMode, Object weakSelf); private native void nativeFinalize(); private native void nativeGetTransformMatrix(float[] mtx); private native long nativeGetTimestamp(); private native void nativeSetDefaultBufferSize(int width, int height); private native void nativeUpdateTexImage(); + private native void nativeReleaseTexImage(); private native int nativeDetachFromGLContext(); private native int nativeAttachToGLContext(int texName); private native int nativeGetQueuedCount(); |