From 3a367c4babf7d86d99daa342c8f3c22f79242bac Mon Sep 17 00:00:00 2001 From: Rob Carr Date: Tue, 10 Mar 2020 15:51:35 -0700 Subject: [PATCH] InsetAnimationControlImpl: Copy SurfaceControl This way the lifetime can be bound to the animation. Otherwise the InsetController owns the lifetime, and it can be challenging to synchronize the two (we would need to update all the running animations when we rebuild the control list). Bug: 150918857 Test: Existing tests pass Change-Id: I86017b2eaee29ab0d8174479d187c9b7dd014305 --- .../view/InsetsAnimationControlCallbacks.java | 6 ++++++ .../android/view/InsetsAnimationControlImpl.java | 12 ++++++++++++ .../view/InsetsAnimationThreadControlRunner.java | 6 ++++++ core/java/android/view/InsetsController.java | 2 +- .../java/com/android/server/wm/InsetsPolicy.java | 7 +++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/InsetsAnimationControlCallbacks.java b/core/java/android/view/InsetsAnimationControlCallbacks.java index a15d6c79417c5..4227f78564a7f 100644 --- a/core/java/android/view/InsetsAnimationControlCallbacks.java +++ b/core/java/android/view/InsetsAnimationControlCallbacks.java @@ -56,4 +56,10 @@ public interface InsetsAnimationControlCallbacks { * apply. */ void applySurfaceParams(SyncRtSurfaceTransactionApplier.SurfaceParams... params); + + /** + * Post a message to release the Surface, guaranteed to happen after all + * previous calls to applySurfaceParams. + */ + void releaseSurfaceControlFromRt(SurfaceControl sc); } diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 2b30c2dd658e0..baee4123ef476 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -180,10 +180,19 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll mAnimation.setAlpha(mPendingAlpha); if (mFinished) { mController.notifyFinished(this, mShownOnFinish); + releaseLeashes(); } return mFinished; } + private void releaseLeashes() { + for (int i = mControls.size() - 1; i >= 0; i--) { + final InsetsSourceControl c = mControls.valueAt(i); + if (c == null) continue; + c.release(mController::releaseSurfaceControlFromRt); + } + } + @Override public void finish(boolean shown) { if (mCancelled || mFinished) { @@ -191,6 +200,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll } setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */); mFinished = true; + mShownOnFinish = shown; } @@ -207,6 +217,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll } mCancelled = true; mListener.onCancelled(); + + releaseLeashes(); } public boolean isCancelled() { diff --git a/core/java/android/view/InsetsAnimationThreadControlRunner.java b/core/java/android/view/InsetsAnimationThreadControlRunner.java index 9c27802293b8f..13b4cd83b4df2 100644 --- a/core/java/android/view/InsetsAnimationThreadControlRunner.java +++ b/core/java/android/view/InsetsAnimationThreadControlRunner.java @@ -75,6 +75,12 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro t.apply(); t.close(); } + + @Override + public void releaseSurfaceControlFromRt(SurfaceControl sc) { + // Since we don't push the SurfaceParams to the RT we can release directly + sc.release(); + } }; @UiThread diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index c1763d62d8297..88e7f2ed9cf1f 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -704,7 +704,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } final InsetsSourceControl control = consumer.getControl(); if (control != null) { - controls.put(consumer.getType(), control); + controls.put(consumer.getType(), new InsetsSourceControl(control)); typesReady |= toPublicType(consumer.getType()); } else if (animationType == ANIMATION_TYPE_SHOW) { diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index 958c8af3af249..30912e55f9080 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -409,6 +409,13 @@ class InsetsPolicy { t.close(); } + // Since we don't push applySurfaceParams to a Handler-queue we don't need + // to push release in this case. + @Override + public void releaseSurfaceControlFromRt(SurfaceControl sc) { + sc.release(); + } + @Override public void startAnimation(InsetsAnimationControlImpl controller, WindowInsetsAnimationControlListener listener, int types,