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

Commit b80c2c9f authored by Evan Rosky's avatar Evan Rosky Committed by Android (Google) Code Review
Browse files

Merge "Use WindowRelayoutResult for all WM->Client layout" into main

parents 00661c03 8fb34909
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
            mOutSurfaceControl = mView.getViewRootImpl().getSurfaceControl();
            mViewVisibility = visibilitySupplier;
            mOutRelayoutResult = new WindowRelayoutResult(mOutFrames, mOutMergedConfiguration,
                            mOutSurfaceControl, mOutInsetsState, mOutControls);
                    mOutInsetsState, mOutControls);
        }

        void runBenchmark(BenchmarkState state) throws RemoteException {
@@ -157,7 +157,8 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
            while (state.keepRunning()) {
                mRelayoutSeq++;
                session.relayout(mWindow, mParams, mWidth, mHeight, mViewVisibility.getAsInt(),
                        mFlags, mRelayoutSeq, 0 /* lastSyncSeqId */, mOutRelayoutResult);
                        mFlags, mRelayoutSeq, 0 /* lastSyncSeqId */, mOutRelayoutResult,
                        mOutSurfaceControl);
            }
        }
    }
+8 −8
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ package android.wm;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

import android.graphics.Rect;
import android.os.RemoteException;
import android.os.SystemClock;
import android.perftests.utils.ManualBenchmarkState;
import android.perftests.utils.ManualBenchmarkState.ManualBenchmarkTest;
import android.perftests.utils.PerfManualStatusReporter;
import android.util.MergedConfiguration;
import android.view.Display;
import android.view.IWindowSession;
import android.view.InputChannel;
@@ -34,6 +34,8 @@ import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.WindowRelayoutResult;
import android.window.ClientWindowFrames;

import androidx.test.filters.LargeTest;

