Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6de279d authored by Chris Li's avatar Chris Li Committed by Automerger Merge Worker
Browse files

Merge "Set animation layer for SurfaceFreezer leash" into sc-v2-dev am: 9f8f8795 am: 6ff51d15

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15898006

Change-Id: Iafff086e71536bf84684d36b1be5f1e0452ec24f
parents a6c6fdb0 6ff51d15
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -123,6 +123,18 @@ class SurfaceFreezer {
        }
    }

    void setLayer(SurfaceControl.Transaction t, int layer) {
        if (mLeash != null) {
            t.setLayer(mLeash, layer);
        }
    }

    void setRelativeLayer(SurfaceControl.Transaction t, SurfaceControl relativeTo, int layer) {
        if (mLeash != null) {
            t.setRelativeLayer(mLeash, relativeTo, layer);
        }
    }

    boolean hasLeash() {
        return mLeash != null;
    }
+18 −8
Original line number Diff line number Diff line
@@ -2335,22 +2335,32 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    }

    protected void setLayer(Transaction t, int layer) {

        if (mSurfaceFreezer.hasLeash()) {
            // When the freezer has created animation leash parent for the window, set the layer
            // there instead.
            mSurfaceFreezer.setLayer(t, layer);
        } else {
            // Route through surface animator to accommodate that our surface control might be
            // attached to the leash, and leash is attached to parent container.
            mSurfaceAnimator.setLayer(t, layer);
        }
    }

    int getLastLayer() {
        return mLastLayer;
    }

    protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {

        if (mSurfaceFreezer.hasLeash()) {
            // When the freezer has created animation leash parent for the window, set the layer
            // there instead.
            mSurfaceFreezer.setRelativeLayer(t, relativeTo, layer);
        } else {
            // Route through surface animator to accommodate that our surface control might be
            // attached to the leash, and leash is attached to parent container.
            mSurfaceAnimator.setRelativeLayer(t, relativeTo, layer);
        }
    }

    protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
        // Don't reparent active leashes since the animator won't know about the change.
+35 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,41 @@ public class WindowContainerTests extends WindowTestsBase {
        verify(surfaceAnimator).setRelativeLayer(t, relativeParent, 1 /* layer */);
    }

    @Test
    public void testAssignAnimationLayer() {
        final WindowContainer container = new WindowContainer(mWm);
        container.mSurfaceControl = mock(SurfaceControl.class);
        final SurfaceAnimator surfaceAnimator = container.mSurfaceAnimator;
        final SurfaceFreezer surfaceFreezer = container.mSurfaceFreezer;
        final SurfaceControl relativeParent = mock(SurfaceControl.class);
        final SurfaceControl.Transaction t = mock(SurfaceControl.Transaction.class);
        spyOn(container);
        spyOn(surfaceAnimator);
        spyOn(surfaceFreezer);

        container.setLayer(t, 1);
        container.setRelativeLayer(t, relativeParent, 2);

        // Set through surfaceAnimator if surfaceFreezer doesn't have leash.
        verify(surfaceAnimator).setLayer(t, 1);
        verify(surfaceAnimator).setRelativeLayer(t, relativeParent, 2);
        verify(surfaceFreezer, never()).setLayer(any(), anyInt());
        verify(surfaceFreezer, never()).setRelativeLayer(any(), any(), anyInt());

        clearInvocations(surfaceAnimator);
        clearInvocations(surfaceFreezer);
        doReturn(true).when(surfaceFreezer).hasLeash();

        container.setLayer(t, 1);
        container.setRelativeLayer(t, relativeParent, 2);

        // Set through surfaceFreezer if surfaceFreezer has leash.
        verify(surfaceFreezer).setLayer(t, 1);
        verify(surfaceFreezer).setRelativeLayer(t, relativeParent, 2);
        verify(surfaceAnimator, never()).setLayer(any(), anyInt());
        verify(surfaceAnimator, never()).setRelativeLayer(any(), any(), anyInt());
    }

    /* 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;