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

Commit 052cca6d authored by Marzia Favaro's avatar Marzia Favaro
Browse files

Use and reparent the task's dim

Instead of using the display area's dimmer, each window has access only
to it's own task's dimmer. The associated dim layer can be reparented to
the display area when needed.

Bug: 352522056
Test: DimmerTests
Flag: com.android.window.flags.use_tasks_dim_only
Change-Id: I4723efbd6bd8fc3a6613970b244b1e69996a472a
parent 93755573
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -179,6 +179,17 @@ flag {
  }
}

flag {
  name: "use_tasks_dim_only"
  namespace: "windowing_frontend"
  description: "Only use the task's dim and reparent it to the display area when needed instead of coordinating multiple dimmers"
  bug: "352522056"
  is_fixed_read_only: true
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
    name: "release_snapshot_aggressively"
    namespace: "windowing_frontend"
+19 −5
Original line number Diff line number Diff line
@@ -28,7 +28,13 @@ import android.view.SurfaceControl;

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


/**
 * Utility class for use by a WindowContainer implementation to add "DimLayer" support, that is
 * black layers of varying opacity at various Z-levels which create the effect of a Dim.
 */
class Dimmer {

    /**
@@ -122,8 +128,10 @@ class Dimmer {
        /**
         * Set the parameters to prepare the dim to be relative parented to the dimming container
         */
        void prepareReparent(@NonNull WindowContainer<?> relativeParent, int relativeLayer) {
        void prepareReparent(@NonNull WindowContainer<?> geometryParent,
                @NonNull WindowContainer<?> relativeParent, int relativeLayer) {
            mAnimationHelper.setRequestedRelativeParent(relativeParent, relativeLayer);
            mAnimationHelper.setRequestedGeometryParent(geometryParent);
        }

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

        private SurfaceControl makeDimLayer() {
@@ -208,13 +217,15 @@ class Dimmer {
     * the child of the host should call adjustRelativeLayer and {@link Dimmer#adjustAppearance} to
     * 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
     */
    public void adjustRelativeLayer(@NonNull WindowContainer<?> dimmingContainer,
    public void adjustPosition(@NonNull WindowContainer<?> geometryParent,
                                    @NonNull WindowContainer<?> dimmingContainer,
                                    int relativeLayer) {
        if (mDimState != null) {
            mDimState.prepareReparent(dimmingContainer, relativeLayer);
            mDimState.prepareReparent(geometryParent, dimmingContainer, relativeLayer);
        }
    }

@@ -236,7 +247,9 @@ class Dimmer {
            return false;
        } else {
            // Someone is dimming, show the requested changes
            if (!Flags.useTasksDimOnly()) {
                mDimState.adjustSurfaceLayout(t);
            }
            final WindowState ws = mDimState.mLastRequestedDimContainer.asWindowState();
            if (!mDimState.mIsVisible && ws != null && ws.mActivityRecord != null
                    && ws.mActivityRecord.mStartingData != null) {
@@ -263,6 +276,7 @@ class Dimmer {
        return mDimState != null ? mDimState.mDimSurface : null;
    }

    @Deprecated
    Rect getDimBounds() {
        return mDimState != null ? mDimState.mDimBounds : null;
    }
+19 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.SurfaceControl;
@@ -48,6 +49,7 @@ public class DimmerAnimationHelper {
        private float mAlpha = -1f;
        private int mBlurRadius = -1;
        private WindowContainer<?> mDimmingContainer = null;
        private WindowContainer<?> mGeometryParent = null;
        private int mRelativeLayer = -1;
        private static final float EPSILON = 0.0001f;

@@ -103,6 +105,11 @@ public class DimmerAnimationHelper {
        mRequestedProperties.mRelativeLayer = relativeLayer;
    }

    // Sets the requested layer to reparent the dim to without applying it immediately
    void setRequestedGeometryParent(WindowContainer<?> geometryParent) {
        mRequestedProperties.mGeometryParent = geometryParent;
    }

    // Sets a requested change without applying it immediately
    void setRequestedAppearance(float alpha, int blurRadius) {
        mRequestedProperties.mAlpha = alpha;
@@ -129,7 +136,9 @@ public class DimmerAnimationHelper {
        }

        dim.ensureVisible(t);
        relativeReparent(dim.mDimSurface,
        reparent(dim.mDimSurface,
                mRequestedProperties.mGeometryParent != mCurrentProperties.mGeometryParent
                        ? mRequestedProperties.mGeometryParent.getSurfaceControl() : null,
                mRequestedProperties.mDimmingContainer.getSurfaceControl(),
                mRequestedProperties.mRelativeLayer, t);

@@ -214,11 +223,17 @@ public class DimmerAnimationHelper {
    }

    /**
     * Change the relative parent of this dim layer
     * Change the geometry and relative parent of this dim layer
     */
    void relativeReparent(@NonNull SurfaceControl dimLayer, @NonNull SurfaceControl relativeParent,
                          int relativePosition, @NonNull SurfaceControl.Transaction t) {
    void reparent(@NonNull SurfaceControl dimLayer,
                  @Nullable SurfaceControl newGeometryParent,
                  @NonNull SurfaceControl relativeParent,
                  int relativePosition,
                  @NonNull SurfaceControl.Transaction t) {
        try {
            if (newGeometryParent != null) {
                t.reparent(dimLayer, newGeometryParent);
            }
            t.setRelativeLayer(dimLayer, relativeParent, relativePosition);
        } catch (NullPointerException e) {
            Log.w(TAG, "Tried to change parent of dim " + dimLayer + " after remove", e);
+8 −0
Original line number Diff line number Diff line
@@ -3201,6 +3201,14 @@ class Task extends TaskFragment {
        return "Task=" + mTaskId;
    }

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

    @Deprecated
    @Override
    Dimmer getDimmer() {
        // If the window is in multi-window mode, we want to dim at the Task level to ensure the dim
+1 −0
Original line number Diff line number Diff line
@@ -3105,6 +3105,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        return forAllWindows(getDimBehindWindow, true);
    }

    @Deprecated
    @Override
    Dimmer getDimmer() {
        // If this is in an embedded TaskFragment and we want the dim applies on the TaskFragment.
Loading