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

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

Merge "Move dim bounds handling into dimmer" into main

parents d23d11ab b332a807
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -261,6 +261,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) {
@@ -276,7 +284,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
@@ -46,6 +46,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;
@@ -53,6 +54,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.
 *
@@ -831,12 +833,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.
@@ -845,7 +850,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
@@ -3297,22 +3297,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
@@ -3157,6 +3157,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).
@@ -3165,6 +3168,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                out.set(getBounds());
            }
        }
    }

    void setEmbeddedDimArea(@EmbeddedDimArea int embeddedDimArea) {
        mEmbeddedDimArea = embeddedDimArea;
@@ -3193,6 +3197,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.
@@ -3201,6 +3206,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                    scheduleAnimation();
                }
            }
        } else {
            if (mDimmer.updateDims(getSyncTransaction())) {
                scheduleAnimation();
            }
        }
    }

    @Override
Loading