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

Commit 552e7363 authored by Tiger Huang's avatar Tiger Huang
Browse files

Send up-to-date InsetsState to the client after rotation

When LOCAL_LAYOUT is enabled, clients compute the window frames on their
own. However, for windows which provide insets, the server computes the
window frames for updating the InsetsState. In this way, all the clients
can receive the up-to-date InsetsState after rotation before the clients
of insets source windows report their frames.

Before LOCAL_LAYOUT is enabled, the server would layout all the windows
after rotation. So the clients receive the up-to-date InsetsStates as
well. The logic remains the same in this CL.

Bug: 161810301
Bug: 175861127
Test: Perform fixed rotation, seamless rotation, and regular rotation.
      See if there is anything unexpected.
Change-Id: I23246f363d5d9ef974a4f7a64041bc9d56042ade
parent 923eb82c
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import static android.view.Surface.ROTATION_0;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static android.view.View.GONE;
import static android.view.ViewRootImpl.LOCAL_LAYOUT;
import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.systemBars;
@@ -2647,29 +2648,27 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mCurrentPrivacyIndicatorBounds =
                mCurrentPrivacyIndicatorBounds.updateStaticBounds(staticBounds);
        if (!Objects.equals(oldBounds, mCurrentPrivacyIndicatorBounds)) {
            final DisplayInfo info = mDisplayInfo;
            if (mDisplayFrames.onDisplayInfoUpdated(info,
                    calculateDisplayCutoutForRotation(info.rotation),
                    calculateRoundedCornersForRotation(info.rotation),
                    calculatePrivacyIndicatorBoundsForRotation(info.rotation))) {
                mInsetsStateController.onDisplayInfoUpdated(true);
            }
            updateDisplayFrames(false /* insetsSourceMayChange */, true /* notifyInsetsChange */);
        }
    }

    void onDisplayInfoChanged() {
        final DisplayInfo info = mDisplayInfo;
        if (mDisplayFrames.onDisplayInfoUpdated(info,
                calculateDisplayCutoutForRotation(info.rotation),
                calculateRoundedCornersForRotation(info.rotation),
                calculatePrivacyIndicatorBoundsForRotation(info.rotation))) {
            // TODO(b/161810301): Set notifyInsetsChange to true while the server no longer performs
            //                    layout.
            mInsetsStateController.onDisplayInfoUpdated(false /* notifyInsetsChanged */);
        }
        updateDisplayFrames(LOCAL_LAYOUT, LOCAL_LAYOUT);
        mMinSizeOfResizeableTaskDp = getMinimalTaskSizeDp();
        mInputMonitor.layoutInputConsumers(info.logicalWidth, info.logicalHeight);
        mDisplayPolicy.onDisplayInfoChanged(info);
        mInputMonitor.layoutInputConsumers(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
        mDisplayPolicy.onDisplayInfoChanged(mDisplayInfo);
    }

    private void updateDisplayFrames(boolean insetsSourceMayChange, boolean notifyInsetsChange) {
        if (mDisplayFrames.update(mDisplayInfo,
                calculateDisplayCutoutForRotation(mDisplayInfo.rotation),
                calculateRoundedCornersForRotation(mDisplayInfo.rotation),
                calculatePrivacyIndicatorBoundsForRotation(mDisplayInfo.rotation))) {
            if (insetsSourceMayChange) {
                mDisplayPolicy.updateInsetsSourceFramesExceptIme(mDisplayFrames);
            }
            mInsetsStateController.onDisplayFramesUpdated(notifyInsetsChange);
        }
    }

    @Override
+7 −6
Original line number Diff line number Diff line
@@ -64,26 +64,26 @@ public class DisplayFrames {
            PrivacyIndicatorBounds indicatorBounds) {
        mDisplayId = displayId;
        mInsetsState = insetsState;
        onDisplayInfoUpdated(info, displayCutout, roundedCorners, indicatorBounds);
        update(info, displayCutout, roundedCorners, indicatorBounds);
    }

    /**
     * Update {@link DisplayFrames} when {@link DisplayInfo} is updated.
     * This is called when {@link DisplayInfo} or {@link PrivacyIndicatorBounds} is updated.
     *
     * @param info the updated {@link DisplayInfo}.
     * @param displayCutout the updated {@link DisplayCutout}.
     * @param roundedCorners the updated {@link RoundedCorners}.
     * @return {@code true} if the insets state has been changed; {@code false} otherwise.
     * @param indicatorBounds the updated {@link PrivacyIndicatorBounds}.
     * @return {@code true} if anything has been changed; {@code false} otherwise.
     */
    public boolean onDisplayInfoUpdated(DisplayInfo info, @NonNull WmDisplayCutout displayCutout,
    public boolean update(DisplayInfo info, @NonNull WmDisplayCutout displayCutout,
            @NonNull RoundedCorners roundedCorners,
            @NonNull PrivacyIndicatorBounds indicatorBounds) {
        mRotation = info.rotation;

        final InsetsState state = mInsetsState;
        final Rect safe = mDisplayCutoutSafe;
        final DisplayCutout cutout = displayCutout.getDisplayCutout();
        if (mDisplayWidth == info.logicalWidth && mDisplayHeight == info.logicalHeight
                && mRotation != info.rotation
                && state.getDisplayCutout().equals(cutout)
                && state.getRoundedCorners().equals(roundedCorners)
                && state.getPrivacyIndicatorBounds().equals(indicatorBounds)) {
@@ -91,6 +91,7 @@ public class DisplayFrames {
        }
        mDisplayWidth = info.logicalWidth;
        mDisplayHeight = info.logicalHeight;
        mRotation = info.rotation;
        final Rect unrestricted = mUnrestricted;
        unrestricted.set(0, 0, mDisplayWidth, mDisplayHeight);
        state.setDisplayFrame(unrestricted);
+0 −4
Original line number Diff line number Diff line
@@ -1498,10 +1498,6 @@ public class DisplayPolicy {
        }
    }

    // TODO(b/161810301): No one is calling this since we haven't moved window layout to the client.
    //                    When that happens, this should be called when the display rotation is
    //                    changed, so that we can dispatch the correct insets to all the clients
    //                    before the insets source windows report their frames to the server.
    void updateInsetsSourceFramesExceptIme(DisplayFrames displayFrames) {
        for (int i = mInsetsSourceWindowsExceptIme.size() - 1; i >= 0; i--) {
            final WindowState win = mInsetsSourceWindowsExceptIme.valueAt(i);
+1 −1
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ class InsetsStateController {
        }
    }

    void onDisplayInfoUpdated(boolean notifyInsetsChange) {
    void onDisplayFramesUpdated(boolean notifyInsetsChange) {
        final ArrayList<WindowState> insetsChangedWindows = new ArrayList<>();
        mDisplayContent.forAllWindows(w -> {
            w.mAboveInsetsState.set(mState, displayCutout());