Load wallpaper bitmap once instead of twice

Fixes: 189976068
Test: visual
Change-Id: I97eba1c58a485b18fbdd93fce04d87df2f95552e
This commit is contained in:
Jay Aliomer
2021-06-15 15:15:50 -04:00
parent 08a0b629cb
commit 3f767f2a8e
2 changed files with 19 additions and 21 deletions

View File

@@ -130,10 +130,7 @@ public class ImageWallpaper extends WallpaperService {
.getBounds();
mHeight = window.height();
mWidth = window.width();
mMiniBitmap = null;
if (mWorker != null && mWorker.getThreadHandler() != null) {
mWorker.getThreadHandler().post(this::updateMiniBitmap);
}
mRenderer.setOnBitmapChanged(this::updateMiniBitmap);
}
EglHelper getEglHelperInstance() {
@@ -177,20 +174,19 @@ public class ImageWallpaper extends WallpaperService {
mPageOffset = (1 - imgWidth) / (float) (mPages - 1);
}
private void updateMiniBitmap() {
mRenderer.useBitmap(b -> {
int size = Math.min(b.getWidth(), b.getHeight());
float scale = 1.0f;
if (size > MIN_SURFACE_WIDTH) {
scale = (float) MIN_SURFACE_WIDTH / (float) size;
}
mImgHeight = b.getHeight();
mImgWidth = b.getWidth();
mMiniBitmap = Bitmap.createScaledBitmap(b, (int) Math.max(scale * b.getWidth(), 1),
(int) Math.max(scale * b.getHeight(), 1), false);
computeAndNotifyLocalColors(mLocalColorsToAdd, mMiniBitmap);
mLocalColorsToAdd.clear();
});
private void updateMiniBitmap(Bitmap b) {
if (b == null) return;
int size = Math.min(b.getWidth(), b.getHeight());
float scale = 1.0f;
if (size > MIN_SURFACE_WIDTH) {
scale = (float) MIN_SURFACE_WIDTH / (float) size;
}
mImgHeight = b.getHeight();
mImgWidth = b.getWidth();
mMiniBitmap = Bitmap.createScaledBitmap(b, (int) Math.max(scale * b.getWidth(), 1),
(int) Math.max(scale * b.getHeight(), 1), false);
computeAndNotifyLocalColors(mLocalColorsToAdd, mMiniBitmap);
mLocalColorsToAdd.clear();
}
private void updateSurfaceSize() {

View File

@@ -46,6 +46,7 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
private final ImageGLWallpaper mWallpaper;
private final Rect mSurfaceSize = new Rect();
private final WallpaperTexture mTexture;
private Consumer<Bitmap> mOnBitmapUpdated;
public ImageWallpaperRenderer(Context context) {
final WallpaperManager wpm = context.getSystemService(WallpaperManager.class);
@@ -60,10 +61,9 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
/**
* @hide
* @return
*/
public void useBitmap(Consumer<Bitmap> c) {
mTexture.use(c);
public void setOnBitmapChanged(Consumer<Bitmap> c) {
mOnBitmapUpdated = c;
}
@Override
@@ -80,6 +80,8 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
mTexture.use(bitmap -> {
if (bitmap == null) {
Log.w(TAG, "reload texture failed!");
} else if (mOnBitmapUpdated != null) {
mOnBitmapUpdated.accept(bitmap);
}
mWallpaper.setup(bitmap);
});