From f690bc649936e0bc2921853665f9d44bae67b132 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 22 Feb 2022 19:22:28 -0800 Subject: [PATCH] ViewRootImpl: Don't pause HWUI so much We have paused and thus flushed the HW renderer before calling relayout for many releases. This has served a multitude of purposes over the years: 1. Ensuring that the WM doesn't destroy the surface or update the default buffer size while we are rendering - WM no longer updates default buffer size or handles surface lifetime 2. Ensure that we can get a proper frame number, previously used for deferTransactionUntil - deferTransactionUntil doesn't exist anymore 3. Ensure that we can call setNextTransaction at an appropriate time - We now call this from an RT thread side callback. This means in the current code we only have to pause it when we ourselves are updating the size. Since this pause requires all previous draws to flush, it should be a nice performance win. Test: Existing tests pass Bug: 220649859 Change-Id: I143de3f44b8bd69754d9e824fc8b729dc296e183 --- core/java/android/view/ViewRootImpl.java | 33 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index feb17f54acd67..3f1cf6851851a 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -824,6 +824,8 @@ public final class ViewRootImpl implements ViewParent, private boolean mRelayoutRequested; + private int mLastTransformHint = Integer.MIN_VALUE; + private String mTag = TAG; public ViewRootImpl(Context context, Display display) { @@ -2878,16 +2880,6 @@ public final class ViewRootImpl implements ViewParent, host.getMeasuredHeight() + ", params=" + params); } - if (mAttachInfo.mThreadedRenderer != null) { - // relayoutWindow may decide to destroy mSurface. As that decision - // happens in WindowManager service, we need to be defensive here - // and stop using the surface in case it gets destroyed. - if (mAttachInfo.mThreadedRenderer.pause()) { - // Animations were running so we need to push a frame - // to resume them - mDirty.set(0, 0, mWidth, mHeight); - } - } if (mFirst || viewVisibilityChanged) { mViewFrameInfo.flags |= FrameInfo.FLAG_WINDOW_VISIBILITY_CHANGED; } @@ -8035,13 +8027,29 @@ public final class ViewRootImpl implements ViewParent, final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); - mSurfaceControl.setTransformHint(transformHint); final WindowConfiguration winConfig = getConfiguration().windowConfiguration; final boolean dragResizing = (relayoutResult & (RELAYOUT_RES_DRAG_RESIZING_DOCKED | RELAYOUT_RES_DRAG_RESIZING_FREEFORM)) != 0; WindowLayout.computeSurfaceSize(mWindowAttributes, winConfig.getMaxBounds(), requestedWidth, requestedHeight, mTmpFrames.frame, dragResizing, mSurfaceSize); + + final boolean transformHintChanged = transformHint != mLastTransformHint; + final boolean sizeChanged = !mLastSurfaceSize.equals(mSurfaceSize); + final boolean surfaceControlChanged = + (relayoutResult & RELAYOUT_RES_SURFACE_CHANGED) == RELAYOUT_RES_SURFACE_CHANGED; + if (mAttachInfo.mThreadedRenderer != null && + (transformHintChanged || sizeChanged || surfaceControlChanged)) { + if (mAttachInfo.mThreadedRenderer.pause()) { + // Animations were running so we need to push a frame + // to resume them + mDirty.set(0, 0, mWidth, mHeight); + } + } + + mLastTransformHint = transformHint; + + mSurfaceControl.setTransformHint(transformHint); if (mAttachInfo.mContentCaptureManager != null) { MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager @@ -8066,6 +8074,9 @@ public final class ViewRootImpl implements ViewParent, dispatchTransformHintChanged(transformHint); } } else { + if (mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.pause()) { + mDirty.set(0, 0, mWidth, mHeight); + } destroySurface(); }