From 0456e9d5cbeef64414e31f61c0647e627988a6dd Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 23 Dec 2021 00:48:25 +0800 Subject: [PATCH] Let the client compute the surface size on its own This is a step to move the layout logic to the client side. We won't obtain the surface size from the server then. This CL also moves the logic about adjusting the LayoutParams of wallpaper to the client side. Bug: 161810301 Test: presubmit Change-Id: I3a81e174035c67a285cab449c0701ee2fe6f6a24 --- .../src/android/wm/RelayoutPerfTest.java | 5 +- .../service/wallpaper/WallpaperService.java | 35 +++++++++++--- core/java/android/view/IWindowSession.aidl | 4 +- core/java/android/view/ViewRootImpl.java | 20 ++++++-- core/java/android/view/WindowLayout.java | 43 +++++++++++++++++ .../android/view/WindowlessWindowManager.java | 15 +----- .../startingsurface/TaskSnapshotWindow.java | 5 +- .../java/com/android/server/wm/Session.java | 5 +- .../server/wm/WallpaperWindowToken.java | 20 -------- .../server/wm/WindowManagerService.java | 10 +--- .../com/android/server/wm/WindowState.java | 46 +++++-------------- .../server/wm/WindowStateAnimator.java | 18 ++------ .../server/wm/WindowSurfaceController.java | 6 +-- .../com/android/server/wm/WindowToken.java | 15 +++--- .../server/wm/WallpaperControllerTests.java | 16 +++---- 15 files changed, 127 insertions(+), 136 deletions(-) diff --git a/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java index 1be68f5d53a44..4b8fae68e65ff 100644 --- a/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java +++ b/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java @@ -20,7 +20,6 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat import android.app.Activity; import android.content.Context; -import android.graphics.Point; import android.os.RemoteException; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; @@ -133,7 +132,6 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase final WindowManager.LayoutParams mParams; final int mWidth; final int mHeight; - final Point mOutSurfaceSize = new Point(); final SurfaceControl mOutSurfaceControl; final IntSupplier mViewVisibility; @@ -156,8 +154,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase while (state.keepRunning()) { session.relayout(mWindow, mParams, mWidth, mHeight, mViewVisibility.getAsInt(), mFlags, mFrameNumber, mOutFrames, - mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls, - mOutSurfaceSize); + mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls); } } } diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index dd4355d3b7a19..75aaebfabf8c6 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -87,6 +87,7 @@ import android.view.SurfaceHolder; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; +import android.view.WindowLayout; import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.window.ClientWindowFrames; @@ -389,8 +390,9 @@ public abstract class WallpaperService extends Service { public void resized(ClientWindowFrames frames, boolean reportDraw, MergedConfiguration mergedConfiguration, boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId) { - Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED, - reportDraw ? 1 : 0); + Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED, + reportDraw ? 1 : 0, + mergedConfiguration); mCaller.sendMessage(msg); } @@ -1028,6 +1030,10 @@ public abstract class WallpaperService extends Service { } } + private void updateConfiguration(MergedConfiguration mergedConfiguration) { + mMergedConfiguration.setTo(mergedConfiguration); + } + void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) { if (mDestroyed) { Log.w(TAG, "Ignoring updateSurface due to destroyed"); @@ -1066,8 +1072,6 @@ public abstract class WallpaperService extends Service { mLayout.x = 0; mLayout.y = 0; - mLayout.width = myWidth; - mLayout.height = myHeight; mLayout.format = mFormat; mCurWindowFlags = mWindowFlags; @@ -1076,6 +1080,23 @@ public abstract class WallpaperService extends Service { | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + + final Configuration config = mMergedConfiguration.getMergedConfiguration(); + final Rect maxBounds = config.windowConfiguration.getMaxBounds(); + if (myWidth == ViewGroup.LayoutParams.MATCH_PARENT + && myHeight == ViewGroup.LayoutParams.MATCH_PARENT) { + mLayout.width = myWidth; + mLayout.height = myHeight; + mLayout.flags &= ~WindowManager.LayoutParams.FLAG_SCALED; + } else { + final float layoutScale = Math.max( + maxBounds.width() / (float) myWidth, + maxBounds.height() / (float) myHeight); + mLayout.width = (int) (myWidth * layoutScale + .5f); + mLayout.height = (int) (myHeight * layoutScale + .5f); + mLayout.flags |= WindowManager.LayoutParams.FLAG_SCALED; + } + mCurWindowPrivateFlags = mWindowPrivateFlags; mLayout.privateFlags = mWindowPrivateFlags; @@ -1122,11 +1143,13 @@ public abstract class WallpaperService extends Service { final int relayoutResult = mSession.relayout( mWindow, mLayout, mWidth, mHeight, View.VISIBLE, 0, -1, mWinFrames, mMergedConfiguration, mSurfaceControl, - mInsetsState, mTempControls, mSurfaceSize); + mInsetsState, mTempControls); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); mSurfaceControl.setTransformHint(transformHint); + WindowLayout.computeSurfaceSize(mLayout, maxBounds, mWidth, mHeight, + mWinFrames.frame, false /* dragResizing */, mSurfaceSize); if (mSurfaceControl.isValid()) { if (mBbqSurfaceControl == null) { @@ -1164,7 +1187,6 @@ public abstract class WallpaperService extends Service { int h = mWinFrames.frame.height(); final DisplayCutout rawCutout = mInsetsState.getDisplayCutout(); - final Configuration config = getResources().getConfiguration(); final Rect visibleFrame = new Rect(mWinFrames.frame); visibleFrame.intersect(mInsetsState.getDisplayFrame()); WindowInsets windowInsets = mInsetsState.calculateInsets(visibleFrame, @@ -2321,6 +2343,7 @@ public abstract class WallpaperService extends Service { } break; case MSG_WINDOW_RESIZED: { final boolean reportDraw = message.arg1 != 0; + mEngine.updateConfiguration(((MergedConfiguration) message.obj)); mEngine.updateSurface(true, false, reportDraw); mEngine.doOffsetsChanged(true); mEngine.scaleAndCropScreenshot(); diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl index 62265663804f7..df0eb8955fd5c 100644 --- a/core/java/android/view/IWindowSession.aidl +++ b/core/java/android/view/IWindowSession.aidl @@ -97,7 +97,6 @@ interface IWindowSession { * since it was last displayed. * @param outSurface Object in which is placed the new display surface. * @param insetsState The current insets state in the system. - * @param outSurfaceSize The width and height of the surface control * * @return int Result flags: {@link WindowManagerGlobal#RELAYOUT_SHOW_FOCUS}, * {@link WindowManagerGlobal#RELAYOUT_FIRST_TIME}. @@ -106,8 +105,7 @@ interface IWindowSession { int requestedWidth, int requestedHeight, int viewVisibility, int flags, long frameNumber, out ClientWindowFrames outFrames, out MergedConfiguration outMergedConfiguration, out SurfaceControl outSurfaceControl, - out InsetsState insetsState, out InsetsSourceControl[] activeControls, - out Point outSurfaceSize); + out InsetsState insetsState, out InsetsSourceControl[] activeControls); /* * Notify the window manager that an application is relaunching and diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 97b5a3181dbf8..14f940dc51bbf 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -83,6 +83,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; import static android.view.WindowManager.LayoutParams.TYPE_TOAST; import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; +import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED; +import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM; import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.IME_FOCUS_CONTROLLER; import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.INSETS_CONTROLLER; @@ -2868,9 +2870,9 @@ public final class ViewRootImpl implements ViewParent, } relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); final boolean freeformResizing = (relayoutResult - & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; + & RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; final boolean dockedResizing = (relayoutResult - & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; + & RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; final boolean dragResizing = freeformResizing || dockedResizing; if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC) != 0) { if (DEBUG_BLAST) { @@ -7928,22 +7930,30 @@ public final class ViewRootImpl implements ViewParent, } } + final int requestedWidth = (int) (mView.getMeasuredWidth() * appScale + 0.5f); + final int requestedHeight = (int) (mView.getMeasuredHeight() * appScale + 0.5f); + long frameNumber = -1; if (mSurface.isValid()) { frameNumber = mSurface.getNextFrameNumber(); } int relayoutResult = mWindowSession.relayout(mWindow, params, - (int) (mView.getMeasuredWidth() * appScale + 0.5f), - (int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility, + requestedWidth, requestedHeight, viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, frameNumber, mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets, - mTempControls, mSurfaceSize); + mTempControls); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); mSurfaceControl.setTransformHint(transformHint); + final WindowConfiguration winConfig = getConfiguration().windowConfiguration; + final boolean dragResizing = (relayoutResult + & (RELAYOUT_RES_DRAG_RESIZING_DOCKED | RELAYOUT_RES_DRAG_RESIZING_FREEFORM)) != 0; + WindowLayout.computeSurfaceSize(mWindowAttributes, winConfig.getMaxBounds(), requestedWidth, + requestedHeight, mTmpFrames.frame, dragResizing, mSurfaceSize); + if (mAttachInfo.mContentCaptureManager != null) { MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager .getMainContentCaptureSession(); diff --git a/core/java/android/view/WindowLayout.java b/core/java/android/view/WindowLayout.java index e5c7d6db37a91..27f89ec4ac79e 100644 --- a/core/java/android/view/WindowLayout.java +++ b/core/java/android/view/WindowLayout.java @@ -36,6 +36,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; import android.app.WindowConfiguration; import android.app.WindowConfiguration.WindowingMode; import android.graphics.Insets; +import android.graphics.Point; import android.graphics.Rect; import android.util.Log; @@ -258,6 +259,7 @@ public class WindowLayout { + " outFrame=" + outFrame.toShortString() + " outParentFrame=" + outParentFrame.toShortString() + " outDisplayFrame=" + outDisplayFrame.toShortString() + + " windowBounds=" + windowBounds.toShortString() + " attachedWindowFrame=" + (attachedWindowFrame != null ? attachedWindowFrame.toShortString() : "null") @@ -272,4 +274,45 @@ public class WindowLayout { return clippedByDisplayCutout; } + + public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds, + int requestedWidth, int requestedHeight, Rect winFrame, boolean dragResizing, + Point outSurfaceSize) { + int width; + int height; + if ((attrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) { + // For a scaled surface, we always want the requested size. + width = requestedWidth; + height = requestedHeight; + } else { + // When we're doing a drag-resizing, request a surface that's fullscreen size, + // so that we don't need to reallocate during the process. This also prevents + // buffer drops due to size mismatch. + if (dragResizing) { + // The maxBounds should match the display size which applies fixed-rotation + // transformation if there is any. + width = maxBounds.width(); + height = maxBounds.height(); + } else { + width = winFrame.width(); + height = winFrame.height(); + } + } + + // This doesn't necessarily mean that there is an error in the system. The sizes might be + // incorrect, because it is before the first layout or draw. + if (width < 1) { + width = 1; + } + if (height < 1) { + height = 1; + } + + // Adjust for surface insets. + final Rect surfaceInsets = attrs.surfaceInsets; + width += surfaceInsets.left + surfaceInsets.right; + height += surfaceInsets.top + surfaceInsets.bottom; + + outSurfaceSize.set(width, height); + } } diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java index 998498b0799a1..5d6e2e94d792a 100644 --- a/core/java/android/view/WindowlessWindowManager.java +++ b/core/java/android/view/WindowlessWindowManager.java @@ -19,7 +19,6 @@ package android.view; import android.annotation.Nullable; import android.content.res.Configuration; import android.graphics.PixelFormat; -import android.graphics.Point; import android.graphics.Rect; import android.graphics.Region; import android.os.IBinder; @@ -267,7 +266,7 @@ public class WindowlessWindowManager implements IWindowSession { int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber, ClientWindowFrames outFrames, MergedConfiguration mergedConfiguration, SurfaceControl outSurfaceControl, InsetsState outInsetsState, - InsetsSourceControl[] outActiveControls, Point outSurfaceSize) { + InsetsSourceControl[] outActiveControls) { final State state; synchronized (this) { state = mStateForWindow.get(window.asBinder()); @@ -286,7 +285,6 @@ public class WindowlessWindowManager implements IWindowSession { WindowManager.LayoutParams attrs = state.mParams; if (viewFlags == View.VISIBLE) { - outSurfaceSize.set(getSurfaceWidth(attrs), getSurfaceHeight(attrs)); t.setOpaque(sc, isOpaque(attrs)).show(sc).apply(); outSurfaceControl.copyFrom(sc, "WindowlessWindowManager.relayout"); } else { @@ -480,17 +478,6 @@ public class WindowlessWindowManager implements IWindowSession { return null; } - private int getSurfaceWidth(WindowManager.LayoutParams attrs) { - final Rect surfaceInsets = attrs.surfaceInsets; - return surfaceInsets != null - ? attrs.width + surfaceInsets.left + surfaceInsets.right : attrs.width; - } - private int getSurfaceHeight(WindowManager.LayoutParams attrs) { - final Rect surfaceInsets = attrs.surfaceInsets; - return surfaceInsets != null - ? attrs.height + surfaceInsets.top + surfaceInsets.bottom : attrs.height; - } - @Override public void grantEmbeddedWindowFocus(IWindow callingWindow, IBinder targetInputToken, boolean grantFocus) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/TaskSnapshotWindow.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/TaskSnapshotWindow.java index 4ecc0b6856268..2c6b3dbeb8a0b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/TaskSnapshotWindow.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/TaskSnapshotWindow.java @@ -126,9 +126,6 @@ public class TaskSnapshotWindow { */ private static final long MAX_DELAY_REMOVAL_TIME_IME_VISIBLE = 600; - //tmp vars for unused relayout params - private static final Point TMP_SURFACE_SIZE = new Point(); - private final Window mWindow; private final Runnable mClearWindowHandler; private final ShellExecutor mSplashScreenExecutor; @@ -246,7 +243,7 @@ public class TaskSnapshotWindow { Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "TaskSnapshot#relayout"); session.relayout(window, layoutParams, -1, -1, View.VISIBLE, 0, -1, tmpFrames, tmpMergedConfiguration, surfaceControl, tmpInsetsState, - tmpControls, TMP_SURFACE_SIZE); + tmpControls); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } catch (RemoteException e) { snapshotSurface.clearWindowSynced(); diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java index 7acc0c52cc4ce..05c5b1149418b 100644 --- a/services/core/java/com/android/server/wm/Session.java +++ b/services/core/java/com/android/server/wm/Session.java @@ -45,7 +45,6 @@ import android.content.ClipDescription; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ShortcutServiceInternal; -import android.graphics.Point; import android.graphics.Rect; import android.graphics.Region; import android.os.Binder; @@ -225,14 +224,14 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient { int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber, ClientWindowFrames outFrames, MergedConfiguration mergedConfiguration, SurfaceControl outSurfaceControl, InsetsState outInsetsState, - InsetsSourceControl[] outActiveControls, Point outSurfaceSize) { + InsetsSourceControl[] outActiveControls) { if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag); int res = mService.relayoutWindow(this, window, attrs, requestedWidth, requestedHeight, viewFlags, flags, frameNumber, outFrames, mergedConfiguration, outSurfaceControl, outInsetsState, - outActiveControls, outSurfaceSize); + outActiveControls); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); diff --git a/services/core/java/com/android/server/wm/WallpaperWindowToken.java b/services/core/java/com/android/server/wm/WallpaperWindowToken.java index fc154a8b3179c..36bb55e5f557d 100644 --- a/services/core/java/com/android/server/wm/WallpaperWindowToken.java +++ b/services/core/java/com/android/server/wm/WallpaperWindowToken.java @@ -28,9 +28,6 @@ import android.annotation.Nullable; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; -import android.view.DisplayInfo; -import android.view.ViewGroup; -import android.view.WindowManager; import android.view.animation.Animation; import com.android.internal.protolog.common.ProtoLog; @@ -190,23 +187,6 @@ class WallpaperWindowToken extends WindowToken { setVisible(visible); } - @Override - void adjustWindowParams(WindowState win, WindowManager.LayoutParams attrs) { - if (attrs.height == ViewGroup.LayoutParams.MATCH_PARENT - || attrs.width == ViewGroup.LayoutParams.MATCH_PARENT) { - return; - } - - final DisplayInfo displayInfo = win.getDisplayInfo(); - - final float layoutScale = Math.max( - (float) displayInfo.logicalHeight / (float) attrs.height, - (float) displayInfo.logicalWidth / (float) attrs.width); - attrs.height = (int) (attrs.height * layoutScale); - attrs.width = (int) (attrs.width * layoutScale); - attrs.flags |= WindowManager.LayoutParams.FLAG_SCALED; - } - boolean hasVisibleNotDrawnWallpaper() { if (!isVisible()) return false; for (int j = mChildren.size() - 1; j >= 0; --j) { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index c1a8ceb4f25f7..348539c3307a9 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -2182,7 +2182,7 @@ public class WindowManagerService extends IWindowManager.Stub int requestedWidth, int requestedHeight, int viewVisibility, int flags, long frameNumber, ClientWindowFrames outFrames, MergedConfiguration mergedConfiguration, SurfaceControl outSurfaceControl, InsetsState outInsetsState, - InsetsSourceControl[] outActiveControls, Point outSurfaceSize) { + InsetsSourceControl[] outActiveControls) { Arrays.fill(outActiveControls, null); int result = 0; boolean configChanged; @@ -2209,7 +2209,6 @@ public class WindowManagerService extends IWindowManager.Stub int privateFlagChanges = 0; if (attrs != null) { displayPolicy.adjustWindowParamsLw(win, attrs); - win.mToken.adjustWindowParams(win, attrs); attrs.flags = sanitizeFlagSlippery(attrs.flags, win.getName(), uid, pid); attrs.inputFeatures = sanitizeSpyWindow(attrs.inputFeatures, win.getName(), uid, pid); @@ -2497,11 +2496,6 @@ public class WindowManagerService extends IWindowManager.Stub displayContent.sendNewConfiguration(); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } - if (winAnimator.mSurfaceController != null) { - win.calculateSurfaceBounds(win.getLayoutingAttrs( - win.getWindowConfiguration().getRotation()), mTmpRect); - outSurfaceSize.set(mTmpRect.width(), mTmpRect.height()); - } getInsetsSourceControls(win, outActiveControls); } @@ -2580,7 +2574,7 @@ public class WindowManagerService extends IWindowManager.Stub WindowSurfaceController surfaceController; try { Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "createSurfaceControl"); - surfaceController = winAnimator.createSurfaceLocked(win.mAttrs.type); + surfaceController = winAnimator.createSurfaceLocked(); } finally { Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 1f837677ab363..36d508e2e762f 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1418,8 +1418,8 @@ class WindowState extends WindowContainer implements WindowManagerP return mWindowFrames.mParentFrame; } - void getCompatFrameSize(Rect outFrame) { - outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height()); + Rect getCompatFrame() { + return mWindowFrames.mCompatFrame; } WindowManager.LayoutParams getAttrs() { @@ -1608,6 +1608,15 @@ class WindowState extends WindowContainer implements WindowManagerP return getDisplayContent().getDisplayInfo(); } + @Override + public Rect getMaxBounds() { + final Rect maxBounds = mToken.getFixedRotationTransformMaxBounds(); + if (maxBounds != null) { + return maxBounds; + } + return super.getMaxBounds(); + } + /** * Returns the insets state for the window. Its sources may be the copies with visibility * modification according to the state of transient bars. @@ -5904,39 +5913,6 @@ class WindowState extends WindowContainer implements WindowManagerP mRedrawForSyncReported = false; } - void calculateSurfaceBounds(WindowManager.LayoutParams attrs, Rect outSize) { - outSize.setEmpty(); - if ((attrs.flags & FLAG_SCALED) != 0) { - // For a scaled surface, we always want the requested size. - outSize.right = mRequestedWidth; - outSize.bottom = mRequestedHeight; - } else { - // When we're doing a drag-resizing, request a surface that's fullscreen size, - // so that we don't need to reallocate during the process. This also prevents - // buffer drops due to size mismatch. - if (isDragResizing()) { - final DisplayInfo displayInfo = getDisplayInfo(); - outSize.right = displayInfo.logicalWidth; - outSize.bottom = displayInfo.logicalHeight; - } else { - getCompatFrameSize(outSize); - } - } - - // This doesn't necessarily mean that there is an error in the system. The sizes might be - // incorrect, because it is before the first layout or draw. - if (outSize.width() < 1) { - outSize.right = 1; - } - if (outSize.height() < 1) { - outSize.bottom = 1; - } - - // Adjust for surface insets. - outSize.inset(-attrs.surfaceInsets.left, -attrs.surfaceInsets.top, - -attrs.surfaceInsets.right, -attrs.surfaceInsets.bottom); - } - /** * This method is used to control whether we return the BLAST_SYNC flag * from relayoutWindow calls on this window (triggering the client to redirect diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 316051e9d242a..c17961e8a5641 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -150,8 +150,6 @@ class WindowStateAnimator { int mAttrType; - private final Rect mTmpSize = new Rect(); - /** * Handles surface changes synchronized to after the client has drawn the surface. This * transaction is currently used to reparent the old surface children to the new surface once @@ -291,7 +289,7 @@ class WindowStateAnimator { } } - WindowSurfaceController createSurfaceLocked(int windowType) { + WindowSurfaceController createSurfaceLocked() { final WindowState w = mWin; if (mSurfaceController != null) { @@ -319,16 +317,9 @@ class WindowStateAnimator { flags |= SurfaceControl.SKIP_SCREENSHOT; } - w.calculateSurfaceBounds(attrs, mTmpSize); - - final int width = mTmpSize.width(); - final int height = mTmpSize.height(); - if (DEBUG_VISIBILITY) { Slog.v(TAG, "Creating surface in session " + mSession.mSurfaceSession + " window " + this - + " w=" + width + " h=" + height - + " x=" + mTmpSize.left + " y=" + mTmpSize.top + " format=" + attrs.format + " flags=" + flags); } @@ -339,8 +330,8 @@ class WindowStateAnimator { final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; - mSurfaceController = new WindowSurfaceController(attrs.getTitle().toString(), width, - height, format, flags, this, windowType); + mSurfaceController = new WindowSurfaceController(attrs.getTitle().toString(), format, + flags, this, attrs.type); mSurfaceController.setColorSpaceAgnostic((attrs.privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC) != 0); @@ -372,8 +363,7 @@ class WindowStateAnimator { if (SHOW_LIGHT_TRANSACTIONS) { Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); WindowManagerService.logSurface(w, "CREATE pos=(" - + w.getFrame().left + "," + w.getFrame().top + ") (" - + width + "x" + height + ")" + " HIDE", false); + + w.getFrame().left + "," + w.getFrame().top + ") HIDE", false); } mLastHidden = true; diff --git a/services/core/java/com/android/server/wm/WindowSurfaceController.java b/services/core/java/com/android/server/wm/WindowSurfaceController.java index fa0d70833f65e..665857c1f045a 100644 --- a/services/core/java/com/android/server/wm/WindowSurfaceController.java +++ b/services/core/java/com/android/server/wm/WindowSurfaceController.java @@ -31,7 +31,6 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import static com.android.server.wm.WindowSurfaceControllerProto.LAYER; import static com.android.server.wm.WindowSurfaceControllerProto.SHOWN; -import android.graphics.Region; import android.os.Debug; import android.os.Trace; import android.util.Slog; @@ -76,8 +75,8 @@ class WindowSurfaceController { // Used to track whether we have called detach children on the way to invisibility. boolean mChildrenDetached; - WindowSurfaceController(String name, int w, int h, int format, - int flags, WindowStateAnimator animator, int windowType) { + WindowSurfaceController(String name, int format, int flags, WindowStateAnimator animator, + int windowType) { mAnimator = animator; title = name; @@ -91,7 +90,6 @@ class WindowSurfaceController { final SurfaceControl.Builder b = win.makeSurface() .setParent(win.getSurfaceControl()) .setName(name) - .setBufferSize(w, h) .setFormat(format) .setFlags(flags) .setMetadata(METADATA_WINDOW_TYPE, windowType) diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index e5a3b7a8748c2..6d8203c710bdd 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -430,6 +430,13 @@ class WindowToken extends WindowContainer { return isFixedRotationTransforming() ? mFixedRotationTransformState.mDisplayFrames : null; } + Rect getFixedRotationTransformMaxBounds() { + return isFixedRotationTransforming() + ? mFixedRotationTransformState.mRotatedOverrideConfiguration.windowConfiguration + .getMaxBounds() + : null; + } + Rect getFixedRotationTransformDisplayBounds() { return isFixedRotationTransforming() ? mFixedRotationTransformState.mRotatedOverrideConfiguration.windowConfiguration @@ -646,14 +653,6 @@ class WindowToken extends WindowContainer { } } - /** - * Gives a chance to this {@link WindowToken} to adjust the {@link - * android.view.WindowManager.LayoutParams} of its windows. - */ - void adjustWindowParams(WindowState win, WindowManager.LayoutParams attrs) { - } - - @CallSuper @Override public void dumpDebug(ProtoOutputStream proto, long fieldId, diff --git a/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java index caaf4e495e638..1f68608d2ce67 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java @@ -20,6 +20,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; +import static android.view.WindowManager.LayoutParams.FLAG_SCALED; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; @@ -116,6 +117,7 @@ public class WallpaperControllerTests extends WindowTestsBase { WindowManager.LayoutParams attrs = wallpaperWindow.getAttrs(); Rect bounds = dc.getBounds(); + int displayWidth = dc.getBounds().width(); int displayHeight = dc.getBounds().height(); // Use a wallpaper with a different ratio than the display @@ -123,20 +125,18 @@ public class WallpaperControllerTests extends WindowTestsBase { int wallpaperHeight = (int) (bounds.height() * 1.10); // Simulate what would be done on the client's side - attrs.width = wallpaperWidth; - attrs.height = wallpaperHeight; - attrs.flags |= FLAG_LAYOUT_NO_LIMITS; + final float layoutScale = Math.max( + displayWidth / (float) wallpaperWidth, displayHeight / (float) wallpaperHeight); + attrs.width = (int) (wallpaperWidth * layoutScale + .5f); + attrs.height = (int) (wallpaperHeight * layoutScale + .5f); + attrs.flags |= FLAG_LAYOUT_NO_LIMITS | FLAG_SCALED; attrs.gravity = Gravity.TOP | Gravity.LEFT; wallpaperWindow.getWindowFrames().mParentFrame.set(dc.getBounds()); - // Calling layoutWindowLw a first time, so adjustWindowParams gets the correct data - dc.getDisplayPolicy().layoutWindowLw(wallpaperWindow, null, dc.mDisplayFrames); - - wallpaperWindowToken.adjustWindowParams(wallpaperWindow, attrs); dc.getDisplayPolicy().layoutWindowLw(wallpaperWindow, null, dc.mDisplayFrames); assertEquals(Configuration.ORIENTATION_PORTRAIT, dc.getConfiguration().orientation); - int expectedWidth = (int) (wallpaperWidth * (displayHeight / (double) wallpaperHeight)); + int expectedWidth = (int) (wallpaperWidth * layoutScale + .5f); // Check that the wallpaper is correctly scaled assertEquals(expectedWidth, wallpaperWindow.getFrame().width());