From bf01a77453feaabfaea09cc12a8e81227f00f2f5 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 18 Feb 2020 08:42:53 -0800 Subject: [PATCH] SurfaceView: Fix BLAST Sync initialization. When the SurfaceView is moved, we need to detect this and trigger the ViewRootImpl to use a BLASTSync transaction for the next draw. First we tried to do this from invalidate but parent invalidation won't always lead to invalidate and so this doesn't work. Doing it from updateSurface which is called from a PreDrawHandler ensures we will be evaluated at least once per draw. Bug: 146598493 Bug: 149251083 Bug: 149315421 Test: Flip the flag. Play with youtube. Change-Id: I652eacf1a016f8b65fd754e47d468227bf8ecf1d --- core/java/android/view/SurfaceView.java | 34 +++++++++---------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 5566e0e4292ee..deff79d5486ab 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -788,9 +788,16 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall final boolean sizeChanged = mSurfaceWidth != myWidth || mSurfaceHeight != myHeight; final boolean windowVisibleChanged = mWindowVisibility != mLastWindowVisibility; boolean redrawNeeded = false; + getLocationInSurface(mLocation); + final boolean positionChanged = mWindowSpaceLeft != mLocation[0] + || mWindowSpaceTop != mLocation[1]; + final boolean layoutSizeChanged = getWidth() != mScreenRect.width() + || getHeight() != mScreenRect.height(); - if (creating || formatChanged || sizeChanged || visibleChanged || (mUseAlpha - && alphaChanged) || windowVisibleChanged) { + + if (creating || formatChanged || sizeChanged || visibleChanged || + (mUseAlpha && alphaChanged) || windowVisibleChanged || + positionChanged || layoutSizeChanged) { getLocationInWindow(mLocation); if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " " @@ -922,6 +929,9 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall mTmpTransaction.setWindowCrop(mSurfaceControl, mSurfaceWidth, mSurfaceHeight); } + } else if ((layoutSizeChanged || positionChanged) && + WindowManagerGlobal.useBLAST()) { + viewRoot.setUseBLASTSyncTransaction(); } mTmpTransaction.setCornerRadius(mSurfaceControl, mCornerRadius); if (sizeChanged && !creating) { @@ -1058,11 +1068,6 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall } else { // Calculate the window position in case RT loses the window // and we need to fallback to a UI-thread driven position update - getLocationInSurface(mLocation); - final boolean positionChanged = mWindowSpaceLeft != mLocation[0] - || mWindowSpaceTop != mLocation[1]; - final boolean layoutSizeChanged = getWidth() != mScreenRect.width() - || getHeight() != mScreenRect.height(); if (positionChanged || layoutSizeChanged) { // Only the position has changed mWindowSpaceLeft = mLocation[0]; mWindowSpaceTop = mLocation[1]; @@ -1539,21 +1544,6 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall t.setRelativeLayer(mSurfaceControl, viewRoot, mSubLayer); } - /** - * @hide - * Note: Base class method is @UnsupportedAppUsage - */ - @Override - public void invalidate(boolean invalidateCache) { - super.invalidate(invalidateCache); - if (!WindowManagerGlobal.useBLAST()) { - return; - } - final ViewRootImpl viewRoot = getViewRootImpl(); - if (viewRoot == null) return; - viewRoot.setUseBLASTSyncTransaction(); - } - /** * Display the view-hierarchy embedded within a {@link SurfaceControlViewHost.SurfacePackage} * within this SurfaceView. If this SurfaceView is above it's host Surface (see