Merge "Add letterboxInsets to TaskSnapshot"

This commit is contained in:
Alex Chau 2021-11-09 10:58:38 +00:00 committed by Android (Google) Code Review
commit 75251249f2
11 changed files with 60 additions and 18 deletions

View File

@ -50,6 +50,7 @@ public class TaskSnapshot implements Parcelable {
/** The size of the snapshot before scaling */
private final Point mTaskSize;
private final Rect mContentInsets;
private final Rect mLetterboxInsets;
// Whether this snapshot is a down-sampled version of the high resolution snapshot, used
// mainly for loading snapshots quickly from disk when user is flinging fast
private final boolean mIsLowResolution;
@ -67,9 +68,10 @@ public class TaskSnapshot implements Parcelable {
public TaskSnapshot(long id,
@NonNull ComponentName topActivityComponent, HardwareBuffer snapshot,
@NonNull ColorSpace colorSpace, int orientation, int rotation, Point taskSize,
Rect contentInsets, boolean isLowResolution, boolean isRealSnapshot,
int windowingMode, @WindowInsetsController.Appearance int appearance,
boolean isTranslucent, boolean hasImeSurface) {
Rect contentInsets, Rect letterboxInsets, boolean isLowResolution,
boolean isRealSnapshot, int windowingMode,
@WindowInsetsController.Appearance int appearance, boolean isTranslucent,
boolean hasImeSurface) {
mId = id;
mTopActivityComponent = topActivityComponent;
mSnapshot = snapshot;
@ -79,6 +81,7 @@ public class TaskSnapshot implements Parcelable {
mRotation = rotation;
mTaskSize = new Point(taskSize);
mContentInsets = new Rect(contentInsets);
mLetterboxInsets = new Rect(letterboxInsets);
mIsLowResolution = isLowResolution;
mIsRealSnapshot = isRealSnapshot;
mWindowingMode = windowingMode;
@ -99,6 +102,7 @@ public class TaskSnapshot implements Parcelable {
mRotation = source.readInt();
mTaskSize = source.readTypedObject(Point.CREATOR);
mContentInsets = source.readTypedObject(Rect.CREATOR);
mLetterboxInsets = source.readTypedObject(Rect.CREATOR);
mIsLowResolution = source.readBoolean();
mIsRealSnapshot = source.readBoolean();
mWindowingMode = source.readInt();
@ -178,6 +182,14 @@ public class TaskSnapshot implements Parcelable {
return mContentInsets;
}
/**
* @return The letterbox insets on the snapshot. These can be clipped off in order to
* remove any letterbox areas in the snapshot.
*/
public Rect getLetterboxInsets() {
return mLetterboxInsets;
}
/**
* @return Whether this snapshot is a down-sampled version of the full resolution.
*/
@ -241,6 +253,7 @@ public class TaskSnapshot implements Parcelable {
dest.writeInt(mRotation);
dest.writeTypedObject(mTaskSize, 0);
dest.writeTypedObject(mContentInsets, 0);
dest.writeTypedObject(mLetterboxInsets, 0);
dest.writeBoolean(mIsLowResolution);
dest.writeBoolean(mIsRealSnapshot);
dest.writeInt(mWindowingMode);
@ -262,6 +275,7 @@ public class TaskSnapshot implements Parcelable {
+ " mRotation=" + mRotation
+ " mTaskSize=" + mTaskSize.toString()
+ " mContentInsets=" + mContentInsets.toShortString()
+ " mLetterboxInsets=" + mLetterboxInsets.toShortString()
+ " mIsLowResolution=" + mIsLowResolution
+ " mIsRealSnapshot=" + mIsRealSnapshot
+ " mWindowingMode=" + mWindowingMode
@ -289,6 +303,7 @@ public class TaskSnapshot implements Parcelable {
private int mRotation;
private Point mTaskSize;
private Rect mContentInsets;
private Rect mLetterboxInsets;
private boolean mIsRealSnapshot;
private int mWindowingMode;
private @WindowInsetsController.Appearance
@ -340,6 +355,11 @@ public class TaskSnapshot implements Parcelable {
return this;
}
public Builder setLetterboxInsets(Rect letterboxInsets) {
mLetterboxInsets = letterboxInsets;
return this;
}
public Builder setIsRealSnapshot(boolean realSnapshot) {
mIsRealSnapshot = realSnapshot;
return this;
@ -387,6 +407,7 @@ public class TaskSnapshot implements Parcelable {
mRotation,
mTaskSize,
mContentInsets,
mLetterboxInsets,
// When building a TaskSnapshot with the Builder class, isLowResolution
// is always false. Low-res snapshots are only created when loading from
// disk.

View File

@ -301,8 +301,8 @@ public class StartingSurfaceDrawerTests {
System.currentTimeMillis(),
new ComponentName("", ""), buffer,
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
Surface.ROTATION_0, taskSize, contentInsets, false,
true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
0 /* systemUiVisibility */, false /* isTranslucent */,
hasImeSurface /* hasImeSurface */);
}

View File

@ -94,8 +94,8 @@ public class TaskSnapshotWindowTest {
System.currentTimeMillis(),
new ComponentName("", ""), buffer,
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
Surface.ROTATION_0, taskSize, contentInsets, false,
true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
0 /* systemUiVisibility */, false /* isTranslucent */, false /* hasImeSurface */);
}

View File

@ -42,6 +42,7 @@ public class ThumbnailData {
public int orientation;
public int rotation;
public Rect insets;
public Rect letterboxInsets;
public boolean reducedResolution;
public boolean isRealSnapshot;
public boolean isTranslucent;
@ -55,6 +56,7 @@ public class ThumbnailData {
orientation = ORIENTATION_UNDEFINED;
rotation = ROTATION_UNDEFINED;
insets = new Rect();
letterboxInsets = new Rect();
reducedResolution = false;
scale = 1f;
isRealSnapshot = true;
@ -97,6 +99,7 @@ public class ThumbnailData {
public ThumbnailData(TaskSnapshot snapshot) {
thumbnail = makeThumbnail(snapshot);
insets = new Rect(snapshot.getContentInsets());
letterboxInsets = new Rect(snapshot.getLetterboxInsets());
orientation = snapshot.getOrientation();
rotation = snapshot.getRotation();
reducedResolution = snapshot.isLowResolution();

View File

@ -41,4 +41,8 @@
// The task height when the snapshot was taken
int32 task_height = 15;
int32 appearance = 16;
int32 letterbox_inset_left = 17;
int32 letterbox_inset_top = 18;
int32 letterbox_inset_right = 19;
int32 letterbox_inset_bottom = 20;
}

View File

@ -298,11 +298,13 @@ class TaskSnapshotController {
final WindowState mainWindow = result.second;
final Rect contentInsets = getSystemBarInsets(task.getBounds(),
mainWindow.getInsetsStateWithVisibilityOverride());
InsetUtils.addInsets(contentInsets, activity.getLetterboxInsets());
final Rect letterboxInsets = activity.getLetterboxInsets();
InsetUtils.addInsets(contentInsets, letterboxInsets);
builder.setIsRealSnapshot(true);
builder.setId(System.currentTimeMillis());
builder.setContentInsets(contentInsets);
builder.setLetterboxInsets(letterboxInsets);
final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
final boolean isShowWallpaper = mainWindow.hasWallpaper();
@ -581,7 +583,8 @@ class TaskSnapshotController {
return null;
}
final Rect contentInsets = new Rect(systemBarInsets);
InsetUtils.addInsets(contentInsets, topChild.getLetterboxInsets());
final Rect letterboxInsets = topChild.getLetterboxInsets();
InsetUtils.addInsets(contentInsets, letterboxInsets);
// Note, the app theme snapshot is never translucent because we enforce a non-translucent
// color above
@ -590,9 +593,9 @@ class TaskSnapshotController {
topChild.mActivityComponent, hwBitmap.getHardwareBuffer(),
hwBitmap.getColorSpace(), mainWindow.getConfiguration().orientation,
mainWindow.getWindowConfiguration().getRotation(), new Point(taskWidth, taskHeight),
contentInsets, false /* isLowResolution */, false /* isRealSnapshot */,
task.getWindowingMode(), getAppearance(task), false /* isTranslucent */,
false /* hasImeSurface */);
contentInsets, letterboxInsets, false /* isLowResolution */,
false /* isRealSnapshot */, task.getWindowingMode(),
getAppearance(task), false /* isTranslucent */, false /* hasImeSurface */);
}
/**

View File

@ -20,7 +20,6 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import android.app.ActivityManager;
import android.window.TaskSnapshot;
import android.content.ComponentName;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
@ -30,6 +29,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.util.Slog;
import android.window.TaskSnapshot;
import com.android.server.wm.nano.WindowManagerProtos.TaskSnapshotProto;
@ -196,6 +196,8 @@ class TaskSnapshotLoader {
return new TaskSnapshot(proto.id, topActivityComponent, buffer,
hwBitmap.getColorSpace(), proto.orientation, proto.rotation, taskSize,
new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
new Rect(proto.letterboxInsetLeft, proto.letterboxInsetTop,
proto.letterboxInsetRight, proto.letterboxInsetBottom),
loadLowResolutionBitmap, proto.isRealSnapshot, proto.windowingMode,
proto.appearance, proto.isTranslucent, false /* hasImeSurface */);
} catch (IOException e) {

View File

@ -23,7 +23,6 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import android.annotation.NonNull;
import android.annotation.TestApi;
import android.window.TaskSnapshot;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Process;
@ -31,6 +30,7 @@ import android.os.SystemClock;
import android.util.ArraySet;
import android.util.AtomicFile;
import android.util.Slog;
import android.window.TaskSnapshot;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@ -380,6 +380,10 @@ class TaskSnapshotPersister {
proto.insetTop = mSnapshot.getContentInsets().top;
proto.insetRight = mSnapshot.getContentInsets().right;
proto.insetBottom = mSnapshot.getContentInsets().bottom;
proto.letterboxInsetLeft = mSnapshot.getLetterboxInsets().left;
proto.letterboxInsetTop = mSnapshot.getLetterboxInsets().top;
proto.letterboxInsetRight = mSnapshot.getLetterboxInsets().right;
proto.letterboxInsetBottom = mSnapshot.getLetterboxInsets().bottom;
proto.isRealSnapshot = mSnapshot.isRealSnapshot();
proto.windowingMode = mSnapshot.getWindowingMode();
proto.appearance = mSnapshot.getAppearance();

View File

@ -1244,7 +1244,8 @@ public class RecentTasksTest extends WindowTestsBase {
}
return new TaskSnapshot(1, new ComponentName("", ""), buffer,
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
Surface.ROTATION_0, taskSize, new Rect() /* insets */, false /* isLowResolution */,
Surface.ROTATION_0, taskSize, new Rect() /* contentInsets */,
new Rect() /* letterboxInsets*/, false /* isLowResolution */,
true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN, 0 /* mSystemUiVisibility */,
false /* isTranslucent */, false /* hasImeSurface */);
}

View File

@ -144,7 +144,8 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
final int orientation = Configuration.ORIENTATION_PORTRAIT;
final float scaleFraction = 0.25f;
final Rect contentInsets = new Rect(1, 2, 3, 4);
final Point taskSize = new Point(5, 6);
final Rect letterboxInsets = new Rect(5, 6, 7, 8);
final Point taskSize = new Point(9, 10);
try {
TaskSnapshot.Builder builder =
@ -156,6 +157,7 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
builder.setColorSpace(sRGB);
builder.setOrientation(orientation);
builder.setContentInsets(contentInsets);
builder.setLetterboxInsets(letterboxInsets);
builder.setIsTranslucent(true);
builder.setSnapshot(buffer);
builder.setIsRealSnapshot(true);
@ -176,6 +178,7 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
assertFalse(snapshot.isLowResolution());
assertEquals(orientation, snapshot.getOrientation());
assertEquals(contentInsets, snapshot.getContentInsets());
assertEquals(letterboxInsets, snapshot.getLetterboxInsets());
assertTrue(snapshot.isTranslucent());
assertSame(buffer, snapshot.getHardwareBuffer());
assertTrue(snapshot.isRealSnapshot());

View File

@ -59,7 +59,8 @@ import java.util.function.Predicate;
*/
class TaskSnapshotPersisterTestBase extends WindowTestsBase {
private static final Rect TEST_INSETS = new Rect(10, 20, 30, 40);
private static final Rect TEST_CONTENT_INSETS = new Rect(10, 20, 30, 40);
private static final Rect TEST_LETTERBOX_INSETS = new Rect();
static final File FILES_DIR = getInstrumentation().getTargetContext().getFilesDir();
static final long MOCK_SNAPSHOT_ID = 12345678;
@ -208,7 +209,7 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
return new TaskSnapshot(MOCK_SNAPSHOT_ID, mTopActivityComponent,
HardwareBuffer.createFromGraphicBuffer(buffer),
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
mRotation, taskSize, TEST_INSETS,
mRotation, taskSize, TEST_CONTENT_INSETS, TEST_LETTERBOX_INSETS,
// When building a TaskSnapshot with the Builder class, isLowResolution
// is always false. Low-res snapshots are only created when loading from
// disk.