Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0904d0af authored by Grace Kloba's avatar Grace Kloba
Browse files

Add allowSynchronousMode to SurfaceTexture constructor.

Change-Id: I54f30a3c16bbe6b813f3bcd1d389da5627531304
parent 62250fbc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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 },
+15 −2
Original line number Diff line number Diff line
@@ -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();
+4 −1
Original line number Diff line number Diff line
@@ -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;

+6 −2
Original line number Diff line number Diff line
@@ -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()) {