@@ -85,10 +87,9 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase
    private static class TestWindow extends BaseIWindow {
        final WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
        final int mRequestedVisibleTypes = WindowInsets.Type.defaultVisible();
        final InsetsState mOutInsetsState = new InsetsState();
        final InsetsSourceControl.Array mOutControls = new InsetsSourceControl.Array();
        final Rect mOutAttachedFrame = new Rect();
        final float[] mOutSizeCompatScale = { 1f };
        final WindowRelayoutResult mRelayoutResult = new WindowRelayoutResult(
                new ClientWindowFrames(), new MergedConfiguration(), new InsetsState(),
                new InsetsSourceControl.Array());

        TestWindow() {
            mLayoutParams.setTitle(TestWindow.class.getName());
@@ -105,9 +106,8 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase
                final InputChannel inputChannel = new InputChannel();

                long startTime = SystemClock.elapsedRealtimeNanos();
                session.addToDisplay(this, mLayoutParams, View.VISIBLE,
                        Display.DEFAULT_DISPLAY, mRequestedVisibleTypes, inputChannel,
                        mOutInsetsState, mOutControls, mOutAttachedFrame, mOutSizeCompatScale);
                session.addToDisplay(this, mLayoutParams, View.VISIBLE, Display.DEFAULT_DISPLAY,
                        mRequestedVisibleTypes, inputChannel, mRelayoutResult);
                final long elapsedTimeNsOfAdd = SystemClock.elapsedRealtimeNanos() - startTime;
                state.addExtraResult("add", elapsedTimeNsOfAdd);

+26 −53
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.app.servertransaction;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ClientTransactionHandler;
@@ -28,6 +26,7 @@ import android.util.Log;
import android.util.MergedConfiguration;
import android.view.IWindow;
import android.view.InsetsState;
import android.view.WindowRelayoutResult;
import android.window.ActivityWindowInfo;
import android.window.ClientWindowFrames;

@@ -43,44 +42,32 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
    private static final String TAG = "WindowStateResizeItem";

    @NonNull
    private final ClientWindowFrames mFrames;

    @NonNull
    private final MergedConfiguration mConfiguration;

    @NonNull
    private final InsetsState mInsetsState;

    /** {@code null} if this is not an Activity window. */
    @Nullable
    private final ActivityWindowInfo mActivityWindowInfo;
    private final WindowRelayoutResult mLayout = new WindowRelayoutResult(new ClientWindowFrames(),
            new MergedConfiguration(), new InsetsState(), null /* insetControls */);

    private final boolean mReportDraw;
    private final boolean mForceLayout;
    private final boolean mAlwaysConsumeSystemBars;
    private final int mDisplayId;
    private final int mSyncSeqId;
    private final boolean mDragResizing;

    public WindowStateResizeItem(@NonNull IWindow window,
            @NonNull ClientWindowFrames frames, boolean reportDraw,
            @NonNull MergedConfiguration configuration, @NonNull InsetsState insetsState,
            boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId, int syncSeqId,
            boolean dragResizing, @Nullable ActivityWindowInfo activityWindowInfo) {
            boolean forceLayout, int displayId, int syncSeqId, boolean dragResizing,
            @Nullable ActivityWindowInfo activityWindowInfo) {
        super(window);
        mFrames = new ClientWindowFrames(frames);
        mConfiguration = new MergedConfiguration(configuration);
        mInsetsState = new InsetsState(insetsState, true /* copySources */);
        mLayout.frames.setTo(frames);
        mLayout.mergedConfiguration.setTo(configuration);
        mLayout.insetsState.set(insetsState, true /* copySources */);
        if (activityWindowInfo != null) {
            mActivityWindowInfo = new ActivityWindowInfo(activityWindowInfo);
            mLayout.activityWindowInfo = new ActivityWindowInfo(activityWindowInfo);
        } else {
            mActivityWindowInfo = null;
            mLayout.activityWindowInfo = null;
        }
        mReportDraw = reportDraw;
        mForceLayout = forceLayout;
        mAlwaysConsumeSystemBars = alwaysConsumeSystemBars;
        mDisplayId = displayId;
        mSyncSeqId = syncSeqId;
        mLayout.syncSeqId = syncSeqId;
        mDragResizing = dragResizing;
    }

@@ -90,9 +77,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER,
                mReportDraw ? "windowResizedReport" : "windowResized");
        try {
            window.resized(mFrames, mReportDraw, mConfiguration, mInsetsState, mForceLayout,
                    mAlwaysConsumeSystemBars, mDisplayId, mSyncSeqId, mDragResizing,
                    mActivityWindowInfo);
            window.resized(mLayout, mReportDraw, mForceLayout, mDisplayId, mDragResizing);
        } catch (RemoteException e) {
            // Should be a local call.
            // An exception could happen if the process is restarted. It is safe to ignore since
@@ -108,31 +93,21 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeTypedObject(mFrames, flags);
        mLayout.writeToParcel(dest, flags);
        dest.writeBoolean(mReportDraw);
        dest.writeTypedObject(mConfiguration, flags);
        dest.writeTypedObject(mInsetsState, flags);
        dest.writeBoolean(mForceLayout);
        dest.writeBoolean(mAlwaysConsumeSystemBars);
        dest.writeInt(mDisplayId);
        dest.writeInt(mSyncSeqId);
        dest.writeBoolean(mDragResizing);
        dest.writeTypedObject(mActivityWindowInfo, flags);
    }

    /** Reads from Parcel. */
    private WindowStateResizeItem(@NonNull Parcel in) {
        super(in);
        mFrames = requireNonNull(in.readTypedObject(ClientWindowFrames.CREATOR));
        mLayout.readFromParcel(in);
        mReportDraw = in.readBoolean();
        mConfiguration = requireNonNull(in.readTypedObject(MergedConfiguration.CREATOR));
        mInsetsState = requireNonNull(in.readTypedObject(InsetsState.CREATOR));
        mForceLayout = in.readBoolean();
        mAlwaysConsumeSystemBars = in.readBoolean();
        mDisplayId = in.readInt();
        mSyncSeqId = in.readInt();
        mDragResizing = in.readBoolean();
        mActivityWindowInfo = in.readTypedObject(ActivityWindowInfo.CREATOR);
    }

    public static final @NonNull Creator<WindowStateResizeItem> CREATOR = new Creator<>() {
@@ -154,32 +129,30 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
            return false;
        }
        final WindowStateResizeItem other = (WindowStateResizeItem) o;
        return Objects.equals(mFrames, other.mFrames)
        return Objects.equals(mLayout.frames, other.mLayout.frames)
                && Objects.equals(mLayout.mergedConfiguration, other.mLayout.mergedConfiguration)
                && Objects.equals(mLayout.insetsState, other.mLayout.insetsState)
                && mReportDraw == other.mReportDraw
                && Objects.equals(mConfiguration, other.mConfiguration)
                && Objects.equals(mInsetsState, other.mInsetsState)
                && mForceLayout == other.mForceLayout
                && mAlwaysConsumeSystemBars == other.mAlwaysConsumeSystemBars
                && mDisplayId == other.mDisplayId
                && mSyncSeqId == other.mSyncSeqId
                && mLayout.syncSeqId == other.mLayout.syncSeqId
                && mDragResizing == other.mDragResizing
                && Objects.equals(mActivityWindowInfo, other.mActivityWindowInfo);
                && Objects.equals(mLayout.activityWindowInfo, other.mLayout.activityWindowInfo);
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + super.hashCode();
        result = 31 * result + Objects.hashCode(mFrames);
        result = 31 * result + Objects.hashCode(mLayout.frames);
        result = 31 * result + Objects.hashCode(mLayout.mergedConfiguration);
        result = 31 * result + Objects.hashCode(mLayout.insetsState);
        result = 31 * result + (mReportDraw ? 1 : 0);
        result = 31 * result + Objects.hashCode(mConfiguration);
        result = 31 * result + Objects.hashCode(mInsetsState);
        result = 31 * result + (mForceLayout ? 1 : 0);
        result = 31 * result + (mAlwaysConsumeSystemBars ? 1 : 0);
        result = 31 * result + mDisplayId;
        result = 31 * result + mSyncSeqId;
        result = 31 * result + mLayout.syncSeqId;
        result = 31 * result + (mDragResizing ? 1 : 0);
        result = 31 * result + Objects.hashCode(mActivityWindowInfo);
        result = 31 * result + Objects.hashCode(mLayout.activityWindowInfo);
        return result;
    }

