diff options
4 files changed, 67 insertions, 44 deletions
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 0c64eeac2ec7..ed9deecd7e88 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -267,7 +267,7 @@ public final class SurfaceControl implements Parcelable { private WeakReference<View> mLocalOwnerView; - static Transaction sGlobalTransaction; + static GlobalTransactionWrapper sGlobalTransaction; static long sTransactionNestCount = 0; /** @@ -1453,7 +1453,7 @@ public final class SurfaceControl implements Parcelable { public static void openTransaction() { synchronized (SurfaceControl.class) { if (sGlobalTransaction == null) { - sGlobalTransaction = new Transaction(); + sGlobalTransaction = new GlobalTransactionWrapper(); } synchronized(SurfaceControl.class) { sTransactionNestCount++; @@ -1487,7 +1487,7 @@ public final class SurfaceControl implements Parcelable { } else if (--sTransactionNestCount > 0) { return; } - sGlobalTransaction.apply(); + sGlobalTransaction.applyGlobalTransaction(false); } } @@ -2555,7 +2555,10 @@ public final class SurfaceControl implements Parcelable { nativeApplyTransaction(mNativeObject, sync); } - private void applyResizedSurfaces() { + /** + * @hide + */ + protected void applyResizedSurfaces() { for (int i = mResizedSurfaces.size() - 1; i >= 0; i--) { final Point size = mResizedSurfaces.valueAt(i); final SurfaceControl surfaceControl = mResizedSurfaces.keyAt(i); @@ -2567,7 +2570,10 @@ public final class SurfaceControl implements Parcelable { mResizedSurfaces.clear(); } - private void notifyReparentedSurfaces() { + /** + * @hide + */ + protected void notifyReparentedSurfaces() { final int reparentCount = mReparentedSurfaces.size(); for (int i = reparentCount - 1; i >= 0; i--) { final SurfaceControl child = mReparentedSurfaces.keyAt(i); @@ -3403,6 +3409,26 @@ public final class SurfaceControl implements Parcelable { } /** + * As part of eliminating usage of the global Transaction we expose + * a SurfaceControl.getGlobalTransaction function. However calling + * apply on this global transaction (rather than using closeTransaction) + * would be very dangerous. So for the global transaction we use this + * subclass of Transaction where the normal apply throws an exception. + */ + private static class GlobalTransactionWrapper extends SurfaceControl.Transaction { + void applyGlobalTransaction(boolean sync) { + applyResizedSurfaces(); + notifyReparentedSurfaces(); + nativeApplyTransaction(mNativeObject, sync); + } + + @Override + public void apply(boolean sync) { + throw new RuntimeException("Global transaction must be applied from closeTransaction"); + } + } + + /** * Acquire a frame rate flexibility token, which allows surface flinger to freely switch display * frame rates. This is used by CTS tests to put the device in a consistent state. See * ISurfaceComposer::acquireFrameRateFlexibilityToken(). The caller must have the @@ -3422,4 +3448,17 @@ public final class SurfaceControl implements Parcelable { public static void releaseFrameRateFlexibilityToken(long token) { nativeReleaseFrameRateFlexibilityToken(token); } + + /** + * This is a refactoring utility function to enable lower levels of code to be refactored + * from using the global transaction (and instead use a passed in Transaction) without + * having to refactor the higher levels at the same time. + * The returned global transaction can't be applied, it must be applied from closeTransaction + * Unless you are working on removing Global Transaction usage in the WindowManager, this + * probably isn't a good function to use. + * @hide + */ + public static Transaction getGlobalTransaction() { + return sGlobalTransaction; + } } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 5defe478c49a..0b53bf6ca8f6 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -5337,7 +5337,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP // Send information to SufaceFlinger about the priority of the current window. updateFrameRateSelectionPriorityIfNeeded(); - mWinAnimator.prepareSurfaceLocked(true); + mWinAnimator.prepareSurfaceLocked(SurfaceControl.getGlobalTransaction(), true); notifyBlastSyncTransaction(); 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 13d8dc4c6be1..f3429769893f 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -652,7 +652,7 @@ class WindowStateAnimator { return true; } - void setSurfaceBoundariesLocked(final boolean recoveringMemory) { + void setSurfaceBoundariesLocked(SurfaceControl.Transaction t, final boolean recoveringMemory) { if (mSurfaceController == null) { return; } @@ -662,11 +662,11 @@ class WindowStateAnimator { final Task task = w.getTask(); if (shouldConsumeMainWindowSizeTransaction()) { - task.getMainWindowSizeChangeTask().getSurfaceControl().deferTransactionUntil( - mWin.getClientViewRootSurface(), mWin.getFrameNumber()); - mSurfaceController.deferTransactionUntil(mWin.getClientViewRootSurface(), - mWin.getFrameNumber()); - SurfaceControl.mergeToGlobalTransaction(task.getMainWindowSizeChangeTransaction()); + t.deferTransactionUntil(task.getMainWindowSizeChangeTask().getSurfaceControl(), + mWin.getClientViewRootSurface(), mWin.getFrameNumber()); + t.deferTransactionUntil(mSurfaceController.mSurfaceControl, + mWin.getClientViewRootSurface(), mWin.getFrameNumber()); + t.merge(task.getMainWindowSizeChangeTransaction()); task.setMainWindowSizeChangeTransaction(null); } @@ -691,8 +691,8 @@ class WindowStateAnimator { // the WS position is reset (so the stack position is shown) at the same // time that the buffer size changes. setOffsetPositionForStackResize(false); - mSurfaceController.deferTransactionUntil(mWin.getClientViewRootSurface(), - mWin.getFrameNumber()); + t.deferTransactionUntil(mSurfaceController.mSurfaceControl, + mWin.getClientViewRootSurface(), mWin.getFrameNumber()); } else { final Task stack = mWin.getRootTask(); mTmpPos.x = 0; @@ -705,9 +705,9 @@ class WindowStateAnimator { } } if (!mIsWallpaper) { - mSurfaceController.setPositionInTransaction(xOffset, yOffset, recoveringMemory); + mSurfaceController.setPosition(t, xOffset, yOffset, recoveringMemory); } else { - setWallpaperPositionAndScale( + setWallpaperPositionAndScale(t, xOffset, yOffset, mWallpaperScale, recoveringMemory); } } @@ -716,7 +716,7 @@ class WindowStateAnimator { // Wallpaper is already updated above when calling setWallpaperPositionAndScale so // we only need to consider the non-wallpaper case here. if (!mIsWallpaper) { - mSurfaceController.setMatrixInTransaction( + mSurfaceController.setMatrix(t, mDsDx * w.mHScale, mDtDx * w.mVScale, mDtDy * w.mHScale, @@ -738,7 +738,7 @@ class WindowStateAnimator { } } - void prepareSurfaceLocked(final boolean recoveringMemory) { + void prepareSurfaceLocked(SurfaceControl.Transaction t, final boolean recoveringMemory) { final WindowState w = mWin; if (!hasSurface()) { @@ -755,7 +755,7 @@ class WindowStateAnimator { computeShownFrameLocked(); - setSurfaceBoundariesLocked(recoveringMemory); + setSurfaceBoundariesLocked(t, recoveringMemory); if (mIsWallpaper && !w.mWallpaperVisible) { // Wallpaper is no longer visible and there is no wp target => hide it. @@ -797,7 +797,7 @@ class WindowStateAnimator { boolean prepared = true; if (mIsWallpaper) { - setWallpaperPositionAndScale( + setWallpaperPositionAndScale(t, mXOffset, mYOffset, mWallpaperScale, recoveringMemory); } else { prepared = @@ -884,7 +884,8 @@ class WindowStateAnimator { Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset"); } mService.openSurfaceTransaction(); - setWallpaperPositionAndScale(dx, dy, scale, false); + setWallpaperPositionAndScale(SurfaceControl.getGlobalTransaction(), + dx, dy, scale, false); } catch (RuntimeException e) { Slog.w(TAG, "Error positioning surface of " + mWin + " pos=(" + dx + "," + dy + ")", e); @@ -899,8 +900,8 @@ class WindowStateAnimator { return true; } - private void setWallpaperPositionAndScale(int dx, int dy, float scale, - boolean recoveringMemory) { + private void setWallpaperPositionAndScale(SurfaceControl.Transaction t, + int dx, int dy, float scale, boolean recoveringMemory) { DisplayInfo displayInfo = mWin.getDisplayInfo(); Matrix matrix = mWin.mTmpMatrix; matrix.setTranslate(dx, dy); @@ -909,9 +910,9 @@ class WindowStateAnimator { matrix.getValues(mWin.mTmpMatrixArray); matrix.reset(); - mSurfaceController.setPositionInTransaction(mWin.mTmpMatrixArray[MTRANS_X], + mSurfaceController.setPosition(t,mWin.mTmpMatrixArray[MTRANS_X], mWin.mTmpMatrixArray[MTRANS_Y], recoveringMemory); - mSurfaceController.setMatrixInTransaction( + mSurfaceController.setMatrix(t, mDsDx * mWin.mTmpMatrixArray[MSCALE_X] * mWin.mHScale, mDtDx * mWin.mTmpMatrixArray[MSKEW_Y] * mWin.mVScale, mDtDy * mWin.mTmpMatrixArray[MSKEW_X] * mWin.mHScale, diff --git a/services/core/java/com/android/server/wm/WindowSurfaceController.java b/services/core/java/com/android/server/wm/WindowSurfaceController.java index 9b40822c8ab5..160ad89b71f4 100644 --- a/services/core/java/com/android/server/wm/WindowSurfaceController.java +++ b/services/core/java/com/android/server/wm/WindowSurfaceController.java @@ -236,10 +236,6 @@ class WindowSurfaceController { } } - void setPositionInTransaction(float left, float top, boolean recoveringMemory) { - setPosition(null, left, top, recoveringMemory); - } - void setPosition(SurfaceControl.Transaction t, float left, float top, boolean recoveringMemory) { final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top; @@ -251,11 +247,7 @@ class WindowSurfaceController { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE POS (setPositionInTransaction) @ (%f,%f): %s", left, top, title); - if (t == null) { - mSurfaceControl.setPosition(left, top); - } else { - t.setPosition(mSurfaceControl, left, top); - } + t.setPosition(mSurfaceControl, left, top); } catch (RuntimeException e) { Slog.w(TAG, "Error positioning surface of " + this + " pos=(" + left + "," + top + ")", e); @@ -266,11 +258,6 @@ class WindowSurfaceController { } } - void setMatrixInTransaction(float dsdx, float dtdx, float dtdy, float dsdy, - boolean recoveringMemory) { - setMatrix(null, dsdx, dtdx, dtdy, dsdy, false); - } - void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx, float dtdy, float dsdy, boolean recoveringMemory) { final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx || @@ -287,11 +274,7 @@ class WindowSurfaceController { try { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE MATRIX [%f,%f,%f,%f]: %s", dsdx, dtdx, dtdy, dsdy, title); - if (t == null) { - mSurfaceControl.setMatrix(dsdx, dtdx, dtdy, dsdy); - } else { - t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy); - } + 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 |