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

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

Switch to compositor shadows for PiP and Freeform windows (disabled by default)

Shadows are generated on PiP and Freeform windows by setting an
elevation on the window's DecorView. The elevation is passed back
to wm as surface insets to generate a large enough surface for the
client to draw its content and render shadows around it.

This cl introduces a new settings which overrides the setElevation
call in DecorView and sets a shadow on the task surface. The
elevation of the DecorView and the surface insets will remain unset.

Add a surface crop to the task surface so we have proper bounds
to draw shadows.

Test: go/wm-smoke
Bug: 136561771

Change-Id: Icc45e4fac3d495df5272d2e5f37163b9e7caeb4c
parent cce89e27
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -9361,6 +9361,16 @@ public final class Settings {
        public static final String DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM =
                "enable_sizecompat_freeform";
        /**
         * If true, shadows drawn around the window will be rendered by the system compositor. If
         * false, shadows will be drawn by the client by setting an elevation on the root view and
         * the contents will be inset by the surface insets.
         * (0 = false, 1 = true)
         * @hide
         */
        public static final String DEVELOPMENT_RENDER_SHADOWS_IN_COMPOSITOR =
                "render_shadows_in_compositor";
       /**
        * Whether user has enabled development settings.
        */
+9 −5
Original line number Diff line number Diff line
@@ -95,8 +95,6 @@ import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowCallbacks;
import android.view.WindowInsets;
import android.view.WindowInsets.Side;
import android.view.WindowInsets.Type;
import android.view.WindowInsetsController;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
@@ -131,9 +129,9 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
    private static final boolean SWEEP_OPEN_MENU = false;

    // The height of a window which has focus in DIP.
    private final static int DECOR_SHADOW_FOCUSED_HEIGHT_IN_DIP = 20;
    public static final int DECOR_SHADOW_FOCUSED_HEIGHT_IN_DIP = 20;
    // The height of a window which has not in DIP.
    private final static int DECOR_SHADOW_UNFOCUSED_HEIGHT_IN_DIP = 5;
    public static final int DECOR_SHADOW_UNFOCUSED_HEIGHT_IN_DIP = 5;

    private static final int SCRIM_LIGHT = 0xe6ffffff; // 90% white

@@ -1629,7 +1627,9 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind

        int opacity = PixelFormat.OPAQUE;
        final WindowConfiguration winConfig = getResources().getConfiguration().windowConfiguration;
        if (winConfig.hasWindowShadow()) {
        // If we draw shadows in the compositor we don't need to force the surface to be
        // translucent.
        if (winConfig.hasWindowShadow() && !mWindow.mRenderShadowsInCompositor) {
            // If the window has a shadow, it must be translucent.
            opacity = PixelFormat.TRANSLUCENT;
        } else{
@@ -2414,6 +2414,10 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
    }

    private void updateElevation() {
        // If rendering shadows in the compositor, don't set an elevation on the view
        if (mWindow.mRenderShadowsInCompositor) {
            return;
        }
        float elevation = 0;
        final boolean wasAdjustedForStack = mElevationAdjustedForStack;
        // Do not use a shadow when we are in resizing mode (mBackdropFrameRenderer not null)
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.policy;

import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES;
import static android.provider.Settings.Global.DEVELOPMENT_RENDER_SHADOWS_IN_COMPOSITOR;
import static android.view.View.SYSTEM_UI_LAYOUT_FLAGS;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -134,6 +135,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    private final static String TAG = "PhoneWindow";

    /* If true, shadows drawn around the window will be rendered by the system compositor. If
     * false, shadows will be drawn by the client by setting an elevation on the root view and
     * the contents will be inset by the shadow radius. */
    public final boolean mRenderShadowsInCompositor;

    private static final boolean DEBUG = false;

    private final static int DEFAULT_BACKGROUND_FADE_DURATION_MS = 300;
@@ -327,6 +333,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    public PhoneWindow(Context context) {
        super(context);
        mLayoutInflater = LayoutInflater.from(context);
        mRenderShadowsInCompositor = Settings.Global.getInt(context.getContentResolver(),
                DEVELOPMENT_RENDER_SHADOWS_IN_COMPOSITOR, 0) != 0;
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -224,6 +224,7 @@ public class SettingsBackupTest {
                    Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES,
                    Settings.Global.DEVELOPMENT_FORCE_RTL,
                    Settings.Global.DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM,
                    Settings.Global.DEVELOPMENT_RENDER_SHADOWS_IN_COMPOSITOR,
                    Settings.Global.DEVICE_DEMO_MODE,
                    Settings.Global.DEVICE_IDLE_CONSTANTS,
                    Settings.Global.BATTERY_SAVER_ADAPTIVE_CONSTANTS,
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowBackground">@null</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:statusBarColor">@*android:color/transparent</item>
        <item name="android:windowAnimationStyle">@style/Animation.PipPhoneOverlayControl</item>
Loading