diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 81e0852fdfa26..23de215eeefc5 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -1598,97 +1598,6 @@ public final class SurfaceControl implements Parcelable { } } - /** - * @hide - */ - public void deferTransactionUntil(SurfaceControl barrier, long frame) { - synchronized(SurfaceControl.class) { - sGlobalTransaction.deferTransactionUntil(this, barrier, frame); - } - } - - /** - * @hide - */ - public void reparentChildren(SurfaceControl newParent) { - synchronized(SurfaceControl.class) { - sGlobalTransaction.reparentChildren(this, newParent); - } - } - - /** - * @hide - */ - public void detachChildren() { - synchronized(SurfaceControl.class) { - sGlobalTransaction.detachChildren(this); - } - } - - /** - * @hide - */ - @UnsupportedAppUsage - public void setLayer(int zorder) { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.setLayer(this, zorder); - } - } - - /** - * @hide - */ - @UnsupportedAppUsage - public void setPosition(float x, float y) { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.setPosition(this, x, y); - } - } - - /** - * @hide - */ - public void setBufferSize(int w, int h) { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.setBufferSize(this, w, h); - } - } - - /** - * @hide - */ - @UnsupportedAppUsage - public void hide() { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.hide(this); - } - } - - /** - * @hide - */ - @UnsupportedAppUsage - public void show() { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.show(this); - } - } - - /** - * @hide - */ - public void setTransparentRegionHint(Region region) { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.setTransparentRegionHint(this, region); - } - } - /** * @hide */ @@ -1719,87 +1628,6 @@ public final class SurfaceControl implements Parcelable { return nativeGetAnimationFrameStats(outStats); } - /** - * @hide - */ - public void setAlpha(float alpha) { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.setAlpha(this, alpha); - } - } - - /** - * @hide - */ - public void setBackgroundBlurRadius(int blur) { - checkNotReleased(); - synchronized (SurfaceControl.class) { - sGlobalTransaction.setBackgroundBlurRadius(this, blur); - } - } - - /** - * @hide - */ - public void setMatrix(float dsdx, float dtdx, float dtdy, float dsdy) { - checkNotReleased(); - synchronized(SurfaceControl.class) { - sGlobalTransaction.setMatrix(this, dsdx, dtdx, dtdy, dsdy); - } - } - - /** - * Sets the Surface to be color space agnostic. If a surface is color space agnostic, - * the color can be interpreted in any color space. - * @param agnostic A boolean to indicate whether the surface is color space agnostic - * @hide - */ - public void setColorSpaceAgnostic(boolean agnostic) { - checkNotReleased(); - synchronized (SurfaceControl.class) { - sGlobalTransaction.setColorSpaceAgnostic(this, agnostic); - } - } - - /** - * Bounds the surface and its children to the bounds specified. Size of the surface will be - * ignored and only the crop and buffer size will be used to determine the bounds of the - * surface. If no crop is specified and the surface has no buffer, the surface bounds is only - * constrained by the size of its parent bounds. - * - * @param crop Bounds of the crop to apply. - * @hide - */ - public void setWindowCrop(Rect crop) { - checkNotReleased(); - synchronized (SurfaceControl.class) { - sGlobalTransaction.setWindowCrop(this, crop); - } - } - - /** - * @hide - */ - public void setOpaque(boolean isOpaque) { - checkNotReleased(); - - synchronized (SurfaceControl.class) { - sGlobalTransaction.setOpaque(this, isOpaque); - } - } - - /** - * @hide - */ - public void setSecure(boolean isSecure) { - checkNotReleased(); - - synchronized (SurfaceControl.class) { - sGlobalTransaction.setSecure(this, isSecure); - } - } - /** * @hide */ diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 113f4d856bdd9..520b833fa8876 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -95,18 +95,18 @@ import static android.view.Display.COLOR_MODE_DEFAULT; import static android.view.Display.INVALID_DISPLAY; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; -import static android.view.WindowManager.TRANSIT_CLOSE; -import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE; -import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE; -import static android.view.WindowManager.TRANSIT_OLD_TASK_OPEN_BEHIND; -import static android.view.WindowManager.TRANSIT_OLD_UNSET; +import static android.view.SurfaceControl.getGlobalTransaction; import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; +import static android.view.WindowManager.TRANSIT_CLOSE; import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND; +import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE; +import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE; +import static android.view.WindowManager.TRANSIT_OLD_UNSET; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; @@ -182,7 +182,6 @@ import static com.android.server.wm.IdentifierProto.USER_ID; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_RECENTS; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION; -import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE; import static com.android.server.wm.Task.ActivityState.DESTROYED; import static com.android.server.wm.Task.ActivityState.DESTROYING; import static com.android.server.wm.Task.ActivityState.FINISHING; @@ -194,6 +193,7 @@ import static com.android.server.wm.Task.ActivityState.RESUMED; import static com.android.server.wm.Task.ActivityState.STARTED; import static com.android.server.wm.Task.ActivityState.STOPPED; import static com.android.server.wm.Task.ActivityState.STOPPING; +import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE; import static com.android.server.wm.TaskPersister.DEBUG; import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION; import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; @@ -3137,7 +3137,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A SurfaceControl.openTransaction(); for (int i = mChildren.size() - 1; i >= 0; i--) { final WindowState w = mChildren.get(i); - w.mWinAnimator.detachChildren(); + w.mWinAnimator.detachChildren(getGlobalTransaction()); } SurfaceControl.closeTransaction(); } @@ -4449,7 +4449,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A SurfaceControl.openTransaction(); try { forAllWindows(win -> { - win.mWinAnimator.hide("immediately hidden"); }, true); + win.mWinAnimator.hide(getGlobalTransaction(), "immediately hidden"); + }, true); } finally { SurfaceControl.closeTransaction(); } diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 0678a5e4383bd..88914e31d5ac1 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -3401,6 +3401,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp boolean destroyLeakedSurfaces() { // Used to indicate that a surface was leaked. mTmpWindow = null; + final Transaction t = mWmService.mTransactionFactory.get(); forAllWindows(w -> { final WindowStateAnimator wsa = w.mWinAnimator; if (wsa.mSurfaceController == null) { @@ -3412,7 +3413,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp + " token=" + w.mToken + " pid=" + w.mSession.mPid + " uid=" + w.mSession.mUid); - wsa.destroySurface(); + wsa.destroySurface(t); mWmService.mForceRemoves.add(w); mTmpWindow = w; } else if (w.mActivityRecord != null && !w.mActivityRecord.isClientVisible()) { @@ -3420,10 +3421,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp + w + " surface=" + wsa.mSurfaceController + " token=" + w.mActivityRecord); ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE LEAK DESTROY: %s", w); - wsa.destroySurface(); + wsa.destroySurface(t); mTmpWindow = w; } }, false /* traverseTopToBottom */); + t.apply(); return mTmpWindow != null; } diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 497087a967f3d..169d5f2155ed4 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -778,7 +778,9 @@ class RootWindowContainer extends WindowContainer if (surfaceController != null) { ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE RECOVER DESTROY: %s", winAnimator.mWin); - winAnimator.destroySurface(); + SurfaceControl.Transaction t = mWmService.mTransactionFactory.get(); + winAnimator.destroySurface(t); + t.apply(); if (winAnimator.mWin.mActivityRecord != null) { winAnimator.mWin.mActivityRecord.removeStartingWindow(); } @@ -926,7 +928,7 @@ class RootWindowContainer extends WindowContainer displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; } win.destroySurfaceUnchecked(); - win.mWinAnimator.destroyPreservedSurfaceLocked(); + win.mWinAnimator.destroyPreservedSurfaceLocked(win.getSyncTransaction()); } while (i > 0); mWmService.mDestroySurface.clear(); } diff --git a/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java b/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java index 3def0911bd766..1779d2a394eb3 100644 --- a/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java +++ b/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java @@ -60,7 +60,7 @@ class TaskScreenshotAnimatable implements SurfaceAnimator.Animatable { surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace()); surface.release(); final float scale = 1.0f * mTask.getBounds().width() / mWidth; - mSurfaceControl.setMatrix(scale, 0, 0, scale); + getPendingTransaction().setMatrix(mSurfaceControl, scale, 0, 0, scale); } getPendingTransaction().show(mSurfaceControl); } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8fd342c25bc32..f233199365360 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -48,6 +48,7 @@ import static android.provider.Settings.Global.DEVELOPMENT_RENDER_SHADOWS_IN_COM import static android.provider.Settings.Global.DEVELOPMENT_WM_DISPLAY_SETTINGS_PATH; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.INVALID_DISPLAY; +import static android.view.SurfaceControl.getGlobalTransaction; import static android.view.WindowManager.DISPLAY_IME_POLICY_FALLBACK_DISPLAY; import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; @@ -2557,7 +2558,7 @@ public class WindowManagerService extends IWindowManager.Stub // side child surfaces, so they will remain preserved in their current state // (rather than be cleaned up immediately by the app code). SurfaceControl.openTransaction(); - winAnimator.detachChildren(); + winAnimator.detachChildren(getGlobalTransaction()); SurfaceControl.closeTransaction(); return focusMayChange; @@ -5349,7 +5350,7 @@ public class WindowManagerService extends IWindowManager.Stub void destroyPreservedSurfaceLocked() { for (int i = mDestroyPreservedSurface.size() - 1; i >= 0 ; i--) { final WindowState w = mDestroyPreservedSurface.get(i); - w.mWinAnimator.destroyPreservedSurfaceLocked(); + w.mWinAnimator.destroyPreservedSurfaceLocked(w.getSyncTransaction()); } mDestroyPreservedSurface.clear(); } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index bc8699e2ee394..3bbdcb8dfedd3 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -32,6 +32,7 @@ import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.SurfaceControl.Transaction; +import static android.view.SurfaceControl.getGlobalTransaction; import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; @@ -617,6 +618,8 @@ class WindowState extends WindowContainer implements WindowManagerP private final Rect mTmpRect = new Rect(); private final Point mTmpPoint = new Point(); + private final Transaction mTmpTransaction; + /** * If a window is on a display which has been re-parented to a view in another window, * use this offset to indicate the correct location. @@ -861,6 +864,7 @@ class WindowState extends WindowContainer implements WindowManagerP int ownerId, int showUserId, boolean ownerCanAddInternalSystemWindow, PowerManagerWrapper powerManagerWrapper) { super(service); + mTmpTransaction = service.mTransactionFactory.get(); mSession = s; mClient = c; mAppOp = appOp; @@ -2176,8 +2180,9 @@ class WindowState extends WindowContainer implements WindowManagerP disposeInputChannel(); - mWinAnimator.destroyDeferredSurfaceLocked(); - mWinAnimator.destroySurfaceLocked(); + mWinAnimator.destroyDeferredSurfaceLocked(mTmpTransaction); + mWinAnimator.destroySurfaceLocked(mTmpTransaction); + mTmpTransaction.apply(); mSession.windowRemovedLocked(); try { mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); @@ -2645,7 +2650,7 @@ class WindowState extends WindowContainer implements WindowManagerP clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY); } if (!isVisibleByPolicy()) { - mWinAnimator.hide("checkPolicyVisibilityChange"); + mWinAnimator.hide(getGlobalTransaction(), "checkPolicyVisibilityChange"); if (isFocused()) { ProtoLog.i(WM_DEBUG_FOCUS_LIGHT, "setAnimationLocked: setting mFocusMayChange true"); @@ -3176,10 +3181,10 @@ class WindowState extends WindowContainer implements WindowManagerP // detaching any surface control the client added from the client. for (int i = mChildren.size() - 1; i >= 0; --i) { final WindowState c = mChildren.get(i); - c.mWinAnimator.detachChildren(); + c.mWinAnimator.detachChildren(getGlobalTransaction()); } - mWinAnimator.detachChildren(); + mWinAnimator.detachChildren(getGlobalTransaction()); } try { @@ -3238,7 +3243,8 @@ class WindowState extends WindowContainer implements WindowManagerP } if (appStopped || mWindowRemovalAllowed) { - mWinAnimator.destroyPreservedSurfaceLocked(); + mWinAnimator.destroyPreservedSurfaceLocked(mTmpTransaction); + mTmpTransaction.apply(); } if (mDestroying) { @@ -3274,7 +3280,8 @@ class WindowState extends WindowContainer implements WindowManagerP // various indicators of whether the client has released the surface. // This is in general unsafe, and most callers should use {@link #destroySurface} void destroySurfaceUnchecked() { - mWinAnimator.destroySurfaceLocked(); + mWinAnimator.destroySurfaceLocked(mTmpTransaction); + mTmpTransaction.apply(); // Clear animating flags now, since the surface is now gone. (Note this is true even // if the surface is saved, to outside world the surface is still NO_SURFACE.) @@ -4800,7 +4807,7 @@ class WindowState extends WindowContainer implements WindowManagerP c.hideWallpaperWindow(wasDeferred, reason); } if (!mWinAnimator.mLastHidden || wasDeferred) { - mWinAnimator.hide(reason); + mWinAnimator.hide(getGlobalTransaction(), reason); getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null; dispatchWallpaperVisibility(false); final DisplayContent displayContent = getDisplayContent(); @@ -4942,7 +4949,7 @@ class WindowState extends WindowContainer implements WindowManagerP // on the new one. This prevents blinking when we change elevation of freeform and // pinned windows. if (!mWinAnimator.tryChangeFormatInPlaceLocked()) { - mWinAnimator.preserveSurfaceLocked(getPendingTransaction()); + mWinAnimator.preserveSurfaceLocked(getSyncTransaction()); result |= RELAYOUT_RES_SURFACE_CHANGED | RELAYOUT_RES_FIRST_TIME; scheduleAnimation(); @@ -4961,7 +4968,7 @@ class WindowState extends WindowContainer implements WindowManagerP // to preserve and destroy windows which are attached to another, they // will keep their surface and its size may change over time. if (mHasSurface && !isChildWindow()) { - mWinAnimator.preserveSurfaceLocked(getPendingTransaction()); + mWinAnimator.preserveSurfaceLocked(getSyncTransaction()); result |= RELAYOUT_RES_SURFACE_CHANGED | RELAYOUT_RES_FIRST_TIME; scheduleAnimation(); @@ -5264,7 +5271,7 @@ class WindowState extends WindowContainer implements WindowManagerP updateFrameRateSelectionPriorityIfNeeded(); updateGlobalScaleIfNeeded(); - mWinAnimator.prepareSurfaceLocked(SurfaceControl.getGlobalTransaction(), true); + mWinAnimator.prepareSurfaceLocked(getSyncTransaction()); super.prepareSurfaces(); } diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 9cc72a2ddf7c2..068d0dfd0602d 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -57,7 +57,6 @@ import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_C import android.content.Context; import android.graphics.Matrix; import android.graphics.PixelFormat; -import android.graphics.Point; import android.graphics.Rect; import android.graphics.Region; import android.os.Debug; @@ -130,10 +129,6 @@ class WindowStateAnimator { float mAlpha = 0; float mLastAlpha = 0; - Rect mTmpStackBounds = new Rect(); - private Rect mTmpAnimatingBounds = new Rect(); - private Rect mTmpSourceBounds = new Rect(); - /** * This is rectangle of the window's surface that is not covered by * system decorations. @@ -154,8 +149,6 @@ class WindowStateAnimator { * window is first added or shown, cleared when the callback has been made. */ boolean mEnteringAnimation; - private final SurfaceControl.Transaction mTmpTransaction; - /** The pixel format of the underlying SurfaceControl */ int mSurfaceFormat; @@ -201,12 +194,6 @@ class WindowStateAnimator { // region. float mWallpaperScale = 1f; - /** - * A flag to determine if the WSA needs to offset its position to compensate for the stack's - * position update before the WSA surface has resized. - */ - private boolean mOffsetPositionForStackResize; - private final Rect mTmpSize = new Rect(); /** @@ -220,13 +207,10 @@ class WindowStateAnimator { private final SurfaceControl.Transaction mPostDrawTransaction = new SurfaceControl.Transaction(); - private final Point mTmpPos = new Point(); - WindowStateAnimator(final WindowState win) { final WindowManagerService service = win.mWmService; mService = service; - mTmpTransaction = service.mTransactionFactory.get(); mAnimator = service.mAnimator; mPolicy = service.mPolicy; mContext = service.mContext; @@ -243,7 +227,7 @@ class WindowStateAnimator { if (DEBUG_ANIM) Slog.v( TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit + ", reportedVisible=" - + (mWin.mActivityRecord != null ? mWin.mActivityRecord.reportedVisible : false)); + + (mWin.mActivityRecord != null && mWin.mActivityRecord.reportedVisible)); mWin.checkPolicyVisibilityChange(); final DisplayContent displayContent = mWin.getDisplayContent(); @@ -284,11 +268,6 @@ class WindowStateAnimator { } } - void hide(String reason) { - hide(mTmpTransaction, reason); - SurfaceControl.mergeToGlobalTransaction(mTmpTransaction); - } - boolean finishDrawingLocked(SurfaceControl.Transaction postDrawTransaction) { final boolean startingWindow = mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; @@ -362,7 +341,7 @@ class WindowStateAnimator { mSurfaceController.mSurfaceControl, mPendingDestroySurface.mSurfaceControl).apply(); } - destroySurfaceLocked(); + destroySurfaceLocked(t); mSurfaceDestroyDeferred = true; return; } @@ -375,10 +354,10 @@ class WindowStateAnimator { } mDestroyPreservedSurfaceUponRedraw = true; mSurfaceDestroyDeferred = true; - destroySurfaceLocked(); + destroySurfaceLocked(t); } - void destroyPreservedSurfaceLocked() { + void destroyPreservedSurfaceLocked(SurfaceControl.Transaction t) { if (!mDestroyPreservedSurfaceUponRedraw) { return; } @@ -397,7 +376,7 @@ class WindowStateAnimator { mSurfaceController.mSurfaceControl).apply(); } - destroyDeferredSurfaceLocked(); + destroyDeferredSurfaceLocked(t); mDestroyPreservedSurfaceUponRedraw = false; } @@ -484,7 +463,6 @@ class WindowStateAnimator { mSurfaceController.setColorSpaceAgnostic((attrs.privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC) != 0); - setOffsetPositionForStackResize(false); mSurfaceFormat = format; w.setHasSurface(true); @@ -529,7 +507,7 @@ class WindowStateAnimator { return mSurfaceController != null && mSurfaceController.hasSurface(); } - void destroySurfaceLocked() { + void destroySurfaceLocked(SurfaceControl.Transaction t) { final ActivityRecord activity = mWin.mActivityRecord; if (activity != null) { if (mWin == activity.mStartingWindow) { @@ -557,14 +535,14 @@ class WindowStateAnimator { if (mPendingDestroySurface != null) { ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s", mWin, new RuntimeException().fillInStackTrace()); - mPendingDestroySurface.destroyNotInTransaction(); + mPendingDestroySurface.destroy(t); } mPendingDestroySurface = mSurfaceController; } } else { ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY: %s. %s", mWin, new RuntimeException().fillInStackTrace()); - destroySurface(); + destroySurface(t); } // Don't hide wallpaper if we're deferring the surface destroy // because of a surface change. @@ -587,12 +565,12 @@ class WindowStateAnimator { mDrawState = NO_SURFACE; } - void destroyDeferredSurfaceLocked() { + void destroyDeferredSurfaceLocked(SurfaceControl.Transaction t) { try { if (mPendingDestroySurface != null) { ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s", mWin, new RuntimeException().fillInStackTrace()); - mPendingDestroySurface.destroyNotInTransaction(); + mPendingDestroySurface.destroy(t); // Don't hide wallpaper if we're destroying a deferred surface // after a surface mode change. if (!mDestroyPreservedSurfaceUponRedraw) { @@ -655,93 +633,49 @@ class WindowStateAnimator { return true; } - void setSurfaceBoundariesLocked(SurfaceControl.Transaction t, final boolean recoveringMemory) { + void setSurfaceBoundariesLocked(SurfaceControl.Transaction t) { if (mSurfaceController == null) { return; } final WindowState w = mWin; - final LayoutParams attrs = mWin.getAttrs(); final Task task = w.getTask(); if (shouldConsumeMainWindowSizeTransaction()) { - t.deferTransactionUntil(task.getMainWindowSizeChangeTask().getSurfaceControl(), - mWin.getClientViewRootSurface(), mWin.getFrameNumber()); - t.deferTransactionUntil(mSurfaceController.mSurfaceControl, - mWin.getClientViewRootSurface(), mWin.getFrameNumber()); - t.merge(task.getMainWindowSizeChangeTransaction()); + // Use pending transaction here instead of the transaction passed in because we want to + // ensure the defer transaction is applied on the main transaction and not on the sync + // transaction. This is because the sync transaction could contain the buffer and we'd + // defer the transaction that contains the buffer we're deferring on. + SurfaceControl.Transaction pendingTransaction = mWin.getPendingTransaction(); + pendingTransaction.deferTransactionUntil( + task.getMainWindowSizeChangeTask().getSurfaceControl(), + mWin.getClientViewRootSurface(), mWin.getFrameNumber()); + pendingTransaction.deferTransactionUntil(mSurfaceController.mSurfaceControl, + mWin.getClientViewRootSurface(), mWin.getFrameNumber()); + pendingTransaction.merge(task.getMainWindowSizeChangeTransaction()); task.setMainWindowSizeChangeTransaction(null); } - float surfaceWidth = mSurfaceController.getWidth(); - float surfaceHeight = mSurfaceController.getHeight(); - - final Rect insets = attrs.surfaceInsets; - - // getFrameNumber is only valid in the call-stack of relayoutWindow - // as this is the only-time we know the client renderer - // is paused. - final boolean relayout = !w.mRelayoutCalled || w.mInRelayout; - if (!w.mSeamlesslyRotated) { // Used to offset the WSA when stack position changes before a resize. int xOffset = mXOffset; int yOffset = mYOffset; - if (mOffsetPositionForStackResize) { - if (relayout) { - // Once a relayout is called, reset the offset back to 0 and defer - // setting it until a new frame with the updated size. This ensures that - // the WS position is reset (so the stack position is shown) at the same - // time that the buffer size changes. - setOffsetPositionForStackResize(false); - t.deferTransactionUntil(mSurfaceController.mSurfaceControl, - mWin.getClientViewRootSurface(), mWin.getFrameNumber()); - } else { - final Task stack = mWin.getRootTask(); - mTmpPos.x = 0; - mTmpPos.y = 0; - if (stack != null) { - stack.getRelativePosition(mTmpPos); - } - xOffset = -mTmpPos.x; - yOffset = -mTmpPos.y; - } - } - if (!mIsWallpaper) { - mSurfaceController.setPosition(t, xOffset, yOffset, recoveringMemory); - } else { - setWallpaperPositionAndScale(t, - xOffset, yOffset, mWallpaperScale, recoveringMemory); - } - } - - if (!w.mSeamlesslyRotated) { - // Wallpaper is already updated above when calling setWallpaperPositionAndScale so - // we only need to consider the non-wallpaper case here. if (!mIsWallpaper) { + mSurfaceController.setPosition(t, xOffset, yOffset); + // Wallpaper is already updated above when calling setWallpaperPositionAndScale so + // we only need to consider the non-wallpaper case here. mSurfaceController.setMatrix(t, - mDsDx * w.mHScale, - mDtDx * w.mVScale, - mDtDy * w.mHScale, - mDsDy * w.mVScale, recoveringMemory); + mDsDx * w.mHScale, + mDtDx * w.mVScale, + mDtDy * w.mHScale, + mDsDy * w.mVScale); + } else { + setWallpaperPositionAndScale(t, xOffset, yOffset, mWallpaperScale); } } } - /** - * Get rect of the task this window is currently in. If there is no task, rect will be set to - * empty. - */ - void getContainerRect(Rect rect) { - final Task task = mWin.getTask(); - if (task != null) { - task.getDimBounds(rect); - } else { - rect.left = rect.top = rect.right = rect.bottom = 0; - } - } - - void prepareSurfaceLocked(SurfaceControl.Transaction t, final boolean recoveringMemory) { + void prepareSurfaceLocked(SurfaceControl.Transaction t) { final WindowState w = mWin; if (!hasSurface()) { @@ -758,13 +692,13 @@ class WindowStateAnimator { computeShownFrameLocked(); - setSurfaceBoundariesLocked(t, recoveringMemory); + setSurfaceBoundariesLocked(t); if (mIsWallpaper && !w.mWallpaperVisible) { // Wallpaper is no longer visible and there is no wp target => hide it. - hide("prepareSurfaceLocked"); + hide(t, "prepareSurfaceLocked"); } else if (w.isParentWindowHidden() || !w.isOnScreen()) { - hide("prepareSurfaceLocked"); + hide(t, "prepareSurfaceLocked"); mWallpaperControllerLocked.hideWallpapers(w); // If we are waiting for this window to handle an orientation change. If this window is @@ -800,21 +734,20 @@ class WindowStateAnimator { boolean prepared = true; if (mIsWallpaper) { - setWallpaperPositionAndScale(t, - mXOffset, mYOffset, mWallpaperScale, recoveringMemory); + setWallpaperPositionAndScale(t, mXOffset, mYOffset, mWallpaperScale); } else { prepared = - mSurfaceController.prepareToShowInTransaction(mShownAlpha, + mSurfaceController.prepareToShowInTransaction(t, mShownAlpha, mDsDx * w.mHScale, mDtDx * w.mVScale, mDtDy * w.mHScale, - mDsDy * w.mVScale, - recoveringMemory); + mDsDy * w.mVScale + ); } if (prepared && mDrawState == HAS_DRAWN) { if (mLastHidden) { - if (showSurfaceRobustlyLocked()) { + if (showSurfaceRobustlyLocked(t)) { markPreservedSurfaceForDestroy(); mAnimator.requestRemovalOfReplacedWindows(w); mLastHidden = false; @@ -888,8 +821,7 @@ class WindowStateAnimator { Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset"); } mService.openSurfaceTransaction(); - setWallpaperPositionAndScale(SurfaceControl.getGlobalTransaction(), - dx, dy, scale, false); + setWallpaperPositionAndScale(SurfaceControl.getGlobalTransaction(), dx, dy, scale); } catch (RuntimeException e) { Slog.w(TAG, "Error positioning surface of " + mWin + " pos=(" + dx + "," + dy + ")", e); @@ -904,8 +836,8 @@ class WindowStateAnimator { return true; } - private void setWallpaperPositionAndScale(SurfaceControl.Transaction t, - int dx, int dy, float scale, boolean recoveringMemory) { + private void setWallpaperPositionAndScale(SurfaceControl.Transaction t, int dx, int dy, + float scale) { DisplayInfo displayInfo = mWin.getDisplayInfo(); Matrix matrix = mWin.mTmpMatrix; matrix.setTranslate(dx, dy); @@ -915,13 +847,12 @@ class WindowStateAnimator { matrix.reset(); mSurfaceController.setPosition(t,mWin.mTmpMatrixArray[MTRANS_X], - mWin.mTmpMatrixArray[MTRANS_Y], recoveringMemory); + mWin.mTmpMatrixArray[MTRANS_Y]); mSurfaceController.setMatrix(t, mDsDx * mWin.mTmpMatrixArray[MSCALE_X] * mWin.mHScale, mDtDx * mWin.mTmpMatrixArray[MSKEW_Y] * mWin.mVScale, mDtDy * mWin.mTmpMatrixArray[MSKEW_X] * mWin.mHScale, - mDsDy * mWin.mTmpMatrixArray[MSCALE_Y] * mWin.mVScale, - recoveringMemory); + mDsDy * mWin.mTmpMatrixArray[MSCALE_Y] * mWin.mVScale); } /** @@ -974,8 +905,8 @@ class WindowStateAnimator { * * @return Returns true if the surface was successfully shown. */ - private boolean showSurfaceRobustlyLocked() { - boolean shown = mSurfaceController.showRobustlyInTransaction(); + private boolean showSurfaceRobustlyLocked(SurfaceControl.Transaction t) { + boolean shown = mSurfaceController.showRobustly(t); if (!shown) return false; @@ -993,7 +924,7 @@ class WindowStateAnimator { } } - SurfaceControl.mergeToGlobalTransaction(mPostDrawTransaction); + t.merge(mPostDrawTransaction); return true; } @@ -1163,10 +1094,6 @@ class WindowStateAnimator { return sb.toString(); } - void reclaimSomeSurfaceMemory(String operation, boolean secure) { - mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure); - } - boolean getShown() { if (mSurfaceController != null) { return mSurfaceController.getShown(); @@ -1174,10 +1101,10 @@ class WindowStateAnimator { return false; } - void destroySurface() { + void destroySurface(SurfaceControl.Transaction t) { try { if (mSurfaceController != null) { - mSurfaceController.destroyNotInTransaction(); + mSurfaceController.destroy(t); } } catch (RuntimeException e) { Slog.w(TAG, "Exception thrown when destroying surface " + this @@ -1189,7 +1116,7 @@ class WindowStateAnimator { } } - void detachChildren() { + void detachChildren(SurfaceControl.Transaction t) { // Do not detach children of starting windows, as their lifecycle is well under control and // it may lead to issues in case we relaunch when we just added the starting window. @@ -1197,14 +1124,10 @@ class WindowStateAnimator { return; } if (mSurfaceController != null) { - mSurfaceController.detachChildren(); + mSurfaceController.detachChildren(t); } } - void setOffsetPositionForStackResize(boolean offsetPositionForStackResize) { - mOffsetPositionForStackResize = offsetPositionForStackResize; - } - SurfaceControl getSurfaceControl() { if (!hasSurface()) { return null; diff --git a/services/core/java/com/android/server/wm/WindowSurfaceController.java b/services/core/java/com/android/server/wm/WindowSurfaceController.java index ec79c5999a3f3..788f004076713 100644 --- a/services/core/java/com/android/server/wm/WindowSurfaceController.java +++ b/services/core/java/com/android/server/wm/WindowSurfaceController.java @@ -20,6 +20,7 @@ import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.view.SurfaceControl.METADATA_OWNER_PID; import static android.view.SurfaceControl.METADATA_OWNER_UID; import static android.view.SurfaceControl.METADATA_WINDOW_TYPE; +import static android.view.SurfaceControl.getGlobalTransaction; import static com.android.internal.protolog.ProtoLogGroup.WM_SHOW_SURFACE_ALLOC; import static com.android.internal.protolog.ProtoLogGroup.WM_SHOW_TRANSACTIONS; @@ -76,8 +77,6 @@ class WindowSurfaceController { private final int mWindowType; private final Session mWindowSession; - private final SurfaceControl.Transaction mTmpTransaction; - // Used to track whether we have called detach children on the way to invisibility. boolean mChildrenDetached; @@ -94,7 +93,6 @@ class WindowSurfaceController { final WindowState win = animator.mWin; mWindowType = windowType; mWindowSession = win.mSession; - mTmpTransaction = mService.mTransactionFactory.get(); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "new SurfaceControl"); final SurfaceControl.Builder b = win.makeSurface() @@ -120,18 +118,18 @@ class WindowSurfaceController { Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } - void detachChildren() { + void detachChildren(SurfaceControl.Transaction t) { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SEVER CHILDREN"); mChildrenDetached = true; if (mSurfaceControl != null) { - mSurfaceControl.detachChildren(); + t.detachChildren(mSurfaceControl); } } void hide(SurfaceControl.Transaction transaction, String reason) { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE HIDE ( %s ): %s", reason, title); - mAnimator.destroyPreservedSurfaceLocked(); + mAnimator.destroyPreservedSurfaceLocked(transaction); if (mSurfaceShown) { hideSurface(transaction); } @@ -149,12 +147,12 @@ class WindowSurfaceController { } } - void destroyNotInTransaction() { + void destroy(SurfaceControl.Transaction t) { ProtoLog.i(WM_SHOW_SURFACE_ALLOC, - "Destroying surface %s called by %s", this, Debug.getCallers(8)); + "Destroying surface %s called by %s", this, Debug.getCallers(8)); try { if (mSurfaceControl != null) { - mTmpTransaction.remove(mSurfaceControl).apply(); + t.remove(mSurfaceControl); } } catch (RuntimeException e) { Slog.w(TAG, "Error destroying surface in: " + this, e); @@ -164,30 +162,22 @@ class WindowSurfaceController { } } - void setPosition(SurfaceControl.Transaction t, float left, float top, - boolean recoveringMemory) { + void setPosition(SurfaceControl.Transaction t, float left, float top) { final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top; - if (surfaceMoved) { - mSurfaceX = left; - mSurfaceY = top; - - try { - ProtoLog.i(WM_SHOW_TRANSACTIONS, - "SURFACE POS (setPositionInTransaction) @ (%f,%f): %s", left, top, title); - - t.setPosition(mSurfaceControl, left, top); - } catch (RuntimeException e) { - Slog.w(TAG, "Error positioning surface of " + this - + " pos=(" + left + "," + top + ")", e); - if (!recoveringMemory) { - mAnimator.reclaimSomeSurfaceMemory("position", true); - } - } + if (!surfaceMoved) { + return; } + + mSurfaceX = left; + mSurfaceY = top; + + ProtoLog.i(WM_SHOW_TRANSACTIONS, + "SURFACE POS (setPositionInTransaction) @ (%f,%f): %s", left, top, title); + + t.setPosition(mSurfaceControl, left, top); } - void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx, - float dtdy, float dsdy, boolean recoveringMemory) { + void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx, float dtdy, float dsdy) { final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx || mLastDtdy != dtdy || mLastDsdy != dsdy; if (!matrixChanged) { @@ -199,43 +189,24 @@ class WindowSurfaceController { mLastDtdy = dtdy; mLastDsdy = dsdy; - try { - ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE MATRIX [%f,%f,%f,%f]: %s", - dsdx, dtdx, dtdy, dsdy, title); - t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy); - } catch (RuntimeException e) { - // If something goes wrong with the surface (such - // as running out of memory), don't take down the - // entire system. - Slog.e(TAG, "Error setting matrix on surface surface" + title - + " MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null); - if (!recoveringMemory) { - mAnimator.reclaimSomeSurfaceMemory("matrix", true); - } - } + ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE MATRIX [%f,%f,%f,%f]: %s", + dsdx, dtdx, dtdy, dsdy, title); + t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy); } - boolean prepareToShowInTransaction(float alpha, - float dsdx, float dtdx, float dsdy, - float dtdy, boolean recoveringMemory) { - if (mSurfaceControl != null) { - try { - mSurfaceAlpha = alpha; - mSurfaceControl.setAlpha(alpha); - mLastDsdx = dsdx; - mLastDtdx = dtdx; - mLastDsdy = dsdy; - mLastDtdy = dtdy; - mSurfaceControl.setMatrix( - dsdx, dtdx, dsdy, dtdy); - } catch (RuntimeException e) { - Slog.w(TAG, "Error updating surface in " + title, e); - if (!recoveringMemory) { - mAnimator.reclaimSomeSurfaceMemory("update", true); - } - return false; - } + boolean prepareToShowInTransaction(SurfaceControl.Transaction t, float alpha, float dsdx, + float dtdx, float dsdy, float dtdy) { + if (mSurfaceControl == null) { + return false; } + + mSurfaceAlpha = alpha; + t.setAlpha(mSurfaceControl, alpha); + mLastDsdx = dsdx; + mLastDtdx = dtdx; + mLastDsdy = dsdy; + mLastDtdy = dtdy; + t.setMatrix(mSurfaceControl, dsdx, dtdx, dsdy, dtdy); return true; } @@ -247,7 +218,7 @@ class WindowSurfaceController { if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion"); mService.openSurfaceTransaction(); try { - mSurfaceControl.setTransparentRegionHint(region); + getGlobalTransaction().setTransparentRegionHint(mSurfaceControl, region); } finally { mService.closeSurfaceTransaction("setTransparentRegion"); if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, @@ -264,7 +235,7 @@ class WindowSurfaceController { if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked"); mService.openSurfaceTransaction(); try { - mSurfaceControl.setOpaque(isOpaque); + getGlobalTransaction().setOpaque(mSurfaceControl, isOpaque); } finally { mService.closeSurfaceTransaction("setOpaqueLocked"); if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked"); @@ -282,7 +253,7 @@ class WindowSurfaceController { if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setBackgroundBlurRadius"); mService.openSurfaceTransaction(); try { - mSurfaceControl.setBackgroundBlurRadius(radius); + getGlobalTransaction().setBackgroundBlurRadius(mSurfaceControl, radius); } finally { mService.closeSurfaceTransaction("setBackgroundBlurRadius"); if (SHOW_LIGHT_TRANSACTIONS) { @@ -300,7 +271,7 @@ class WindowSurfaceController { if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked"); mService.openSurfaceTransaction(); try { - mSurfaceControl.setSecure(isSecure); + getGlobalTransaction().setSecure(mSurfaceControl, isSecure); } finally { mService.closeSurfaceTransaction("setSecure"); if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked"); @@ -318,7 +289,7 @@ class WindowSurfaceController { } mService.openSurfaceTransaction(); try { - mSurfaceControl.setColorSpaceAgnostic(agnostic); + getGlobalTransaction().setColorSpaceAgnostic(mSurfaceControl, agnostic); } finally { mService.closeSurfaceTransaction("setColorSpaceAgnostic"); if (SHOW_LIGHT_TRANSACTIONS) { @@ -327,7 +298,7 @@ class WindowSurfaceController { } } - boolean showRobustlyInTransaction() { + boolean showRobustly(SurfaceControl.Transaction t) { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE SHOW (performLayout): %s", title); if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this + " during relayout"); @@ -336,21 +307,9 @@ class WindowSurfaceController { return true; } - try { - setShown(true); - mSurfaceControl.show(); - return true; - } catch (RuntimeException e) { - Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + this, e); - } - - mAnimator.reclaimSomeSurfaceMemory("show", true); - return false; - } - - void deferTransactionUntil(SurfaceControl barrier, long frame) { - // TODO: Logging - mSurfaceControl.deferTransactionUntil(barrier, frame); + setShown(true); + t.show(mSurfaceControl); + return true; } boolean clearWindowContentFrameStats() { @@ -391,14 +350,6 @@ class WindowSurfaceController { } } - int getWidth() { - return mSurfaceW; - } - - int getHeight() { - return mSurfaceH; - } - void dumpDebug(ProtoOutputStream proto, long fieldId) { final long token = proto.start(fieldId); proto.write(SHOWN, mSurfaceShown);