Merge "Only use simple rects for cutout region" into pi-dev
am: 4764921dcc
Change-Id: Icfb41008189d5c01f90afd4992428433043b4c4e
This commit is contained in:
@@ -29,6 +29,7 @@ import android.graphics.Path;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.Region;
|
import android.graphics.Region;
|
||||||
|
import android.graphics.Region.Op;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -325,14 +326,9 @@ public final class DisplayCutout {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static DisplayCutout fromBoundingRect(int left, int top, int right, int bottom) {
|
public static DisplayCutout fromBoundingRect(int left, int top, int right, int bottom) {
|
||||||
Path path = new Path();
|
Region r = Region.obtain();
|
||||||
path.reset();
|
r.set(left, top, right, bottom);
|
||||||
path.moveTo(left, top);
|
return fromBounds(r);
|
||||||
path.lineTo(left, bottom);
|
|
||||||
path.lineTo(right, bottom);
|
|
||||||
path.lineTo(right, top);
|
|
||||||
path.close();
|
|
||||||
return fromBounds(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -340,26 +336,19 @@ public final class DisplayCutout {
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static DisplayCutout fromBounds(Path path) {
|
public static DisplayCutout fromBounds(Region region) {
|
||||||
RectF clipRect = new RectF();
|
return new DisplayCutout(ZERO_RECT, region, false /* copyArguments */);
|
||||||
path.computeBounds(clipRect, false /* unused */);
|
|
||||||
Region clipRegion = Region.obtain();
|
|
||||||
clipRegion.set((int) clipRect.left, (int) clipRect.top,
|
|
||||||
(int) clipRect.right, (int) clipRect.bottom);
|
|
||||||
|
|
||||||
Region bounds = new Region();
|
|
||||||
bounds.setPath(path, clipRegion);
|
|
||||||
clipRegion.recycle();
|
|
||||||
return new DisplayCutout(ZERO_RECT, bounds, false /* copyArguments */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the bounding path according to @android:string/config_mainBuiltInDisplayCutout.
|
* Creates the display cutout according to
|
||||||
|
* @android:string/config_mainBuiltInDisplayCutoutRectApproximation, which is the closest
|
||||||
|
* rectangle-base approximation of the cutout.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static DisplayCutout fromResources(Resources res, int displayWidth, int displayHeight) {
|
public static DisplayCutout fromResourcesRectApproximation(Resources res, int displayWidth, int displayHeight) {
|
||||||
return fromSpec(res.getString(R.string.config_mainBuiltInDisplayCutout),
|
return fromSpec(res.getString(R.string.config_mainBuiltInDisplayCutoutRectApproximation),
|
||||||
displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT);
|
displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +358,8 @@ public final class DisplayCutout {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static Path pathFromResources(Resources res, int displayWidth, int displayHeight) {
|
public static Path pathFromResources(Resources res, int displayWidth, int displayHeight) {
|
||||||
return pathAndDisplayCutoutFromSpec(res.getString(R.string.config_mainBuiltInDisplayCutout),
|
return pathAndDisplayCutoutFromSpec(
|
||||||
|
res.getString(R.string.config_mainBuiltInDisplayCutout),
|
||||||
displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT).first;
|
displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +407,7 @@ public final class DisplayCutout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Path p;
|
final Path p;
|
||||||
|
final Region r = Region.obtain();
|
||||||
try {
|
try {
|
||||||
p = PathParser.createPathFromPathData(spec);
|
p = PathParser.createPathFromPathData(spec);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -431,6 +422,8 @@ public final class DisplayCutout {
|
|||||||
m.postTranslate(offsetX, 0);
|
m.postTranslate(offsetX, 0);
|
||||||
p.transform(m);
|
p.transform(m);
|
||||||
|
|
||||||
|
addToRegion(p, r);
|
||||||
|
|
||||||
if (bottomSpec != null) {
|
if (bottomSpec != null) {
|
||||||
final Path bottomPath;
|
final Path bottomPath;
|
||||||
try {
|
try {
|
||||||
@@ -443,9 +436,10 @@ public final class DisplayCutout {
|
|||||||
m.postTranslate(0, displayHeight);
|
m.postTranslate(0, displayHeight);
|
||||||
bottomPath.transform(m);
|
bottomPath.transform(m);
|
||||||
p.addPath(bottomPath);
|
p.addPath(bottomPath);
|
||||||
|
addToRegion(bottomPath, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pair<Path, DisplayCutout> result = new Pair<>(p, fromBounds(p));
|
final Pair<Path, DisplayCutout> result = new Pair<>(p, fromBounds(r));
|
||||||
synchronized (CACHE_LOCK) {
|
synchronized (CACHE_LOCK) {
|
||||||
sCachedSpec = spec;
|
sCachedSpec = spec;
|
||||||
sCachedDisplayWidth = displayWidth;
|
sCachedDisplayWidth = displayWidth;
|
||||||
@@ -456,6 +450,14 @@ public final class DisplayCutout {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addToRegion(Path p, Region r) {
|
||||||
|
final RectF rectF = new RectF();
|
||||||
|
final Rect rect = new Rect();
|
||||||
|
p.computeBounds(rectF, false /* unused */);
|
||||||
|
rectF.round(rect);
|
||||||
|
r.op(rect, Op.UNION);
|
||||||
|
}
|
||||||
|
|
||||||
private static Region boundingRectsToRegion(List<Rect> rects) {
|
private static Region boundingRectsToRegion(List<Rect> rects) {
|
||||||
Region result = Region.obtain();
|
Region result = Region.obtain();
|
||||||
if (rects != null) {
|
if (rects != null) {
|
||||||
|
|||||||
@@ -2961,6 +2961,14 @@
|
|||||||
-->
|
-->
|
||||||
<string translatable="false" name="config_mainBuiltInDisplayCutout"></string>
|
<string translatable="false" name="config_mainBuiltInDisplayCutout"></string>
|
||||||
|
|
||||||
|
<!-- Like config_mainBuiltInDisplayCutout, but this path is used to report the
|
||||||
|
one single bounding rect per device edge to the app via
|
||||||
|
{@link DisplayCutout#getBoundingRect}. Note that this path should try to match the visual
|
||||||
|
appearance of the cutout as much as possible, and may be smaller than
|
||||||
|
config_mainBuiltInDisplayCutout
|
||||||
|
-->
|
||||||
|
<string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@string/config_mainBuiltInDisplayCutout</string>
|
||||||
|
|
||||||
<!-- Whether the display cutout region of the main built-in display should be forced to
|
<!-- Whether the display cutout region of the main built-in display should be forced to
|
||||||
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -3338,6 +3338,7 @@
|
|||||||
|
|
||||||
<java-symbol type="string" name="global_action_logout" />
|
<java-symbol type="string" name="global_action_logout" />
|
||||||
<java-symbol type="string" name="config_mainBuiltInDisplayCutout" />
|
<java-symbol type="string" name="config_mainBuiltInDisplayCutout" />
|
||||||
|
<java-symbol type="string" name="config_mainBuiltInDisplayCutoutRectApproximation" />
|
||||||
<java-symbol type="drawable" name="messaging_user" />
|
<java-symbol type="drawable" name="messaging_user" />
|
||||||
<java-symbol type="bool" name="config_fillMainBuiltInDisplayCutout" />
|
<java-symbol type="bool" name="config_fillMainBuiltInDisplayCutout" />
|
||||||
<java-symbol type="drawable" name="ic_logout" />
|
<java-symbol type="drawable" name="ic_logout" />
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
@right
|
@right
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string>
|
||||||
|
|
||||||
<!-- Whether the display cutout region of the main built-in display should be forced to
|
<!-- Whether the display cutout region of the main built-in display should be forced to
|
||||||
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -49,6 +49,8 @@
|
|||||||
@dp
|
@dp
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string>
|
||||||
|
|
||||||
<!-- Whether the display cutout region of the main built-in display should be forced to
|
<!-- Whether the display cutout region of the main built-in display should be forced to
|
||||||
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
@dp
|
@dp
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string>
|
||||||
|
|
||||||
<!-- Whether the display cutout region of the main built-in display should be forced to
|
<!-- Whether the display cutout region of the main built-in display should be forced to
|
||||||
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
@dp
|
@dp
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string>
|
||||||
|
|
||||||
<!-- Whether the display cutout region of the main built-in display should be forced to
|
<!-- Whether the display cutout region of the main built-in display should be forced to
|
||||||
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
@dp
|
@dp
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string>
|
||||||
|
|
||||||
<!-- Whether the display cutout region of the main built-in display should be forced to
|
<!-- Whether the display cutout region of the main built-in display should be forced to
|
||||||
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import android.os.Looper;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.Trace;
|
import android.os.Trace;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.PathParser;
|
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
@@ -404,8 +402,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
|||||||
&& SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) {
|
&& SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) {
|
||||||
mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND;
|
mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND;
|
||||||
}
|
}
|
||||||
mInfo.displayCutout = DisplayCutout.fromResources(res, mInfo.width,
|
mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res,
|
||||||
mInfo.height);
|
mInfo.width, mInfo.height);
|
||||||
mInfo.type = Display.TYPE_BUILT_IN;
|
mInfo.type = Display.TYPE_BUILT_IN;
|
||||||
mInfo.densityDpi = (int)(phys.density * 160 + 0.5f);
|
mInfo.densityDpi = (int)(phys.density * 160 + 0.5f);
|
||||||
mInfo.xDpi = phys.xDpi;
|
mInfo.xDpi = phys.xDpi;
|
||||||
|
|||||||
@@ -1253,11 +1253,21 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
|
|||||||
cutout, mInitialDisplayWidth, mInitialDisplayHeight);
|
cutout, mInitialDisplayWidth, mInitialDisplayHeight);
|
||||||
}
|
}
|
||||||
final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
|
final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
|
||||||
final Path bounds = cutout.getBounds().getBoundaryPath();
|
final List<Rect> bounds = WmDisplayCutout.computeSafeInsets(
|
||||||
|
cutout, mInitialDisplayWidth, mInitialDisplayHeight)
|
||||||
|
.getDisplayCutout().getBoundingRects();
|
||||||
transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
|
transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
|
||||||
mTmpMatrix);
|
mTmpMatrix);
|
||||||
bounds.transform(mTmpMatrix);
|
final Region region = Region.obtain();
|
||||||
return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(bounds),
|
for (int i = 0; i < bounds.size(); i++) {
|
||||||
|
final Rect rect = bounds.get(i);
|
||||||
|
final RectF rectF = new RectF(bounds.get(i));
|
||||||
|
mTmpMatrix.mapRect(rectF);
|
||||||
|
rectF.round(rect);
|
||||||
|
region.op(rect, Op.UNION);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(region),
|
||||||
rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
|
rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
|
||||||
rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
|
rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import android.os.IBinder;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.Trace;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -620,6 +621,8 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
|
|||||||
|
|
||||||
private void updateInputWindows(boolean inDrag) {
|
private void updateInputWindows(boolean inDrag) {
|
||||||
|
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
|
||||||
|
|
||||||
// TODO: multi-display
|
// TODO: multi-display
|
||||||
navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION, DEFAULT_DISPLAY);
|
navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION, DEFAULT_DISPLAY);
|
||||||
pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP, DEFAULT_DISPLAY);
|
pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP, DEFAULT_DISPLAY);
|
||||||
@@ -645,6 +648,8 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
|
|||||||
mService.mInputManager.setInputWindows(mInputWindowHandles, mFocusedInputWindowHandle);
|
mService.mInputManager.setInputWindows(mInputWindowHandles, mFocusedInputWindowHandle);
|
||||||
|
|
||||||
clearInputWindowHandlesLw();
|
clearInputWindowHandlesLw();
|
||||||
|
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.graphics.Matrix;
|
|||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.RectF;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.InstrumentationRegistry;
|
||||||
@@ -172,15 +173,14 @@ public class PhoneWindowManagerTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static DisplayCutout displayCutoutForRotation(int rotation) {
|
private static DisplayCutout displayCutoutForRotation(int rotation) {
|
||||||
Path p = new Path();
|
RectF rectF = new RectF(DISPLAY_WIDTH / 4, 0, DISPLAY_WIDTH * 3 / 4, DISPLAY_CUTOUT_HEIGHT);
|
||||||
p.addRect(DISPLAY_WIDTH / 4, 0, DISPLAY_WIDTH * 3 / 4, DISPLAY_CUTOUT_HEIGHT,
|
|
||||||
Path.Direction.CCW);
|
|
||||||
|
|
||||||
Matrix m = new Matrix();
|
Matrix m = new Matrix();
|
||||||
transformPhysicalToLogicalCoordinates(rotation, DISPLAY_WIDTH, DISPLAY_HEIGHT, m);
|
transformPhysicalToLogicalCoordinates(rotation, DISPLAY_WIDTH, DISPLAY_HEIGHT, m);
|
||||||
p.transform(m);
|
m.mapRect(rectF);
|
||||||
|
|
||||||
return DisplayCutout.fromBounds(p);
|
return DisplayCutout.fromBoundingRect((int) rectF.left, (int) rectF.top,
|
||||||
|
(int) rectF.right, (int) rectF.bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestContextWrapper extends ContextWrapper {
|
static class TestContextWrapper extends ContextWrapper {
|
||||||
|
|||||||
Reference in New Issue
Block a user