From 5242af609eee5cac1bd994ccb283d3e80721c435 Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Tue, 21 Dec 2021 22:02:46 +0800 Subject: [PATCH] Let the client set transform hint on its own This is a step to move the layout logic to the client side. We won't invoke IWindowSession#relayout then. Bug: 161810301 Test: atest WmTests Change-Id: Ib5ac048a573907af0a81f3e228575d9458862cfd --- .../android/service/wallpaper/WallpaperService.java | 11 +++++++++-- core/java/android/view/Display.java | 12 ++++++++++++ core/java/android/view/ViewRootImpl.java | 8 +++++++- data/etc/services.core.protolog.json | 6 ------ .../com/android/server/wm/WindowManagerService.java | 8 -------- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 73ffd66486d25..47064204a246d 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -271,6 +271,7 @@ public abstract class WallpaperService extends Service { private Display mDisplay; private Context mDisplayContext; private int mDisplayState; + private @Surface.Rotation int mDisplayInstallOrientation; private float mWallpaperDimAmount = 0.05f; SurfaceControl mSurfaceControl = new SurfaceControl(); @@ -1082,6 +1083,11 @@ public abstract class WallpaperService extends Service { mWindow, mLayout, mWidth, mHeight, View.VISIBLE, 0, -1, mWinFrames, mMergedConfiguration, mSurfaceControl, mInsetsState, mTempControls, mSurfaceSize); + + final int transformHint = SurfaceControl.rotationToBufferTransform( + (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); + mSurfaceControl.setTransformHint(transformHint); + if (mSurfaceControl.isValid()) { if (mBbqSurfaceControl == null) { mBbqSurfaceControl = new SurfaceControl.Builder() @@ -1095,9 +1101,9 @@ public abstract class WallpaperService extends Service { .build(); updateSurfaceDimming(); } - // Propagate transform hint from WM so we can use the right hint for the + // Propagate transform hint from WM, so we can use the right hint for the // first frame. - mBbqSurfaceControl.setTransformHint(mSurfaceControl.getTransformHint()); + mBbqSurfaceControl.setTransformHint(transformHint); Surface blastSurface = getOrCreateBLASTSurface(mSurfaceSize.x, mSurfaceSize.y, mFormat); // If blastSurface == null that means it hasn't changed since the last @@ -1335,6 +1341,7 @@ public abstract class WallpaperService extends Service { mWallpaperDimAmount = mDisplayContext.getResources().getFloat( com.android.internal.R.dimen.config_wallpaperDimAmount); mDisplayState = mDisplay.getState(); + mDisplayInstallOrientation = mDisplay.getInstallOrientation(); if (DEBUG) Log.v(TAG, "onCreate(): " + this); onCreate(mSurfaceHolder); diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 70266c1717a1f..d6e074fbe1787 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -927,6 +927,18 @@ public final class Display { } } + /** + * Returns the install orientation of the display. + * @hide + */ + @Surface.Rotation + public int getInstallOrientation() { + synchronized (mLock) { + updateDisplayInfoLocked(); + return mDisplayInfo.installOrientation; + } + } + /** * @deprecated use {@link #getRotation} * @return orientation of this display. diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 74129312b41b3..9e16c77626565 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -391,6 +391,8 @@ public final class ViewRootImpl implements ViewParent, final DisplayManager mDisplayManager; final String mBasePackageName; + private @Surface.Rotation int mDisplayInstallOrientation; + final int[] mTmpLocation = new int[2]; final TypedValue mTmpValue = new TypedValue(); @@ -1017,6 +1019,7 @@ public final class ViewRootImpl implements ViewParent, mView = view; mAttachInfo.mDisplayState = mDisplay.getState(); + mDisplayInstallOrientation = mDisplay.getInstallOrientation(); mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); mFallbackEventHandler.setView(view); mWindowAttributes.copyFrom(attrs); @@ -7898,6 +7901,10 @@ public final class ViewRootImpl implements ViewParent, mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets, mTempControls, mSurfaceSize); + final int transformHint = SurfaceControl.rotationToBufferTransform( + (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); + mSurfaceControl.setTransformHint(transformHint); + if (mAttachInfo.mContentCaptureManager != null) { MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager .getMainContentCaptureSession(); @@ -7916,7 +7923,6 @@ public final class ViewRootImpl implements ViewParent, mAttachInfo.mThreadedRenderer.setSurfaceControl(mSurfaceControl); mAttachInfo.mThreadedRenderer.setBlastBufferQueue(mBlastBufferQueue); } - int transformHint = mSurfaceControl.getTransformHint(); if (mPreviousTransformHint != transformHint) { mPreviousTransformHint = transformHint; dispatchTransformHintChanged(transformHint); diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json index 1f5f4e66c5277..6fe6c0a269549 100644 --- a/data/etc/services.core.protolog.json +++ b/data/etc/services.core.protolog.json @@ -805,12 +805,6 @@ "group": "WM_DEBUG_REMOTE_ANIMATIONS", "at": "com\/android\/server\/wm\/RemoteAnimationController.java" }, - "-1248290210": { - "message": "Passing transform hint %d for window %s", - "level": "VERBOSE", - "group": "WM_DEBUG_ORIENTATION", - "at": "com\/android\/server\/wm\/WindowManagerService.java" - }, "-1228653755": { "message": "Launch on display check: displayId=%d callingPid=%d callingUid=%d", "level": "DEBUG", diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 51605c55d5db6..c347fbd4f00d1 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -2430,14 +2430,6 @@ public class WindowManagerService extends IWindowManager.Stub configChanged = displayContent.updateOrientation(); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); - final DisplayInfo displayInfo = win.getDisplayInfo(); - final int transformHint = (displayInfo.rotation + displayInfo.installOrientation) % 4; - outSurfaceControl.setTransformHint( - SurfaceControl.rotationToBufferTransform(transformHint)); - ProtoLog.v(WM_DEBUG_ORIENTATION, - "Passing transform hint %d for window %s", - transformHint, win); - if (toBeDisplayed && win.mIsWallpaper) { displayContent.mWallpaperController.updateWallpaperOffset(win, false /* sync */); }