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

Commit 910d0afa authored by Marzia Favaro's avatar Marzia Favaro Committed by Android (Google) Code Review
Browse files

Merge changes Ic46eaa4c,I545a39ec,I9d816c21 into main

* changes:
  Fix finish callback transaction
  Restrict to assumptions that have been valid for a while
  Refactor dimmer getter
parents 56852762 31068add
Loading
Loading
Loading
Loading
+15 −16
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ class Dimmer {
        SurfaceControl mDimSurface;
        final WindowContainer<?> mHostContainer;
        // The last container to request to dim
        private WindowContainer<?> mLastRequestedDimContainer;
        private WindowState mLastDimmingWindow;
        /** Animation */
        private final DimmerAnimationHelper mAnimationHelper;
        boolean mSkipAnimation = false;
@@ -129,8 +129,8 @@ class Dimmer {
         * Set the parameters to prepare the dim to be relative parented to the dimming container
         */
        void prepareReparent(@NonNull WindowContainer<?> geometryParent,
                @NonNull WindowContainer<?> relativeParent, int relativeLayer) {
            mAnimationHelper.setRequestedRelativeParent(relativeParent, relativeLayer);
                @NonNull WindowState relativeParent) {
            mAnimationHelper.setRequestedRelativeParent(relativeParent);
            mAnimationHelper.setRequestedGeometryParent(geometryParent);
        }

@@ -146,7 +146,7 @@ class Dimmer {
         * Whether anyone is currently requesting the dim
         */
        boolean isDimming() {
            return mLastRequestedDimContainer != null
            return mLastDimmingWindow != null
                    && (mHostContainer.isVisibleRequested() || !Flags.useTasksDimOnly());
        }

@@ -186,7 +186,7 @@ class Dimmer {
     */
    void resetDimStates() {
        if (mDimState != null) {
            mDimState.mLastRequestedDimContainer = null;
            mDimState.mLastDimmingWindow = null;
        }
    }

@@ -200,7 +200,7 @@ class Dimmer {
     * @param alpha      Dim amount
     * @param blurRadius Blur amount
     */
    protected void adjustAppearance(@NonNull WindowContainer<?> dimmingContainer,
    protected void adjustAppearance(@NonNull WindowState dimmingContainer,
                                    float alpha, int blurRadius) {
        final DimState d = obtainDimState(dimmingContainer);
        d.prepareLookChange(alpha, blurRadius);
@@ -218,14 +218,13 @@ class Dimmer {
     * continue dimming. Indeed, this method won't be able to keep dimming or get a new DimState
     * without also adjusting the appearance.
     * @param geometryParent    The container that defines the geometry of the dim
     * @param dimmingContainer      The container which to dim above. Should be a child of the host.
     * @param relativeLayer  The position of the dim wrt the container
     * @param dimmingContainer      The container that is dimming. The dim layer will be rel-z
     *                              parented below it
     */
    public void adjustPosition(@NonNull WindowContainer<?> geometryParent,
                                    @NonNull WindowContainer<?> dimmingContainer,
                                    int relativeLayer) {
                                    @NonNull WindowState dimmingContainer) {
        if (mDimState != null) {
            mDimState.prepareReparent(geometryParent, dimmingContainer, relativeLayer);
            mDimState.prepareReparent(geometryParent, dimmingContainer);
        }
    }

@@ -250,9 +249,9 @@ class Dimmer {
            if (!Flags.useTasksDimOnly()) {
                mDimState.adjustSurfaceLayout(t);
            }
            final WindowState ws = mDimState.mLastRequestedDimContainer.asWindowState();
            if (!mDimState.mIsVisible && ws != null && ws.mActivityRecord != null
                    && ws.mActivityRecord.mStartingData != null) {
            if (!mDimState.mIsVisible && mDimState.mLastDimmingWindow != null
                    && mDimState.mLastDimmingWindow.mActivityRecord != null
                    && mDimState.mLastDimmingWindow.mActivityRecord.mStartingData != null) {
                // Skip enter animation while starting window is on top of its activity
                mDimState.mSkipAnimation = true;
            }
@@ -262,11 +261,11 @@ class Dimmer {
    }

    @NonNull
    private DimState obtainDimState(@NonNull WindowContainer<?> container) {
    private DimState obtainDimState(@NonNull WindowState window) {
        if (mDimState == null) {
            mDimState = new DimState();
        }
        mDimState.mLastRequestedDimContainer = container;
        mDimState.mLastDimmingWindow = window;
        return mDimState;
    }

+22 −19
Original line number Diff line number Diff line
@@ -48,9 +48,8 @@ public class DimmerAnimationHelper {
    static class Change {
        private float mAlpha = -1f;
        private int mBlurRadius = -1;
        private WindowContainer<?> mDimmingContainer = null;
        private WindowState mDimmingContainer = null;
        private WindowContainer<?> mGeometryParent = null;
        private int mRelativeLayer = -1;
        private static final float EPSILON = 0.0001f;

        Change() {}
@@ -64,7 +63,6 @@ public class DimmerAnimationHelper {
            mBlurRadius = other.mBlurRadius;
            mDimmingContainer = other.mDimmingContainer;
            mGeometryParent = other.mGeometryParent;
            mRelativeLayer = other.mRelativeLayer;
        }

        // Same alpha and blur
@@ -84,7 +82,7 @@ public class DimmerAnimationHelper {
        @Override
        public String toString() {
            return "Dim state: alpha=" + mAlpha + ", blur=" + mBlurRadius + ", container="
                    + mDimmingContainer + ", relativePosition=" + mRelativeLayer;
                    + mDimmingContainer + ", geometryParent " + mGeometryParent;
        }
    }

@@ -100,14 +98,13 @@ public class DimmerAnimationHelper {
    }

    void setExitParameters() {
        setRequestedRelativeParent(mRequestedProperties.mDimmingContainer, -1 /* relativeLayer */);
        setRequestedRelativeParent(mRequestedProperties.mDimmingContainer);
        setRequestedAppearance(0f /* alpha */, 0 /* blur */);
    }

    // Sets a requested change without applying it immediately
    void setRequestedRelativeParent(@NonNull WindowContainer<?> relativeParent, int relativeLayer) {
    void setRequestedRelativeParent(@NonNull WindowState relativeParent) {
        mRequestedProperties.mDimmingContainer = relativeParent;
        mRequestedProperties.mRelativeLayer = relativeLayer;
    }

    // Sets the requested layer to reparent the dim to without applying it immediately
@@ -124,7 +121,7 @@ public class DimmerAnimationHelper {
    /**
     * Commit the last changes we received. Called after
     * {@link Change#setExitParameters()},
     * {@link Change#setRequestedRelativeParent(WindowContainer, int)}, or
     * {@link Change#setRequestedRelativeParent(WindowContainer)}, or
     * {@link Change#setRequestedAppearance(float, int)}
     */
    void applyChanges(@NonNull SurfaceControl.Transaction t, @NonNull Dimmer.DimState dim) {
@@ -147,8 +144,8 @@ public class DimmerAnimationHelper {
        reparent(dim.mDimSurface,
                startProperties.mGeometryParent != mRequestedProperties.mGeometryParent
                        ? mRequestedProperties.mGeometryParent.getSurfaceControl() : null,
                mRequestedProperties.mDimmingContainer.getSurfaceControl(),
                mRequestedProperties.mRelativeLayer, t);
                mRequestedProperties.mDimmingContainer != startProperties.mDimmingContainer
                        ? mRequestedProperties.mDimmingContainer.getSurfaceControl() : null, t);

        if (!startProperties.hasSameVisualProperties(mRequestedProperties)) {
            stopCurrentAnimation(dim.mDimSurface);
@@ -187,9 +184,11 @@ public class DimmerAnimationHelper {
        mLocalAnimationAdapter.startAnimation(dim.mDimSurface, t,
                ANIMATION_TYPE_DIMMER, /* finishCallback */ (type, animator) -> {
                    synchronized (dim.mHostContainer.mWmService.mGlobalLock) {
                        setCurrentAlphaBlur(dim.mDimSurface, t);
                        SurfaceControl.Transaction finishTransaction =
                                dim.mHostContainer.getSyncTransaction();
                        setCurrentAlphaBlur(dim.mDimSurface, finishTransaction);
                        if (targetAlpha == 0f && !dim.isDimming()) {
                            dim.remove(t);
                            dim.remove(finishTransaction);
                        }
                        mLocalAnimationAdapter = null;
                        mAlphaAnimationSpec = null;
@@ -232,14 +231,15 @@ public class DimmerAnimationHelper {
     */
    static void reparent(@NonNull SurfaceControl dimLayer,
                  @Nullable SurfaceControl newGeometryParent,
                  @NonNull SurfaceControl relativeParent,
                  int relativePosition,
                  @Nullable SurfaceControl newRelativeParent,
                  @NonNull SurfaceControl.Transaction t) {
        try {
            if (newGeometryParent != null) {
                t.reparent(dimLayer, newGeometryParent);
            }
            t.setRelativeLayer(dimLayer, relativeParent, relativePosition);
            if (newRelativeParent != null) {
                t.setRelativeLayer(dimLayer, newRelativeParent, -1);
            }
        } catch (NullPointerException e) {
            Log.w(TAG, "Tried to change parent of dim " + dimLayer + " after remove", e);
        }
@@ -256,11 +256,14 @@ public class DimmerAnimationHelper {

    private static long getDimDuration(@NonNull WindowContainer<?> container) {
        // Use the same duration as the animation on the WindowContainer
        if (container.mSurfaceAnimator != null) {
            AnimationAdapter animationAdapter = container.mSurfaceAnimator.getAnimation();
            final float durationScale = container.mWmService.getTransitionAnimationScaleLocked();
            return animationAdapter == null ? (long) (DEFAULT_DIM_ANIM_DURATION_MS * durationScale)
                    : animationAdapter.getDurationHint();
        }
        return 0;
    }

    /**
     * Collects the animation specifics
+7 −7
Original line number Diff line number Diff line
@@ -3192,13 +3192,6 @@ class Task extends TaskFragment {
        return "Task=" + mTaskId;
    }

    WindowContainer<?> getDimmerParent() {
        if (!inMultiWindowMode() && isTranslucentForTransition()) {
            return getRootDisplayArea();
        }
        return this;
    }

    @Deprecated
    @Override
    Dimmer getDimmer() {
@@ -3222,6 +3215,13 @@ class Task extends TaskFragment {
        return mDimmer;
    }

    boolean isSuitableForDimming() {
        // If the window is in multi-window mode, we want to dim at the Task level to ensure the dim
        // bounds match the area the app lives in.
        // If translucent, we will move the dim to the display area
        return inMultiWindowMode() || !isTranslucentAndVisible();
    }

    @Override
    void prepareSurfaces() {
        mDimmer.resetDimStates();
+2 −6
Original line number Diff line number Diff line
@@ -492,12 +492,8 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
    boolean canApplyDim(@NonNull Task task) {
        if (mTransientLaunches == null) return true;
        if (Flags.useTasksDimOnly()) {
            WindowContainer<?> dimmerParent = task.getDimmerParent();
            if (dimmerParent == null) {
                return false;
            }
            // Always allow to dim if the host only affects its task.
            if (dimmerParent.asTask() == task) {
            if (task.isSuitableForDimming()) {
                // Always allow to dim if the dimming occurs at task level (dim parented to task)
                return true;
            }
        } else {
+23 −10
Original line number Diff line number Diff line
@@ -5196,14 +5196,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            Dimmer dimmer;
            WindowContainer<?> geometryParent = task;
            if (Flags.useTasksDimOnly()) {
                if (task != null) {
                    geometryParent = task.getDimmerParent();
                    dimmer = task.mDimmer;
                } else {
                    RootDisplayArea displayArea = getRootDisplayArea();
                    geometryParent = displayArea;
                    dimmer = displayArea != null ? displayArea.getDimmer() : null;
                }
                geometryParent = getDimParent();
                dimmer = getDimController();
                if (dimmer == null) {
                    ProtoLog.e(WM_DEBUG_DIMMER, "WindowState %s does not have task or"
                            + " display area for dimming", this);
@@ -5216,9 +5210,28 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            if (isVisibleNow()) {
                dimmer.adjustAppearance(this, dimAmount, blurRadius);
            }
            dimmer.adjustPosition(geometryParent,
                    this /* relativeParent */, -1 /* relativeLayer */);
            dimmer.adjustPosition(geometryParent, this /* relativeParent */);
        }
    }

    private Dimmer getDimController() {
        Task task = getTask();
        if (task != null) {
            return task.mDimmer;
        }
        RootDisplayArea displayArea = getRootDisplayArea();
        if (displayArea != null) {
            return displayArea.getDimmer();
        }
        return null;
    }

    private WindowContainer<?> getDimParent() {
        Task task = getTask();
        if (task != null && task.isSuitableForDimming()) {
            return task;
        }
        return getRootDisplayArea();
    }

    private boolean shouldDrawBlurBehind() {
Loading