From 15d0ac57f79b8eac469394391ecdc5c45b67da6d Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 5 Sep 2019 00:05:47 +0800 Subject: Reduce relayoutWindow when requestTransparentRegion The pixel format should only need to apply once if the private flags is actually changed. The subsequent request doesn't change the window attributes. The most common case is from SurfaceView#onAttachedToWindow and performDrawFinished. Also remove mWindowAttributesChangesFlag which is never checked. It was added in commit f21c9b0f and its functionality was replaced by commit 40e0383d. Bug: 140407614 Test: Enable log of relayoutWindow in WindowManagerService. Launch a sample app with a button which will add a SurfaceView if clicked. The relayoutWindow log won't appear after the second time pressing the button. Change-Id: I13d36e390faad17a8e39a8c17c95fee5d3111960 --- core/java/android/view/ViewRootImpl.java | 23 +++++++++++------------ core/java/android/view/WindowManager.java | 2 -- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3a51eaa5d7d1..85aba3c3f535 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -468,7 +468,6 @@ public final class ViewRootImpl implements ViewParent, private final UnhandledKeyManager mUnhandledKeyManager = new UnhandledKeyManager(); boolean mWindowAttributesChanged = false; - int mWindowAttributesChangesFlag = 0; // These can be accessed by any thread, must be protected with a lock. // Surface can never be reassigned or cleared (use Surface.clear()). @@ -865,7 +864,6 @@ public final class ViewRootImpl implements ViewParent, mSoftInputMode = attrs.softInputMode; mWindowAttributesChanged = true; - mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; mAttachInfo.mRootView = view; mAttachInfo.mScalingRequired = mTranslator != null; mAttachInfo.mApplicationScale = @@ -1269,14 +1267,12 @@ public final class ViewRootImpl implements ViewParent, attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; - mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); - if ((mWindowAttributesChangesFlag - & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { + final int changes = mWindowAttributes.copyFrom(attrs); + if ((changes & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { // Recompute system ui visibility. mAttachInfo.mRecomputeGlobalAttributes = true; } - if ((mWindowAttributesChangesFlag - & WindowManager.LayoutParams.LAYOUT_CHANGED) != 0) { + if ((changes & WindowManager.LayoutParams.LAYOUT_CHANGED) != 0) { // Request to update light center. mAttachInfo.mNeedsUpdateLightCenter = true; } @@ -2037,8 +2033,6 @@ public final class ViewRootImpl implements ViewParent, } } - mWindowAttributesChangesFlag = 0; - Rect frame = mWinFrame; if (mFirst) { mFullRedrawNeeded = true; @@ -3313,14 +3307,19 @@ public final class ViewRootImpl implements ViewParent, public void requestTransparentRegion(View child) { // the test below should not fail unless someone is messing with us checkThread(); - if (mView == child) { + if (mView != child) { + return; + } + + if ((mView.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; // Need to make sure we re-evaluate the window attributes next // time around, to ensure the window has the correct format. mWindowAttributesChanged = true; - mWindowAttributesChangesFlag = 0; - requestLayout(); } + + // Always request layout to apply the latest transparent region. + requestLayout(); } /** diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 9cd356f6d653..b2d70321178e 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -2891,8 +2891,6 @@ public interface WindowManager extends ViewManager { public static final int COLOR_MODE_CHANGED = 1 << 26; /** {@hide} */ public static final int INSET_FLAGS_CHANGED = 1 << 27; - /** {@hide} */ - public static final int EVERYTHING_CHANGED = 0xffffffff; // internal buffer to backup/restore parameters under compatibility mode. private int[] mCompatibilityParamsBackup = null; -- cgit v1.2.3-59-g8ed1b