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

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

Use ClientWindowFrames to collect frames computed by WindowLayout

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

ClientWindowFrames is used to carry window frames dispatched from the
server to the client for now. Later, the window frames will be computed
at the client side, and the frames will be sent to the server side via
ClientWindowFrames.

Bug: 161810301
Test: presubmit (no behavior change but only code refactors)
Change-Id: I83d8cfff2432e09759ef5b3d5f3b21731fc71bff
parent 54102c21
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -546,7 +546,6 @@ public final class ViewRootImpl implements ViewParent,


    private final Rect mVisRect = new Rect(); // used to retrieve visible rect of focused view.
    private final Rect mVisRect = new Rect(); // used to retrieve visible rect of focused view.
    private final Rect mTempRect = new Rect();
    private final Rect mTempRect = new Rect();
    private final Rect mTempRect2 = new Rect();


    private final WindowLayout mWindowLayout = new WindowLayout();
    private final WindowLayout mWindowLayout = new WindowLayout();


@@ -1198,8 +1197,7 @@ public final class ViewRootImpl implements ViewParent,
                        displayCutoutSafe, winConfig.getBounds(), winConfig.getWindowingMode(),
                        displayCutoutSafe, winConfig.getBounds(), winConfig.getWindowingMode(),
                        UNSPECIFIED_LENGTH, UNSPECIFIED_LENGTH,
                        UNSPECIFIED_LENGTH, UNSPECIFIED_LENGTH,
                        mInsetsController.getRequestedVisibilities(),
                        mInsetsController.getRequestedVisibilities(),
                        getAttachedWindowFrame(), 1f /* compactScale */,
                        getAttachedWindowFrame(), 1f /* compactScale */, mTmpFrames);
                        mTmpFrames.displayFrame, mTempRect2, mTmpFrames.frame);
                setFrame(mTmpFrames.frame);
                setFrame(mTmpFrames.frame);
                registerBackCallbackOnWindow();
                registerBackCallbackOnWindow();
                if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
                if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
+9 −10
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.Log;
import android.util.Log;
import android.window.ClientWindowFrames;


