diff options
| author | 2022-03-01 11:39:52 -0800 | |
|---|---|---|
| committer | 2022-03-01 11:39:52 -0800 | |
| commit | 0a682bf137d4683c99bc60deeac646f4d060a6af (patch) | |
| tree | 0cf0e494a4b5bcb680dd3422ee28cbafaf32476c | |
| parent | aa0ee6502b89864f03a48180abe7b61cc074d1da (diff) | |
Close Transactions explicitly
Ensure one-shot, scheduled Transactions are closed after application.
While individual Transaction instances aren't all that heavy, this
avoids unnecessary GC pressure and churn.
Bug: 216159702
Test: atest WmTests SystemUITests FrameworksCoreTests
Change-Id: Iec053dd8163fb9b300fd1e9eb9f1472a0d0dd782
| -rw-r--r-- | core/java/android/view/InsetsSourceConsumer.java | 26 | ||||
| -rw-r--r-- | core/java/android/view/SyncRtSurfaceTransactionApplier.java | 8 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 3 |
3 files changed, 24 insertions, 13 deletions
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index b1582cf9f023..6aab6359d23e 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -98,6 +98,13 @@ public class InsetsSourceConsumer { */ private boolean mIsAnimationPending; + /** + * @param type The {@link InternalInsetsType} of the consumed insets. + * @param state The current {@link InsetsState} of the consumed insets. + * @param transactionSupplier The source of new {@link Transaction} instances. The supplier + * must provide *new* instances, which will be explicitly closed by this class. + * @param controller The {@link InsetsController} to use for insets interaction. + */ public InsetsSourceConsumer(@InternalInsetsType int type, InsetsState state, Supplier<Transaction> transactionSupplier, InsetsController controller) { mType = type; @@ -390,16 +397,17 @@ public class InsetsSourceConsumer { return; } - final Transaction t = mTransactionSupplier.get(); - if (DEBUG) Log.d(TAG, "applyRequestedVisibilityToControl: " + mRequestedVisible); - if (mRequestedVisible) { - t.show(mSourceControl.getLeash()); - } else { - t.hide(mSourceControl.getLeash()); + try (Transaction t = mTransactionSupplier.get()) { + if (DEBUG) Log.d(TAG, "applyRequestedVisibilityToControl: " + mRequestedVisible); + if (mRequestedVisible) { + t.show(mSourceControl.getLeash()); + } else { + t.hide(mSourceControl.getLeash()); + } + // Ensure the alpha value is aligned with the actual requested visibility. + t.setAlpha(mSourceControl.getLeash(), mRequestedVisible ? 1 : 0); + t.apply(); } - // Ensure the alpha value is aligned with the actual requested visibility. - t.setAlpha(mSourceControl.getLeash(), mRequestedVisible ? 1 : 0); - t.apply(); onPerceptible(mRequestedVisible); } diff --git a/core/java/android/view/SyncRtSurfaceTransactionApplier.java b/core/java/android/view/SyncRtSurfaceTransactionApplier.java index 3e2110341693..e9c937cc0f9b 100644 --- a/core/java/android/view/SyncRtSurfaceTransactionApplier.java +++ b/core/java/android/view/SyncRtSurfaceTransactionApplier.java @@ -65,10 +65,12 @@ public class SyncRtSurfaceTransactionApplier { applyParams(t, params); mTargetViewRootImpl.registerRtFrameCallback(frame -> { - if (mTargetSc == null || !mTargetSc.isValid()) { - return; + if (mTargetSc != null && mTargetSc.isValid()) { + applyTransaction(t, frame); } - applyTransaction(t, frame); + // The transaction was either dropped, successfully applied, or merged with a future + // transaction, so we can safely release its resources. + t.close(); }); // Make sure a frame gets scheduled. diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 8bb7e677362c..4edb344e5632 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -4175,7 +4175,7 @@ public final class ViewRootImpl implements ViewParent, + " didProduceBuffer=" + didProduceBuffer); } - Transaction tmpTransaction = new Transaction(); + final Transaction tmpTransaction = new Transaction(); tmpTransaction.merge(mRtBLASTSyncTransaction); // If frame wasn't drawn, clear out the next transaction so it doesn't affect the next @@ -4206,6 +4206,7 @@ public final class ViewRootImpl implements ViewParent, blastSyncConsumer.accept(mSurfaceChangedTransaction); } } + tmpTransaction.close(); if (reportNextDraw) { pendingDrawFinished(); |