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

Commit c1cf2472 authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Use ClientWindowFrames to collect frames computed by WindowLayout" into tm-dev

parents 8ea0eb70 45790587
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -552,7 +552,6 @@ public final class ViewRootImpl implements ViewParent,

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

    private final WindowLayout mWindowLayout = new WindowLayout();

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

/**
 * Computes window frames.
@@ -56,15 +57,17 @@ public class WindowLayout {
    private final Rect mTempDisplayCutoutSafeExceptMaybeBarsRect = 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,
            int requestedWidth, int requestedHeight, InsetsVisibilities requestedVisibilities,
            Rect attachedWindowFrame, float compatScale, Rect outDisplayFrame, Rect outParentFrame,
            Rect outFrame) {
            Rect attachedWindowFrame, float compatScale, ClientWindowFrames outFrames) {
        final int type = attrs.type;
        final int fl = attrs.flags;
        final int pfl = attrs.privateFlags;
        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
        final Insets insets = state.calculateInsets(windowBounds, attrs.getFitInsetsTypes(),
@@ -95,7 +98,7 @@ public class WindowLayout {
        final DisplayCutout cutout = state.getDisplayCutout();
        final Rect displayCutoutSafeExceptMaybeBars = mTempDisplayCutoutSafeExceptMaybeBarsRect;
        displayCutoutSafeExceptMaybeBars.set(displayCutoutSafe);
        boolean clippedByDisplayCutout = false;
        outFrames.isParentFrameClippedByDisplayCutout = false;
        if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS && !cutout.isEmpty()) {
            // Ensure that windows with a non-ALWAYS display cutout mode are laid out in
            // the cutout safe zone.
@@ -158,7 +161,7 @@ public class WindowLayout {
            if (!attachedInParent && !floatingInScreenWindow) {
                mTempRect.set(outParentFrame);
                outParentFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
                clippedByDisplayCutout = !mTempRect.equals(outParentFrame);
                outFrames.isParentFrameClippedByDisplayCutout = !mTempRect.equals(outParentFrame);
            }
            outDisplayFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
        }
@@ -287,9 +290,7 @@ public class WindowLayout {
        }

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

        return clippedByDisplayCutout;
    }

    public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds,
+23 −13
Original line number Diff line number Diff line
@@ -27,47 +27,55 @@ import android.os.Parcelable;
 */
public class ClientWindowFrames implements Parcelable {
    /** 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
     * 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. */
    public final @NonNull Rect backdropFrame;
    public final @NonNull Rect backdropFrame = new Rect();

    public boolean isParentFrameClippedByDisplayCutout;

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

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

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

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

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

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

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

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

    private final WindowLayout mWindowLayout = new WindowLayout();

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

@@ -1534,12 +1533,12 @@ public class DisplayPolicy {

        sTmpLastParentFrame.set(pf);

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

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

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

    WindowState getTopFullscreenOpaqueWindow() {
+4 −4
Original line number 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.
    void setFrame() {
        // 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.

    void setFrames(ClientWindowFrames clientWindowFrames) {
        mHaveFrame = true;

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

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