/**
/**
 * Computes window frames.
 * Computes window frames.
@@ -56,15 +57,17 @@ public class WindowLayout {
    private final Rect mTempDisplayCutoutSafeExceptMaybeBarsRect = new Rect();
    private final Rect mTempDisplayCutoutSafeExceptMaybeBarsRect = new Rect();
    private final Rect mTempRect = new Rect();
    private final Rect mTempRect = new Rect();


    public boolean computeFrames(WindowManager.LayoutParams attrs, InsetsState state,
    public void computeFrames(WindowManager.LayoutParams attrs, InsetsState state,
            Rect displayCutoutSafe, Rect windowBounds, @WindowingMode int windowingMode,
            Rect displayCutoutSafe, Rect windowBounds, @WindowingMode int windowingMode,
            int requestedWidth, int requestedHeight, InsetsVisibilities requestedVisibilities,
            int requestedWidth, int requestedHeight, InsetsVisibilities requestedVisibilities,
            Rect attachedWindowFrame, float compatScale, Rect outDisplayFrame, Rect outParentFrame,
            Rect attachedWindowFrame, float compatScale, ClientWindowFrames outFrames) {
            Rect outFrame) {
        final int type = attrs.type;
        final int type = attrs.type;
        final int fl = attrs.flags;
        final int fl = attrs.flags;
        final int pfl = attrs.privateFlags;
        final int pfl = attrs.privateFlags;
        final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) == FLAG_LAYOUT_IN_SCREEN;
        final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) == FLAG_LAYOUT_IN_SCREEN;
        final Rect outDisplayFrame = outFrames.displayFrame;
        final Rect outParentFrame = outFrames.parentFrame;
        final Rect outFrame = outFrames.frame;


        // Compute bounds restricted by insets
        // Compute bounds restricted by insets
        final Insets insets = state.calculateInsets(windowBounds, attrs.getFitInsetsTypes(),
        final Insets insets = state.calculateInsets(windowBounds, attrs.getFitInsetsTypes(),
@@ -95,7 +98,7 @@ public class WindowLayout {
        final DisplayCutout cutout = state.getDisplayCutout();
        final DisplayCutout cutout = state.getDisplayCutout();
        final Rect displayCutoutSafeExceptMaybeBars = mTempDisplayCutoutSafeExceptMaybeBarsRect;
        final Rect displayCutoutSafeExceptMaybeBars = mTempDisplayCutoutSafeExceptMaybeBarsRect;
        displayCutoutSafeExceptMaybeBars.set(displayCutoutSafe);
        displayCutoutSafeExceptMaybeBars.set(displayCutoutSafe);
        boolean clippedByDisplayCutout = false;
        outFrames.isParentFrameClippedByDisplayCutout = false;
        if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS && !cutout.isEmpty()) {
        if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS && !cutout.isEmpty()) {
            // Ensure that windows with a non-ALWAYS display cutout mode are laid out in
            // Ensure that windows with a non-ALWAYS display cutout mode are laid out in
            // the cutout safe zone.
            // the cutout safe zone.
@@ -158,7 +161,7 @@ public class WindowLayout {
            if (!attachedInParent && !floatingInScreenWindow) {
            if (!attachedInParent && !floatingInScreenWindow) {
                mTempRect.set(outParentFrame);
                mTempRect.set(outParentFrame);
                outParentFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
                outParentFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
                clippedByDisplayCutout = !mTempRect.equals(outParentFrame);
                outFrames.isParentFrameClippedByDisplayCutout = !mTempRect.equals(outParentFrame);
            }
            }
            outDisplayFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
            outDisplayFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
        }
        }
@@ -287,9 +290,7 @@ public class WindowLayout {
        }
        }


        if (DEBUG) Log.d(TAG, "computeWindowFrames " + attrs.getTitle()
        if (DEBUG) Log.d(TAG, "computeWindowFrames " + attrs.getTitle()
                + " outFrame=" + outFrame.toShortString()
                + " outFrames=" + outFrames
                + " outParentFrame=" + outParentFrame.toShortString()
                + " outDisplayFrame=" + outDisplayFrame.toShortString()
                + " windowBounds=" + windowBounds.toShortString()
                + " windowBounds=" + windowBounds.toShortString()
                + " attachedWindowFrame=" + (attachedWindowFrame != null
                + " attachedWindowFrame=" + (attachedWindowFrame != null
                        ? attachedWindowFrame.toShortString()
                        ? attachedWindowFrame.toShortString()
@@ -302,8 +303,6 @@ public class WindowLayout {
                + " attrs=" + attrs
                + " attrs=" + attrs
                + " state=" + state
                + " state=" + state
                + " requestedVisibilities=" + requestedVisibilities);
                + " requestedVisibilities=" + requestedVisibilities);

        return clippedByDisplayCutout;
    }
    }


    public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds,
    public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds,
+23 −13
Original line number Original line Diff line number Diff line
@@ -27,47 +27,55 @@ import android.os.Parcelable;
 */
 */
public class ClientWindowFrames implements Parcelable {
public class ClientWindowFrames implements Parcelable {
    /** The actual window bounds. */
    /** The actual window bounds. */
    public final @NonNull Rect frame;
    public final @NonNull Rect frame = new Rect();


    /**
    /**
     * The container frame that is usually the same as display size. It may exclude the area of
     * The container frame that is usually the same as display size. It may exclude the area of
     * insets if the window layout parameter has specified fit-insets-sides.
     * insets if the window layout parameter has specified fit-insets-sides.
     */
     */
    public final @NonNull Rect displayFrame;
    public final @NonNull Rect displayFrame = new Rect();

    /**
     * The frame to be referenced while applying gravity and MATCH_PARENT.
     */
    public final @NonNull Rect parentFrame = new Rect();


    /** The background area while the window is resizing. */
    /** The background area while the window is resizing. */
    public final @NonNull Rect backdropFrame;
    public final @NonNull Rect backdropFrame = new Rect();

