diff options
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 6 | ||||
| -rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 17 | ||||
| -rw-r--r-- | include/gui/SurfaceTexture.h | 5 | ||||
| -rw-r--r-- | libs/gui/SurfaceTexture.cpp | 8 |
5 files changed, 29 insertions, 8 deletions
diff --git a/api/current.txt b/api/current.txt index 516d3fc2ec44..19557f585bcc 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8364,6 +8364,7 @@ package android.graphics { public class SurfaceTexture { ctor public SurfaceTexture(int); + ctor public SurfaceTexture(int, boolean); method public long getTimestamp(); method public void getTransformMatrix(float[]); method public void setOnFrameAvailableListener(android.graphics.SurfaceTexture.OnFrameAvailableListener); diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index a8cb6f753565..30ef8dfad904 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -155,9 +155,9 @@ static void SurfaceTexture_classInit(JNIEnv* env, jclass clazz) } static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jint texName, - jobject weakThiz) + jobject weakThiz, jboolean allowSynchronous) { - sp<SurfaceTexture> surfaceTexture(new SurfaceTexture(texName)); + sp<SurfaceTexture> surfaceTexture(new SurfaceTexture(texName, allowSynchronous)); if (surfaceTexture == 0) { jniThrowException(env, OutOfResourcesException, "Unable to create native SurfaceTexture"); @@ -222,7 +222,7 @@ static jint SurfaceTexture_getQueuedCount(JNIEnv* env, jobject thiz) static JNINativeMethod gSurfaceTextureMethods[] = { {"nativeClassInit", "()V", (void*)SurfaceTexture_classInit }, - {"nativeInit", "(ILjava/lang/Object;)V", (void*)SurfaceTexture_init }, + {"nativeInit", "(ILjava/lang/Object;Z)V", (void*)SurfaceTexture_init }, {"nativeFinalize", "()V", (void*)SurfaceTexture_finalize }, {"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize }, {"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage }, diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index 9e498d0fea9c..adb6eac3e6d5 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -93,6 +93,19 @@ public class SurfaceTexture { * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) */ public SurfaceTexture(int texName) { + this(texName, true); + } + + /** + * Construct a new SurfaceTexture to stream images to a given OpenGL texture. + * + * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) + * @param allowSynchronousMode whether the SurfaceTexture can run in the synchronous mode. + * When the image stream comes from OpenGL, SurfaceTexture may run in the synchronous + * mode where the producer side may be blocked to avoid skipping frames. To avoid the + * thread block, set allowSynchronousMode to false. + */ + public SurfaceTexture(int texName, boolean allowSynchronousMode) { Looper looper; if ((looper = Looper.myLooper()) != null) { mEventHandler = new EventHandler(looper); @@ -101,7 +114,7 @@ public class SurfaceTexture { } else { mEventHandler = null; } - nativeInit(texName, new WeakReference<SurfaceTexture>(this)); + nativeInit(texName, new WeakReference<SurfaceTexture>(this), allowSynchronousMode); } /** @@ -213,7 +226,7 @@ public class SurfaceTexture { } } - private native void nativeInit(int texName, Object weakSelf); + private native void nativeInit(int texName, Object weakSelf, boolean allowSynchronousMode); private native void nativeFinalize(); private native void nativeGetTransformMatrix(float[] mtx); private native long nativeGetTimestamp(); diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h index 9294df674358..e558dfd6c252 100644 --- a/include/gui/SurfaceTexture.h +++ b/include/gui/SurfaceTexture.h @@ -56,7 +56,7 @@ public: // tex indicates the name OpenGL texture to which images are to be streamed. // This texture name cannot be changed once the SurfaceTexture is created. - SurfaceTexture(GLuint tex); + SurfaceTexture(GLuint tex, bool allowSynchronousMode = true); virtual ~SurfaceTexture(); @@ -361,6 +361,9 @@ private: // mSynchronousMode whether we're in synchronous mode or not bool mSynchronousMode; + // mAllowSynchronousMode whether we allow synchronous mode or not + const bool mAllowSynchronousMode; + // mDequeueCondition condition used for dequeueBuffer in synchronous mode mutable Condition mDequeueCondition; diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index 3cecdb401ab1..37e6d1187db8 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -78,7 +78,7 @@ static float mtxRot270[16] = { static void mtxMul(float out[16], const float a[16], const float b[16]); -SurfaceTexture::SurfaceTexture(GLuint tex) : +SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) : mDefaultWidth(1), mDefaultHeight(1), mPixelFormat(PIXEL_FORMAT_RGBA_8888), @@ -91,7 +91,8 @@ SurfaceTexture::SurfaceTexture(GLuint tex) : mCurrentTimestamp(0), mNextTransform(0), mTexName(tex), - mSynchronousMode(false) { + mSynchronousMode(false), + mAllowSynchronousMode(allowSynchronousMode) { LOGV("SurfaceTexture::SurfaceTexture"); sp<ISurfaceComposer> composer(ComposerService::getComposerService()); mGraphicBufferAlloc = composer->createGraphicBufferAlloc(); @@ -371,6 +372,9 @@ status_t SurfaceTexture::setSynchronousMode(bool enabled) { Mutex::Autolock lock(mMutex); status_t err = OK; + if (!mAllowSynchronousMode && enabled) + return err; + if (!enabled) { // going to asynchronous mode, drain the queue while (mSynchronousMode != enabled && !mQueue.isEmpty()) { |