From 65de8793f825cb69b340e66c26204013489c1c20 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 28 Apr 2022 23:53:01 +0800 Subject: [PATCH] Update renderer surface if rotation is changed There may have several buffers, especially on a high refresh rate device. Because the render may only update partial region of the buffer after the first rotated frame, then the content in previous rotation may show at the no change regions. This restores the concept of b2e3780, but still preserves the optimization of commit 5deb763. Because the condition doesn't associate with force-layout request. Bug: 229366100 Test: No afterimages flicker after rotating 180 degrees with an activity uses seamless rotation. Change-Id: If20d30f849e07c7ccbe3a96a5c82bd106df84312 --- core/java/android/view/ViewRootImpl.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3ed81eab9a906..6d8b94c2f5265 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -600,6 +600,7 @@ public final class ViewRootImpl implements ViewParent, int mSyncSeqId = 0; int mLastSyncSeqId = 0; + private boolean mUpdateSurfaceNeeded; boolean mFullRedrawNeeded; boolean mNewSurfaceNeeded; boolean mForceNextWindowRelayout; @@ -2962,6 +2963,8 @@ public final class ViewRootImpl implements ViewParent, !mFirst, INVALID_DISPLAY /* same display */); updatedConfiguration = true; } + final boolean updateSurfaceNeeded = mUpdateSurfaceNeeded; + mUpdateSurfaceNeeded = false; surfaceSizeChanged = false; if (!mLastSurfaceSize.equals(mSurfaceSize)) { @@ -3040,7 +3043,7 @@ public final class ViewRootImpl implements ViewParent, if (isHardwareEnabled()) { mAttachInfo.mThreadedRenderer.destroy(); } - } else if ((surfaceReplaced || surfaceSizeChanged) + } else if ((surfaceReplaced || surfaceSizeChanged || updateSurfaceNeeded) && mSurfaceHolder == null && mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) { @@ -5187,6 +5190,18 @@ public final class ViewRootImpl implements ViewParent, throw new IllegalArgumentException("No merged config provided."); } + final int lastRotation = mLastReportedMergedConfiguration.getMergedConfiguration() + .windowConfiguration.getRotation(); + final int newRotation = mergedConfiguration.getMergedConfiguration() + .windowConfiguration.getRotation(); + if (lastRotation != newRotation) { + // Trigger ThreadedRenderer#updateSurface() if the surface control doesn't change. + // Because even if the actual surface size is not changed, e.g. flip 180 degrees, + // the buffers may still have content in previous rotation. And the next draw may + // not update all regions, that causes some afterimages to flicker. + mUpdateSurfaceNeeded = true; + } + Configuration globalConfig = mergedConfiguration.getGlobalConfiguration(); final Configuration overrideConfig = mergedConfiguration.getOverrideConfiguration(); if (DEBUG_CONFIGURATION) Log.v(mTag,