    public boolean isParentFrameClippedByDisplayCutout;


    public ClientWindowFrames() {
    public ClientWindowFrames() {
        frame = new Rect();
        displayFrame = new Rect();
        backdropFrame = new Rect();
    }
    }


    public ClientWindowFrames(ClientWindowFrames other) {
    public ClientWindowFrames(ClientWindowFrames other) {
        frame = new Rect(other.frame);
        frame.set(other.frame);
        displayFrame = new Rect(other.displayFrame);
        displayFrame.set(other.displayFrame);
        backdropFrame = new Rect(other.backdropFrame);
        parentFrame.set(other.parentFrame);
        backdropFrame.set(other.backdropFrame);
        isParentFrameClippedByDisplayCutout = other.isParentFrameClippedByDisplayCutout;
    }
    }


    private ClientWindowFrames(Parcel in) {
    private ClientWindowFrames(Parcel in) {
        frame = Rect.CREATOR.createFromParcel(in);
        readFromParcel(in);
        displayFrame = Rect.CREATOR.createFromParcel(in);
        backdropFrame = Rect.CREATOR.createFromParcel(in);
    }
    }


    /** Needed for AIDL out parameters. */
    /** Needed for AIDL out parameters. */
    public void readFromParcel(Parcel in) {
    public void readFromParcel(Parcel in) {
        frame.readFromParcel(in);
        frame.readFromParcel(in);
        displayFrame.readFromParcel(in);
        displayFrame.readFromParcel(in);
        parentFrame.readFromParcel(in);
        backdropFrame.readFromParcel(in);
        backdropFrame.readFromParcel(in);
        isParentFrameClippedByDisplayCutout = in.readBoolean();
    }
    }


    @Override
    @Override
    public void writeToParcel(Parcel dest, int flags) {
    public void writeToParcel(Parcel dest, int flags) {
        frame.writeToParcel(dest, flags);
        frame.writeToParcel(dest, flags);
        displayFrame.writeToParcel(dest, flags);
        displayFrame.writeToParcel(dest, flags);
        parentFrame.writeToParcel(dest, flags);
        backdropFrame.writeToParcel(dest, flags);
        backdropFrame.writeToParcel(dest, flags);
        dest.writeBoolean(isParentFrameClippedByDisplayCutout);
    }
    }


    @Override
    @Override
@@ -75,7 +83,9 @@ public class ClientWindowFrames implements Parcelable {
        final StringBuilder sb = new StringBuilder(32);
        final StringBuilder sb = new StringBuilder(32);
        return "ClientWindowFrames{frame=" + frame.toShortString(sb)
        return "ClientWindowFrames{frame=" + frame.toShortString(sb)
                + " display=" + displayFrame.toShortString(sb)
                + " display=" + displayFrame.toShortString(sb)
                + " backdrop=" + backdropFrame.toShortString(sb) + "}";
                + " parentFrame=" + parentFrame.toShortString(sb)
                + " backdrop=" + backdropFrame.toShortString(sb)
                + " parentClippedByDisplayCutout=" + isParentFrameClippedByDisplayCutout + "}";
    }
    }


