From a4b69f84f8c14a951f5c4aa838eb0ab4b7c2de08 Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Fri, 1 Apr 2022 00:06:01 +0800 Subject: [PATCH] Introduce WindowlessWindowLayout The window frame computed by WindowlessWindowManager doesn't take the window bounds, insets state, gravity, ... into account, but only width and height in LayoutParams. This CL introduces WindowlessWindowLayout which aligns the logic in WindowlessWindowManager#relayout. When we enable LOCAL_LAYOUT, the frame of windowless window will be compatible. Bug: 161810301 Bug: 175858823 Test: atest SurfaceControlViewHostTests#testEmbeddedViewResizes Change-Id: I460445e9d6b61117edbdaddeac6a00a838b3caa8 --- .../android/view/SurfaceControlViewHost.java | 6 +-- core/java/android/view/ViewRootImpl.java | 12 +++--- .../android/view/WindowManagerGlobal.java | 2 +- .../android/view/WindowlessWindowLayout.java | 39 +++++++++++++++++++ 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 core/java/android/view/WindowlessWindowLayout.java diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java index f7bca5bfe1887..d75ff2fc7dc29 100644 --- a/core/java/android/view/SurfaceControlViewHost.java +++ b/core/java/android/view/SurfaceControlViewHost.java @@ -29,8 +29,6 @@ import android.os.Parcelable; import android.os.RemoteException; import android.util.Log; import android.window.WindowTokenClient; -import android.view.InsetsState; -import android.view.WindowManagerGlobal; import android.view.accessibility.IAccessibilityEmbeddedConnection; import java.util.Objects; @@ -280,7 +278,7 @@ public class SurfaceControlViewHost { public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d, @NonNull WindowlessWindowManager wwm, boolean useSfChoreographer) { mWm = wwm; - mViewRoot = new ViewRootImpl(c, d, mWm, useSfChoreographer); + mViewRoot = new ViewRootImpl(c, d, mWm, new WindowlessWindowLayout(), useSfChoreographer); addConfigCallback(c, d); WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot); @@ -310,7 +308,7 @@ public class SurfaceControlViewHost { mWm = new WindowlessWindowManager(context.getResources().getConfiguration(), mSurfaceControl, hostToken); - mViewRoot = new ViewRootImpl(context, display, mWm); + mViewRoot = new ViewRootImpl(context, display, mWm, new WindowlessWindowLayout()); addConfigCallback(context, display); WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3ed81eab9a906..bd6398445a715 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -559,7 +559,7 @@ 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 WindowLayout mWindowLayout = new WindowLayout(); + private final WindowLayout mWindowLayout; private ViewRootImpl mParentViewRoot; @@ -854,18 +854,20 @@ public final class ViewRootImpl implements ViewParent, private String mTag = TAG; public ViewRootImpl(Context context, Display display) { - this(context, display, WindowManagerGlobal.getWindowSession(), + this(context, display, WindowManagerGlobal.getWindowSession(), new WindowLayout(), false /* useSfChoreographer */); } - public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session) { - this(context, display, session, false /* useSfChoreographer */); + public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session, + WindowLayout windowLayout) { + this(context, display, session, windowLayout, false /* useSfChoreographer */); } public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session, - boolean useSfChoreographer) { + WindowLayout windowLayout, boolean useSfChoreographer) { mContext = context; mWindowSession = session; + mWindowLayout = windowLayout; mDisplay = display; mBasePackageName = context.getBasePackageName(); mThread = Thread.currentThread(); diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index aae930edb7299..85a5762f7f3d0 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -386,7 +386,7 @@ public final class WindowManagerGlobal { root = new ViewRootImpl(view.getContext(), display); } else { root = new ViewRootImpl(view.getContext(), display, - windowlessSession); + windowlessSession, new WindowlessWindowLayout()); } view.setLayoutParams(wparams); diff --git a/core/java/android/view/WindowlessWindowLayout.java b/core/java/android/view/WindowlessWindowLayout.java new file mode 100644 index 0000000000000..7cc50c579d0d6 --- /dev/null +++ b/core/java/android/view/WindowlessWindowLayout.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.view; + +import android.app.WindowConfiguration.WindowingMode; +import android.graphics.Rect; +import android.window.ClientWindowFrames; + +/** + * Computes window frames for the windowless window. + * @hide + */ +public class WindowlessWindowLayout extends WindowLayout { + + @Override + 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, ClientWindowFrames outFrames) { + outFrames.frame.set(0, 0, attrs.width, attrs.height); + outFrames.displayFrame.set(outFrames.frame); + outFrames.parentFrame.set(outFrames.frame); + } +} +