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

Commit e2c70e16 authored by Marzia Favaro's avatar Marzia Favaro
Browse files

Remove legacy edge extension code from TransitionAnimationHelper

Bug: 398776229
Test: N/A
Flag: EXEMPT removing unused code
Change-Id: Icdf2becf6a49e17cb565dc9945edeff7f8bf0856
parent b072c6bd
Loading
Loading
Loading
Loading
+0 −34
Original line number Diff line number Diff line
@@ -20,11 +20,9 @@ import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_OFFSET;
import static android.window.TransitionInfo.FLAG_IS_BEHIND_STARTING_WINDOW;
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;

import static com.android.wm.shell.activityembedding.ActivityEmbeddingAnimationSpec.createShowSnapshotForClosingAnimation;
import static com.android.wm.shell.transition.TransitionAnimationHelper.addBackgroundToTransition;
import static com.android.wm.shell.transition.TransitionAnimationHelper.edgeExtendWindow;
import static com.android.wm.shell.transition.TransitionAnimationHelper.getTransitionBackgroundColorIfSet;
import static com.android.wm.shell.transition.Transitions.TRANSIT_TASK_FRAGMENT_DRAG_RESIZE;

@@ -144,10 +142,6 @@ class ActivityEmbeddingAnimationRunner {
            // ending states.
            prepareForJumpCut(info, startTransaction);
        } else {
            if (!com.android.graphics.libgui.flags.Flags.edgeExtensionShader()) {
                addEdgeExtensionIfNeeded(startTransaction, finishTransaction,
                        postStartTransactionCallbacks, adapters);
            }
            addBackgroundColorIfNeeded(info, startTransaction, finishTransaction, adapters);
            for (ActivityEmbeddingAnimationAdapter adapter : adapters) {
                duration = Math.max(duration, adapter.getDurationHint());
@@ -330,34 +324,6 @@ class ActivityEmbeddingAnimationRunner {
        }
    }

    /** Adds edge extension to the surfaces that have such an animation property. */
    private void addEdgeExtensionIfNeeded(@NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction,
            @NonNull List<Consumer<SurfaceControl.Transaction>> postStartTransactionCallbacks,
            @NonNull List<ActivityEmbeddingAnimationAdapter> adapters) {
        for (ActivityEmbeddingAnimationAdapter adapter : adapters) {
            final Animation animation = adapter.mAnimation;
            if (animation.getExtensionEdges() == 0) {
                continue;
            }
            if (adapter.mChange.hasFlags(FLAG_TRANSLUCENT)
                    && adapter.mChange.getActivityComponent() != null) {
                // Skip edge extension for translucent activity.
                continue;
            }
            final TransitionInfo.Change change = adapter.mChange;
            if (TransitionUtil.isOpeningType(adapter.mChange.getMode())) {
                // Need to screenshot after startTransaction is applied otherwise activity
                // may not be visible or ready yet.
                postStartTransactionCallbacks.add(
                        t -> edgeExtendWindow(change, animation, t, finishTransaction));
            } else {
                // Can screenshot now (before startTransaction is applied)
                edgeExtendWindow(change, animation, startTransaction, finishTransaction);
            }
        }
    }

    /** Adds background color to the transition if any animation has such a property. */
    private void addBackgroundColorIfNeeded(@NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction startTransaction,
+3 −16
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITI
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_NONE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_OPEN;
import static com.android.wm.shell.transition.DefaultSurfaceAnimator.buildSurfaceAnimation;
import static com.android.wm.shell.transition.TransitionAnimationHelper.edgeExtendWindow;
import static com.android.wm.shell.transition.TransitionAnimationHelper.getTransitionBackgroundColorIfSet;
import static com.android.wm.shell.transition.TransitionAnimationHelper.getTransitionTypeFromInfo;
import static com.android.wm.shell.transition.TransitionAnimationHelper.isCoveredByOpaqueFullscreenChange;
@@ -519,21 +518,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
                        backgroundColorForTransition);

                if (!isTask && a.getExtensionEdges() != 0x0) {
                    if (com.android.graphics.libgui.flags.Flags.edgeExtensionShader()) {
                    startTransaction.setEdgeExtensionEffect(
                            change.getLeash(), a.getExtensionEdges());
                    finishTransaction.setEdgeExtensionEffect(change.getLeash(), /* edge */ 0);
                    } else {
                        if (!TransitionUtil.isOpeningType(mode)) {
                            // Can screenshot now (before startTransaction is applied)
                            edgeExtendWindow(change, a, startTransaction, finishTransaction);
                        } else {
                            // Need to screenshot after startTransaction is applied otherwise
                            // activity may not be visible or ready yet.
                            postStartTransactionCallbacks
                                    .add(t -> edgeExtendWindow(change, a, t, finishTransaction));
                        }
                    }
                }

                final Rect clipRect = TransitionUtil.isClosingType(mode)
+0 −134
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.window.TransitionInfo.FLAGS_IS_NON_APP_WINDOW;
import static android.window.TransitionInfo.FLAG_IS_DISPLAY;
import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT;
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;

import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_CLOSE;
@@ -39,20 +38,10 @@ import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.WindowConfiguration;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Shader;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.window.ScreenCapture;
import android.window.TransitionInfo;

import com.android.internal.R;
@@ -328,129 +317,6 @@ public class TransitionAnimationHelper {
        finishTransaction.remove(animationBackgroundSurface);
    }

    /**
     * Adds edge extension surface to the given {@code change} for edge extension animation.
     */
    public static void edgeExtendWindow(@NonNull TransitionInfo.Change change,
            @NonNull Animation a, @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction) {
        // Do not create edge extension surface for transfer starting window change.
        // The app surface could be empty thus nothing can draw on the hardware renderer, which will
        // block this thread when calling Surface#unlockCanvasAndPost.
        if ((change.getFlags() & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) != 0) {
            return;
        }
        final Transformation transformationAtStart = new Transformation();
        a.getTransformationAt(0, transformationAtStart);
        final Transformation transformationAtEnd = new Transformation();
        a.getTransformationAt(1, transformationAtEnd);

        // We want to create an extension surface that is the maximal size and the animation will
        // take care of cropping any part that overflows.
        final Insets maxExtensionInsets = Insets.min(
                transformationAtStart.getInsets(), transformationAtEnd.getInsets());

        final int targetSurfaceHeight = Math.max(change.getStartAbsBounds().height(),
                change.getEndAbsBounds().height());
        final int targetSurfaceWidth = Math.max(change.getStartAbsBounds().width(),
                change.getEndAbsBounds().width());
        if (maxExtensionInsets.left < 0) {
            final Rect edgeBounds = new Rect(0, 0, 1, targetSurfaceHeight);
            final Rect extensionRect = new Rect(0, 0,
                    -maxExtensionInsets.left, targetSurfaceHeight);
            final int xPos = maxExtensionInsets.left;
            final int yPos = 0;
            createExtensionSurface(change.getLeash(), edgeBounds, extensionRect, xPos, yPos,
                    "Left Edge Extension", startTransaction, finishTransaction);
        }

        if (maxExtensionInsets.top < 0) {
            final Rect edgeBounds = new Rect(0, 0, targetSurfaceWidth, 1);
            final Rect extensionRect = new Rect(0, 0,
                    targetSurfaceWidth, -maxExtensionInsets.top);
            final int xPos = 0;
            final int yPos = maxExtensionInsets.top;
            createExtensionSurface(change.getLeash(), edgeBounds, extensionRect, xPos, yPos,
                    "Top Edge Extension", startTransaction, finishTransaction);
        }

        if (maxExtensionInsets.right < 0) {
            final Rect edgeBounds = new Rect(targetSurfaceWidth - 1, 0,
                    targetSurfaceWidth, targetSurfaceHeight);
            final Rect extensionRect = new Rect(0, 0,
                    -maxExtensionInsets.right, targetSurfaceHeight);
            final int xPos = targetSurfaceWidth;
            final int yPos = 0;
            createExtensionSurface(change.getLeash(), edgeBounds, extensionRect, xPos, yPos,
                    "Right Edge Extension", startTransaction, finishTransaction);
        }

        if (maxExtensionInsets.bottom < 0) {
            final Rect edgeBounds = new Rect(0, targetSurfaceHeight - 1,
                    targetSurfaceWidth, targetSurfaceHeight);
            final Rect extensionRect = new Rect(0, 0,
                    targetSurfaceWidth, -maxExtensionInsets.bottom);
            final int xPos = maxExtensionInsets.left;
            final int yPos = targetSurfaceHeight;
            createExtensionSurface(change.getLeash(), edgeBounds, extensionRect, xPos, yPos,
                    "Bottom Edge Extension", startTransaction, finishTransaction);
        }
    }

    /**
     * Takes a screenshot of {@code surfaceToExtend}'s edge and extends it for edge extension
     * animation.
     */
    private static SurfaceControl createExtensionSurface(@NonNull SurfaceControl surfaceToExtend,
            @NonNull Rect edgeBounds, @NonNull Rect extensionRect, int xPos, int yPos,
            @NonNull String layerName, @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction) {
        final SurfaceControl edgeExtensionLayer = new SurfaceControl.Builder()
                .setName(layerName)
                .setParent(surfaceToExtend)
                .setHidden(true)
                .setCallsite("TransitionAnimationHelper#createExtensionSurface")
                .setOpaque(true)
                .setBufferSize(extensionRect.width(), extensionRect.height())
                .build();

        final ScreenCapture.LayerCaptureArgs captureArgs =
                new ScreenCapture.LayerCaptureArgs.Builder(surfaceToExtend)
                        .setSourceCrop(edgeBounds)
                        .setFrameScale(1)
                        .setPixelFormat(PixelFormat.RGBA_8888)
                        .setChildrenOnly(true)
                        .setAllowProtected(false)
                        .setCaptureSecureLayers(true)
                        .build();
        final ScreenCapture.ScreenshotHardwareBuffer edgeBuffer =
                ScreenCapture.captureLayers(captureArgs);

        if (edgeBuffer == null) {
            ProtoLog.e(ShellProtoLogGroup.WM_SHELL_TRANSITIONS,
                    "Failed to capture edge of window.");
            return null;
        }

        final BitmapShader shader = new BitmapShader(edgeBuffer.asBitmap(),
                Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        final Paint paint = new Paint();
        paint.setShader(shader);

        final Surface surface = new Surface(edgeExtensionLayer);
        final Canvas c = surface.lockHardwareCanvas();
        c.drawRect(extensionRect, paint);
        surface.unlockCanvasAndPost(c);
        surface.release();

        startTransaction.setLayer(edgeExtensionLayer, Integer.MIN_VALUE);
        startTransaction.setPosition(edgeExtensionLayer, xPos, yPos);
        startTransaction.setVisibility(edgeExtensionLayer, true);
        finishTransaction.remove(edgeExtensionLayer);

        return edgeExtensionLayer;
    }

    /**
     * Returns whether there is an opaque fullscreen Change positioned in front of the given Change
     * in the given TransitionInfo.