Merge "Update sync rt applier for background blur" into rvc-dev am: 896f664c77 am: 3b0029a226

Change-Id: I5373ebeec2311e88583ee474c281e2316e5fb70c
This commit is contained in:
Automerger Merge Worker
2020-03-04 20:20:06 +00:00
8 changed files with 213 additions and 51 deletions

View File

@@ -282,10 +282,14 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
if (leash != null) { if (leash != null) {
// TODO: use a better interpolation for fade. // TODO: use a better interpolation for fade.
alpha = mFade ? ((float) inset / maxInset * 0.3f + 0.7f) : alpha; alpha = mFade ? ((float) inset / maxInset * 0.3f + 0.7f) : alpha;
surfaceParams.add(new SurfaceParams(leash, side == ISIDE_FLOATING ? 1 : alpha, SurfaceParams params = new SurfaceParams.Builder(leash)
mTmpMatrix, null /* windowCrop */, 0 /* layer */, 0f /* cornerRadius*/, .withAlpha(side == ISIDE_FLOATING ? 1 : alpha)
side == ISIDE_FLOATING ? state.getSource(source.getType()).isVisible() .withMatrix(mTmpMatrix)
: inset != 0 /* visible */)); .withVisibility(side == ISIDE_FLOATING
? state.getSource(source.getType()).isVisible()
: inset != 0 /* visible */)
.build();
surfaceParams.add(params);
} }
} }
} }

View File

