From 1e780ab02d7c6c1d9d55e6302f45a40402b1167d Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 14 Apr 2022 16:10:46 -0700 Subject: [PATCH] SurfaceView: Ensure position update listener sets at least once If we destroy and recreate a SurfaceView in the same frame its possible for positionChanged for the new surface to arrive before positionLost for the old surface. In this case we won't clear mRtLastReportedPosition, and so we won't set any position at all on the new surface. Bug: 229052731 Test: Existing tests pass Change-Id: I896496afa5b05848f96b20697d33911cae9639a7 --- core/java/android/view/SurfaceView.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 6be6f9d110ada..96b1abb62dbf4 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -1274,6 +1274,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall private class SurfaceViewPositionUpdateListener implements RenderNode.PositionUpdateListener { private final int mRtSurfaceWidth; private final int mRtSurfaceHeight; + private boolean mRtFirst = true; private final SurfaceControl.Transaction mPositionChangedTransaction = new SurfaceControl.Transaction(); @@ -1284,14 +1285,15 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall @Override public void positionChanged(long frameNumber, int left, int top, int right, int bottom) { - if (mRTLastReportedPosition.left == left + if (!mRtFirst && (mRTLastReportedPosition.left == left && mRTLastReportedPosition.top == top && mRTLastReportedPosition.right == right && mRTLastReportedPosition.bottom == bottom && mRTLastReportedSurfaceSize.x == mRtSurfaceWidth - && mRTLastReportedSurfaceSize.y == mRtSurfaceHeight) { + && mRTLastReportedSurfaceSize.y == mRtSurfaceHeight)) { return; } + mRtFirst = false; try { if (DEBUG_POSITION) { Log.d(TAG, String.format(