diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 9a53a43d906a9..42a6175c0b27d 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -282,10 +282,14 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll if (leash != null) { // TODO: use a better interpolation for fade. alpha = mFade ? ((float) inset / maxInset * 0.3f + 0.7f) : alpha; - surfaceParams.add(new SurfaceParams(leash, side == ISIDE_FLOATING ? 1 : alpha, - mTmpMatrix, null /* windowCrop */, 0 /* layer */, 0f /* cornerRadius*/, - side == ISIDE_FLOATING ? state.getSource(source.getType()).isVisible() - : inset != 0 /* visible */)); + SurfaceParams params = new SurfaceParams.Builder(leash) + .withAlpha(side == ISIDE_FLOATING ? 1 : alpha) + .withMatrix(mTmpMatrix) + .withVisibility(side == ISIDE_FLOATING + ? state.getSource(source.getType()).isVisible() + : inset != 0 /* visible */) + .build(); + surfaceParams.add(params); } } } diff --git a/core/java/android/view/SyncRtSurfaceTransactionApplier.java b/core/java/android/view/SyncRtSurfaceTransactionApplier.java index 15252b11d5ac4..206e4f936edf0 100644 --- a/core/java/android/view/SyncRtSurfaceTransactionApplier.java +++ b/core/java/android/view/SyncRtSurfaceTransactionApplier.java @@ -36,7 +36,8 @@ public class SyncRtSurfaceTransactionApplier { public static final int FLAG_WINDOW_CROP = 1 << 2; public static final int FLAG_LAYER = 1 << 3; public static final int FLAG_CORNER_RADIUS = 1 << 4; - public static final int FLAG_VISIBILITY = 1 << 5; + public static final int FLAG_BACKGROUND_BLUR_RADIUS = 1 << 5; + public static final int FLAG_VISIBILITY = 1 << 6; private SurfaceControl mTargetSc; private final ViewRootImpl mTargetViewRootImpl; @@ -108,6 +109,9 @@ public class SyncRtSurfaceTransactionApplier { if ((params.flags & FLAG_CORNER_RADIUS) != 0) { t.setCornerRadius(params.surface, params.cornerRadius); } + if ((params.flags & FLAG_BACKGROUND_BLUR_RADIUS) != 0) { + t.setBackgroundBlurRadius(params.surface, params.backgroundBlurRadius); + } if ((params.flags & FLAG_VISIBILITY) != 0) { if (params.visible) { t.show(params.surface); @@ -153,6 +157,7 @@ public class SyncRtSurfaceTransactionApplier { int flags; float alpha; float cornerRadius; + int backgroundBlurRadius; Matrix matrix; Rect windowCrop; int layer; @@ -215,6 +220,16 @@ public class SyncRtSurfaceTransactionApplier { return this; } + /** + * @param radius the Radius for blur to apply to the background surfaces. + * @return this Builder + */ + public Builder withBackgroundBlur(int radius) { + this.backgroundBlurRadius = radius; + flags |= FLAG_BACKGROUND_BLUR_RADIUS; + return this; + } + /** * @param visible The visibility to apply to the surface. * @return this Builder @@ -230,12 +245,13 @@ public class SyncRtSurfaceTransactionApplier { */ public SurfaceParams build() { return new SurfaceParams(surface, flags, alpha, matrix, windowCrop, layer, - cornerRadius, visible); + cornerRadius, backgroundBlurRadius, visible); } } private SurfaceParams(SurfaceControl surface, int params, float alpha, Matrix matrix, - Rect windowCrop, int layer, float cornerRadius, boolean visible) { + Rect windowCrop, int layer, float cornerRadius, int backgroundBlurRadius, + boolean visible) { this.flags = params; this.surface = surface; this.alpha = alpha; @@ -243,34 +259,7 @@ public class SyncRtSurfaceTransactionApplier { this.windowCrop = new Rect(windowCrop); this.layer = layer; this.cornerRadius = cornerRadius; - this.visible = visible; - } - - - /** - * Constructs surface parameters to be applied when the current view state gets pushed to - * RenderThread. - * - * @param surface The surface to modify. - * @param alpha Alpha to apply. - * @param matrix Matrix to apply. - * @param windowCrop Crop to apply. - * @param layer The layer to apply. - * @param cornerRadius The corner radius to apply. - * @param visible The visibility to apply. - * - * @deprecated Use {@link SurfaceParams.Builder} to create an instance. - */ - @Deprecated - public SurfaceParams(SurfaceControl surface, float alpha, Matrix matrix, - Rect windowCrop, int layer, float cornerRadius, boolean visible) { - this.flags = FLAG_ALL; - this.surface = surface; - this.alpha = alpha; - this.matrix = new Matrix(matrix); - this.windowCrop = windowCrop != null ? new Rect(windowCrop) : null; - this.layer = layer; - this.cornerRadius = cornerRadius; + this.backgroundBlurRadius = backgroundBlurRadius; this.visible = visible; } @@ -283,7 +272,10 @@ public class SyncRtSurfaceTransactionApplier { public final float alpha; @VisibleForTesting - final float cornerRadius; + public final float cornerRadius; + + @VisibleForTesting + public final int backgroundBlurRadius; @VisibleForTesting public final Matrix matrix; diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java index cd12141c32688..c2a4af93b9171 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java @@ -17,11 +17,24 @@ package com.android.systemui.shared.system; import android.view.SurfaceControl; +import android.view.View; +import android.view.ViewRootImpl; public class SurfaceControlCompat { - SurfaceControl mSurfaceControl; + final SurfaceControl mSurfaceControl; public SurfaceControlCompat(SurfaceControl surfaceControl) { mSurfaceControl = surfaceControl; } + + public SurfaceControlCompat(View v) { + ViewRootImpl viewRootImpl = v.getViewRootImpl(); + mSurfaceControl = viewRootImpl != null + ? viewRootImpl.getSurfaceControl() + : null; + } + + public boolean isValid() { + return mSurfaceControl != null && mSurfaceControl.isValid(); + } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java index 7dcf4b0c11aea..2e6b195d6a169 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java @@ -38,6 +38,15 @@ import java.util.function.Consumer; */ public class SyncRtSurfaceTransactionApplierCompat { + public static final int FLAG_ALL = 0xffffffff; + public static final int FLAG_ALPHA = 1; + public static final int FLAG_MATRIX = 1 << 1; + public static final int FLAG_WINDOW_CROP = 1 << 2; + public static final int FLAG_LAYER = 1 << 3; + public static final int FLAG_CORNER_RADIUS = 1 << 4; + public static final int FLAG_BACKGROUND_BLUR_RADIUS = 1 << 5; + public static final int FLAG_VISIBILITY = 1 << 6; + private static final int MSG_UPDATE_SEQUENCE_NUMBER = 0; private final SurfaceControl mBarrierSurfaceControl; @@ -143,14 +152,31 @@ public class SyncRtSurfaceTransactionApplierCompat { public static void applyParams(TransactionCompat t, SyncRtSurfaceTransactionApplierCompat.SurfaceParams params) { - t.setMatrix(params.surface, params.matrix); - if (params.windowCrop != null) { + if ((params.flags & FLAG_MATRIX) != 0) { + t.setMatrix(params.surface, params.matrix); + } + if ((params.flags & FLAG_WINDOW_CROP) != 0) { t.setWindowCrop(params.surface, params.windowCrop); } - t.setAlpha(params.surface, params.alpha); - t.setLayer(params.surface, params.layer); - t.setCornerRadius(params.surface, params.cornerRadius); - t.show(params.surface); + if ((params.flags & FLAG_ALPHA) != 0) { + t.setAlpha(params.surface, params.alpha); + } + if ((params.flags & FLAG_LAYER) != 0) { + t.setLayer(params.surface, params.layer); + } + if ((params.flags & FLAG_CORNER_RADIUS) != 0) { + t.setCornerRadius(params.surface, params.cornerRadius); + } + if ((params.flags & FLAG_BACKGROUND_BLUR_RADIUS) != 0) { + t.setBackgroundBlurRadius(params.surface, params.backgroundBlurRadius); + } + if ((params.flags & FLAG_VISIBILITY) != 0) { + if (params.visible) { + t.show(params.surface); + } else { + t.hide(params.surface); + } + } } /** @@ -183,6 +209,102 @@ public class SyncRtSurfaceTransactionApplierCompat { } public static class SurfaceParams { + public static class Builder { + final SurfaceControlCompat surface; + int flags; + float alpha; + float cornerRadius; + int backgroundBlurRadius; + Matrix matrix; + Rect windowCrop; + int layer; + boolean visible; + + /** + * @param surface The surface to modify. + */ + public Builder(SurfaceControlCompat surface) { + this.surface = surface; + } + + /** + * @param alpha The alpha value to apply to the surface. + * @return this Builder + */ + public Builder withAlpha(float alpha) { + this.alpha = alpha; + flags |= FLAG_ALPHA; + return this; + } + + /** + * @param matrix The matrix to apply to the surface. + * @return this Builder + */ + public Builder withMatrix(Matrix matrix) { + this.matrix = matrix; + flags |= FLAG_MATRIX; + return this; + } + + /** + * @param windowCrop The window crop to apply to the surface. + * @return this Builder + */ + public Builder withWindowCrop(Rect windowCrop) { + this.windowCrop = windowCrop; + flags |= FLAG_WINDOW_CROP; + return this; + } + + /** + * @param layer The layer to assign the surface. + * @return this Builder + */ + public Builder withLayer(int layer) { + this.layer = layer; + flags |= FLAG_LAYER; + return this; + } + + /** + * @param radius the Radius for rounded corners to apply to the surface. + * @return this Builder + */ + public Builder withCornerRadius(float radius) { + this.cornerRadius = radius; + flags |= FLAG_CORNER_RADIUS; + return this; + } + + /** + * @param radius the Radius for blur to apply to the background surfaces. + * @return this Builder + */ + public Builder withBackgroundBlur(int radius) { + this.backgroundBlurRadius = radius; + flags |= FLAG_BACKGROUND_BLUR_RADIUS; + return this; + } + + /** + * @param visible The visibility to apply to the surface. + * @return this Builder + */ + public Builder withVisibility(boolean visible) { + this.visible = visible; + flags |= FLAG_VISIBILITY; + return this; + } + + /** + * @return a new SurfaceParams instance + */ + public SurfaceParams build() { + return new SurfaceParams(surface, flags, alpha, matrix, windowCrop, layer, + cornerRadius, backgroundBlurRadius, visible); + } + } /** * Constructs surface parameters to be applied when the current view state gets pushed to @@ -195,19 +317,33 @@ public class SyncRtSurfaceTransactionApplierCompat { */ public SurfaceParams(SurfaceControlCompat surface, float alpha, Matrix matrix, Rect windowCrop, int layer, float cornerRadius) { + this(surface, FLAG_ALL & ~(FLAG_VISIBILITY | FLAG_BACKGROUND_BLUR_RADIUS), alpha, + matrix, windowCrop, layer, cornerRadius, 0 /* backgroundBlurRadius */, true); + } + + private SurfaceParams(SurfaceControlCompat surface, int flags, float alpha, Matrix matrix, + Rect windowCrop, int layer, float cornerRadius, int backgroundBlurRadius, + boolean visible) { + this.flags = flags; this.surface = surface; this.alpha = alpha; this.matrix = new Matrix(matrix); this.windowCrop = windowCrop != null ? new Rect(windowCrop) : null; this.layer = layer; this.cornerRadius = cornerRadius; + this.backgroundBlurRadius = backgroundBlurRadius; + this.visible = visible; } + private final int flags; + public final SurfaceControlCompat surface; public final float alpha; - final float cornerRadius; + public final float cornerRadius; + public final int backgroundBlurRadius; public final Matrix matrix; public final Rect windowCrop; public final int layer; + public final boolean visible; } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java index 8f4926fe14a30..c1c91f7e50794 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java @@ -87,6 +87,12 @@ public class TransactionCompat { return this; } + public TransactionCompat setBackgroundBlurRadius(SurfaceControlCompat surfaceControl, + int radius) { + mTransaction.setBackgroundBlurRadius(surfaceControl.mSurfaceControl, radius); + return this; + } + public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl, SurfaceControl barrier, long frameNumber) { mTransaction.deferTransactionUntil(surfaceControl.mSurfaceControl, barrier, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java index 5fc043ada22df..53605e5a308a1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java @@ -274,8 +274,14 @@ public class ActivityLaunchAnimator { Matrix m = new Matrix(); m.postTranslate(0, (float) (mParams.top - app.position.y)); mWindowCrop.set(mParams.left, 0, mParams.right, mParams.getHeight()); - SurfaceParams params = new SurfaceParams(app.leash, 1f /* alpha */, m, mWindowCrop, - app.prefixOrderIndex, mCornerRadius, true /* visible */); + SurfaceParams params = new SurfaceParams.Builder(app.leash) + .withAlpha(1f) + .withMatrix(m) + .withWindowCrop(mWindowCrop) + .withLayer(app.prefixOrderIndex) + .withCornerRadius(mCornerRadius) + .withVisibility(true) + .build(); mSyncRtTransactionApplier.scheduleApply(params); } diff --git a/services/core/java/com/android/server/wm/SurfaceAnimator.java b/services/core/java/com/android/server/wm/SurfaceAnimator.java index 1e54e69c0635e..3b3234a4bec0a 100644 --- a/services/core/java/com/android/server/wm/SurfaceAnimator.java +++ b/services/core/java/com/android/server/wm/SurfaceAnimator.java @@ -48,6 +48,7 @@ import java.lang.annotation.RetentionPolicy; class SurfaceAnimator { private static final String TAG = TAG_WITH_CLASS_NAME ? "SurfaceAnimator" : TAG_WM; + private final WindowManagerService mService; private AnimationAdapter mAnimation; private @AnimationType int mAnimationType; @@ -142,7 +143,7 @@ class SurfaceAnimator { } mLeash = freezer != null ? freezer.takeLeashForAnimation() : null; if (mLeash == null) { - mLeash = createAnimationLeash(mAnimatable, surface, t, + mLeash = createAnimationLeash(mAnimatable, surface, t, type, mAnimatable.getSurfaceWidth(), mAnimatable.getSurfaceHeight(), 0 /* x */, 0 /* y */, hidden); mAnimatable.onAnimationLeashCreated(t, mLeash); @@ -372,13 +373,16 @@ class SurfaceAnimator { } static SurfaceControl createAnimationLeash(Animatable animatable, SurfaceControl surface, - Transaction t, int width, int height, int x, int y, boolean hidden) { + Transaction t, @AnimationType int type, int width, int height, int x, int y, + boolean hidden) { if (DEBUG_ANIM) Slog.i(TAG, "Reparenting to leash"); final SurfaceControl.Builder builder = animatable.makeAnimationLeash() .setParent(animatable.getAnimationLeashParent()) .setHidden(hidden) - .setName(surface + " - animation-leash"); + .setName(surface + " - animation-leash") + .setColorLayer(); final SurfaceControl leash = builder.build(); + t.unsetColor(leash); t.setWindowCrop(leash, width, height); t.setPosition(leash, x, y); t.show(leash); diff --git a/services/core/java/com/android/server/wm/SurfaceFreezer.java b/services/core/java/com/android/server/wm/SurfaceFreezer.java index 20435ea7dfafb..36861aa1f88e8 100644 --- a/services/core/java/com/android/server/wm/SurfaceFreezer.java +++ b/services/core/java/com/android/server/wm/SurfaceFreezer.java @@ -18,6 +18,7 @@ package com.android.server.wm; import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; +import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_SCREEN_ROTATION; import android.annotation.NonNull; import android.annotation.Nullable; @@ -73,8 +74,8 @@ class SurfaceFreezer { mFreezeBounds.set(startBounds); mLeash = SurfaceAnimator.createAnimationLeash(mAnimatable, mAnimatable.getSurfaceControl(), - t, startBounds.width(), startBounds.height(), startBounds.left, startBounds.top, - false /* hidden */); + t, ANIMATION_TYPE_SCREEN_ROTATION, startBounds.width(), startBounds.height(), + startBounds.left, startBounds.top, false /* hidden */); mAnimatable.onAnimationLeashCreated(t, mLeash); SurfaceControl freezeTarget = mAnimatable.getFreezeSnapshotTarget();