@@ -187,8 +160,8 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
    public String toString() {
        return "WindowStateResizeItem{" + super.toString()
                + ", reportDrawn=" + mReportDraw
                + ", configuration=" + mConfiguration
                + ", activityWindowInfo=" + mActivityWindowInfo
                + ", configuration=" + mLayout.mergedConfiguration
                + ", activityWindowInfo=" + mLayout.activityWindowInfo
                + "}";
    }
}
+9 −11
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ import android.view.WindowLayout;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.WindowRelayoutResult;
import android.window.ActivityWindowInfo;
import android.window.ClientWindowFrames;
import android.window.ScreenCapture;

@@ -312,7 +311,7 @@ public abstract class WallpaperService extends Service {

        SurfaceControl mSurfaceControl = new SurfaceControl();
        WindowRelayoutResult mRelayoutResult = new WindowRelayoutResult(
                mWinFrames, mMergedConfiguration, mSurfaceControl, mInsetsState, mTempControls);
                mWinFrames, mMergedConfiguration, mInsetsState, mTempControls);

        private final Point mSurfaceSize = new Point();
        private final Point mLastSurfaceSize = new Point();
@@ -484,14 +483,11 @@ public abstract class WallpaperService extends Service {

        final BaseIWindow mWindow = new BaseIWindow() {
            @Override
            public void resized(ClientWindowFrames frames, boolean reportDraw,
                    MergedConfiguration mergedConfiguration, InsetsState insetsState,
                    boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId,
                    int syncSeqId, boolean dragResizing,
                    @Nullable ActivityWindowInfo activityWindowInfo) {
            public void resized(WindowRelayoutResult layout, boolean reportDraw,
                    boolean forceLayout, int displayId, boolean dragResizing) {
                Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED,
                        reportDraw ? 1 : 0,
                        mergedConfiguration);
                        layout.mergedConfiguration);
                mIWallpaperEngine.mPendingResizeCount.incrementAndGet();
                mCaller.sendMessage(msg);
            }
@@ -1291,10 +1287,12 @@ public abstract class WallpaperService extends Service {
                                com.android.internal.R.style.Animation_Wallpaper;
                        InputChannel inputChannel = new InputChannel();

                        final WindowRelayoutResult addRes = new WindowRelayoutResult(
                                new ClientWindowFrames(), new MergedConfiguration(), mInsetsState,
                                mTempControls);
                        if (mSession.addToDisplay(mWindow, mLayout, View.VISIBLE,
                                mDisplay.getDisplayId(), WindowInsets.Type.defaultVisible(),
                                inputChannel, mInsetsState, mTempControls, new Rect(),
                                new float[1]) < 0) {
                                inputChannel, addRes) < 0) {
                            Log.w(TAG, "Failed to add window while updating wallpaper surface.");
                            return;
                        }
@@ -1314,7 +1312,7 @@ 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, 0, 0, mRelayoutResult);
                            View.VISIBLE, 0, 0, 0, mRelayoutResult, mSurfaceControl);
                    final Rect outMaxBounds = mMergedConfiguration.getMergedConfiguration()
                            .windowConfiguration.getMaxBounds();
                    if (!outMaxBounds.equals(maxBounds)) {
+3 −8
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
package android.view;

import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.util.MergedConfiguration;
@@ -30,8 +29,7 @@ import android.view.IScrollCaptureResponseListener;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.inputmethod.ImeTracker;
import android.window.ActivityWindowInfo;
import android.window.ClientWindowFrames;
import android.view.WindowRelayoutResult;

import com.android.internal.os.IResultReceiver;

@@ -59,11 +57,8 @@ oneway interface IWindow {
     * Please dispatch through WindowStateResizeItem instead of directly calling this method from
     * the system server.
     */
    void resized(in ClientWindowFrames frames, boolean reportDraw,
            in MergedConfiguration newMergedConfiguration, in InsetsState insetsState,
            boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId,
            int syncSeqId, boolean dragResizing,
            in @nullable ActivityWindowInfo activityWindowInfo);
    void resized(in WindowRelayoutResult layout, boolean reportDraw, boolean forceLayout,
            int displayId, boolean dragResizing);

    /**
     * Called when this window retrieved control over a specified set of insets sources.
Loading