Trigger touch boost when the viewVisibility of ViewRootImpl changed
This main purpose of this CL is to trigger touch boost when when the viewVisibility of ViewRootImpl is changed and the visibility is visible.
Also, having frame rate boost when a ViewRootImpl is first available.
This can ensure the transitions / animations are smooth after a laucher
is lauching a new window.
Test: atest ViewRootImplTest
Bug: 315141420
Change-Id: Ib61775ed4c13142d73bdbe6a577fe61e2635984e
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index d27f787..0ba0f710 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -3218,6 +3218,12 @@
endDragResizing();
destroyHardwareResources();
}
+
+ if (sToolkitSetFrameRateReadOnlyFlagValue && viewVisibility == View.VISIBLE) {
+ // Boost frame rate when the viewVisibility becomes true.
+ // This is mainly for lanuchers that lanuch new windows.
+ boostFrameRate(FRAME_RATE_TOUCH_BOOST_TIME);
+ }
}
// Non-visible windows can't hold accessibility focus.
@@ -3927,6 +3933,11 @@
focused.restoreDefaultFocus();
}
}
+
+ if (sToolkitSetFrameRateReadOnlyFlagValue) {
+ // Boost the frame rate when the ViewRootImpl first becomes available.
+ boostFrameRate(FRAME_RATE_TOUCH_BOOST_TIME);
+ }
}
final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible;
@@ -11992,7 +12003,7 @@
try {
if (mLastPreferredFrameRateCategory != frameRateCategory) {
mFrameRateTransaction.setFrameRateCategory(mSurfaceControl,
- frameRateCategory, false).applyAsyncUnsafe();
+ frameRateCategory, false).applyAsyncUnsafe();
mLastPreferredFrameRateCategory = frameRateCategory;
}
} catch (Exception e) {
@@ -12115,6 +12126,22 @@
return mPreferredFrameRate;
}
+ /**
+ * Get the value of mIsFrameRateBoosting
+ */
+ @VisibleForTesting
+ public boolean getIsFrameRateBoosting() {
+ return mIsFrameRateBoosting;
+ }
+
+ private void boostFrameRate(int boostTimeOut) {
+ mIsFrameRateBoosting = true;
+ setPreferredFrameRateCategory(mPreferredFrameRateCategory);
+ mHandler.removeMessages(MSG_TOUCH_BOOST_TIMEOUT);
+ mHandler.sendEmptyMessageDelayed(MSG_TOUCH_BOOST_TIMEOUT,
+ boostTimeOut);
+ }
+
@Override
public boolean transferHostTouchGestureToEmbedded(
@NonNull SurfaceControlViewHost.SurfacePackage surfacePackage) {
diff --git a/core/tests/coretests/src/android/view/ViewRootImplTest.java b/core/tests/coretests/src/android/view/ViewRootImplTest.java
index 6172622..b30a0c8 100644
--- a/core/tests/coretests/src/android/view/ViewRootImplTest.java
+++ b/core/tests/coretests/src/android/view/ViewRootImplTest.java
@@ -472,6 +472,7 @@
* Test the value of the frame rate cateogry based on the visibility of a view
* Invsible: FRAME_RATE_CATEGORY_NO_PREFERENCE
* Visible: FRAME_RATE_CATEGORY_NORMAL
+ * Also, mIsFrameRateBoosting should be true when the visibility becomes visible
*/
@Test
@RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
@@ -485,6 +486,7 @@
assertEquals(viewRootImpl.getPreferredFrameRateCategory(),
FRAME_RATE_CATEGORY_NO_PREFERENCE);
});
+ sInstrumentation.waitForIdleSync();
sInstrumentation.runOnMainSync(() -> {
view.setVisibility(View.VISIBLE);
@@ -492,6 +494,11 @@
assertEquals(viewRootImpl.getPreferredFrameRateCategory(),
FRAME_RATE_CATEGORY_NORMAL);
});
+ sInstrumentation.waitForIdleSync();
+
+ sInstrumentation.runOnMainSync(() -> {
+ assertEquals(viewRootImpl.getIsFrameRateBoosting(), true);
+ });
}
/**