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

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

Merge "Introduce IWindowSession#relayoutAsync" into tm-qpr-dev

parents 08fc9723 37124333
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -153,9 +153,9 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
            final IWindowSession session = WindowManagerGlobal.getWindowSession();
            while (state.keepRunning()) {
                session.relayout(mWindow, mParams, mWidth, mHeight,
                        mViewVisibility.getAsInt(), mFlags, mOutFrames,
                        mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls,
                        new Bundle());
                        mViewVisibility.getAsInt(), mFlags, 0 /* seq */, 0 /* lastSyncSeqId */,
                        mOutFrames, mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState,
                        mOutControls, new Bundle());
            }
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -1154,8 +1154,8 @@ public abstract class WallpaperService extends Service {
                        mLayout.surfaceInsets.set(0, 0, 0, 0);
                    }
                    final int relayoutResult = mSession.relayout(mWindow, mLayout, mWidth, mHeight,
                            View.VISIBLE, 0, mWinFrames, mMergedConfiguration, mSurfaceControl,
                            mInsetsState, mTempControls, mSyncSeqIdBundle);
                            View.VISIBLE, 0, 0, 0, mWinFrames, mMergedConfiguration,
                            mSurfaceControl, mInsetsState, mTempControls, mSyncSeqIdBundle);

                    final int transformHint = SurfaceControl.rotationToBufferTransform(
                            (mDisplayInstallOrientation + mDisplay.getRotation()) % 4);
