Clean-up ColorFade's shaders and buffers.
Bug: 17672241
Change-Id: I73328ee4d83c3a8700b7b19b661bcaec7ada877f
diff --git a/services/core/java/com/android/server/display/ColorFade.java b/services/core/java/com/android/server/display/ColorFade.java
index 920fdfb..f549f3d 100644
--- a/services/core/java/com/android/server/display/ColorFade.java
+++ b/services/core/java/com/android/server/display/ColorFade.java
@@ -226,12 +226,15 @@
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 @@
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 @@
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,10 +327,20 @@
Slog.d(TAG, "dismiss");
}
- destroyScreenshotTexture();
- destroyEglSurface();
- destroySurface();
- mPrepared = false;
+ if (mPrepared) {
+ attachEglContext();
+ try {
+ destroyScreenshotTexture();
+ destroyGLShaders();
+ destroyGLBuffers();
+ destroyEglSurface();
+ } finally {
+ detachEglContext();
+ }
+ destroySurface();
+ GLES20.glFlush();
+ mPrepared = false;
+ }
}
/**
@@ -468,14 +491,8 @@
private void destroyScreenshotTexture() {
if (mTexNamesGenerated) {
mTexNamesGenerated = false;
- if (attachEglContext()) {
- try {
- GLES20.glDeleteTextures(1, mTexNames, 0);
- checkGlErrors("glDeleteTextures");
- } finally {
- detachEglContext();
- }
- }
+ GLES20.glDeleteTextures(1, mTexNames, 0);
+ checkGlErrors("glDeleteTextures");
}
}