OSDN Git Service

Fix cutout with temp inset bounds
authorJorim Jaggi <jjaggi@google.com>
Wed, 18 Apr 2018 15:27:27 +0000 (17:27 +0200)
committerJorim Jaggi <jjaggi@google.com>
Thu, 19 Apr 2018 14:36:10 +0000 (16:36 +0200)
Cutout needs to be calculated before shifting back, otherwise it
will end up at the wrong position.

Test: WindowFrameTests
Test: Resize with cutout, less jank
Bug: 78214347
Change-Id: I4eebd61aff9c13b2b53d0ed1afa7e4159eb29b29

services/core/java/com/android/server/wm/WindowState.java
services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java

index 61ce062..6af730f 100644 (file)
@@ -1088,6 +1088,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                             :  Math.max(mFrame.bottom - mStableFrame.bottom, 0));
         }
 
+        mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
+
         // Offset the actual frame by the amount layout frame is off.
         mFrame.offset(-layoutXDiff, -layoutYDiff);
         mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
@@ -1095,10 +1097,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
         mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
         mStableFrame.offset(-layoutXDiff, -layoutYDiff);
 
-        // TODO(roosa): Figure out what frame exactly this needs to be calculated with.
-        mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
-
-
         mCompatFrame.set(mFrame);
         if (mEnforceSizeCompat) {
             // If there is a size compatibility scale being applied to the
index 4638635..5a56332 100644 (file)
@@ -441,6 +441,28 @@ public class WindowFrameTests extends WindowTestsBase {
         assertEquals(w.mDisplayCutout.getDisplayCutout().getSafeInsetRight(), 0);
     }
 
+    @Test
+    public void testDisplayCutout_tempInsetBounds() {
+        // Regular fullscreen task and window
+        TaskWithBounds task = new TaskWithBounds(new Rect(0, -500, 1000, 1500));
+        task.mFullscreenForTest = false;
+        task.mInsetBounds.set(0, 0, 1000, 2000);
+        WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT);
+        w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
+
+        final Rect pf = new Rect(0, -500, 1000, 1500);
+        // Create a display cutout of size 50x50, aligned top-center
+        final WmDisplayCutout cutout = WmDisplayCutout.computeSafeInsets(
+                fromBoundingRect(500, 0, 550, 50), pf.width(), pf.height());
+
+        w.computeFrameLw(pf, pf, pf, pf, pf, pf, pf, pf, cutout, false);
+
+        assertEquals(w.mDisplayCutout.getDisplayCutout().getSafeInsetTop(), 50);
+        assertEquals(w.mDisplayCutout.getDisplayCutout().getSafeInsetBottom(), 0);
+        assertEquals(w.mDisplayCutout.getDisplayCutout().getSafeInsetLeft(), 0);
+        assertEquals(w.mDisplayCutout.getDisplayCutout().getSafeInsetRight(), 0);
+    }
+
     private WindowStateWithTask createWindow(Task task, int width, int height) {
         final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(TYPE_APPLICATION);
         attrs.width = width;