Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c44c692 authored by Daniel Norman's avatar Daniel Norman
Browse files

Adds back using WindowState for magnification letterbox bounds.

This is a partial revert of
commit 35280c1d.
Magnification bounds still use WindowStates for its window iteration
instead of InputWindowHandles, so that change shouldn't have fully
removed WindowState letterbox bounds handling yet.

This change also includes a fix for the bounds calculation: the previous
logic assumed that the letterbox insets were negative instead of
positive. This new version reverses that assumption.

Example bounds for an app in landscape mode, letterboxed to the center
of the screen:
      app bounds       = Rect(663, 0 - 1677, 1080)
      letterbox bounds = SkRegion((0,0,663,1080)(1677,0,2340,1080))

Bug: 248059823
Test: use magnification on a letterboxed app
Test: log app & letterbox bounds, ensure they match expected values
Change-Id: Ic77474c416d0e7097428ea0303302958701e8387
parent bdf75500
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.content.pm.PackageManagerInternal;
import android.graphics.BLASTBufferQueue;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
@@ -965,6 +966,13 @@ final class AccessibilityController {
                        availableBounds.op(navBarInsets, Region.Op.DIFFERENCE);
                    }

                    // Count letterbox into nonMagnifiedBounds
                    if (windowState.areAppWindowBoundsLetterboxed()) {
                        Region letterboxBounds = getLetterboxBounds(windowState);
                        nonMagnifiedBounds.op(letterboxBounds, Region.Op.UNION);
                        availableBounds.op(letterboxBounds, Region.Op.DIFFERENCE);
                    }

                    // Update accounted bounds
                    Region accountedBounds = mTempRegion2;
                    accountedBounds.set(mMagnificationRegion);
@@ -1014,6 +1022,27 @@ final class AccessibilityController {
                }
            }

            private Region getLetterboxBounds(WindowState windowState) {
                final ActivityRecord appToken = windowState.mActivityRecord;
                if (appToken == null) {
                    return new Region();
                }

                final Rect boundsWithoutLetterbox = windowState.getBounds();
                final Rect letterboxInsets = appToken.getLetterboxInsets();

                final Rect boundsIncludingLetterbox = Rect.copyOrNull(boundsWithoutLetterbox);
                // Letterbox insets from mActivityRecord are positive, so we negate them to grow the
                // bounds to include the letterbox.
                boundsIncludingLetterbox.inset(
                        Insets.subtract(Insets.NONE, Insets.of(letterboxInsets)));

                final Region letterboxBounds = new Region();
                letterboxBounds.set(boundsIncludingLetterbox);
                letterboxBounds.op(boundsWithoutLetterbox, Region.Op.DIFFERENCE);
                return letterboxBounds;
            }

            private boolean isExcludedWindowType(int windowType) {
                return windowType == TYPE_MAGNIFICATION_OVERLAY
                        // Omit the touch region of window magnification to avoid the cut out of the