Merge "Reintroduce WCG drawing if supported" into tm-qpr-dev

This commit is contained in:
Aurélien Pomini
2022-10-10 13:58:11 +00:00
committed by Android (Google) Code Review

View File

@@ -528,6 +528,7 @@ public class ImageWallpaper extends WallpaperService {
@VisibleForTesting @VisibleForTesting
static final int MIN_SURFACE_HEIGHT = 128; static final int MIN_SURFACE_HEIGHT = 128;
private Bitmap mBitmap; private Bitmap mBitmap;
private boolean mWideColorGamut = false;
/* /*
* Counter to unload the bitmap as soon as possible. * Counter to unload the bitmap as soon as possible.
@@ -674,14 +675,16 @@ public class ImageWallpaper extends WallpaperService {
@VisibleForTesting @VisibleForTesting
void drawFrameOnCanvas(Bitmap bitmap) { void drawFrameOnCanvas(Bitmap bitmap) {
Trace.beginSection("ImageWallpaper.CanvasEngine#drawFrame"); Trace.beginSection("ImageWallpaper.CanvasEngine#drawFrame");
// TODO change SurfaceHolder API to add wcg support Surface surface = mSurfaceHolder.getSurface();
Canvas c = mSurfaceHolder.lockHardwareCanvas(); Canvas canvas = mWideColorGamut
if (c != null) { ? surface.lockHardwareWideColorGamutCanvas()
: surface.lockHardwareCanvas();
if (canvas != null) {
Rect dest = mSurfaceHolder.getSurfaceFrame(); Rect dest = mSurfaceHolder.getSurfaceFrame();
try { try {
c.drawBitmap(bitmap, null, dest, null); canvas.drawBitmap(bitmap, null, dest, null);
} finally { } finally {
mSurfaceHolder.unlockCanvasAndPost(c); surface.unlockCanvasAndPost(canvas);
} }
} }
Trace.endSection(); Trace.endSection();
@@ -778,6 +781,8 @@ public class ImageWallpaper extends WallpaperService {
mBitmap.recycle(); mBitmap.recycle();
} }
mBitmap = bitmap; mBitmap = bitmap;
mWideColorGamut = mWallpaperManager.wallpaperSupportsWcg(
WallpaperManager.FLAG_SYSTEM);
// +2 usages for the color extraction and the delayed unload. // +2 usages for the color extraction and the delayed unload.
mBitmapUsages += 2; mBitmapUsages += 2;
@@ -839,10 +844,6 @@ public class ImageWallpaper extends WallpaperService {
public void onOffsetsChanged(float xOffset, float yOffset, public void onOffsetsChanged(float xOffset, float yOffset,
float xOffsetStep, float yOffsetStep, float xOffsetStep, float yOffsetStep,
int xPixelOffset, int yPixelOffset) { int xPixelOffset, int yPixelOffset) {
/*
* TODO check this formula. mPages is always >= 4, even when launcher is single-paged
* this formula is also used in the GL engine
*/
final int pages; final int pages;
if (xOffsetStep > 0 && xOffsetStep <= 1) { if (xOffsetStep > 0 && xOffsetStep <= 1) {
pages = Math.round(1 / xOffsetStep) + 1; pages = Math.round(1 / xOffsetStep) + 1;