Loading services/core/java/com/android/server/wm/SurfaceFreezer.java +17 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ class SurfaceFreezer { */ void freeze(SurfaceControl.Transaction t, Rect startBounds, Point relativePosition, @Nullable SurfaceControl freezeTarget) { reset(t); mFreezeBounds.set(startBounds); mLeash = SurfaceAnimator.createAnimationLeash(mAnimatable, mAnimatable.getSurfaceControl(), Loading Loading @@ -139,6 +140,22 @@ class SurfaceFreezer { } } /** Resets the snapshot before taking another one if the animation hasn't been started yet. */ private void reset(SurfaceControl.Transaction t) { // Those would have been taken by the SurfaceAnimator if the animation has been started, so // we can remove the leash directly. // No need to reset the mAnimatable leash, as this is called before a new animation leash is // created, so another #onAnimationLeashCreated will be called. if (mSnapshot != null) { mSnapshot.destroy(t); mSnapshot = null; } if (mLeash != null) { t.remove(mLeash); mLeash = null; } } void setLayer(SurfaceControl.Transaction t, int layer) { if (mLeash != null) { t.setLayer(mLeash, layer); Loading services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java +27 −0 Original line number Diff line number Diff line Loading @@ -1173,6 +1173,33 @@ public class WindowContainerTests extends WindowTestsBase { assertNull(surfaceAnimator.mSnapshot); } @Test public void testRemoveUnstartedFreezeSurfaceWhenFreezeAgain() { final WindowContainer container = createTaskFragmentWithParentTask( createTask(mDisplayContent), false); container.mSurfaceControl = mock(SurfaceControl.class); final SurfaceFreezer surfaceFreezer = container.mSurfaceFreezer; final SurfaceControl.Transaction t = mock(SurfaceControl.Transaction.class); spyOn(container); doReturn(t).when(container).getPendingTransaction(); doReturn(t).when(container).getSyncTransaction(); // Leash and snapshot created for change transition. container.initializeChangeTransition(new Rect(0, 0, 1000, 2000)); assertNotNull(surfaceFreezer.mLeash); // Can't really take a snapshot, manually set one. final SurfaceFreezer.Snapshot snapshot = mock(SurfaceFreezer.Snapshot.class); surfaceFreezer.mSnapshot = snapshot; final SurfaceControl prevLeash = surfaceFreezer.mLeash; container.initializeChangeTransition(new Rect(0, 0, 1500, 2500)); verify(t).remove(prevLeash); verify(snapshot).destroy(t); } /* Used so we can gain access to some protected members of the {@link WindowContainer} class */ private static class TestWindowContainer extends WindowContainer<TestWindowContainer> { private final int mLayer; Loading Loading
services/core/java/com/android/server/wm/SurfaceFreezer.java +17 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ class SurfaceFreezer { */ void freeze(SurfaceControl.Transaction t, Rect startBounds, Point relativePosition, @Nullable SurfaceControl freezeTarget) { reset(t); mFreezeBounds.set(startBounds); mLeash = SurfaceAnimator.createAnimationLeash(mAnimatable, mAnimatable.getSurfaceControl(), Loading Loading @@ -139,6 +140,22 @@ class SurfaceFreezer { } } /** Resets the snapshot before taking another one if the animation hasn't been started yet. */ private void reset(SurfaceControl.Transaction t) { // Those would have been taken by the SurfaceAnimator if the animation has been started, so // we can remove the leash directly. // No need to reset the mAnimatable leash, as this is called before a new animation leash is // created, so another #onAnimationLeashCreated will be called. if (mSnapshot != null) { mSnapshot.destroy(t); mSnapshot = null; } if (mLeash != null) { t.remove(mLeash); mLeash = null; } } void setLayer(SurfaceControl.Transaction t, int layer) { if (mLeash != null) { t.setLayer(mLeash, layer); Loading
services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java +27 −0 Original line number Diff line number Diff line Loading @@ -1173,6 +1173,33 @@ public class WindowContainerTests extends WindowTestsBase { assertNull(surfaceAnimator.mSnapshot); } @Test public void testRemoveUnstartedFreezeSurfaceWhenFreezeAgain() { final WindowContainer container = createTaskFragmentWithParentTask( createTask(mDisplayContent), false); container.mSurfaceControl = mock(SurfaceControl.class); final SurfaceFreezer surfaceFreezer = container.mSurfaceFreezer; final SurfaceControl.Transaction t = mock(SurfaceControl.Transaction.class); spyOn(container); doReturn(t).when(container).getPendingTransaction(); doReturn(t).when(container).getSyncTransaction(); // Leash and snapshot created for change transition. container.initializeChangeTransition(new Rect(0, 0, 1000, 2000)); assertNotNull(surfaceFreezer.mLeash); // Can't really take a snapshot, manually set one. final SurfaceFreezer.Snapshot snapshot = mock(SurfaceFreezer.Snapshot.class); surfaceFreezer.mSnapshot = snapshot; final SurfaceControl prevLeash = surfaceFreezer.mLeash; container.initializeChangeTransition(new Rect(0, 0, 1500, 2500)); verify(t).remove(prevLeash); verify(snapshot).destroy(t); } /* Used so we can gain access to some protected members of the {@link WindowContainer} class */ private static class TestWindowContainer extends WindowContainer<TestWindowContainer> { private final int mLayer; Loading