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

Commit a3402c33 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

TextureView/GLES20Canvas: Support synchronous GLConsumers

Always update to the newest available frame from a GLConsumer.
Otherwise, with a synchronous queue, rendering can fall behind and
eventually deadlock with producer.

Bug: 10830400
Change-Id: I7f1d752c80ae5dac892a26d82e86806c27f5d955
parent 7cb93f4e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -878,6 +878,23 @@ static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject cl
    sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));

    if (surfaceTexture->updateTexImage() == NO_ERROR) {
        int64_t frameNumber = surfaceTexture->getFrameNumber();
        // If the GLConsumer queue is in synchronous mode, need to discard all
        // but latest frame, using the frame number to tell when we no longer
        // have newer frames to target. Since we can't tell which mode it is in,
        // do this unconditionally.
        int dropCounter = 0;
        while (surfaceTexture->updateTexImage() == NO_ERROR) {
            int64_t newFrameNumber = surfaceTexture->getFrameNumber();
            if (newFrameNumber == frameNumber) break;
            frameNumber = newFrameNumber;
            dropCounter++;
        }
        #if DEBUG_RENDERER
        if (dropCounter > 0) {
            RENDERER_LOGD("Dropped %d frames on texture layer update", dropCounter);
        }
        #endif
        surfaceTexture->getTransformMatrix(transform);
        GLenum renderTarget = surfaceTexture->getCurrentTextureTarget();