am 61a848dd: Merge "Fix Bitmap leaks in ImageWallpaper" into lmp-mr1-dev

* commit '61a848dd2e095336c341af68ed01564c0f3cb442':
  Fix Bitmap leaks in ImageWallpaper
This commit is contained in:
Adrian Roos
2014-11-17 13:56:04 +00:00
committed by Android Git Automerger

View File

@@ -174,7 +174,7 @@ public class ImageWallpaper extends WallpaperService {
public void trimMemory(int level) { public void trimMemory(int level) {
if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW && if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW &&
mBackground != null && mIsHwAccelerated) { mBackground != null) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "trimMemory"); Log.d(TAG, "trimMemory");
} }
@@ -212,6 +212,7 @@ public class ImageWallpaper extends WallpaperService {
unregisterReceiver(mReceiver); unregisterReceiver(mReceiver);
} }
mBackground = null; mBackground = null;
mWallpaperManager.forgetLoadedWallpaper();
} }
void updateSurfaceSize(SurfaceHolder surfaceHolder) { void updateSurfaceSize(SurfaceHolder surfaceHolder) {
@@ -337,6 +338,7 @@ public class ImageWallpaper extends WallpaperService {
} }
void drawFrame() { void drawFrame() {
try {
int newRotation = ((WindowManager) getSystemService(WINDOW_SERVICE)). int newRotation = ((WindowManager) getSystemService(WINDOW_SERVICE)).
getDefaultDisplay().getRotation(); getDefaultDisplay().getRotation();
@@ -351,7 +353,8 @@ public class ImageWallpaper extends WallpaperService {
final Rect frame = sh.getSurfaceFrame(); final Rect frame = sh.getSurfaceFrame();
final int dw = frame.width(); final int dw = frame.width();
final int dh = frame.height(); final int dh = frame.height();
boolean surfaceDimensionsChanged = dw != mLastSurfaceWidth || dh != mLastSurfaceHeight; boolean surfaceDimensionsChanged = dw != mLastSurfaceWidth
|| dh != mLastSurfaceHeight;
boolean redrawNeeded = surfaceDimensionsChanged || newRotation != mLastRotation; boolean redrawNeeded = surfaceDimensionsChanged || newRotation != mLastRotation;
if (!redrawNeeded && !mOffsetsChanged) { if (!redrawNeeded && !mOffsetsChanged) {
@@ -402,8 +405,10 @@ public class ImageWallpaper extends WallpaperService {
// will remain unchanged // will remain unchanged
final int availwUnscaled = dw - mBackground.getWidth(); final int availwUnscaled = dw - mBackground.getWidth();
final int availhUnscaled = dh - mBackground.getHeight(); final int availhUnscaled = dh - mBackground.getHeight();
if (availwUnscaled < 0) xPixels += (int)(availwUnscaled * (mXOffset - .5f) + .5f); if (availwUnscaled < 0)
if (availhUnscaled < 0) yPixels += (int)(availhUnscaled * (mYOffset - .5f) + .5f); xPixels += (int) (availwUnscaled * (mXOffset - .5f) + .5f);
if (availhUnscaled < 0)
yPixels += (int) (availhUnscaled * (mYOffset - .5f) + .5f);
mOffsetsChanged = false; mOffsetsChanged = false;
mRedrawNeeded = false; mRedrawNeeded = false;
@@ -431,17 +436,18 @@ public class ImageWallpaper extends WallpaperService {
} }
} else { } else {
drawWallpaperWithCanvas(sh, availw, availh, xPixels, yPixels); drawWallpaperWithCanvas(sh, availw, availh, xPixels, yPixels);
if (FIXED_SIZED_SURFACE) { }
} finally {
if (FIXED_SIZED_SURFACE && !mIsHwAccelerated) {
// If the surface is fixed-size, we should only need to // If the surface is fixed-size, we should only need to
// draw it once and then we'll let the window manager // draw it once and then we'll let the window manager
// position it appropriately. As such, we no longer needed // position it appropriately. As such, we no longer needed
// the loaded bitmap. Yay! // the loaded bitmap. Yay!
// hw-accelerated path retains bitmap for faster rotation // hw-accelerated renderer retains bitmap for faster rotation
mBackground = null; mBackground = null;
mWallpaperManager.forgetLoadedWallpaper(); mWallpaperManager.forgetLoadedWallpaper();
} }
} }
} }
private void updateWallpaperLocked() { private void updateWallpaperLocked() {