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

Commit 1c2c0b52 authored by Tony Huang's avatar Tony Huang Committed by Android (Google) Code Review
Browse files

Merge "Reduce flicker when split pair switching" into tm-qpr-dev

parents 2dbb6cb4 15bbf373
Loading
Loading
Loading
Loading
+45 −32
Original line number Original line Diff line number Diff line
@@ -154,7 +154,8 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
    private StageCoordinator mStageCoordinator;
    private StageCoordinator mStageCoordinator;
    // Only used for the legacy recents animation from splitscreen to allow the tasks to be animated
    // Only used for the legacy recents animation from splitscreen to allow the tasks to be animated
    // outside the bounds of the roots by being reparented into a higher level fullscreen container
    // outside the bounds of the roots by being reparented into a higher level fullscreen container
    private SurfaceControl mSplitTasksContainerLayer;
    private SurfaceControl mGoingToRecentsTasksLayer;
    private SurfaceControl mStartingSplitTasksLayer;


    public SplitScreenController(Context context,
    public SplitScreenController(Context context,
            ShellInit shellInit,
            ShellInit shellInit,
@@ -509,33 +510,33 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
    }
    }


    RemoteAnimationTarget[] onGoingToRecentsLegacy(RemoteAnimationTarget[] apps) {
    RemoteAnimationTarget[] onGoingToRecentsLegacy(RemoteAnimationTarget[] apps) {
        if (ENABLE_SHELL_TRANSITIONS) return null;

        if (isSplitScreenVisible()) {
        if (isSplitScreenVisible()) {
            // Evict child tasks except the top visible one under split root to ensure it could be
            // Evict child tasks except the top visible one under split root to ensure it could be
            // launched as full screen when switching to it on recents.
            // launched as full screen when switching to it on recents.
            final WindowContainerTransaction wct = new WindowContainerTransaction();
            final WindowContainerTransaction wct = new WindowContainerTransaction();
            mStageCoordinator.prepareEvictInvisibleChildTasks(wct);
            mStageCoordinator.prepareEvictInvisibleChildTasks(wct);
            mSyncQueue.queue(wct);
            mSyncQueue.queue(wct);
        }
        } else {
        return reparentSplitTasksForAnimation(apps, false /* enterSplitScreen */);
            return null;
        }
        }


    RemoteAnimationTarget[] onStartingSplitLegacy(RemoteAnimationTarget[] apps) {
        SurfaceControl.Transaction t = mTransactionPool.acquire();
        try {
        if (mGoingToRecentsTasksLayer != null) {
            return reparentSplitTasksForAnimation(apps, true /* enterSplitScreen */);
            t.remove(mGoingToRecentsTasksLayer);
        } finally {
            for (RemoteAnimationTarget appTarget : apps) {
                if (appTarget.leash != null) {
                    appTarget.leash.release();
                }
            }
        }
        }
        mGoingToRecentsTasksLayer = reparentSplitTasksForAnimation(apps, t,
                "SplitScreenController#onGoingToRecentsLegacy" /* callsite */);
        t.apply();
        mTransactionPool.release(t);

        return new RemoteAnimationTarget[]{mStageCoordinator.getDividerBarLegacyTarget()};
    }
    }


    private RemoteAnimationTarget[] reparentSplitTasksForAnimation(RemoteAnimationTarget[] apps,
    RemoteAnimationTarget[] onStartingSplitLegacy(RemoteAnimationTarget[] apps) {
            boolean enterSplitScreen) {
        if (ENABLE_SHELL_TRANSITIONS) return null;
        if (ENABLE_SHELL_TRANSITIONS) return null;


        if (enterSplitScreen) {
        int openingApps = 0;
        int openingApps = 0;
        for (int i = 0; i < apps.length; ++i) {
        for (int i = 0; i < apps.length; ++i) {
            if (apps[i].mode == MODE_OPENING) openingApps++;
            if (apps[i].mode == MODE_OPENING) openingApps++;
@@ -544,32 +545,44 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
            // Not having enough apps to enter split screen
            // Not having enough apps to enter split screen
            return null;
            return null;
        }
        }
        } else if (!isSplitScreenVisible()) {

            return null;
        SurfaceControl.Transaction t = mTransactionPool.acquire();
        if (mStartingSplitTasksLayer != null) {
            t.remove(mStartingSplitTasksLayer);
        }
        }
        mStartingSplitTasksLayer = reparentSplitTasksForAnimation(apps, t,
                "SplitScreenController#onStartingSplitLegacy" /* callsite */);
        t.apply();
        mTransactionPool.release(t);


        final SurfaceControl.Transaction transaction = mTransactionPool.acquire();
        try {
        if (mSplitTasksContainerLayer != null) {
            return new RemoteAnimationTarget[]{mStageCoordinator.getDividerBarLegacyTarget()};
            // Remove the previous layer before recreating
        } finally {
            transaction.remove(mSplitTasksContainerLayer);
            for (RemoteAnimationTarget appTarget : apps) {
                if (appTarget.leash != null) {
                    appTarget.leash.release();
                }
            }
        }
        }
    }

    private SurfaceControl reparentSplitTasksForAnimation(RemoteAnimationTarget[] apps,
            SurfaceControl.Transaction t, String callsite) {
        final SurfaceControl.Builder builder = new SurfaceControl.Builder(new SurfaceSession())
        final SurfaceControl.Builder builder = new SurfaceControl.Builder(new SurfaceSession())
                .setContainerLayer()
                .setContainerLayer()
                .setName("RecentsAnimationSplitTasks")
                .setName("RecentsAnimationSplitTasks")
                .setHidden(false)
                .setHidden(false)
                .setCallsite("SplitScreenController#onGoingtoRecentsLegacy");
                .setCallsite(callsite);
        mRootTDAOrganizer.attachToDisplayArea(DEFAULT_DISPLAY, builder);
        mRootTDAOrganizer.attachToDisplayArea(DEFAULT_DISPLAY, builder);
        mSplitTasksContainerLayer = builder.build();
        final SurfaceControl splitTasksLayer = builder.build();


        for (int i = 0; i < apps.length; ++i) {
        for (int i = 0; i < apps.length; ++i) {
            final RemoteAnimationTarget appTarget = apps[i];
            final RemoteAnimationTarget appTarget = apps[i];
            transaction.reparent(appTarget.leash, mSplitTasksContainerLayer);
            t.reparent(appTarget.leash, splitTasksLayer);
            transaction.setPosition(appTarget.leash, appTarget.screenSpaceBounds.left,
            t.setPosition(appTarget.leash, appTarget.screenSpaceBounds.left,
                    appTarget.screenSpaceBounds.top);
                    appTarget.screenSpaceBounds.top);
        }
        }
        transaction.apply();
        return splitTasksLayer;
        mTransactionPool.release(transaction);
        return new RemoteAnimationTarget[]{mStageCoordinator.getDividerBarLegacyTarget()};
    }
    }
    /**
    /**
     * Sets drag info to be logged when splitscreen is entered.
     * Sets drag info to be logged when splitscreen is entered.