Skip to content

Commit 5f0d976

Browse files
committed
Track size changes correctly for static wallpapers
Previous logic compared the surface size to the bitmap size to determine whether to reload the bitmap. This was based on an assumption that the bitmap would be created at the same sizea s the surface. However, the process of how those sizes get determined is different for surfaces and wallpapers, causing an occasional issue where the bitmap gets reloaded frequently, every time the wallpaper is asked to redraw, even though it always gets recreated at the same size. New logic checks previous surface dimensions against current surface dimensions to determine whether the bitmap should be reloaded; we really only want to reload it when the surface size changes. Issue #7373200 pause when toggling between All Apps and Home screen; Home button stays illuminated for a long time Change-Id: I108777b72bd42616ad7cf8274af1b3e6b2ed94e7
1 parent 18937b2 commit 5f0d976

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

packages/SystemUI/src/com/android/systemui/ImageWallpaper.java

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class DrawableEngine extends Engine {
109109
private WallpaperObserver mReceiver;
110110

111111
Bitmap mBackground;
112-
int mBackgroundWidth = -1, mBackgroundHeight = -1;
112+
int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
113113
int mLastRotation = -1;
114114
float mXOffset;
115115
float mYOffset;
@@ -156,7 +156,7 @@ public void onReceive(Context context, Intent intent) {
156156
}
157157

158158
synchronized (mLock) {
159-
mBackgroundWidth = mBackgroundHeight = -1;
159+
mLastSurfaceWidth = mLastSurfaceHeight = -1;
160160
mBackground = null;
161161
mRedrawNeeded = true;
162162
drawFrameLocked();
@@ -172,6 +172,9 @@ public DrawableEngine() {
172172
public void trimMemory(int level) {
173173
if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW &&
174174
mBackground != null && mIsHwAccelerated) {
175+
if (DEBUG) {
176+
Log.d(TAG, "trimMemory");
177+
}
175178
mBackground.recycle();
176179
mBackground = null;
177180
mWallpaperManager.forgetLoadedWallpaper();
@@ -286,13 +289,13 @@ public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int he
286289
@Override
287290
public void onSurfaceDestroyed(SurfaceHolder holder) {
288291
super.onSurfaceDestroyed(holder);
289-
mBackgroundWidth = mBackgroundHeight = -1;
292+
mLastSurfaceWidth = mLastSurfaceHeight = -1;
290293
}
291294

292295
@Override
293296
public void onSurfaceCreated(SurfaceHolder holder) {
294297
super.onSurfaceCreated(holder);
295-
mBackgroundWidth = mBackgroundHeight = -1;
298+
mLastSurfaceWidth = mLastSurfaceHeight = -1;
296299
}
297300

298301
@Override
@@ -314,9 +317,9 @@ void drawFrameLocked() {
314317
final int dh = frame.height();
315318
int newRotation = ((WindowManager) getSystemService(WINDOW_SERVICE)).
316319
getDefaultDisplay().getRotation();
320+
boolean surfaceDimensionsChanged = dw != mLastSurfaceWidth || dh != mLastSurfaceHeight;
317321

318-
boolean redrawNeeded = dw != mBackgroundWidth || dh != mBackgroundHeight ||
319-
newRotation != mLastRotation;
322+
boolean redrawNeeded = surfaceDimensionsChanged || newRotation != mLastRotation;
320323
if (!redrawNeeded && !mOffsetsChanged) {
321324
if (DEBUG) {
322325
Log.d(TAG, "Suppressed drawFrame since redraw is not needed "
@@ -327,21 +330,41 @@ void drawFrameLocked() {
327330
mLastRotation = newRotation;
328331

329332
// Load bitmap if it is not yet loaded or if it was loaded at a different size
330-
if (mBackground == null || dw != mBackgroundWidth || dh != mBackgroundHeight) {
333+
if (mBackground == null || surfaceDimensionsChanged) {
331334
if (DEBUG) {
332-
Log.d(TAG, "Reloading bitmap");
335+
Log.d(TAG, "Reloading bitmap: mBackground, bgw, bgh, dw, dh = " +
336+
mBackground + ", " +
337+
((mBackground == null) ? 0 : mBackground.getWidth()) + ", " +
338+
((mBackground == null) ? 0 : mBackground.getHeight()) + ", " +
339+
dw + ", " + dh);
333340
}
334-
mWallpaperManager.forgetLoadedWallpaper();
335341
updateWallpaperLocked();
342+
if (mBackground == null) {
343+
if (DEBUG) {
344+
Log.d(TAG, "Unable to load bitmap");
345+
}
346+
return;
347+
}
348+
if (DEBUG) {
349+
if (dw != mBackground.getWidth() || dh != mBackground.getHeight()) {
350+
Log.d(TAG, "Surface != bitmap dimensions: surface w/h, bitmap w/h: " +
351+
dw + ", " + dh + ", " + mBackground.getWidth() + ", " +
352+
mBackground.getHeight());
353+
}
354+
}
336355
}
337356

338-
final int availw = dw - mBackgroundWidth;
339-
final int availh = dh - mBackgroundHeight;
357+
final int availw = dw - mBackground.getWidth();
358+
final int availh = dh - mBackground.getHeight();
340359
int xPixels = availw < 0 ? (int)(availw * mXOffset + .5f) : (availw / 2);
341360
int yPixels = availh < 0 ? (int)(availh * mYOffset + .5f) : (availh / 2);
342361

343362
mOffsetsChanged = false;
344363
mRedrawNeeded = false;
364+
if (surfaceDimensionsChanged) {
365+
mLastSurfaceWidth = dw;
366+
mLastSurfaceHeight = dh;
367+
}
345368
mLastXTranslation = xPixels;
346369
mLastYTranslation = yPixels;
347370
if (!redrawNeeded && xPixels == mLastXTranslation && yPixels == mLastYTranslation) {
@@ -374,9 +397,10 @@ void drawFrameLocked() {
374397

375398
}
376399

377-
void updateWallpaperLocked() {
400+
private void updateWallpaperLocked() {
378401
Throwable exception = null;
379402
try {
403+
mWallpaperManager.forgetLoadedWallpaper(); // force reload
380404
mBackground = mWallpaperManager.getBitmap();
381405
} catch (RuntimeException e) {
382406
exception = e;
@@ -397,9 +421,6 @@ void updateWallpaperLocked() {
397421
Log.w(TAG, "Unable reset to default wallpaper!", ex);
398422
}
399423
}
400-
401-
mBackgroundWidth = mBackground != null ? mBackground.getWidth() : 0;
402-
mBackgroundHeight = mBackground != null ? mBackground.getHeight() : 0;
403424
}
404425

405426
private void drawWallpaperWithCanvas(SurfaceHolder sh, int w, int h, int x, int y) {
@@ -413,7 +434,8 @@ private void drawWallpaperWithCanvas(SurfaceHolder sh, int w, int h, int x, int
413434
c.translate(x, y);
414435
if (w < 0 || h < 0) {
415436
c.save(Canvas.CLIP_SAVE_FLAG);
416-
c.clipRect(0, 0, mBackgroundWidth, mBackgroundHeight, Op.DIFFERENCE);
437+
c.clipRect(0, 0, mBackground.getWidth(), mBackground.getHeight(),
438+
Op.DIFFERENCE);
417439
c.drawColor(0xff000000);
418440
c.restore();
419441
}
@@ -429,8 +451,8 @@ private void drawWallpaperWithCanvas(SurfaceHolder sh, int w, int h, int x, int
429451
private boolean drawWallpaperWithOpenGL(SurfaceHolder sh, int w, int h, int left, int top) {
430452
if (!initGL(sh)) return false;
431453

432-
final float right = left + mBackgroundWidth;
433-
final float bottom = top + mBackgroundHeight;
454+
final float right = left + mBackground.getWidth();
455+
final float bottom = top + mBackground.getHeight();
434456

435457
final Rect frame = sh.getSurfaceFrame();
436458
final Matrix4f ortho = new Matrix4f();

0 commit comments

Comments
 (0)