From 1dd148d9ac105af3dce7ee6776c8ba738ad2afad Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 2 Apr 2020 15:24:51 -0700 Subject: BLASTBufferQueue: Fix unnecessary copying of Surface When we call mSurface.transferFrom(getOrCreateBLASTSurface()) we always end up incrementing mSurface.generationId, because BLASTBufferQueue.java::getSurface will always return a new native wrapper object. We had a similar situation with mSurface.copyFrom(mSurfaceControl), and had to build IGBP comparison in to the native method. Here though, it's easier to just rely on the stability of the Surface (never changes for the lifetime of the BLASTBufferQueueAdapter) to avoid duplicate calls to transferFrom. Bug: 152501005 Test: Existing tests pass. Change-Id: I64b9a6ae3cabfa75974e040460638417bfac6845 --- core/java/android/view/ViewRootImpl.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'core/java/android/view/ViewRootImpl.java') diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index b5e8dd8212e3..3534bb0f763f 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -1748,13 +1748,17 @@ public final class ViewRootImpl implements ViewParent, return null; } + Surface ret = null; if (mBlastBufferQueue == null) { mBlastBufferQueue = new BLASTBufferQueue( mBlastSurfaceControl, width, height); + // We only return the Surface the first time, as otherwise + // it hasn't changed and there is no need to update. + ret = mBlastBufferQueue.getSurface(); } mBlastBufferQueue.update(mBlastSurfaceControl, width, height); - return mBlastBufferQueue.getSurface(); + return ret; } private void setBoundsLayerCrop() { @@ -7349,8 +7353,14 @@ public final class ViewRootImpl implements ViewParent, if (!mUseBLASTAdapter) { mSurface.copyFrom(mSurfaceControl); } else { - mSurface.transferFrom(getOrCreateBLASTSurface(mSurfaceSize.x, - mSurfaceSize.y)); + final Surface blastSurface = getOrCreateBLASTSurface(mSurfaceSize.x, + mSurfaceSize.y); + // If blastSurface == null that means it hasn't changed since the last time we + // called. In this situation, avoid calling transferFrom as we would then + // inc the generation ID and cause EGL resources to be recreated. + if (blastSurface != null) { + mSurface.transferFrom(blastSurface); + } } } else { destroySurface(); -- cgit v1.2.3