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

Commit fd6fb674 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Draw shadows in root task instead of leaf task and use EffectLayer to draw shadows

Temporarily disable compositor shadows for freeform until root task has the correct/non-fullscreen bounds.

Fixes: 148807641

Test: adb shell settings put global render_shadows_in_compositor 1
Test: go/wm-smoke
Change-Id: I10371d2a2977bc4d10204d3cf4b052da5165e0e6
parent 62709b5a
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -321,14 +321,12 @@ public final class SurfaceControl implements Parcelable {
    public static final int FX_SURFACE_NORMAL   = 0x00000000;

    /**
     * Surface creation flag: Creates a Dim surface.
     * Everything behind this surface is dimmed by the amount specified
     * in {@link Transaction#setAlpha(SurfaceControl, float)}.  It is an error to lock a Dim
     * surface, since it doesn't have a backing store.
     * Surface creation flag: Creates a effect surface which
     * represents a solid color and or shadows.
     *
     * @hide
     */
    public static final int FX_SURFACE_DIM = 0x00020000;
    public static final int FX_SURFACE_EFFECT = 0x00020000;

    /**
     * Surface creation flag: Creates a container surface.
@@ -739,11 +737,11 @@ public final class SurfaceControl implements Parcelable {
         */
        public Builder setColorLayer() {
            unsetBufferSize();
            return setFlags(FX_SURFACE_DIM, FX_SURFACE_MASK);
            return setFlags(FX_SURFACE_EFFECT, FX_SURFACE_MASK);
        }

        private boolean isColorLayerSet() {
            return  (mFlags & FX_SURFACE_DIM) == FX_SURFACE_DIM;
            return  (mFlags & FX_SURFACE_EFFECT) == FX_SURFACE_EFFECT;
        }

        /**
@@ -2075,6 +2073,7 @@ public final class SurfaceControl implements Parcelable {

        private final ArrayMap<SurfaceControl, Point> mResizedSurfaces = new ArrayMap<>();
        Runnable mFreeNativeResources;
        private static final float[] INVALID_COLOR = {-1, -1, -1};

        /**
         * @hide
@@ -2530,8 +2529,9 @@ public final class SurfaceControl implements Parcelable {
        }

        /**
         * Sets a color for the Surface.
         * @param color A float array with three values to represent r, g, b in range [0..1]
         * Fills the surface with the specified color.
         * @param color A float array with three values to represent r, g, b in range [0..1]. An
         * invalid color will remove the color fill.
         * @hide
         */
        @UnsupportedAppUsage
@@ -2541,6 +2541,16 @@ public final class SurfaceControl implements Parcelable {
            return this;
        }

        /**
         * Removes color fill.
        * @hide
        */
        public Transaction unsetColor(SurfaceControl sc) {
            checkPreconditions(sc);
            nativeSetColor(mNativeObject, sc.mNativeObject, INVALID_COLOR);
            return this;
        }

        /**
         * Sets the security of the surface.  Setting the flag is equivalent to creating the
         * Surface with the {@link #SECURE} flag.
+9 −4
Original line number Diff line number Diff line
@@ -1627,9 +1627,12 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind

        int opacity = PixelFormat.OPAQUE;
        final WindowConfiguration winConfig = getResources().getConfiguration().windowConfiguration;
        // TODO(b/149585281) remove when root task has the correct bounds for freeform
        final boolean renderShadowsInCompositor = mWindow.mRenderShadowsInCompositor
                && winConfig.getWindowingMode() != WINDOWING_MODE_FREEFORM;
        // If we draw shadows in the compositor we don't need to force the surface to be
        // translucent.
        if (winConfig.hasWindowShadow() && !mWindow.mRenderShadowsInCompositor) {
        if (winConfig.hasWindowShadow() && !renderShadowsInCompositor) {
            // If the window has a shadow, it must be translucent.
            opacity = PixelFormat.TRANSLUCENT;
        } else{
@@ -2414,16 +2417,18 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
    }

    private void updateElevation() {
        final int windowingMode =
                getResources().getConfiguration().windowConfiguration.getWindowingMode();
        final boolean renderShadowsInCompositor = mWindow.mRenderShadowsInCompositor
                && windowingMode != WINDOWING_MODE_FREEFORM;
        // If rendering shadows in the compositor, don't set an elevation on the view
        if (mWindow.mRenderShadowsInCompositor) {
        if (renderShadowsInCompositor) {
            return;
        }
        float elevation = 0;
        final boolean wasAdjustedForStack = mElevationAdjustedForStack;
        // Do not use a shadow when we are in resizing mode (mBackdropFrameRenderer not null)
        // since the shadow is bound to the content size and not the target size.
        final int windowingMode =
                getResources().getConfiguration().windowConfiguration.getWindowingMode();
        if ((windowingMode == WINDOWING_MODE_FREEFORM) && !isResizing()) {
            elevation = hasWindowFocus() ?
                    DECOR_SHADOW_FOCUSED_HEIGHT_IN_DIP : DECOR_SHADOW_UNFOCUSED_HEIGHT_IN_DIP;
+14 −4
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ class Task extends WindowContainer<WindowContainer> {
    static final int INVALID_MIN_SIZE = -1;
    private float mShadowRadius = 0;
    private final Rect mLastSurfaceCrop = new Rect();
    private static final boolean ENABLE_FREEFORM_COMPOSITOR_SHADOWS = false;

    /**
     * The modes to control how the stack is moved to the front when calling {@link Task#reparent}.
@@ -2553,8 +2554,10 @@ class Task extends WindowContainer<WindowContainer> {
    }

    private void updateSurfaceCrop() {
        // TODO(b/149585281) remove when root task has the correct bounds for freeform
        // Only update the crop if we are drawing shadows on the task.
        if (mSurfaceControl == null || !mWmService.mRenderShadowsInCompositor) {
        if (mSurfaceControl == null || !mWmService.mRenderShadowsInCompositor
                || !isRootTask() || !ENABLE_FREEFORM_COMPOSITOR_SHADOWS) {
            return;
        }

@@ -2977,9 +2980,15 @@ class Task extends WindowContainer<WindowContainer> {
        return true;
    }

    @Override
    void onSurfaceShown(SurfaceControl.Transaction t) {
        super.onSurfaceShown(t);
        t.unsetColor(mSurfaceControl);
    }

    @Override
    SurfaceControl.Builder makeSurface() {
        return super.makeSurface().setMetadata(METADATA_TASK_ID, mTaskId);
        return super.makeSurface().setColorLayer().setMetadata(METADATA_TASK_ID, mTaskId);
    }

    boolean isTaskAnimating() {
@@ -3934,7 +3943,8 @@ class Task extends WindowContainer<WindowContainer> {
            return dipToPixel(PINNED_WINDOWING_MODE_ELEVATION_IN_DIP,
                    mDisplayContent.getDisplayMetrics());
        }
        if (inFreeformWindowingMode()) {
        // TODO(b/149585281) remove when root task has the correct bounds for freeform
        if (ENABLE_FREEFORM_COMPOSITOR_SHADOWS && inFreeformWindowingMode()) {
            final int elevation = taskIsFocused
                    ? DECOR_SHADOW_FOCUSED_HEIGHT_IN_DIP : DECOR_SHADOW_UNFOCUSED_HEIGHT_IN_DIP;
            return dipToPixel(elevation, mDisplayContent.getDisplayMetrics());
@@ -3949,7 +3959,7 @@ class Task extends WindowContainer<WindowContainer> {
     */
    private void updateShadowsRadius(boolean taskIsFocused,
            SurfaceControl.Transaction pendingTransaction) {
        if (!mWmService.mRenderShadowsInCompositor) return;
        if (!mWmService.mRenderShadowsInCompositor || !isRootTask()) return;

        final float newShadowRadius = getShadowRadius(taskIsFocused);
        if (mShadowRadius != newShadowRadius) {
+9 −1
Original line number Diff line number Diff line
@@ -365,6 +365,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            // build a surface.
            setSurfaceControl(makeSurface().build());
            getPendingTransaction().show(mSurfaceControl);
            onSurfaceShown(getPendingTransaction());
            updateSurfacePosition();
        } else {
            // If we have a surface but a new parent, we just need to perform a reparent. Go through
@@ -383,6 +384,13 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        scheduleAnimation();
    }

    /**
     * Called when the surface is shown for the first time.
     */
    void onSurfaceShown(Transaction t) {
        // do nothing
    }

    // Temp. holders for a chain of containers we are currently processing.
    private final LinkedList<WindowContainer> mTmpChain1 = new LinkedList<>();
    private final LinkedList<WindowContainer> mTmpChain2 = new LinkedList<>();
@@ -1908,7 +1916,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<

    @Override
    public Builder makeAnimationLeash() {
        return makeSurface();
        return makeSurface().setContainerLayer();
    }

    @Override