+27 −26
Original line number Diff line number Diff line
@@ -75,41 +75,42 @@ interface IWindowSession {
     * @param requestedWidth The width the window wants to be.
     * @param requestedHeight The height the window wants to be.
     * @param viewVisibility Window root view's visibility.
     * @param flags Request flags: {@link WindowManagerGlobal#RELAYOUT_INSETS_PENDING},
     * {@link WindowManagerGlobal#RELAYOUT_DEFER_SURFACE_DESTROY}.
     * @param outFrame Rect in which is placed the new position/size on
     * screen.
     * @param outContentInsets Rect in which is placed the offsets from
     * <var>outFrame</var> in which the content of the window should be
     * placed.  This can be used to modify the window layout to ensure its
     * contents are visible to the user, taking into account system windows
     * like the status bar or a soft keyboard.
     * @param outVisibleInsets Rect in which is placed the offsets from
     * <var>outFrame</var> in which the window is actually completely visible
     * to the user.  This can be used to temporarily scroll the window's
     * contents to make sure the user can see it.  This is different than
     * <var>outContentInsets</var> in that these insets change transiently,
     * so complex relayout of the window should not happen based on them.
     * @param outOutsets Rect in which is placed the dead area of the screen that we would like to
     * treat as real display. Example of such area is a chin in some models of wearable devices.
     * @param outBackdropFrame Rect which is used draw the resizing background during a resize
     * operation.
     * @param flags Request flags: {@link WindowManagerGlobal#RELAYOUT_INSETS_PENDING}.
     * @param seq The calling sequence of {@link #relayout} and {@link #relayoutAsync}.
     * @param lastSyncSeqId The last SyncSeqId that the client applied.
     * @param outFrames The window frames used by the client side for layout.
     * @param outMergedConfiguration New config container that holds global, override and merged
     * config for window, if it is now becoming visible and the merged configuration has changed
     * since it was last displayed.
     * @param outSurface Object in which is placed the new display surface.
     *                               config for window, if it is now becoming visible and the merged
     *                               config has changed since it was last displayed.
     * @param outSurfaceControl Object in which is placed the new display surface.
     * @param insetsState The current insets state in the system.
     *
     * @return int Result flags: {@link WindowManagerGlobal#RELAYOUT_SHOW_FOCUS},
     * {@link WindowManagerGlobal#RELAYOUT_FIRST_TIME}.
     * @param activeControls Objects which allow controlling {@link InsetsSource}s.
     * @param bundle A temporary object to obtain the latest SyncSeqId.
     * @return int Result flags, defined in {@link WindowManagerGlobal}.
     */
    int relayout(IWindow window, in WindowManager.LayoutParams attrs,
            int requestedWidth, int requestedHeight, int viewVisibility,
            int flags, out ClientWindowFrames outFrames,
            int flags, int seq, int lastSyncSeqId, out ClientWindowFrames outFrames,
            out MergedConfiguration outMergedConfiguration, out SurfaceControl outSurfaceControl,
            out InsetsState insetsState, out InsetsSourceControl[] activeControls,
            out Bundle bundle);

    /**
     * Similar to {@link #relayout} but this is an oneway method which doesn't return anything.
     *
     * @param window The window being modified.
     * @param attrs If non-null, new attributes to apply to the window.
     * @param requestedWidth The width the window wants to be.
     * @param requestedHeight The height the window wants to be.
     * @param viewVisibility Window root view's visibility.
     * @param flags Request flags: {@link WindowManagerGlobal#RELAYOUT_INSETS_PENDING}.
     * @param seq The calling sequence of {@link #relayout} and {@link #relayoutAsync}.
     * @param lastSyncSeqId The last SyncSeqId that the client applied.
     */
    oneway void relayoutAsync(IWindow window, in WindowManager.LayoutParams attrs,
            int requestedWidth, int requestedHeight, int viewVisibility, int flags, int seq,
            int lastSyncSeqId);

    /*
     * Notify the window manager that an application is relaunching and
     * windows should be prepared for replacement.
+88 −40
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
@@ -706,6 +707,8 @@ public final class ViewRootImpl implements ViewParent,
    final Rect mPendingBackDropFrame = new Rect();

    boolean mPendingAlwaysConsumeSystemBars;
    private int mRelayoutSeq;
    private final Rect mWinFrameInScreen = new Rect();
    private final InsetsState mTempInsets = new InsetsState();
    private final InsetsSourceControl[] mTempControls = new InsetsSourceControl[SIZE];
    private final WindowConfiguration mTempWinConfig = new WindowConfiguration();
@@ -3333,10 +3336,18 @@ public final class ViewRootImpl implements ViewParent,
                }
            }
        } else {
            // If a relayout isn't going to happen, we still need to check if this window can draw
            // when mCheckIfCanDraw is set. This is because it means we had a sync in the past, but
            // have not been told by WMS that the sync is complete and that we can continue to draw
            if (mCheckIfCanDraw) {
            // Not the first pass and no window/insets/visibility change but the window
            // may have moved and we need check that and if so to update the left and right
            // in the attach info. We translate only the window frame since on window move
            // the window manager tells us only for the new frame but the insets are the
            // same and we do not want to translate them more than once.
            maybeHandleWindowMove(frame);
        }

        if (!mRelayoutRequested && mCheckIfCanDraw) {
            // We had a sync previously, but we didn't call IWindowSession#relayout in this
            // traversal. So we don't know if the sync is complete that we can continue to draw.
            // Here invokes cancelDraw to obtain the information.
            try {
                cancelDraw = mWindowSession.cancelDraw(mWindow);
                cancelReason = "wm_sync";
@@ -3347,14 +3358,6 @@ public final class ViewRootImpl implements ViewParent,
            }
        }

            // Not the first pass and no window/insets/visibility change but the window
            // may have moved and we need check that and if so to update the left and right
            // in the attach info. We translate only the window frame since on window move
            // the window manager tells us only for the new frame but the insets are the
            // same and we do not want to translate them more than once.
            maybeHandleWindowMove(frame);
        }

        if (surfaceSizeChanged || surfaceReplaced || surfaceCreated || windowAttributesChanged) {
            // If the surface has been replaced, there's a chance the bounds layer is not parented
            // to the new layer. When updating bounds layer, also reparent to the main VRI
@@ -8082,7 +8085,43 @@ public final class ViewRootImpl implements ViewParent,

    private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility,
            boolean insetsPending) throws RemoteException {
        mRelayoutRequested = true;
        final WindowConfiguration winConfigFromAm = getConfiguration().windowConfiguration;
        final WindowConfiguration winConfigFromWm =
                mLastReportedMergedConfiguration.getGlobalConfiguration().windowConfiguration;
        final WindowConfiguration winConfig = getCompatWindowConfiguration();
        final int measuredWidth = mView.getMeasuredWidth();
        final int measuredHeight = mView.getMeasuredHeight();
        final boolean relayoutAsync;
        if (LOCAL_LAYOUT && !mFirst && viewVisibility == mViewVisibility
                && mWindowAttributes.type != TYPE_APPLICATION_STARTING
                && mSyncSeqId <= mLastSyncSeqId
                && winConfigFromAm.diff(winConfigFromWm, false /* compareUndefined */) == 0) {
            final InsetsState state = mInsetsController.getState();
            final Rect displayCutoutSafe = mTempRect;
            state.getDisplayCutoutSafe(displayCutoutSafe);
            mWindowLayout.computeFrames(mWindowAttributes.forRotation(winConfig.getRotation()),
                    state, displayCutoutSafe, winConfig.getBounds(), winConfig.getWindowingMode(),
                    measuredWidth, measuredHeight, mInsetsController.getRequestedVisibilities(),
                    1f /* compatScale */, mTmpFrames);
            mWinFrameInScreen.set(mTmpFrames.frame);
            if (mTranslator != null) {
                mTranslator.translateRectInAppWindowToScreen(mWinFrameInScreen);
            }

            // If the position and the size of the frame are both changed, it will trigger a BLAST
            // sync, and we still need to call relayout to obtain the syncSeqId. Otherwise, we just
            // need to send attributes via relayoutAsync.
            final Rect oldFrame = mWinFrame;
            final Rect newFrame = mTmpFrames.frame;
            final boolean positionChanged =
                    newFrame.top != oldFrame.top || newFrame.left != oldFrame.left;
            final boolean sizeChanged =
                    newFrame.width() != oldFrame.width() || newFrame.height() != oldFrame.height();
            relayoutAsync = !positionChanged || !sizeChanged;
        } else {
            relayoutAsync = false;
        }

        float appScale = mAttachInfo.mApplicationScale;
        boolean restore = false;
        if (params != null && mTranslator != null) {
@@ -8104,26 +8143,47 @@ public final class ViewRootImpl implements ViewParent,
            }
        }

        final int requestedWidth = (int) (mView.getMeasuredWidth() * appScale + 0.5f);
        final int requestedHeight = (int) (mView.getMeasuredHeight() * appScale + 0.5f);

        int relayoutResult = mWindowSession.relayout(mWindow, params,
        final int requestedWidth = (int) (measuredWidth * appScale + 0.5f);
        final int requestedHeight = (int) (measuredHeight * appScale + 0.5f);
        int relayoutResult = 0;
        mRelayoutSeq++;
        if (relayoutAsync) {
            mWindowSession.relayoutAsync(mWindow, params,
                    requestedWidth, requestedHeight, viewVisibility,
                    insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, mRelayoutSeq,
                    mLastSyncSeqId);
        } else {
            relayoutResult = mWindowSession.relayout(mWindow, params,
                    requestedWidth, requestedHeight, viewVisibility,
                insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0,
                mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets,
                mTempControls, mRelayoutBundle);
                    insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, mRelayoutSeq,
                    mLastSyncSeqId, mTmpFrames, mPendingMergedConfiguration, mSurfaceControl,
                    mTempInsets, mTempControls, mRelayoutBundle);
            mRelayoutRequested = true;
            final int maybeSyncSeqId = mRelayoutBundle.getInt("seqid");
            if (maybeSyncSeqId > 0) {
                mSyncSeqId = maybeSyncSeqId;
            }
            mWinFrameInScreen.set(mTmpFrames.frame);
            if (mTranslator != null) {
                mTranslator.translateRectInScreenToAppWindow(mTmpFrames.frame);
                mTranslator.translateRectInScreenToAppWindow(mTmpFrames.displayFrame);
                mTranslator.translateRectInScreenToAppWindow(mTmpFrames.attachedFrame);
                mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
                mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
            }
            mInvSizeCompatScale = 1f / mTmpFrames.sizeCompatScale;
            mInsetsController.onStateChanged(mTempInsets);
            mInsetsController.onControlsChanged(mTempControls);

            mPendingAlwaysConsumeSystemBars =
                    (relayoutResult & RELAYOUT_RES_CONSUME_ALWAYS_SYSTEM_BARS) != 0;
        }

        final int transformHint = SurfaceControl.rotationToBufferTransform(
                (mDisplayInstallOrientation + mDisplay.getRotation()) % 4);

        final WindowConfiguration winConfig = getCompatWindowConfiguration();
        WindowLayout.computeSurfaceSize(mWindowAttributes, winConfig.getMaxBounds(), requestedWidth,
                requestedHeight, mTmpFrames.frame, mPendingDragResizing, mSurfaceSize);
                requestedHeight, mWinFrameInScreen, mPendingDragResizing, mSurfaceSize);

        final boolean transformHintChanged = transformHint != mLastTransformHint;
        final boolean sizeChanged = !mLastSurfaceSize.equals(mSurfaceSize);
@@ -8170,23 +8230,11 @@ public final class ViewRootImpl implements ViewParent,
            destroySurface();
        }

        mPendingAlwaysConsumeSystemBars =
                (relayoutResult & RELAYOUT_RES_CONSUME_ALWAYS_SYSTEM_BARS) != 0;

        if (restore) {
            params.restore();
        }

        if (mTranslator != null) {
            mTranslator.translateRectInScreenToAppWindow(mTmpFrames.frame);
            mTranslator.translateRectInScreenToAppWindow(mTmpFrames.displayFrame);
            mTranslator.translateRectInScreenToAppWindow(mTmpFrames.attachedFrame);
            mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
            mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
        }
        setFrame(mTmpFrames.frame);
        mInsetsController.onStateChanged(mTempInsets);
        mInsetsController.onControlsChanged(mTempControls);
        return relayoutResult;
    }

+29 −10
Original line number Diff line number Diff line
@@ -286,10 +286,11 @@ public class WindowlessWindowManager implements IWindowSession {

    @Override
    public int relayout(IWindow window, WindowManager.LayoutParams inAttrs,
            int requestedWidth, int requestedHeight, int viewFlags, int flags,
            ClientWindowFrames outFrames, MergedConfiguration mergedConfiguration,
            SurfaceControl outSurfaceControl, InsetsState outInsetsState,
            InsetsSourceControl[] outActiveControls, Bundle outSyncSeqIdBundle) {
            int requestedWidth, int requestedHeight, int viewFlags, int flags, int seq,
            int lastSyncSeqId, ClientWindowFrames outFrames,
            MergedConfiguration outMergedConfiguration, SurfaceControl outSurfaceControl,
            InsetsState outInsetsState, InsetsSourceControl[] outActiveControls,
            Bundle outSyncSeqIdBundle) {
        final State state;
        synchronized (this) {
            state = mStateForWindow.get(window.asBinder());
@@ -309,15 +310,23 @@ public class WindowlessWindowManager implements IWindowSession {

        if (viewFlags == View.VISIBLE) {
            t.setOpaque(sc, isOpaque(attrs)).show(sc).apply();
            if (outSurfaceControl != null) {
                outSurfaceControl.copyFrom(sc, "WindowlessWindowManager.relayout");
            }
        } else {
            t.hide(sc).apply();
            if (outSurfaceControl != null) {
                outSurfaceControl.release();
            }
        }
        if (outFrames != null) {
            outFrames.frame.set(0, 0, attrs.width, attrs.height);
            outFrames.displayFrame.set(outFrames.frame);
        }

        mergedConfiguration.setConfiguration(mConfiguration, mConfiguration);
        if (outMergedConfiguration != null) {
            outMergedConfiguration.setConfiguration(mConfiguration, mConfiguration);
        }

        if ((attrChanges & WindowManager.LayoutParams.FLAGS_CHANGED) != 0
                && state.mInputChannelToken != null) {
@@ -335,13 +344,23 @@ public class WindowlessWindowManager implements IWindowSession {
            }
        }

        if (mInsetsState != null) {
        if (outInsetsState != null && mInsetsState != null) {
            outInsetsState.set(mInsetsState);
        }

        return 0;
    }

    @Override
    public void relayoutAsync(IWindow window, WindowManager.LayoutParams inAttrs,
            int requestedWidth, int requestedHeight, int viewFlags, int flags, int seq,
            int lastSyncSeqId) {
        relayout(window, inAttrs, requestedWidth, requestedHeight, viewFlags, flags, seq,
                lastSyncSeqId, null /* outFrames */, null /* outMergedConfiguration */,
                null /* outSurfaceControl */, null /* outInsetsState */,
                null /* outActiveControls */, null /* outSyncSeqIdBundle */);
    }

    @Override
    public void prepareToReplaceWindows(android.os.IBinder appToken, boolean childrenOnly) {
    }
Loading