From 1a3245d5a1a5a3446c4cbd6cf5504e35dc0f2954 Mon Sep 17 00:00:00 2001 From: James O'Leary Date: Wed, 2 Jun 2021 10:21:58 -0400 Subject: [PATCH 1/2] Only rescale wallpaper if its > display height WallpaperPicker assigns wallpapers, this code caches them. The assigned wallpaper is ~always slightly smaller than the display size There's no need to scale _up_ the assigned wallpaper, it will only permanently introduce scaling artifacts while increasing the amount of storage required to store the wallpaper. Most importantly, it creates an inconsistency between the colors WallpaperColors.fromBitmap returns, and the WallpaperColors returned by the system from the cached copy. This causes a large problem for dynamic color, as it means the colors displayed in Wallpaper Picker will differ from the colors actually extracted by the system. Bug: 189931209 Test: Test tons and tons of wallpapers over a couple days. Change-Id: Ifefd3e56df57f55cead985c3f182db2de10dc769 --- .../com/android/server/wallpaper/WallpaperManagerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index c888e545b24ea..6f2d020837f64 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -628,7 +628,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } // scale if the crop height winds up not matching the recommended metrics - needScale = wpData.mHeight != cropHint.height() + needScale = cropHint.height() > wpData.mHeight || cropHint.height() > GLHelper.getMaxTextureSize() || cropHint.width() > GLHelper.getMaxTextureSize(); From b0c0318d097cdfa8244a882cea4eb72ecb57398a Mon Sep 17 00:00:00 2001 From: James O'Leary Date: Wed, 2 Jun 2021 10:24:17 -0400 Subject: [PATCH 2/2] Cache set wallpaper as PNG instead of JPEG JPEG is a lossy image format: if image bytes are encoded to JPEG, then the JPEG is decoded to image bytes, those bytes will _always_ differ from the original bytes. Caching as PNG ensures that the same colors will be extracted from the wallpaper as were displayed in the Wallpaper Picker preview using WallpaperColors.fromBitmap. Otherwise, the cached wallpaper differs from the bitmap used with WallpaperColors.fromBitmap for the preview in wallpaper picker. Bug: 189931209 Test: Test tons and tons of wallpapers over a couple days. Change-Id: Ifc451f540d5e944055a5e0fb4be6a79c4bd5a939 --- .../com/android/server/wallpaper/WallpaperManagerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 6f2d020837f64..53f1035ee4226 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -752,7 +752,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub f = new FileOutputStream(wallpaper.cropFile); bos = new BufferedOutputStream(f, 32*1024); - finalCrop.compress(Bitmap.CompressFormat.JPEG, 100, bos); + finalCrop.compress(Bitmap.CompressFormat.PNG, 100, bos); bos.flush(); // don't rely on the implicit flush-at-close when noting success success = true; }