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

Commit ead6d20c authored by Tiger Huang's avatar Tiger Huang
Browse files

Let setFrames can take frames passed from the client

This is a step to move the window layout to the client.

If the frames passed to WindowState#setFrames are from the client, we
need to apply mGlobalScale to them; if the frames are from the server,
we only need to apply mInvGlobalScale to mCompatFrame.

This CL also

- moves logic from mPerformLayout to setFrames, such as updateLastFrames
  and layoutLetterbox, because we won't need mPerformLayout when
  LOCAL_LAYOUT is enabled.

- removes a redundant performLayout from getNavBarPosition, because we
  don't update mNavigationBarPosition in performLayout now.

Bug: 161810301
Test: ApiDemos > App > Activity > Max Aspect Ratio > 1:1, verify navbar
      is visible
Change-Id: I0d892b4773d950c4f1f85503c43742f5990f6117
parent 5b19a158
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -839,10 +839,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                w.onResizeHandled();
            }

            if (w.mActivityRecord != null) {
                w.mActivityRecord.layoutLetterbox(w);
            }

            if (DEBUG_LAYOUT) Slog.v(TAG, "  LAYOUT: mFrame=" + w.getFrame()
                    + " mParentFrame=" + w.getParentFrame()
                    + " mDisplayFrame=" + w.getDisplayFrame());
+1 −1
Original line number Diff line number Diff line
@@ -1552,7 +1552,7 @@ public class DisplayPolicy {
                win.getRequestedVisibilities(), attachedWindowFrame, win.mGlobalScale,
                sTmpClientFrames);

        win.setFrames(sTmpClientFrames);
        win.setFrames(sTmpClientFrames, win.mRequestedWidth, win.mRequestedHeight);
    }

    WindowState getTopFullscreenOpaqueWindow() {
+11 −3
Original line number Diff line number Diff line
@@ -2640,8 +2640,18 @@ public class WindowManagerService extends IWindowManager.Stub

    void updateWindowLayout(Session session, IWindow client, LayoutParams attrs, int flags,
            ClientWindowFrames clientWindowFrames, int requestedWidth, int requestedHeight) {
        final long origId = Binder.clearCallingIdentity();
        synchronized (mGlobalLock) {
            final WindowState win = windowForClientLocked(session, client, false);
            if (win == null) {
                return;
            }
            win.setFrames(clientWindowFrames, requestedWidth, requestedHeight);

            // TODO(b/161810301): Finish the implementation.
        }
        Binder.restoreCallingIdentity(origId);
    }

    public boolean outOfMemoryWindow(Session session, IWindow client) {
        final long origId = Binder.clearCallingIdentity();
@@ -6304,8 +6314,6 @@ public class WindowManagerService extends IWindowManager.Stub
                        + " callers=" + Debug.getCallers(3));
                return NAV_BAR_INVALID;
            }
            displayContent.performLayout(false /* initial */,
                    false /* updateInputWindows */);
            return displayContent.getDisplayPolicy().getNavBarPosition();
        }
    }
+47 −21
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static android.view.InsetsState.ITYPE_INVALID;
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
import static android.view.SurfaceControl.Transaction;
import static android.view.SurfaceControl.getGlobalTransaction;
import static android.view.ViewRootImpl.LOCAL_LAYOUT;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
@@ -1399,31 +1400,36 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return mActivityRecord != null && mActivityRecord.mWaitForEnteringPinnedMode;
    }

    // TODO(b/161810301): Make the frame be passed from the client side.
    void setFrames(ClientWindowFrames clientWindowFrames) {
        mHaveFrame = true;

    void setFrames(ClientWindowFrames clientWindowFrames, int requestedWidth, int requestedHeight) {
        final WindowFrames windowFrames = mWindowFrames;
        mTmpRect.set(windowFrames.mParentFrame);

        if (LOCAL_LAYOUT) {
            windowFrames.mCompatFrame.set(clientWindowFrames.frame);

            windowFrames.mFrame.set(clientWindowFrames.frame);
            windowFrames.mDisplayFrame.set(clientWindowFrames.displayFrame);
            windowFrames.mParentFrame.set(clientWindowFrames.parentFrame);
        windowFrames.mFrame.set(clientWindowFrames.frame);
        windowFrames.setParentFrameWasClippedByDisplayCutout(
                clientWindowFrames.isParentFrameClippedByDisplayCutout);

        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight
                || !mTmpRect.equals(windowFrames.mParentFrame)) {
            mLastRequestedWidth = mRequestedWidth;
            mLastRequestedHeight = mRequestedHeight;
            windowFrames.setContentChanged(true);
            if (hasCompatScale()) {
                // The frames sent from the client need to be adjusted to the real coordinate space.
                windowFrames.mFrame.scale(mGlobalScale);
                windowFrames.mDisplayFrame.scale(mGlobalScale);
                windowFrames.mParentFrame.scale(mGlobalScale);
            }
        } else {
            windowFrames.mDisplayFrame.set(clientWindowFrames.displayFrame);
            windowFrames.mParentFrame.set(clientWindowFrames.parentFrame);
            windowFrames.mFrame.set(clientWindowFrames.frame);

            windowFrames.mCompatFrame.set(windowFrames.mFrame);
            if (hasCompatScale()) {
            // Also the scaled frame that we report to the app needs to be
            // adjusted to be in its coordinate space.
                // Also, the scaled frame that we report to the app needs to be adjusted to be in
                // its coordinate space.
                windowFrames.mCompatFrame.scale(mInvGlobalScale);
            }
        }
        windowFrames.setParentFrameWasClippedByDisplayCutout(
                clientWindowFrames.isParentFrameClippedByDisplayCutout);

        // Calculate relative frame
        windowFrames.mRelFrame.set(windowFrames.mFrame);
@@ -1441,6 +1447,13 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        windowFrames.mRelFrame.offsetTo(windowFrames.mFrame.left - parentLeft,
                windowFrames.mFrame.top - parentTop);

        if (requestedWidth != mLastRequestedWidth || requestedHeight != mLastRequestedHeight
                || !mTmpRect.equals(windowFrames.mParentFrame)) {
            mLastRequestedWidth = requestedWidth;
            mLastRequestedHeight = requestedHeight;
            windowFrames.setContentChanged(true);
        }

        if (mAttrs.type == TYPE_DOCK_DIVIDER) {
            if (!windowFrames.mFrame.equals(windowFrames.mLastFrame)) {
                mMovedByResize = true;
@@ -1456,6 +1469,19 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }

        updateSourceFrame(windowFrames.mFrame);

        if (LOCAL_LAYOUT) {
            if (!mHaveFrame) {
                // The first frame should not be considered as moved.
                updateLastFrames();
            }
        }

        if (mActivityRecord != null && !mIsChildWindow) {
            mActivityRecord.layoutLetterbox(this);
        }
        mSurfacePlacementNeeded = true;
        mHaveFrame = true;
    }

    void updateSourceFrame(Rect winFrame) {