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

Commit 50f9b6e7 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh Committed by android-build-merger
Browse files

Merge "Camera2 Legacy: catch more surface abandoned error"

am: 03f14bef

Change-Id: If2e05eeb8c7fe24f97fc0c5e20bfe03a6c8c9e23
parents bb08c030 03f14bef
Loading
Loading
Loading
Loading
+34 −6
Original line number Diff line number Diff line
@@ -248,7 +248,8 @@ public class SurfaceTextureRenderer {
        return program;
    }

    private void drawFrame(SurfaceTexture st, int width, int height, int flipType) {
    private void drawFrame(SurfaceTexture st, int width, int height, int flipType)
            throws LegacyExceptionUtils.BufferQueueAbandonedException {
        checkGlError("onDrawFrame start");
        st.getTransformMatrix(mSTMatrix);

@@ -343,7 +344,7 @@ public class SurfaceTextureRenderer {
                /*offset*/ 0);

        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, /*offset*/ 0, /*count*/ 4);
        checkGlError("glDrawArrays");
        checkGlDrawError("glDrawArrays");
    }

    /**
@@ -548,7 +549,29 @@ public class SurfaceTextureRenderer {
    private void checkGlError(String msg) {
        int error;
        while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
            throw new IllegalStateException(msg + ": GLES20 error: 0x" + Integer.toHexString(error));
            throw new IllegalStateException(
                    msg + ": GLES20 error: 0x" + Integer.toHexString(error));
        }
    }

    private void checkGlDrawError(String msg)
            throws LegacyExceptionUtils.BufferQueueAbandonedException {
        int error;
        boolean surfaceAbandoned = false;
        boolean glError = false;
        while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
            if (error == GLES20.GL_OUT_OF_MEMORY) {
                surfaceAbandoned = true;
            } else {
                glError = true;
            }
        }
        if (glError) {
            throw new IllegalStateException(
                    msg + ": GLES20 error: 0x" + Integer.toHexString(error));
        }
        if (surfaceAbandoned) {
            throw new LegacyExceptionUtils.BufferQueueAbandonedException();
        }
    }

@@ -759,9 +782,14 @@ public class SurfaceTextureRenderer {
            if (LegacyCameraDevice.containsSurfaceId(holder.surface, targetSurfaceIds)) {
                makeCurrent(holder.eglSurface);
                // glReadPixels reads from the bottom of the buffer, so add an extra vertical flip
                try {
                    drawFrame(mSurfaceTexture, holder.width, holder.height,
                            (mFacing == CameraCharacteristics.LENS_FACING_FRONT) ?
                                    FLIP_TYPE_BOTH : FLIP_TYPE_VERTICAL);
                } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
                    // Should never hit this.
                    throw new IllegalStateException("Surface abandoned, skipping drawFrame...", e);
                }
                mPBufferPixels.clear();
                GLES20.glReadPixels(/*x*/ 0, /*y*/ 0, holder.width, holder.height,
                        GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, mPBufferPixels);