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
This commit is contained in:
Robert Carr
2020-02-18 08:42:53 -08:00
parent e49a32946f
commit bf01a77453

View File

@@ -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