Merge "Try crop letterbox prior than content insets" into udc-dev am: 8edd2ab2e6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23382776 Change-Id: I3df861632d3071c63ebad31d233091301465a5fb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -43,6 +43,7 @@ import static com.android.internal.policy.DecorView.NAVIGATION_BAR_COLOR_VIEW_AT
|
|||||||
import static com.android.internal.policy.DecorView.STATUS_BAR_COLOR_VIEW_ATTRIBUTES;
|
import static com.android.internal.policy.DecorView.STATUS_BAR_COLOR_VIEW_ATTRIBUTES;
|
||||||
import static com.android.internal.policy.DecorView.getNavigationBarRect;
|
import static com.android.internal.policy.DecorView.getNavigationBarRect;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityThread;
|
import android.app.ActivityThread;
|
||||||
@@ -183,7 +184,7 @@ public class SnapshotDrawerUtils {
|
|||||||
|
|
||||||
// We consider nearly matched dimensions as there can be rounding errors and the user
|
// We consider nearly matched dimensions as there can be rounding errors and the user
|
||||||
// won't notice very minute differences from scaling one dimension more than the other
|
// won't notice very minute differences from scaling one dimension more than the other
|
||||||
final boolean aspectRatioMismatch = !isAspectRatioMatch(mFrame, mSnapshot);
|
boolean aspectRatioMismatch = !isAspectRatioMatch(mFrame, mSnapshot);
|
||||||
|
|
||||||
// Keep a reference to it such that it doesn't get destroyed when finalized.
|
// Keep a reference to it such that it doesn't get destroyed when finalized.
|
||||||
SurfaceControl childSurfaceControl = new SurfaceControl.Builder(session)
|
SurfaceControl childSurfaceControl = new SurfaceControl.Builder(session)
|
||||||
@@ -199,8 +200,20 @@ public class SnapshotDrawerUtils {
|
|||||||
// still hidden.
|
// still hidden.
|
||||||
mTransaction.show(childSurfaceControl);
|
mTransaction.show(childSurfaceControl);
|
||||||
if (aspectRatioMismatch) {
|
if (aspectRatioMismatch) {
|
||||||
// Clip off ugly navigation bar.
|
Rect crop = null;
|
||||||
final Rect crop = calculateSnapshotCrop();
|
final Rect letterboxInsets = mSnapshot.getLetterboxInsets();
|
||||||
|
if (letterboxInsets.left != 0 || letterboxInsets.top != 0
|
||||||
|
|| letterboxInsets.right != 0 || letterboxInsets.bottom != 0) {
|
||||||
|
// Clip off letterbox.
|
||||||
|
crop = calculateSnapshotCrop(letterboxInsets);
|
||||||
|
// If the snapshot can cover the frame, then no need to draw background.
|
||||||
|
aspectRatioMismatch = !isAspectRatioMatch(mFrame, crop);
|
||||||
|
}
|
||||||
|
// if letterbox doesn't match window frame, try crop by content insets
|
||||||
|
if (aspectRatioMismatch) {
|
||||||
|
// Clip off ugly navigation bar.
|
||||||
|
crop = calculateSnapshotCrop(mSnapshot.getContentInsets());
|
||||||
|
}
|
||||||
frame = calculateSnapshotFrame(crop);
|
frame = calculateSnapshotFrame(crop);
|
||||||
mTransaction.setWindowCrop(childSurfaceControl, crop);
|
mTransaction.setWindowCrop(childSurfaceControl, crop);
|
||||||
mTransaction.setPosition(childSurfaceControl, frame.left, frame.top);
|
mTransaction.setPosition(childSurfaceControl, frame.left, frame.top);
|
||||||
@@ -242,14 +255,13 @@ public class SnapshotDrawerUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the snapshot crop in snapshot coordinate space.
|
* Calculates the snapshot crop in snapshot coordinate space.
|
||||||
*
|
* @param insets Content insets or Letterbox insets
|
||||||
* @return crop rect in snapshot coordinate space.
|
* @return crop rect in snapshot coordinate space.
|
||||||
*/
|
*/
|
||||||
Rect calculateSnapshotCrop() {
|
Rect calculateSnapshotCrop(@NonNull Rect insets) {
|
||||||
final Rect rect = new Rect();
|
final Rect rect = new Rect();
|
||||||
final HardwareBuffer snapshot = mSnapshot.getHardwareBuffer();
|
final HardwareBuffer snapshot = mSnapshot.getHardwareBuffer();
|
||||||
rect.set(0, 0, snapshot.getWidth(), snapshot.getHeight());
|
rect.set(0, 0, snapshot.getWidth(), snapshot.getHeight());
|
||||||
final Rect insets = mSnapshot.getContentInsets();
|
|
||||||
|
|
||||||
final float scaleX = (float) snapshot.getWidth() / mSnapshot.getTaskSize().x;
|
final float scaleX = (float) snapshot.getWidth() / mSnapshot.getTaskSize().x;
|
||||||
final float scaleY = (float) snapshot.getHeight() / mSnapshot.getTaskSize().y;
|
final float scaleY = (float) snapshot.getHeight() / mSnapshot.getTaskSize().y;
|
||||||
@@ -334,6 +346,15 @@ public class SnapshotDrawerUtils {
|
|||||||
- ((float) frame.width() / frame.height())) <= 0.01f;
|
- ((float) frame.width() / frame.height())) <= 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAspectRatioMatch(Rect frame1, Rect frame2) {
|
||||||
|
if (frame1.isEmpty() || frame2.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Math.abs(
|
||||||
|
((float) frame2.width() / frame2.height())
|
||||||
|
- ((float) frame1.width() / frame1.height())) <= 0.01f;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get or create a TaskDescription from a RunningTaskInfo.
|
* Get or create a TaskDescription from a RunningTaskInfo.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -158,32 +158,42 @@ public class SnapshotDrawerUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateSnapshotCrop() {
|
public void testCalculateSnapshotCrop() {
|
||||||
setupSurface(100, 100, new Rect(0, 10, 0, 10), 0, new Rect(0, 0, 100, 100));
|
final Rect contentInsets = new Rect(0, 10, 0, 10);
|
||||||
assertEquals(new Rect(0, 0, 100, 90), mSnapshotSurface.calculateSnapshotCrop());
|
setupSurface(100, 100, contentInsets, 0, new Rect(0, 0, 100, 100));
|
||||||
|
assertEquals(new Rect(0, 0, 100, 90),
|
||||||
|
mSnapshotSurface.calculateSnapshotCrop(contentInsets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateSnapshotCrop_taskNotOnTop() {
|
public void testCalculateSnapshotCrop_taskNotOnTop() {
|
||||||
setupSurface(100, 100, new Rect(0, 10, 0, 10), 0, new Rect(0, 50, 100, 150));
|
final Rect contentInsets = new Rect(0, 10, 0, 10);
|
||||||
assertEquals(new Rect(0, 10, 100, 90), mSnapshotSurface.calculateSnapshotCrop());
|
setupSurface(100, 100, contentInsets, 0, new Rect(0, 50, 100, 150));
|
||||||
|
assertEquals(new Rect(0, 10, 100, 90),
|
||||||
|
mSnapshotSurface.calculateSnapshotCrop(contentInsets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateSnapshotCrop_navBarLeft() {
|
public void testCalculateSnapshotCrop_navBarLeft() {
|
||||||
setupSurface(100, 100, new Rect(10, 10, 0, 0), 0, new Rect(0, 0, 100, 100));
|
final Rect contentInsets = new Rect(0, 10, 0, 0);
|
||||||
assertEquals(new Rect(10, 0, 100, 100), mSnapshotSurface.calculateSnapshotCrop());
|
setupSurface(100, 100, contentInsets, 0, new Rect(0, 0, 100, 100));
|
||||||
|
assertEquals(new Rect(10, 0, 100, 100),
|
||||||
|
mSnapshotSurface.calculateSnapshotCrop(contentInsets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateSnapshotCrop_navBarRight() {
|
public void testCalculateSnapshotCrop_navBarRight() {
|
||||||
setupSurface(100, 100, new Rect(0, 10, 10, 0), 0, new Rect(0, 0, 100, 100));
|
final Rect contentInsets = new Rect(0, 10, 10, 0);
|
||||||
assertEquals(new Rect(0, 0, 90, 100), mSnapshotSurface.calculateSnapshotCrop());
|
setupSurface(100, 100, contentInsets, 0, new Rect(0, 0, 100, 100));
|
||||||
|
assertEquals(new Rect(0, 0, 90, 100),
|
||||||
|
mSnapshotSurface.calculateSnapshotCrop(contentInsets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateSnapshotCrop_waterfall() {
|
public void testCalculateSnapshotCrop_waterfall() {
|
||||||
setupSurface(100, 100, new Rect(5, 10, 5, 10), 0, new Rect(0, 0, 100, 100));
|
final Rect contentInsets = new Rect(5, 10, 5, 10);
|
||||||
assertEquals(new Rect(5, 0, 95, 90), mSnapshotSurface.calculateSnapshotCrop());
|
setupSurface(100, 100, contentInsets, 0, new Rect(0, 0, 100, 100));
|
||||||
|
assertEquals(new Rect(5, 0, 95, 90),
|
||||||
|
mSnapshotSurface.calculateSnapshotCrop(contentInsets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user