From 11514a9032345c6ded05ef70176b5b82efc6fe64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pomini?= Date: Thu, 29 Jun 2023 12:28:29 +0000 Subject: [PATCH] Load and draw bitmap only once with ImageWallpaper Given that ImageWallpaper uses surface.SetFixedSize with the dimensions of the image, and that WallpaperController moves the without redrawing the bitmap (e.g. in case of rotation/unfold), the bitmap only needs to be drawn once (in theory). Bug: 288582051 Bug: 265018814 Test: manual on foldable: fold, unfold, rotate, with one or two ImageWallpaper engines Test: atest ImageWallpaperTest Change-Id: I1a61c5d30c5f4d6abff4eac76195b74dfb18fe6f --- .../src/com/android/systemui/wallpapers/ImageWallpaper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java index 316b54eb0c80a..091a54fe98017 100644 --- a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java +++ b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java @@ -109,6 +109,7 @@ public class ImageWallpaper extends WallpaperService { private WallpaperManager mWallpaperManager; private final WallpaperLocalColorExtractor mWallpaperLocalColorExtractor; private SurfaceHolder mSurfaceHolder; + private boolean mDrawn = false; @VisibleForTesting static final int MIN_SURFACE_WIDTH = 128; @VisibleForTesting @@ -238,6 +239,7 @@ public class ImageWallpaper extends WallpaperService { private void drawFrameSynchronized() { synchronized (mLock) { + if (mDrawn) return; drawFrameInternal(); } } @@ -275,6 +277,7 @@ public class ImageWallpaper extends WallpaperService { Rect dest = mSurfaceHolder.getSurfaceFrame(); try { canvas.drawBitmap(bitmap, null, dest, null); + mDrawn = true; } finally { surface.unlockCanvasAndPost(canvas); }