Merge "Load wallpaper bitmap once instead of twice" into sc-dev am: 6d21beab20
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14985019 Change-Id: I20b57a0dfe4c08c8d481a61ef5a8e0be598a09f9
This commit is contained in:
@@ -130,10 +130,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
.getBounds();
|
.getBounds();
|
||||||
mHeight = window.height();
|
mHeight = window.height();
|
||||||
mWidth = window.width();
|
mWidth = window.width();
|
||||||
mMiniBitmap = null;
|
mRenderer.setOnBitmapChanged(this::updateMiniBitmap);
|
||||||
if (mWorker != null && mWorker.getThreadHandler() != null) {
|
|
||||||
mWorker.getThreadHandler().post(this::updateMiniBitmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EglHelper getEglHelperInstance() {
|
EglHelper getEglHelperInstance() {
|
||||||
@@ -177,8 +174,8 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
mPageOffset = (1 - imgWidth) / (float) (mPages - 1);
|
mPageOffset = (1 - imgWidth) / (float) (mPages - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMiniBitmap() {
|
private void updateMiniBitmap(Bitmap b) {
|
||||||
mRenderer.useBitmap(b -> {
|
if (b == null) return;
|
||||||
int size = Math.min(b.getWidth(), b.getHeight());
|
int size = Math.min(b.getWidth(), b.getHeight());
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
if (size > MIN_SURFACE_WIDTH) {
|
if (size > MIN_SURFACE_WIDTH) {
|
||||||
@@ -190,7 +187,6 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
(int) Math.max(scale * b.getHeight(), 1), false);
|
(int) Math.max(scale * b.getHeight(), 1), false);
|
||||||
computeAndNotifyLocalColors(mLocalColorsToAdd, mMiniBitmap);
|
computeAndNotifyLocalColors(mLocalColorsToAdd, mMiniBitmap);
|
||||||
mLocalColorsToAdd.clear();
|
mLocalColorsToAdd.clear();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSurfaceSize() {
|
private void updateSurfaceSize() {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
|
|||||||
private final ImageGLWallpaper mWallpaper;
|
private final ImageGLWallpaper mWallpaper;
|
||||||
private final Rect mSurfaceSize = new Rect();
|
private final Rect mSurfaceSize = new Rect();
|
||||||
private final WallpaperTexture mTexture;
|
private final WallpaperTexture mTexture;
|
||||||
|
private Consumer<Bitmap> mOnBitmapUpdated;
|
||||||
|
|
||||||
public ImageWallpaperRenderer(Context context) {
|
public ImageWallpaperRenderer(Context context) {
|
||||||
final WallpaperManager wpm = context.getSystemService(WallpaperManager.class);
|
final WallpaperManager wpm = context.getSystemService(WallpaperManager.class);
|
||||||
@@ -60,10 +61,9 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public void useBitmap(Consumer<Bitmap> c) {
|
public void setOnBitmapChanged(Consumer<Bitmap> c) {
|
||||||
mTexture.use(c);
|
mOnBitmapUpdated = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,6 +80,8 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
|
|||||||
mTexture.use(bitmap -> {
|
mTexture.use(bitmap -> {
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
Log.w(TAG, "reload texture failed!");
|
Log.w(TAG, "reload texture failed!");
|
||||||
|
} else if (mOnBitmapUpdated != null) {
|
||||||
|
mOnBitmapUpdated.accept(bitmap);
|
||||||
}
|
}
|
||||||
mWallpaper.setup(bitmap);
|
mWallpaper.setup(bitmap);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user