    @Override
    @Override
+9 −10
Original line number Original line Diff line number Diff line
@@ -136,6 +136,7 @@ import android.view.WindowManager.LayoutParams;
import android.view.WindowManagerGlobal;
import android.view.WindowManagerGlobal;
import android.view.WindowManagerPolicyConstants;
import android.view.WindowManagerPolicyConstants;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager;
import android.window.ClientWindowFrames;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -340,9 +341,7 @@ public class DisplayPolicy {
    private static final Rect sTmpRect2 = new Rect();
    private static final Rect sTmpRect2 = new Rect();
    private static final Rect sTmpLastParentFrame = new Rect();
    private static final Rect sTmpLastParentFrame = new Rect();
    private static final Rect sTmpDisplayCutoutSafe = new Rect();
    private static final Rect sTmpDisplayCutoutSafe = new Rect();
    private static final Rect sTmpDisplayFrame = new Rect();
    private static final ClientWindowFrames sTmpClientFrames = new ClientWindowFrames();
    private static final Rect sTmpParentFrame = new Rect();
    private static final Rect sTmpFrame = new Rect();


    private final WindowLayout mWindowLayout = new WindowLayout();
    private final WindowLayout mWindowLayout = new WindowLayout();


@@ -1474,8 +1473,8 @@ public class DisplayPolicy {
                    displayFrames.mUnrestricted, win.getWindowingMode(), UNSPECIFIED_LENGTH,
                    displayFrames.mUnrestricted, win.getWindowingMode(), UNSPECIFIED_LENGTH,
                    UNSPECIFIED_LENGTH, win.getRequestedVisibilities(),
                    UNSPECIFIED_LENGTH, win.getRequestedVisibilities(),
                    null /* attachedWindowFrame */, win.mGlobalScale,
                    null /* attachedWindowFrame */, win.mGlobalScale,
                    sTmpDisplayFrame, sTmpParentFrame, sTmpFrame);
                    sTmpClientFrames);
            controller.computeSimulatedState(win, displayFrames, sTmpFrame);
            controller.computeSimulatedState(win, displayFrames, sTmpClientFrames.frame);
        }
        }
    }
    }


@@ -1518,12 +1517,12 @@ public class DisplayPolicy {


        sTmpLastParentFrame.set(pf);
        sTmpLastParentFrame.set(pf);


        final boolean clippedByDisplayCutout = mWindowLayout.computeFrames(attrs,
        mWindowLayout.computeFrames(attrs, win.getInsetsState(), displayFrames.mDisplayCutoutSafe,
                win.getInsetsState(), displayFrames.mDisplayCutoutSafe,
                win.getBounds(), win.getWindowingMode(), requestedWidth, requestedHeight,
                win.getBounds(), win.getWindowingMode(), requestedWidth, requestedHeight,
                win.getRequestedVisibilities(), attachedWindowFrame, win.mGlobalScale,
                win.getRequestedVisibilities(), attachedWindowFrame, win.mGlobalScale,
                df, pf, f);
                sTmpClientFrames);
        windowFrames.setParentFrameWasClippedByDisplayCutout(clippedByDisplayCutout);
        windowFrames.setParentFrameWasClippedByDisplayCutout(
                sTmpClientFrames.isParentFrameClippedByDisplayCutout);


        if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
        if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
                + ": sim=#" + Integer.toHexString(attrs.softInputMode)
                + ": sim=#" + Integer.toHexString(attrs.softInputMode)
@@ -1536,7 +1535,7 @@ public class DisplayPolicy {
            windowFrames.setContentChanged(true);
            windowFrames.setContentChanged(true);
        }
        }


        win.setFrame();
        win.setFrames(sTmpClientFrames);
    }
    }


    WindowState getTopFullscreenOpaqueWindow() {
    WindowState getTopFullscreenOpaqueWindow() {
+4 −4
Original line number Original line Diff line number Diff line
@@ -1393,13 +1393,13 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    }
    }


    // TODO(b/161810301): Make the frame be passed from the client side.
    // TODO(b/161810301): Make the frame be passed from the client side.
    void setFrame() {
    void setFrames(ClientWindowFrames clientWindowFrames) {
        // TODO(b/161810301): Set the window frame here. We don't have to do it now because
        //                    DisplayPolicy has already done it for the window.

        mHaveFrame = true;
        mHaveFrame = true;


        final WindowFrames windowFrames = mWindowFrames;
        final WindowFrames windowFrames = mWindowFrames;
        windowFrames.mDisplayFrame.set(clientWindowFrames.displayFrame);
        windowFrames.mParentFrame.set(clientWindowFrames.parentFrame);
        windowFrames.mFrame.set(clientWindowFrames.frame);


        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
            mLastRequestedWidth = mRequestedWidth;
            mLastRequestedWidth = mRequestedWidth;
Loading