diff options
| author | Robert Carr <racarr@google.com> | 2019-12-19 01:33:24 -0800 |
|---|---|---|
| committer | Robert Carr <racarr@google.com> | 2019-12-30 21:34:06 -0800 |
| commit | 85bb940f72f39776a54740ab043bd4965c7bfb81 (patch) | |
| tree | f12cdc66310b71c586dc9ffdec57798d421b451c /core/java/android/view/SurfaceView.java | |
| parent | f06d584d39723ed4ddfb326c256d67121d5e5d5a (diff) | |
Port SurfaceView deferTransaction usage to BLAST
When the SurfaceView is invalidated (e.g. geometry has changed) we ask
the ViewRootImpl to render the next buffer in to a BLAST transaction which
the SurfaceView will also use from it's RT callbacks in place of deferTransactionUntil
Test: Flip USE_BLAST_BUFFERQUEUE flag. Run SurfaceViewSyncTests.
Bug: 146598493
Change-Id: I43d301f25101afae32ad1c43a3a3210c5aeadd0f
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
| -rw-r--r-- | core/java/android/view/SurfaceView.java | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 0b5af2d01349..7e195b553a6c 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -379,9 +379,11 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall * This gets called on a RenderThread worker thread, so members accessed here must * be protected by a lock. */ + final boolean useBLAST = ViewRootImpl.USE_BLAST_BUFFERQUEUE; viewRoot.registerRtFrameCallback(frame -> { try { - final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); + final SurfaceControl.Transaction t = useBLAST ? + viewRoot.getBLASTSyncTransaction() : new SurfaceControl.Transaction(); synchronized (mSurfaceControlLock) { if (!parent.isValid()) { if (DEBUG) { @@ -404,7 +406,9 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall + " updateSurfaceAlpha RT: set alpha=" + alpha); } t.setAlpha(mSurfaceControl, alpha); - t.deferTransactionUntilSurface(mSurfaceControl, parent, frame); + if (!useBLAST) { + t.deferTransactionUntilSurface(mSurfaceControl, parent, frame); + } } // It's possible that mSurfaceControl is released in the UI thread before // the transaction completes. If that happens, an exception is thrown, which @@ -1101,33 +1105,39 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall Surface viewRootSurface, long nextViewRootFrameNumber) { } - private void applySurfaceTransforms(SurfaceControl surface, Rect position, long frameNumber) { - if (frameNumber > 0) { + private void applySurfaceTransforms(SurfaceControl surface, SurfaceControl.Transaction t, + Rect position, long frameNumber) { + if (frameNumber > 0 && ViewRootImpl.USE_BLAST_BUFFERQUEUE == false) { final ViewRootImpl viewRoot = getViewRootImpl(); - mRtTransaction.deferTransactionUntilSurface(surface, viewRoot.mSurface, + t.deferTransactionUntilSurface(surface, viewRoot.mSurface, frameNumber); } - mRtTransaction.setPosition(surface, position.left, position.top); - mRtTransaction.setMatrix(surface, + t.setPosition(surface, position.left, position.top); + t.setMatrix(surface, position.width() / (float) mSurfaceWidth, 0.0f, 0.0f, position.height() / (float) mSurfaceHeight); if (mViewVisibility) { - mRtTransaction.show(surface); + t.show(surface); } } private void setParentSpaceRectangle(Rect position, long frameNumber) { + final boolean useBLAST = ViewRootImpl.USE_BLAST_BUFFERQUEUE; final ViewRootImpl viewRoot = getViewRootImpl(); + final SurfaceControl.Transaction t = useBLAST ? viewRoot.getBLASTSyncTransaction() : + mRtTransaction; - applySurfaceTransforms(mSurfaceControl, position, frameNumber); + applySurfaceTransforms(mSurfaceControl, t, position, frameNumber); - applyChildSurfaceTransaction_renderWorker(mRtTransaction, viewRoot.mSurface, + applyChildSurfaceTransaction_renderWorker(t, viewRoot.mSurface, frameNumber); - mRtTransaction.apply(); + if (!useBLAST) { + t.apply(); + } } private Rect mRTLastReportedPosition = new Rect(); @@ -1176,6 +1186,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall @Override public void positionLost(long frameNumber) { + boolean useBLAST = ViewRootImpl.USE_BLAST_BUFFERQUEUE; if (DEBUG) { Log.d(TAG, String.format("%d windowPositionLost, frameNr = %d", System.identityHashCode(this), frameNumber)); @@ -1187,13 +1198,18 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall } final ViewRootImpl viewRoot = getViewRootImpl(); - if (frameNumber > 0 && viewRoot != null) { + + final SurfaceControl.Transaction t = useBLAST ? + (viewRoot != null ? viewRoot.getBLASTSyncTransaction() : mRtTransaction) : + mRtTransaction; + + if (frameNumber > 0 && viewRoot != null && !useBLAST) { if (viewRoot.mSurface.isValid()) { mRtTransaction.deferTransactionUntilSurface(mSurfaceControl, viewRoot.mSurface, frameNumber); } } - mRtTransaction.hide(mSurfaceControl); + t.hide(mSurfaceControl); synchronized (mSurfaceControlLock) { if (mRtReleaseSurfaces) { @@ -1206,7 +1222,11 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall mRtHandlingPositionUpdates = false; } - mRtTransaction.apply(); + // If we aren't using BLAST, we apply the transaction locally, otherise we let the ViewRoot apply it for us. + // If the ViewRoot is null, we behave as if we aren't using BLAST so we need to apply the transaction. + if (!useBLAST || viewRoot == null) { + mRtTransaction.apply(); + } } }; @@ -1496,4 +1516,19 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall t.setRelativeLayer(mBackgroundControl, viewRoot, Integer.MIN_VALUE); t.setRelativeLayer(mSurfaceControl, viewRoot, mSubLayer); } + + /** + * @hide + * Note: Base class method is @UnsupportedAppUsage + */ + @Override + public void invalidate(boolean invalidateCache) { + super.invalidate(invalidateCache); + if (ViewRootImpl.USE_BLAST_BUFFERQUEUE == false) { + return; + } + final ViewRootImpl viewRoot = getViewRootImpl(); + if (viewRoot == null) return; + viewRoot.setUseBLASTSyncTransaction(); + } } |
