Merge "Fix synchronisation in BackgroundBlurDrawable" into sc-dev

This commit is contained in:
Galia Peycheva
2021-02-26 14:30:04 +00:00
committed by Android (Google) Code Review
4 changed files with 578 additions and 142 deletions

View File

@@ -3504,64 +3504,4 @@ public final class SurfaceControl implements Parcelable {
public static Transaction getGlobalTransaction() {
return sGlobalTransaction;
}
/**
* Wrapper for sending blur data to SurfaceFlinger.
* @hide
*/
public static final class BlurRegion {
public int blurRadius;
public float cornerRadiusTL;
public float cornerRadiusTR;
public float cornerRadiusBL;
public float cornerRadiusBR;
public float alpha = 1;
public boolean visible = true;
public final Rect rect = new Rect();
private final float[] mFloatArray = new float[10];
public BlurRegion() {
}
public BlurRegion(BlurRegion other) {
rect.set(other.rect);
blurRadius = other.blurRadius;
alpha = other.alpha;
cornerRadiusTL = other.cornerRadiusTL;
cornerRadiusTR = other.cornerRadiusTR;
cornerRadiusBL = other.cornerRadiusBL;
cornerRadiusBR = other.cornerRadiusBR;
}
/**
* Serializes this class into a float array that's more JNI friendly.
*/
public float[] toFloatArray() {
mFloatArray[0] = blurRadius;
mFloatArray[1] = alpha;
mFloatArray[2] = rect.left;
mFloatArray[3] = rect.top;
mFloatArray[4] = rect.right;
mFloatArray[5] = rect.bottom;
mFloatArray[6] = cornerRadiusTL;
mFloatArray[7] = cornerRadiusTR;
mFloatArray[8] = cornerRadiusBL;
mFloatArray[9] = cornerRadiusBR;
return mFloatArray;
}
@Override
public String toString() {
return "BlurRegion{"
+ "blurRadius=" + blurRadius
+ ", corners={" + cornerRadiusTL
+ "," + cornerRadiusTR
+ "," + cornerRadiusBL
+ "," + cornerRadiusBR
+ "}, alpha=" + alpha
+ ", rect=" + rect
+ "}";
}
}
}

View File

@@ -3969,11 +3969,12 @@ public final class ViewRootImpl implements ViewParent,
}
private void addFrameCallbackIfNeeded() {
boolean nextDrawUseBlastSync = mNextDrawUseBlastSync;
boolean hasBlur = mBlurRegionAggregator.hasRegions();
boolean reportNextDraw = mReportNextDraw;
final boolean nextDrawUseBlastSync = mNextDrawUseBlastSync;
final boolean reportNextDraw = mReportNextDraw;
final boolean hasBlurUpdates = mBlurRegionAggregator.hasUpdates();
final boolean needsCallbackForBlur = hasBlurUpdates || mBlurRegionAggregator.hasRegions();
if (!nextDrawUseBlastSync && !reportNextDraw && !hasBlur) {
if (!nextDrawUseBlastSync && !reportNextDraw && !needsCallbackForBlur) {
return;
}
@@ -3981,18 +3982,22 @@ public final class ViewRootImpl implements ViewParent,
Log.d(mTag, "Creating frameDrawingCallback"
+ " nextDrawUseBlastSync=" + nextDrawUseBlastSync
+ " reportNextDraw=" + reportNextDraw
+ " hasBlur=" + hasBlur);
+ " hasBlurUpdates=" + hasBlurUpdates);
}
// The callback will run on a worker thread pool from the render thread.
final BackgroundBlurDrawable.BlurRegion[] blurRegionsForFrame =
needsCallbackForBlur ? mBlurRegionAggregator.getBlurRegionsCopyForRT() : null;
// The callback will run on the render thread.
HardwareRenderer.FrameDrawingCallback frameDrawingCallback = frame -> {
if (DEBUG_BLAST) {
Log.d(mTag, "Received frameDrawingCallback frameNum=" + frame + "."
+ " Creating transactionCompleteCallback=" + nextDrawUseBlastSync);
}
if (hasBlur) {
mBlurRegionAggregator.dispatchBlurTransactionIfNeeded(frame);
if (needsCallbackForBlur) {
mBlurRegionAggregator
.dispatchBlurTransactionIfNeeded(frame, blurRegionsForFrame, hasBlurUpdates);
}
if (mBlastBufferQueue == null) {