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

Commit 48ca08a2 authored by Michael Wright's avatar Michael Wright Committed by Android Git Automerger
Browse files

am 43a7dcc1: am 265d3e9d: Merge "Clean-up ColorFade\'s shaders and buffers." into lmp-dev

* commit '43a7dcc1':
  Clean-up ColorFade's shaders and buffers.
parents 06f6b38b 43a7dcc1
Loading
Loading
Loading
Loading
+29 −12
Original line number Diff line number Diff line
@@ -226,12 +226,15 @@ final class ColorFade {
                GLES20.GL_VERTEX_SHADER);
        int fshader = loadShader(context, com.android.internal.R.raw.color_fade_frag,
                GLES20.GL_FRAGMENT_SHADER);
        GLES20.glReleaseShaderCompiler();
        if (vshader == 0 || fshader == 0) return false;

        mProgram = GLES20.glCreateProgram();

        GLES20.glAttachShader(mProgram, vshader);
        GLES20.glAttachShader(mProgram, fshader);
        GLES20.glDeleteShader(vshader);
        GLES20.glDeleteShader(fshader);

        GLES20.glLinkProgram(mProgram);

@@ -254,6 +257,11 @@ final class ColorFade {
        return true;
    }

    private void destroyGLShaders() {
        GLES20.glDeleteProgram(mProgram);
        checkGlErrors("glDeleteProgram");
    }

    private boolean initGLBuffers() {
        //Fill vertices
        setQuad(mVertexBuffer, 0, 0, mDisplayWidth, mDisplayHeight);
@@ -288,6 +296,11 @@ final class ColorFade {
        return true;
    }

    private void destroyGLBuffers() {
        GLES20.glDeleteBuffers(2, mGLBuffers, 0);
        checkGlErrors("glDeleteBuffers");
    }

    private static void setQuad(FloatBuffer vtx, float x, float y, float w, float h) {
        if (DEBUG) {
            Slog.d(TAG, "setQuad: x=" + x + ", y=" + y + ", w=" + w + ", h=" + h);
@@ -314,11 +327,21 @@ final class ColorFade {
            Slog.d(TAG, "dismiss");
        }

        if (mPrepared) {
            attachEglContext();
            try {
                destroyScreenshotTexture();
                destroyGLShaders();
                destroyGLBuffers();
                destroyEglSurface();
            } finally {
                detachEglContext();
            }
            destroySurface();
            GLES20.glFlush();
            mPrepared = false;
        }
    }

    /**
     * Draws an animation frame showing the color fade activated at the
@@ -468,14 +491,8 @@ final class ColorFade {
    private void destroyScreenshotTexture() {
        if (mTexNamesGenerated) {
            mTexNamesGenerated = false;
            if (attachEglContext()) {
                try {
            GLES20.glDeleteTextures(1, mTexNames, 0);
            checkGlErrors("glDeleteTextures");
                } finally {
                    detachEglContext();
                }
            }
        }
    }