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

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

Move dim bounds handling into dimmer

Assumptions on who owns dim and who is its parent changed. Logic should
have needed to be revised and it's easier to move everything inside
dimmer rather than having all the different containers handle it by
themselves (with the current assumptions).

Improve test coverage for activity embedding and freeform bounds
assumptions.

Bug: 366132859
Test: DimmerTests
Test: BlurTests
Flag: com.android.window.flags.use_tasks_dim_only
Change-Id: I0eb887f5f75ad7ba3a60fb61ec2996114fccac7e
parent d2583645
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -260,6 +260,14 @@ class Dimmer {
        }
    }

    boolean hasDimState() {
        return mDimState != null;
    }

    boolean isDimming() {
        return mDimState != null && mDimState.isDimming();
    }

    @NonNull
    private DimState obtainDimState(@NonNull WindowState window) {
        if (mDimState == null) {
@@ -275,7 +283,6 @@ class Dimmer {
        return mDimState != null ? mDimState.mDimSurface : null;
    }

    @Deprecated
    Rect getDimBounds() {
        return mDimState != null ? mDimState.mDimBounds : null;
    }
+31 −0
Original line number Diff line number Diff line
@@ -27,11 +27,13 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Rect;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.SurfaceControl;

import com.android.internal.protolog.ProtoLog;
import com.android.window.flags.Flags;

import java.io.PrintWriter;

@@ -153,6 +155,9 @@ public class DimmerAnimationHelper {
                        ? mRequestedProperties.mGeometryParent.getSurfaceControl() : null,
                mRequestedProperties.mDimmingContainer != startProperties.mDimmingContainer
                        ? mRequestedProperties.mDimmingContainer.getSurfaceControl() : null, t);
        if (Flags.useTasksDimOnly()) {
            setBounds(dim, mCurrentProperties.mDimmingContainer, t);
        }

        if (!startProperties.hasSameVisualProperties(mRequestedProperties)) {
            stopCurrentAnimation(dim.mDimSurface);
@@ -253,6 +258,32 @@ public class DimmerAnimationHelper {
        }
    }

    static void setBounds(@NonNull Dimmer.DimState dim, @NonNull WindowState relativeParent,
                          @NonNull SurfaceControl.Transaction t) {
        TaskFragment taskFragment = relativeParent.getTaskFragment();
        Rect taskFragmentBounds = taskFragment != null ? taskFragment.getBounds() : null;
        Task task = relativeParent.getTask();
        Rect taskBounds = task != null ? task.getBounds() : null;
        Rect hostBounds = dim.mHostContainer.getBounds();
        boolean isEmbedded = taskFragment != null && taskFragment.isEmbedded();

        Rect relativeBounds = new Rect();
        if (isEmbedded) {
            // Embedded activities can be dimmed at task or fragment level
            dim.mDimBounds.set(taskFragment.isDimmingOnParentTask()
                    ? taskBounds : taskFragmentBounds);
            relativeBounds.set(dim.mDimBounds);
            relativeBounds.offset(-taskBounds.left, -taskBounds.top);
        } else {
            dim.mDimBounds.set(hostBounds);
            relativeBounds.set(dim.mDimBounds);
            relativeBounds.offsetTo(0, 0);
        }

        t.setWindowCrop(dim.mDimSurface, relativeBounds.width(), relativeBounds.height());
        t.setPosition(dim.mDimSurface, relativeBounds.left, relativeBounds.top);
    }

    void setCurrentAlphaBlur(@NonNull Dimmer.DimState dim, @NonNull SurfaceControl.Transaction t) {
        final SurfaceControl sc = dim.mDimSurface;
        try {
+11 −6
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.window.IDisplayAreaOrganizer;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLog;
import com.android.server.policy.WindowManagerPolicy;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.util.Comparator;
@@ -54,6 +55,7 @@ import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * Container for grouping WindowContainer below DisplayContent.
 *
@@ -833,12 +835,15 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
        void prepareSurfaces() {
            mDimmer.resetDimStates();
            super.prepareSurfaces();
            final Rect dimBounds = mDimmer.getDimBounds();
            Rect dimBounds = null;
            if (!Flags.useTasksDimOnly()) {
                dimBounds = mDimmer.getDimBounds();
                if (dimBounds != null) {
                    // Bounds need to be relative, as the dim layer is a child.
                    getBounds(dimBounds);
                    dimBounds.offsetTo(0 /* newLeft */, 0 /* newTop */);
                }
            }

            // If SystemUI is dragging for recents, we want to reset the dim state so any dim layer
            // on the display level fades out.
@@ -847,7 +852,7 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
                mDimmer.resetDimStates();
            }

            if (dimBounds != null) {
            if (mDimmer.hasDimState()) {
                if (mDimmer.updateDims(getSyncTransaction())) {
                    scheduleAnimation();
                }
+14 −11
Original line number Diff line number Diff line
@@ -3231,22 +3231,25 @@ class Task extends TaskFragment {
        mDimmer.resetDimStates();
        super.prepareSurfaces();

        final Rect dimBounds = mDimmer.getDimBounds();
        Rect dimBounds = null;
        if (!Flags.useTasksDimOnly()) {
            dimBounds = mDimmer.getDimBounds();
            if (dimBounds != null) {
                getDimBounds(dimBounds);

                // Bounds need to be relative, as the dim layer is a child.
                if (inFreeformWindowingMode()) {
                    getBounds(mTmpRect);
                dimBounds.offsetTo(dimBounds.left - mTmpRect.left, dimBounds.top - mTmpRect.top);
                    dimBounds.offset(-mTmpRect.left, -mTmpRect.top);
                } else {
                    dimBounds.offsetTo(0, 0);
                }
            }
        }

        final SurfaceControl.Transaction t = getSyncTransaction();

        if (dimBounds != null && mDimmer.updateDims(t)) {
        if (mDimmer.hasDimState() && mDimmer.updateDims(t)) {
            scheduleAnimation();
        }

+19 −9
Original line number Diff line number Diff line
@@ -3153,6 +3153,9 @@ class TaskFragment extends WindowContainer<WindowContainer> {

    /** Bounds to be used for dimming, as well as touch related tests. */
    void getDimBounds(@NonNull Rect out) {
        if (Flags.useTasksDimOnly() && mDimmer.hasDimState()) {
            out.set(mDimmer.getDimBounds());
        } else {
            if (mIsEmbedded && isDimmingOnParentTask() && getDimmer().getDimBounds() != null) {
                // Return the task bounds if the dimmer is showing and should cover on the Task (not
                // just on this embedded TaskFragment).
@@ -3161,6 +3164,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                out.set(getBounds());
            }
        }
    }

    void setEmbeddedDimArea(@EmbeddedDimArea int embeddedDimArea) {
        mEmbeddedDimArea = embeddedDimArea;
@@ -3189,6 +3193,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        mDimmer.resetDimStates();
        super.prepareSurfaces();

        if (!Flags.useTasksDimOnly()) {
            final Rect dimBounds = mDimmer.getDimBounds();
            if (dimBounds != null) {
                // Bounds need to be relative, as the dim layer is a child.
@@ -3197,6 +3202,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                    scheduleAnimation();
                }
            }
        } else {
            if (mDimmer.updateDims(getSyncTransaction())) {
                scheduleAnimation();
            }
        }
    }

    @Override
Loading