@@ -36,7 +36,8 @@ public class SyncRtSurfaceTransactionApplier {
public static final int FLAG_WINDOW_CROP = 1 << 2; public static final int FLAG_WINDOW_CROP = 1 << 2;
public static final int FLAG_LAYER = 1 << 3; public static final int FLAG_LAYER = 1 << 3;
public static final int FLAG_CORNER_RADIUS = 1 << 4; 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 SurfaceControl mTargetSc;
private final ViewRootImpl mTargetViewRootImpl; private final ViewRootImpl mTargetViewRootImpl;
@@ -108,6 +109,9 @@ public class SyncRtSurfaceTransactionApplier {
if ((params.flags & FLAG_CORNER_RADIUS) != 0) { if ((params.flags & FLAG_CORNER_RADIUS) != 0) {
t.setCornerRadius(params.surface, params.cornerRadius); 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.flags & FLAG_VISIBILITY) != 0) {
if (params.visible) { if (params.visible) {
t.show(params.surface); t.show(params.surface);
@@ -153,6 +157,7 @@ public class SyncRtSurfaceTransactionApplier {
int flags; int flags;
float alpha; float alpha;
float cornerRadius; float cornerRadius;
int backgroundBlurRadius;
Matrix matrix; Matrix matrix;
Rect windowCrop; Rect windowCrop;
int layer; int layer;
@@ -215,6 +220,16 @@ public class SyncRtSurfaceTransactionApplier {
return this; 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. * @param visible The visibility to apply to the surface.
* @return this Builder * @return this Builder
@@ -230,12 +245,13 @@ public class SyncRtSurfaceTransactionApplier {
*/ */
public SurfaceParams build() { public SurfaceParams build() {
return new SurfaceParams(surface, flags, alpha, matrix, windowCrop, layer, return new SurfaceParams(surface, flags, alpha, matrix, windowCrop, layer,
cornerRadius, visible); cornerRadius, backgroundBlurRadius, visible);
} }
} }
private SurfaceParams(SurfaceControl surface, int params, float alpha, Matrix matrix, 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.flags = params;
this.surface = surface; this.surface = surface;
this.alpha = alpha; this.alpha = alpha;
@@ -243,34 +259,7 @@ public class SyncRtSurfaceTransactionApplier {
this.windowCrop = new Rect(windowCrop); this.windowCrop = new Rect(windowCrop);
this.layer = layer; this.layer = layer;
this.cornerRadius = cornerRadius; this.cornerRadius = cornerRadius;
this.visible = visible; this.backgroundBlurRadius = backgroundBlurRadius;
}
/**
* 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.visible = visible; this.visible = visible;
} }
@@ -283,7 +272,10 @@ public class SyncRtSurfaceTransactionApplier {
public final float alpha; public final float alpha;
@VisibleForTesting @VisibleForTesting
final float cornerRadius; public final float cornerRadius;
@VisibleForTesting
public final int backgroundBlurRadius;
@VisibleForTesting @VisibleForTesting
public final Matrix matrix; public final Matrix matrix;

View File

@@ -17,11 +17,24 @@
package com.android.systemui.shared.system; package com.android.systemui.shared.system;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.View;
import android.view.ViewRootImpl;
public class SurfaceControlCompat { public class SurfaceControlCompat {
SurfaceControl mSurfaceControl; final SurfaceControl mSurfaceControl;
public SurfaceControlCompat(SurfaceControl surfaceControl) { public SurfaceControlCompat(SurfaceControl surfaceControl) {
mSurfaceControl = 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();
}
} }

View File

@@ -38,6 +38,15 @@ import java.util.function.Consumer;
*/ */
public class SyncRtSurfaceTransactionApplierCompat { 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 static final int MSG_UPDATE_SEQUENCE_NUMBER = 0;
private final SurfaceControl mBarrierSurfaceControl; private final SurfaceControl mBarrierSurfaceControl;
@@ -143,14 +152,31 @@ public class SyncRtSurfaceTransactionApplierCompat {
public static void applyParams(TransactionCompat t, public static void applyParams(TransactionCompat t,
SyncRtSurfaceTransactionApplierCompat.SurfaceParams params) { SyncRtSurfaceTransactionApplierCompat.SurfaceParams params) {
t.setMatrix(params.surface, params.matrix); if ((params.flags & FLAG_MATRIX) != 0) {
if (params.windowCrop != null) { t.setMatrix(params.surface, params.matrix);
}
if ((params.flags & FLAG_WINDOW_CROP) != 0) {
t.setWindowCrop(params.surface, params.windowCrop); t.setWindowCrop(params.surface, params.windowCrop);
} }
t.setAlpha(params.surface, params.alpha); if ((params.flags & FLAG_ALPHA) != 0) {
t.setLayer(params.surface, params.layer); t.setAlpha(params.surface, params.alpha);
t.setCornerRadius(params.surface, params.cornerRadius); }
t.show(params.surface); 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 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 * 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, public SurfaceParams(SurfaceControlCompat surface, float alpha, Matrix matrix,
Rect windowCrop, int layer, float cornerRadius) { 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.surface = surface;
this.alpha = alpha; this.alpha = alpha;
this.matrix = new Matrix(matrix); this.matrix = new Matrix(matrix);
this.windowCrop = windowCrop != null ? new Rect(windowCrop) : null; this.windowCrop = windowCrop != null ? new Rect(windowCrop) : null;
this.layer = layer; this.layer = layer;
this.cornerRadius = cornerRadius; this.cornerRadius = cornerRadius;
this.backgroundBlurRadius = backgroundBlurRadius;
this.visible = visible;
} }
private final int flags;
public final SurfaceControlCompat surface; public final SurfaceControlCompat surface;
public final float alpha; public final float alpha;
final float cornerRadius; public final float cornerRadius;
public final int backgroundBlurRadius;
public final Matrix matrix; public final Matrix matrix;
public final Rect windowCrop; public final Rect windowCrop;
public final int layer; public final int layer;
public final boolean visible;
} }
} }

View File

@@ -87,6 +87,12 @@ public class TransactionCompat {
return this; return this;
} }
public TransactionCompat setBackgroundBlurRadius(SurfaceControlCompat surfaceControl,
int radius) {
mTransaction.setBackgroundBlurRadius(surfaceControl.mSurfaceControl, radius);
return this;
}
public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl, public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
SurfaceControl barrier, long frameNumber) { SurfaceControl barrier, long frameNumber) {
mTransaction.deferTransactionUntil(surfaceControl.mSurfaceControl, barrier, mTransaction.deferTransactionUntil(surfaceControl.mSurfaceControl, barrier,

View File

@@ -274,8 +274,14 @@ public class ActivityLaunchAnimator {
Matrix m = new Matrix(); Matrix m = new Matrix();
m.postTranslate(0, (float) (mParams.top - app.position.y)); m.postTranslate(0, (float) (mParams.top - app.position.y));
mWindowCrop.set(mParams.left, 0, mParams.right, mParams.getHeight()); mWindowCrop.set(mParams.left, 0, mParams.right, mParams.getHeight());
SurfaceParams params = new SurfaceParams(app.leash, 1f /* alpha */, m, mWindowCrop, SurfaceParams params = new SurfaceParams.Builder(app.leash)
app.prefixOrderIndex, mCornerRadius, true /* visible */); .withAlpha(1f)
.withMatrix(m)
.withWindowCrop(mWindowCrop)
.withLayer(app.prefixOrderIndex)
.withCornerRadius(mCornerRadius)
.withVisibility(true)
.build();
mSyncRtTransactionApplier.scheduleApply(params); mSyncRtTransactionApplier.scheduleApply(params);
} }

View File

@@ -48,6 +48,7 @@ import java.lang.annotation.RetentionPolicy;
class SurfaceAnimator { class SurfaceAnimator {
private static final String TAG = TAG_WITH_CLASS_NAME ? "SurfaceAnimator" : TAG_WM; private static final String TAG = TAG_WITH_CLASS_NAME ? "SurfaceAnimator" : TAG_WM;
private final WindowManagerService mService; private final WindowManagerService mService;
private AnimationAdapter mAnimation; private AnimationAdapter mAnimation;
private @AnimationType int mAnimationType; private @AnimationType int mAnimationType;
@@ -142,7 +143,7 @@ class SurfaceAnimator {
} }
mLeash = freezer != null ? freezer.takeLeashForAnimation() : null; mLeash = freezer != null ? freezer.takeLeashForAnimation() : null;
if (mLeash == null) { if (mLeash == null) {
mLeash = createAnimationLeash(mAnimatable, surface, t, mLeash = createAnimationLeash(mAnimatable, surface, t, type,
mAnimatable.getSurfaceWidth(), mAnimatable.getSurfaceHeight(), 0 /* x */, mAnimatable.getSurfaceWidth(), mAnimatable.getSurfaceHeight(), 0 /* x */,
0 /* y */, hidden); 0 /* y */, hidden);
mAnimatable.onAnimationLeashCreated(t, mLeash); mAnimatable.onAnimationLeashCreated(t, mLeash);
@@ -372,13 +373,16 @@ class SurfaceAnimator {
} }
static SurfaceControl createAnimationLeash(Animatable animatable, SurfaceControl surface, 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"); if (DEBUG_ANIM) Slog.i(TAG, "Reparenting to leash");
final SurfaceControl.Builder builder = animatable.makeAnimationLeash() final SurfaceControl.Builder builder = animatable.makeAnimationLeash()
.setParent(animatable.getAnimationLeashParent()) .setParent(animatable.getAnimationLeashParent())
.setHidden(hidden) .setHidden(hidden)
.setName(surface + " - animation-leash"); .setName(surface + " - animation-leash")
.setColorLayer();
final SurfaceControl leash = builder.build(); final SurfaceControl leash = builder.build();
t.unsetColor(leash);
t.setWindowCrop(leash, width, height); t.setWindowCrop(leash, width, height);
t.setPosition(leash, x, y); t.setPosition(leash, x, y);
t.show(leash); t.show(leash);

View File

@@ -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.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; 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.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -73,8 +74,8 @@ class SurfaceFreezer {
mFreezeBounds.set(startBounds); mFreezeBounds.set(startBounds);
mLeash = SurfaceAnimator.createAnimationLeash(mAnimatable, mAnimatable.getSurfaceControl(), mLeash = SurfaceAnimator.createAnimationLeash(mAnimatable, mAnimatable.getSurfaceControl(),
t, startBounds.width(), startBounds.height(), startBounds.left, startBounds.top, t, ANIMATION_TYPE_SCREEN_ROTATION, startBounds.width(), startBounds.height(),
false /* hidden */); startBounds.left, startBounds.top, false /* hidden */);
mAnimatable.onAnimationLeashCreated(t, mLeash); mAnimatable.onAnimationLeashCreated(t, mLeash);
SurfaceControl freezeTarget = mAnimatable.getFreezeSnapshotTarget(); SurfaceControl freezeTarget = mAnimatable.getFreezeSnapshotTarget();