Merge "Clean up graphics resources." into lmp-mr1-dev

This commit is contained in:
Michael Wright
2015-01-14 21:21:39 +00:00
committed by Android (Google) Code Review
2 changed files with 12 additions and 40 deletions

View File

@@ -105,10 +105,6 @@ public class ImageWallpaper extends WallpaperService {
static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
static final int EGL_OPENGL_ES2_BIT = 4; static final int EGL_OPENGL_ES2_BIT = 4;
// TODO: Not currently used, keeping around until we know we don't need it
@SuppressWarnings({"UnusedDeclaration"})
private WallpaperObserver mReceiver;
Bitmap mBackground; Bitmap mBackground;
int mBackgroundWidth = -1, mBackgroundHeight = -1; int mBackgroundWidth = -1, mBackgroundHeight = -1;
int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1; int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
@@ -151,22 +147,6 @@ public class ImageWallpaper extends WallpaperService {
private static final int TRIANGLE_VERTICES_DATA_POS_OFFSET = 0; private static final int TRIANGLE_VERTICES_DATA_POS_OFFSET = 0;
private static final int TRIANGLE_VERTICES_DATA_UV_OFFSET = 3; private static final int TRIANGLE_VERTICES_DATA_UV_OFFSET = 3;
class WallpaperObserver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (DEBUG) {
Log.d(TAG, "onReceive");
}
mLastSurfaceWidth = mLastSurfaceHeight = -1;
mBackground = null;
mBackgroundWidth = -1;
mBackgroundHeight = -1;
mRedrawNeeded = true;
drawFrame();
}
}
public DrawableEngine() { public DrawableEngine() {
super(); super();
setFixedSizeAllowed(true); setFixedSizeAllowed(true);
@@ -194,12 +174,6 @@ public class ImageWallpaper extends WallpaperService {
super.onCreate(surfaceHolder); super.onCreate(surfaceHolder);
// TODO: Don't need this currently because the wallpaper service
// will restart the image wallpaper whenever the image changes.
//IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
//mReceiver = new WallpaperObserver();
//registerReceiver(mReceiver, filter, null, mHandler);
updateSurfaceSize(surfaceHolder); updateSurfaceSize(surfaceHolder);
setOffsetNotificationsEnabled(false); setOffsetNotificationsEnabled(false);
@@ -208,9 +182,6 @@ public class ImageWallpaper extends WallpaperService {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mReceiver != null) {
unregisterReceiver(mReceiver);
}
mBackground = null; mBackground = null;
mWallpaperManager.forgetLoadedWallpaper(); mWallpaperManager.forgetLoadedWallpaper();
} }
@@ -562,7 +533,7 @@ public class ImageWallpaper extends WallpaperService {
boolean status = mEgl.eglSwapBuffers(mEglDisplay, mEglSurface); boolean status = mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
checkEglError(); checkEglError();
finishGL(); finishGL(texture, program);
return status; return status;
} }
@@ -615,21 +586,18 @@ public class ImageWallpaper extends WallpaperService {
int program = glCreateProgram(); int program = glCreateProgram();
glAttachShader(program, vertexShader); glAttachShader(program, vertexShader);
checkGlError();
glAttachShader(program, fragmentShader); glAttachShader(program, fragmentShader);
checkGlError();
glLinkProgram(program); glLinkProgram(program);
checkGlError(); checkGlError();
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
int[] status = new int[1]; int[] status = new int[1];
glGetProgramiv(program, GL_LINK_STATUS, status, 0); glGetProgramiv(program, GL_LINK_STATUS, status, 0);
if (status[0] != GL_TRUE) { if (status[0] != GL_TRUE) {
String error = glGetProgramInfoLog(program); String error = glGetProgramInfoLog(program);
Log.d(GL_LOG_TAG, "Error while linking program:\n" + error); Log.d(GL_LOG_TAG, "Error while linking program:\n" + error);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
glDeleteProgram(program); glDeleteProgram(program);
return 0; return 0;
} }
@@ -672,7 +640,11 @@ public class ImageWallpaper extends WallpaperService {
} }
} }
private void finishGL() { private void finishGL(int texture, int program) {
int[] textures = new int[1];
textures[0] = texture;
glDeleteTextures(1, textures, 0);
glDeleteProgram(program);
mEgl.eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); mEgl.eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
mEgl.eglDestroySurface(mEglDisplay, mEglSurface); mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
mEgl.eglDestroyContext(mEglDisplay, mEglContext); mEgl.eglDestroyContext(mEglDisplay, mEglContext);

View File

@@ -464,13 +464,13 @@ final class ColorFade {
try { try {
SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay( SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(
SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s); SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
st.updateTexImage();
st.getTransformMatrix(mTexMatrix);
} finally { } finally {
s.release(); s.release();
st.release();
} }
st.updateTexImage();
st.getTransformMatrix(mTexMatrix);
// Set up texture coordinates for a quad. // Set up texture coordinates for a quad.
// We might need to change this if the texture ends up being // We might need to change this if the texture ends up being
// a different size from the display for some reason. // a different size from the display for some reason.