From 25c129cc6aff0ebd033843739d97bd1ec3c9cd38 Mon Sep 17 00:00:00 2001 From: chaviw Date: Wed, 7 Oct 2020 11:38:22 -0700 Subject: [PATCH] Changed logic about how to check if VRI replaced its surface. SurfaceView checks if VRI hasn't changed its surface when deciding whether to call updateRelativeZ in updateSurface. This is to give surfaceReplaced a chance to send the updateRelativeZ in the same transaction as swapping the surfaces. However, SV was only checking generation id, which may not have changed when using a blast layer. Instead, VRI will increment the sequence id when the surface has been replaced. SV can check that value and only do an immediate updateRelativeZ when the sequence id has not changed. Test: Blast + Split + SV with no flicker Change-Id: Icdf9f1fbe12fe77052030aa37d808517c5a6cd38 --- core/java/android/view/SurfaceView.java | 9 +++------ core/java/android/view/ViewRootImpl.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index e3067a664f2ea..7b6a4f877d020 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -41,7 +41,6 @@ import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.Looper; -import android.os.RemoteException; import android.os.SystemClock; import android.provider.Settings; import android.util.AttributeSet; @@ -225,13 +224,12 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall private SurfaceControl.Transaction mRtTransaction = new SurfaceControl.Transaction(); private SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction(); - private int mParentSurfaceGenerationId; + private int mParentSurfaceSequenceId; private RemoteAccessibilityController mRemoteAccessibilityController = new RemoteAccessibilityController(this); private final Matrix mTmpMatrix = new Matrix(); - private final float[] mMatrixValues = new float[9]; SurfaceControlViewHost.SurfacePackage mSurfacePackage; @@ -943,11 +941,10 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall // SurfaceChangedCallback to update the relative z. This is needed so that // we do not change the relative z before the server is ready to swap the // parent surface. - if (creating || (mParentSurfaceGenerationId - == viewRoot.mSurface.getGenerationId())) { + if (creating || (mParentSurfaceSequenceId == viewRoot.getSurfaceSequenceId())) { updateRelativeZ(mTmpTransaction); } - mParentSurfaceGenerationId = viewRoot.mSurface.getGenerationId(); + mParentSurfaceSequenceId = viewRoot.getSurfaceSequenceId(); if (mViewVisibility) { mTmpTransaction.show(mSurfaceControl); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 7e02549a0aaad..c173837d6ed47 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -701,6 +701,11 @@ public final class ViewRootImpl implements ViewParent, private HashSet mRootScrollCaptureCallbacks; + /** + * Increment this value when the surface has been replaced. + */ + private int mSurfaceSequenceId = 0; + private String mTag = TAG; public ViewRootImpl(Context context, Display display) { @@ -2608,7 +2613,7 @@ public final class ViewRootImpl implements ViewParent, boolean surfaceSizeChanged = false; boolean surfaceCreated = false; boolean surfaceDestroyed = false; - /* True if surface generation id changes. */ + // True if surface generation id changes or relayout result is RELAYOUT_RES_SURFACE_CHANGED. boolean surfaceReplaced = false; final boolean windowAttributesChanged = mWindowAttributesChanged; @@ -2703,6 +2708,7 @@ public final class ViewRootImpl implements ViewParent, updateColorModeIfNeeded(lp.getColorMode()); surfaceCreated = !hadSurface && mSurface.isValid(); surfaceDestroyed = hadSurface && !mSurface.isValid(); + // When using Blast, the surface generation id may not change when there's a new // SurfaceControl. In that case, we also check relayout flag // RELAYOUT_RES_SURFACE_CHANGED since it should indicate that WMS created a new @@ -2711,6 +2717,9 @@ public final class ViewRootImpl implements ViewParent, || (relayoutResult & RELAYOUT_RES_SURFACE_CHANGED) == RELAYOUT_RES_SURFACE_CHANGED) && mSurface.isValid(); + if (surfaceReplaced) { + mSurfaceSequenceId++; + } if (cutoutChanged) { mAttachInfo.mDisplayCutout.set(mPendingDisplayCutout); @@ -9879,4 +9888,8 @@ public final class ViewRootImpl implements ViewParent, boolean useBLAST() { return mUseBLASTAdapter && !mForceDisableBLAST; } + + int getSurfaceSequenceId() { + return mSurfaceSequenceId; + } }