[dVRR] Call updateInfrequentCount after setCategoryFromCategoryCounts
In some use cases, the intermittent update state could be updated right after Views vote that causes inconsistency between the voted category and the category that is sent to SurfaceFlinger.
This Cl moves updateInfrequentCount after setCategoryFromCategoryCounts to avoid that. Although we need one more frame to change the intermittent update state, we can now ensure the consistency.
Fixes: 338173334
Test: atest ViewRootImplTest / atest ViewFrameRateTest`
Change-Id: I8eb775a45eb7bc5d3cb4a0f759525228296203dd
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index f0d27da..f51d909 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -4257,8 +4257,8 @@
// when the values are applicable.
if (mDrawnThisFrame) {
mDrawnThisFrame = false;
- updateInfrequentCount();
setCategoryFromCategoryCounts();
+ updateInfrequentCount();
setPreferredFrameRate(mPreferredFrameRate);
setPreferredFrameRateCategory(mPreferredFrameRateCategory);
if (!mIsFrameRateConflicted) {
diff --git a/core/tests/coretests/src/android/view/ViewRootImplTest.java b/core/tests/coretests/src/android/view/ViewRootImplTest.java
index 5caf77d..7c098f2 100644
--- a/core/tests/coretests/src/android/view/ViewRootImplTest.java
+++ b/core/tests/coretests/src/android/view/ViewRootImplTest.java
@@ -1138,6 +1138,8 @@
mView = new View(sContext);
WindowManager.LayoutParams wmlp = new WindowManager.LayoutParams(TYPE_APPLICATION_OVERLAY);
wmlp.token = new Binder(); // Set a fake token to bypass 'is your activity running' check
+ int expected = toolkitFrameRateDefaultNormalReadOnly()
+ ? FRAME_RATE_CATEGORY_NORMAL : FRAME_RATE_CATEGORY_HIGH;
sInstrumentation.runOnMainSync(() -> {
WindowManager wm = sContext.getSystemService(WindowManager.class);
@@ -1157,8 +1159,6 @@
Thread.sleep(delay);
sInstrumentation.runOnMainSync(() -> {
mView.invalidate();
- int expected = toolkitFrameRateDefaultNormalReadOnly()
- ? FRAME_RATE_CATEGORY_NORMAL : FRAME_RATE_CATEGORY_HIGH;
runAfterDraw(() -> assertEquals(expected,
mViewRootImpl.getLastPreferredFrameRateCategory()));
});
@@ -1168,8 +1168,6 @@
Thread.sleep(delay);
sInstrumentation.runOnMainSync(() -> {
mView.invalidate();
- int expected = toolkitFrameRateDefaultNormalReadOnly()
- ? FRAME_RATE_CATEGORY_NORMAL : FRAME_RATE_CATEGORY_HIGH;
runAfterDraw(() -> assertEquals(expected,
mViewRootImpl.getLastPreferredFrameRateCategory()));
});
@@ -1177,12 +1175,26 @@
// Infrequent update
Thread.sleep(delay);
sInstrumentation.runOnMainSync(() -> {
- mView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_DEFAULT);
mView.invalidate();
runAfterDraw(() -> assertEquals(FRAME_RATE_CATEGORY_NORMAL,
mViewRootImpl.getLastPreferredFrameRateCategory()));
});
waitForAfterDraw();
+
+ // When the View vote, it's still considered as intermittent update state
+ sInstrumentation.runOnMainSync(() -> {
+ mView.invalidate();
+ runAfterDraw(() -> assertEquals(FRAME_RATE_CATEGORY_NORMAL,
+ mViewRootImpl.getLastPreferredFrameRateCategory()));
+ });
+ waitForAfterDraw();
+
+ // Becomes frequent update state
+ sInstrumentation.runOnMainSync(() -> {
+ mView.invalidate();
+ runAfterDraw(() -> assertEquals(expected,
+ mViewRootImpl.getLastPreferredFrameRateCategory()));
+ });
}
/**