From f30a6ab670bc0958bf9ce78331430b46c1e94c62 Mon Sep 17 00:00:00 2001 From: Galia Peycheva Date: Wed, 7 Oct 2020 15:32:41 +0200 Subject: [PATCH] Add background blur in WindowManager The CL adds background blur to the WindowManager LayoutParams as a hidden API. The background blur is then passed on to the SurfaceControl in WindowStateAnimator.prepareSurfaces. Bug: 167166562 Test: m && flash && start app that requests background blur && verify it works Change-Id: I5dad3d8d5c75e1feff8fa035452dfe5c90efaa88 --- core/java/android/view/SurfaceControl.java | 10 +++++++ core/java/android/view/WindowManager.java | 20 +++++++++++++ data/etc/services.core.protolog.json | 30 ++++--------------- .../server/wm/WindowStateAnimator.java | 1 + .../server/wm/WindowSurfaceController.java | 22 ++++++++++++++ 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index ed9deecd7e88f..13f3494864d78 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -1632,6 +1632,16 @@ public final class SurfaceControl implements Parcelable { } } + /** + * @hide + */ + public void setBackgroundBlurRadius(int blur) { + checkNotReleased(); + synchronized (SurfaceControl.class) { + sGlobalTransaction.setBackgroundBlurRadius(this, blur); + } + } + /** * @hide */ diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index e96e98b437a13..b0ed1bc30ec35 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -2938,6 +2938,13 @@ public interface WindowManager extends ViewManager { */ public boolean preferMinimalPostProcessing = false; + /** + * Indicates that this window wants to have blurred content behind it. + * + * @hide + */ + public int backgroundBlurRadius = 0; + /** * The color mode requested by this window. The target display may * not be able to honor the request. When the color mode is not set @@ -3262,6 +3269,7 @@ public interface WindowManager extends ViewManager { out.writeInt(mFitInsetsSides); out.writeBoolean(mFitInsetsIgnoringVisibility); out.writeBoolean(preferMinimalPostProcessing); + out.writeInt(backgroundBlurRadius); if (providesInsetsTypes != null) { out.writeInt(providesInsetsTypes.length); out.writeIntArray(providesInsetsTypes); @@ -3329,6 +3337,7 @@ public interface WindowManager extends ViewManager { mFitInsetsSides = in.readInt(); mFitInsetsIgnoringVisibility = in.readBoolean(); preferMinimalPostProcessing = in.readBoolean(); + backgroundBlurRadius = in.readInt(); int insetsTypesLength = in.readInt(); if (insetsTypesLength > 0) { providesInsetsTypes = new int[insetsTypesLength]; @@ -3381,6 +3390,8 @@ public interface WindowManager extends ViewManager { public static final int INSET_FLAGS_CHANGED = 1 << 27; /** {@hide} */ public static final int MINIMAL_POST_PROCESSING_PREFERENCE_CHANGED = 1 << 28; + /** {@hide} */ + public static final int BACKGROUND_BLUR_RADIUS_CHANGED = 1 << 29; // internal buffer to backup/restore parameters under compatibility mode. private int[] mCompatibilityParamsBackup = null; @@ -3566,6 +3577,11 @@ public interface WindowManager extends ViewManager { changes |= MINIMAL_POST_PROCESSING_PREFERENCE_CHANGED; } + if (backgroundBlurRadius != o.backgroundBlurRadius) { + backgroundBlurRadius = o.backgroundBlurRadius; + changes |= BACKGROUND_BLUR_RADIUS_CHANGED; + } + // This can't change, it's only set at window creation time. hideTimeoutMilliseconds = o.hideTimeoutMilliseconds; @@ -3729,6 +3745,10 @@ public interface WindowManager extends ViewManager { sb.append(" preferMinimalPostProcessing="); sb.append(preferMinimalPostProcessing); } + if (backgroundBlurRadius != 0) { + sb.append(" backgroundBlurRadius="); + sb.append(backgroundBlurRadius); + } sb.append(System.lineSeparator()); sb.append(prefix).append(" fl=").append( ViewDebug.flagsToString(LayoutParams.class, "flags", flags)); diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json index 59727d5b25559..520c4d1e5d387 100644 --- a/data/etc/services.core.protolog.json +++ b/data/etc/services.core.protolog.json @@ -1405,12 +1405,6 @@ "group": "WM_DEBUG_RECENTS_ANIMATIONS", "at": "com\/android\/server\/wm\/RecentsAnimationController.java" }, - "-444624452": { - "message": "REPARENT from: %s to: %s", - "level": "INFO", - "group": "WM_SHOW_TRANSACTIONS", - "at": "com\/android\/server\/wm\/WindowSurfaceController.java" - }, "-443173857": { "message": "Moving pending starting from %s to %s", "level": "VERBOSE", @@ -1519,12 +1513,6 @@ "group": "WM_DEBUG_STATES", "at": "com\/android\/server\/wm\/Task.java" }, - "-324085783": { - "message": "SURFACE CROP %s: %s", - "level": "INFO", - "group": "WM_SHOW_TRANSACTIONS", - "at": "com\/android\/server\/wm\/WindowSurfaceController.java" - }, "-322743468": { "message": "setInputMethodInputTarget %s", "level": "INFO", @@ -1711,12 +1699,6 @@ "group": "WM_DEBUG_APP_TRANSITIONS_ANIM", "at": "com\/android\/server\/wm\/WindowContainer.java" }, - "-29233992": { - "message": "SURFACE CLEAR CROP: %s", - "level": "INFO", - "group": "WM_SHOW_TRANSACTIONS", - "at": "com\/android\/server\/wm\/WindowSurfaceController.java" - }, "-21399771": { "message": "activity %s already destroying, skipping request with reason:%s", "level": "VERBOSE", @@ -2683,6 +2665,12 @@ "group": "WM_ERROR", "at": "com\/android\/server\/wm\/WindowManagerService.java" }, + "1035154109": { + "message": "SURFACE backgroundBlur=%o: %s", + "level": "INFO", + "group": "WM_SHOW_TRANSACTIONS", + "at": "com\/android\/server\/wm\/WindowSurfaceController.java" + }, "1040675582": { "message": "Can't report activity configuration update - client not running, activityRecord=%s", "level": "WARN", @@ -2815,12 +2803,6 @@ "group": "WM_DEBUG_FOCUS", "at": "com\/android\/server\/wm\/WindowToken.java" }, - "1220075598": { - "message": "SURFACE SIZE %dx%d: %s", - "level": "INFO", - "group": "WM_SHOW_TRANSACTIONS", - "at": "com\/android\/server\/wm\/WindowSurfaceController.java" - }, "1224184681": { "message": "No longer Stopped: %s", "level": "VERBOSE", diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index f3429769893fb..e96bba2e320dd 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -859,6 +859,7 @@ class WindowStateAnimator { if (displayed) { w.mToken.hasVisible = true; + mSurfaceController.setBackgroundBlurRadius(w.mAttrs.backgroundBlurRadius); } } diff --git a/services/core/java/com/android/server/wm/WindowSurfaceController.java b/services/core/java/com/android/server/wm/WindowSurfaceController.java index cbe0a4232c973..abb987a7c80c9 100644 --- a/services/core/java/com/android/server/wm/WindowSurfaceController.java +++ b/services/core/java/com/android/server/wm/WindowSurfaceController.java @@ -68,6 +68,8 @@ class WindowSurfaceController { private float mLastDsdy = 0; private float mLastDtdy = 1; + private int mLastBackgroundBlurRadius = 0; + private float mSurfaceAlpha = 0; private int mSurfaceLayer = 0; @@ -285,6 +287,26 @@ class WindowSurfaceController { } } + void setBackgroundBlurRadius(int radius) { + ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE backgroundBlur=%o: %s", radius, title); + + if (mSurfaceControl == null || radius == mLastBackgroundBlurRadius) { + return; + } + mLastBackgroundBlurRadius = radius; + + if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setBackgroundBlurRadius"); + mService.openSurfaceTransaction(); + try { + mSurfaceControl.setBackgroundBlurRadius(radius); + } finally { + mService.closeSurfaceTransaction("setBackgroundBlurRadius"); + if (SHOW_LIGHT_TRANSACTIONS) { + Slog.i(TAG, "<<< CLOSE TRANSACTION setBackgroundBlurRadius"); + } + } + } + void setSecure(boolean isSecure) { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isSecure=%b: %s", isSecure, title);