summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Riddle Hsu <riddlehsu@google.com> 2023-05-08 20:56:10 +0800
committer Riddle Hsu <riddlehsu@google.com> 2023-05-08 12:59:39 +0000
commit2d2e953cd35e6baad56e9d32c76762a51f00290c (patch)
tree3810ae313535e3a4279eabaff97782f368adef85
parentf3475fcf118e8069ed6c2123f9c5bc0882d91107 (diff)
Do not redraw if no change on reparent
An example is when transferring a starting window in a task with embedded activities. The configuration of the starting window will be overridden by task, so there won't be configuration change when transferring the window between activities. And if the window was drawn, it is unnecessary to request redraw by onSyncReparent -> WindowState#prepareSync() -> requestRedrawForSync(). Though this can avoid potential SurfaceSyncGroup timeout indirectly, this is still a reasonable performance optimization. Bug: 279798720 Test: atest SyncEngineTests#testReparentIn Change-Id: Iebfb662b579eceecc470719fa6a2dc8ba8df332f
-rw-r--r--services/core/java/com/android/server/wm/WindowContainer.java8
-rw-r--r--services/core/java/com/android/server/wm/WindowState.java7
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/SyncEngineTests.java16
3 files changed, 31 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 829a33d4bfb7..e94748f111f4 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -3990,6 +3990,9 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
}
// Otherwise this is the "root" of a synced subtree, so continue on to preparation.
}
+ if (oldParent != null && newParent != null && !shouldUpdateSyncOnReparent()) {
+ return;
+ }
// This container's situation has changed so we need to restart its sync.
// We cannot reset the sync without a chance of a deadlock since it will request a new
@@ -4004,6 +4007,11 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
prepareSync();
}
+ /** Returns {@code true} if {@link #mSyncState} needs to be updated when reparenting. */
+ protected boolean shouldUpdateSyncOnReparent() {
+ return true;
+ }
+
void registerWindowContainerListener(WindowContainerListener listener) {
registerWindowContainerListener(listener, true /* shouldPropConfig */);
}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 032f08a92abb..bab7a78a7286 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -5635,6 +5635,13 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
}
@Override
+ protected boolean shouldUpdateSyncOnReparent() {
+ // Keep the sync state in case the client is drawing for the latest conifguration or the
+ // configuration is not changed after reparenting. This avoids a redundant redraw request.
+ return mSyncState != SYNC_STATE_NONE && !mLastConfigReportedToClient;
+ }
+
+ @Override
boolean prepareSync() {
if (!mDrawHandlers.isEmpty()) {
Slog.w(TAG, "prepareSync with mDrawHandlers, " + this + ", " + Debug.getCallers(8));
diff --git a/services/tests/wmtests/src/com/android/server/wm/SyncEngineTests.java b/services/tests/wmtests/src/com/android/server/wm/SyncEngineTests.java
index a3a36841d807..5eebe746d64b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SyncEngineTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SyncEngineTests.java
@@ -26,6 +26,7 @@ import static com.android.server.wm.BLASTSyncEngine.METHOD_NONE;
import static com.android.server.wm.WindowContainer.POSITION_BOTTOM;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
import static com.android.server.wm.WindowContainer.SYNC_STATE_NONE;
+import static com.android.server.wm.WindowContainer.SYNC_STATE_READY;
import static com.android.server.wm.WindowState.BLAST_TIMEOUT_DURATION;
import static org.junit.Assert.assertEquals;
@@ -38,7 +39,9 @@ import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.spy;
import android.platform.test.annotations.Presubmit;
+import android.util.MergedConfiguration;
import android.view.SurfaceControl;
+import android.window.ClientWindowFrames;
import androidx.test.filters.SmallTest;
@@ -306,6 +309,19 @@ public class SyncEngineTests extends WindowTestsBase {
assertEquals(SYNC_STATE_NONE, parentWC.mSyncState);
assertEquals(SYNC_STATE_NONE, topChildWC.mSyncState);
assertEquals(SYNC_STATE_NONE, botChildWC.mSyncState);
+
+ // If the appearance of window won't change after reparenting, its sync state can be kept.
+ final WindowState w = createWindow(null, TYPE_BASE_APPLICATION, "win");
+ parentWC.onRequestedOverrideConfigurationChanged(w.getConfiguration());
+ w.reparent(botChildWC, POSITION_TOP);
+ parentWC.prepareSync();
+ // Assume the window has drawn with the latest configuration.
+ w.fillClientWindowFramesAndConfiguration(new ClientWindowFrames(),
+ new MergedConfiguration(), true /* useLatestConfig */, true /* relayoutVisible */);
+ assertTrue(w.onSyncFinishedDrawing());
+ assertEquals(SYNC_STATE_READY, w.mSyncState);
+ w.reparent(topChildWC, POSITION_TOP);
+ assertEquals(SYNC_STATE_READY, w.mSyncState);
}
@Test