From d95134d7c215d3959c44a8e0b94cf12e26c38181 Mon Sep 17 00:00:00 2001 From: Tiger Date: Fri, 11 Nov 2022 18:38:56 +0800 Subject: [PATCH] Refine the naming about compatible scale There can be 2 reasons that we need to apply compatible scale to a window: 1. The app doesn't support large screen. We would layout the window as if it is on a small display. And then we need to scale its window up to match the display. 2. We put a running app into a container that the size doesn't fit. We need to down-scale the app so that it can fit the container. The scaling of case 2 is also known as size-compat-scale which is fully controlled at the server side. The client shouldn't know about it. And this CL refines the naming. Fix: 258393096 Bug: 254187021 Test: presubmit Change-Id: Ifbd2ca725bed231d9e6dd8190df3dc773d4402b7 (cherry picked from commit bcbd60c45c047c625bd66d7cc018b0c65f02d3fd) Merged-In: Ifbd2ca725bed231d9e6dd8190df3dc773d4402b7 --- core/java/android/view/ViewRootImpl.java | 26 +++++++++---------- .../android/window/ClientWindowFrames.java | 10 +++---- .../com/android/server/wm/ActivityRecord.java | 4 +-- .../server/wm/LetterboxUiController.java | 5 ++-- .../server/wm/WindowManagerService.java | 4 +-- .../com/android/server/wm/WindowState.java | 20 +++++++------- .../com/android/server/wm/WindowToken.java | 2 +- .../wm/DualDisplayAreaGroupPolicyTest.java | 2 +- .../android/server/wm/SizeCompatTests.java | 2 +- 9 files changed, 37 insertions(+), 38 deletions(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index d21ba014e1667..550bf348d1c7e 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -720,7 +720,7 @@ public final class ViewRootImpl implements ViewParent, private final InsetsState mTempInsets = new InsetsState(); private final InsetsSourceControl[] mTempControls = new InsetsSourceControl[SIZE]; private final WindowConfiguration mTempWinConfig = new WindowConfiguration(); - private float mInvSizeCompatScale = 1f; + private float mInvCompatScale = 1f; final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets = new ViewTreeObserver.InternalInsetsInfo(); @@ -1119,11 +1119,11 @@ public final class ViewRootImpl implements ViewParent, private WindowConfiguration getCompatWindowConfiguration() { final WindowConfiguration winConfig = getConfiguration().windowConfiguration; - if (mInvSizeCompatScale == 1f) { + if (mInvCompatScale == 1f) { return winConfig; } mTempWinConfig.setTo(winConfig); - mTempWinConfig.scale(mInvSizeCompatScale); + mTempWinConfig.scale(mInvCompatScale); return mTempWinConfig; } @@ -1257,11 +1257,11 @@ public final class ViewRootImpl implements ViewParent, controlInsetsForCompatibility(mWindowAttributes); Rect attachedFrame = new Rect(); - final float[] sizeCompatScale = { 1f }; + final float[] compatScale = { 1f }; res = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes, getHostVisibility(), mDisplay.getDisplayId(), userId, mInsetsController.getRequestedVisibilities(), inputChannel, mTempInsets, - mTempControls, attachedFrame, sizeCompatScale); + mTempControls, attachedFrame, compatScale); if (!attachedFrame.isValid()) { attachedFrame = null; } @@ -1271,8 +1271,8 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateRectInScreenToAppWindow(attachedFrame); } mTmpFrames.attachedFrame = attachedFrame; - mTmpFrames.sizeCompatScale = sizeCompatScale[0]; - mInvSizeCompatScale = 1f / sizeCompatScale[0]; + mTmpFrames.compatScale = compatScale[0]; + mInvCompatScale = 1f / compatScale[0]; } catch (RemoteException e) { mAdded = false; mView = null; @@ -1794,24 +1794,24 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateRectInScreenToAppWindow(displayFrame); mTranslator.translateRectInScreenToAppWindow(attachedFrame); } - final float sizeCompatScale = frames.sizeCompatScale; + final float compatScale = frames.compatScale; final boolean frameChanged = !mWinFrame.equals(frame); final boolean configChanged = !mLastReportedMergedConfiguration.equals(mergedConfiguration); final boolean attachedFrameChanged = LOCAL_LAYOUT && !Objects.equals(mTmpFrames.attachedFrame, attachedFrame); final boolean displayChanged = mDisplay.getDisplayId() != displayId; final boolean resizeModeChanged = mResizeMode != resizeMode; - final boolean sizeCompatScaleChanged = mTmpFrames.sizeCompatScale != sizeCompatScale; + final boolean compatScaleChanged = mTmpFrames.compatScale != compatScale; if (msg == MSG_RESIZED && !frameChanged && !configChanged && !attachedFrameChanged && !displayChanged && !resizeModeChanged && !forceNextWindowRelayout - && !sizeCompatScaleChanged) { + && !compatScaleChanged) { return; } mPendingDragResizing = resizeMode != RESIZE_MODE_INVALID; mResizeMode = resizeMode; - mTmpFrames.sizeCompatScale = sizeCompatScale; - mInvSizeCompatScale = 1f / sizeCompatScale; + mTmpFrames.compatScale = compatScale; + mInvCompatScale = 1f / compatScale; if (configChanged) { // If configuration changed - notify about that and, maybe, about move to display. @@ -8240,7 +8240,7 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets); mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls); } - mInvSizeCompatScale = 1f / mTmpFrames.sizeCompatScale; + mInvCompatScale = 1f / mTmpFrames.compatScale; mInsetsController.onStateChanged(mTempInsets); mInsetsController.onControlsChanged(mTempControls); diff --git a/core/java/android/window/ClientWindowFrames.java b/core/java/android/window/ClientWindowFrames.java index f274d1a15ba55..0ce076b6eb96e 100644 --- a/core/java/android/window/ClientWindowFrames.java +++ b/core/java/android/window/ClientWindowFrames.java @@ -49,7 +49,7 @@ public class ClientWindowFrames implements Parcelable { public boolean isParentFrameClippedByDisplayCutout; - public float sizeCompatScale = 1f; + public float compatScale = 1f; public ClientWindowFrames() { } @@ -62,7 +62,7 @@ public class ClientWindowFrames implements Parcelable { attachedFrame = new Rect(other.attachedFrame); } isParentFrameClippedByDisplayCutout = other.isParentFrameClippedByDisplayCutout; - sizeCompatScale = other.sizeCompatScale; + compatScale = other.compatScale; } private ClientWindowFrames(Parcel in) { @@ -76,7 +76,7 @@ public class ClientWindowFrames implements Parcelable { parentFrame.readFromParcel(in); attachedFrame = in.readTypedObject(Rect.CREATOR); isParentFrameClippedByDisplayCutout = in.readBoolean(); - sizeCompatScale = in.readFloat(); + compatScale = in.readFloat(); } @Override @@ -86,7 +86,7 @@ public class ClientWindowFrames implements Parcelable { parentFrame.writeToParcel(dest, flags); dest.writeTypedObject(attachedFrame, flags); dest.writeBoolean(isParentFrameClippedByDisplayCutout); - dest.writeFloat(sizeCompatScale); + dest.writeFloat(compatScale); } @Override @@ -97,7 +97,7 @@ public class ClientWindowFrames implements Parcelable { + " parentFrame=" + parentFrame.toShortString(sb) + (attachedFrame != null ? " attachedFrame=" + attachedFrame.toShortString() : "") + (isParentFrameClippedByDisplayCutout ? " parentClippedByDisplayCutout" : "") - + (sizeCompatScale != 1f ? " sizeCompatScale=" + sizeCompatScale : "") + "}"; + + (compatScale != 1f ? " sizeCompatScale=" + compatScale : "") + "}"; } @Override diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index e19e921852ff6..206d0930e2849 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -7940,8 +7940,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } @Override - float getSizeCompatScale() { - return hasSizeCompatBounds() ? mSizeCompatScale : super.getSizeCompatScale(); + float getCompatScale() { + return hasSizeCompatBounds() ? mSizeCompatScale : super.getCompatScale(); } @Override diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 76ee733cbb279..bcea6f4db1dc5 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -576,9 +576,8 @@ final class LetterboxUiController { // Rounded corners should be displayed above the taskbar. bounds.bottom = Math.min(bounds.bottom, getTaskbarInsetsSource(mainWindow).getFrame().top); - if (mActivityRecord.inSizeCompatMode() - && mActivityRecord.getSizeCompatScale() < 1.0f) { - bounds.scale(1.0f / mActivityRecord.getSizeCompatScale()); + if (mActivityRecord.inSizeCompatMode() && mActivityRecord.getCompatScale() < 1.0f) { + bounds.scale(1.0f / mActivityRecord.getCompatScale()); } } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 68b853dd2695e..b3a7754bc2d53 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1883,7 +1883,7 @@ public class WindowManagerService extends IWindowManager.Stub // Make this invalid which indicates a null attached frame. outAttachedFrame.set(0, 0, -1, -1); } - outSizeCompatScale[0] = win.getSizeCompatScaleForClient(); + outSizeCompatScale[0] = win.getCompatScaleForClient(); } Binder.restoreCallingIdentity(origId); @@ -8866,7 +8866,7 @@ public class WindowManagerService extends IWindowManager.Stub outInsetsState.set(state, true /* copySources */); if (WindowState.hasCompatScale(attrs, token, overrideScale)) { final float compatScale = token != null && token.hasSizeCompatBounds() - ? token.getSizeCompatScale() * overrideScale + ? token.getCompatScale() * overrideScale : overrideScale; outInsetsState.scale(1f / compatScale); } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 45606f9658589..664c27db32268 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -475,7 +475,7 @@ class WindowState extends WindowContainer implements WindowManagerP // Current transformation being applied. float mGlobalScale = 1f; float mInvGlobalScale = 1f; - float mSizeCompatScale = 1f; + float mCompatScale = 1f; final float mOverrideScale; float mHScale = 1f, mVScale = 1f; float mLastHScale = 1f, mLastVScale = 1f; @@ -1254,21 +1254,21 @@ class WindowState extends WindowContainer implements WindowManagerP void updateGlobalScale() { if (hasCompatScale()) { - mSizeCompatScale = (mOverrideScale == 1f || mToken.hasSizeCompatBounds()) - ? mToken.getSizeCompatScale() + mCompatScale = (mOverrideScale == 1f || mToken.hasSizeCompatBounds()) + ? mToken.getCompatScale() : 1f; - mGlobalScale = mSizeCompatScale * mOverrideScale; + mGlobalScale = mCompatScale * mOverrideScale; mInvGlobalScale = 1f / mGlobalScale; return; } - mGlobalScale = mInvGlobalScale = mSizeCompatScale = 1f; + mGlobalScale = mInvGlobalScale = mCompatScale = 1f; } - float getSizeCompatScaleForClient() { - // If the size compat scale is because of the size compat bounds, we only scale down its - // coordinates at the server side without letting the client know. - return mToken.hasSizeCompatBounds() ? 1f : mSizeCompatScale; + float getCompatScaleForClient() { + // If this window in the size compat mode. The scaling is fully controlled at the server + // side. The client doesn't need to take it into account. + return mToken.hasSizeCompatBounds() ? 1f : mCompatScale; } /** @@ -3867,7 +3867,7 @@ class WindowState extends WindowContainer implements WindowManagerP } } - outFrames.sizeCompatScale = getSizeCompatScaleForClient(); + outFrames.compatScale = getCompatScaleForClient(); // Note: in the cases where the window is tied to an activity, we should not send a // configuration update when the window has requested to be hidden. Doing so can lead to diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index 805559035ef9f..3611a8065aef3 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -258,7 +258,7 @@ class WindowToken extends WindowContainer { * @return The scale for applications running in compatibility mode. Multiply the size in the * application by this scale will be the size in the screen. */ - float getSizeCompatScale() { + float getCompatScale() { return mDisplayContent.mCompatibleScreenScale; } diff --git a/services/tests/wmtests/src/com/android/server/wm/DualDisplayAreaGroupPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/DualDisplayAreaGroupPolicyTest.java index 2956c14155b93..3ab4495bd7ca4 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DualDisplayAreaGroupPolicyTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/DualDisplayAreaGroupPolicyTest.java @@ -206,7 +206,7 @@ public class DualDisplayAreaGroupPolicyTest extends WindowTestsBase { assertThat(newTaskBounds).isEqualTo(newDagBounds); // Activity config bounds is unchanged, size compat bounds is (860x[860x860/1200=616]) - assertThat(mFirstActivity.getSizeCompatScale()).isLessThan(1f); + assertThat(mFirstActivity.getCompatScale()).isLessThan(1f); assertThat(activityConfigBounds.width()).isEqualTo(activityBounds.width()); assertThat(activityConfigBounds.height()).isEqualTo(activityBounds.height()); assertThat(activitySizeCompatBounds.height()).isEqualTo(newTaskBounds.height()); diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 06eea298600c1..17108359ab894 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -3205,7 +3205,7 @@ public class SizeCompatTests extends WindowTestsBase { /** Asserts that the size of activity is larger than its parent so it is scaling. */ private void assertScaled() { assertTrue(mActivity.inSizeCompatMode()); - assertNotEquals(1f, mActivity.getSizeCompatScale(), 0.0001f /* delta */); + assertNotEquals(1f, mActivity.getCompatScale(), 0.0001f /* delta */); } /** Asserts that the activity is best fitted in the parent. */