RefreshRatePolicy: getPreferredRefreshRate should consider preferredRefreshRate

If an app set the WindowManager.LayoutParams#preferredRefreshRate, refresh
rate policy should return it the the preferred refresh rate of the window
if all the other signals (preferredDisplayModeId or deny list) doesn't
have a vote.

Test: atest RefreshRatePolicyTest FrameRateSelectionPriorityTests
Bug: 192413241
Change-Id: I55dc5c2acc8b66cfedbd0c0f0fb66c57eeaa36fe
This commit is contained in:
Ady Abraham
2021-06-29 15:48:11 -07:00
parent d003be9369
commit 1e5c50bbe3
2 changed files with 33 additions and 1 deletions

View File

@@ -151,6 +151,10 @@ class RefreshRatePolicy {
}
}
if (w.mAttrs.preferredRefreshRate != 0) {
return w.mAttrs.preferredRefreshRate;
}
return 0;
}

View File

@@ -228,7 +228,7 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {
}
@Test
public void testPreferredRefreshRate() {
public void testDenyListPreferredRefreshRate() {
final WindowState appWindow = createWindow("appWindow");
assertNotNull("Window state is created", appWindow);
when(appWindow.getDisplayContent().getDisplayPolicy()).thenReturn(mDisplayPolicy);
@@ -281,4 +281,32 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {
verify(appWindow.getPendingTransaction(), never()).setFrameRate(
any(SurfaceControl.class), anyInt(), anyInt(), anyInt());
}
@Test
public void testAppPreferredRefreshRate() {
final WindowState appWindow = createWindow("appWindow");
assertNotNull("Window state is created", appWindow);
when(appWindow.getDisplayContent().getDisplayPolicy()).thenReturn(mDisplayPolicy);
appWindow.mAttrs.packageName = "com.android.test";
appWindow.mAttrs.preferredRefreshRate = 60;
assertEquals(0, mRefreshRatePolicy.getPreferredModeId(appWindow));
assertEquals(60, mRefreshRatePolicy.getPreferredRefreshRate(appWindow), FLOAT_TOLERANCE);
appWindow.updateFrameRateSelectionPriorityIfNeeded();
assertEquals(RefreshRatePolicy.LAYER_PRIORITY_UNSET, appWindow.mFrameRateSelectionPriority);
assertEquals(60, appWindow.mAppPreferredFrameRate, FLOAT_TOLERANCE);
// Call the function a few times.
appWindow.updateFrameRateSelectionPriorityIfNeeded();
appWindow.updateFrameRateSelectionPriorityIfNeeded();
// Since nothing changed in the priority state, the transaction should not be updating.
verify(appWindow.getPendingTransaction(), never()).setFrameRateSelectionPriority(
any(SurfaceControl.class), anyInt());
verify(appWindow.getPendingTransaction(), times(1)).setFrameRate(
appWindow.getSurfaceControl(), 60,
Surface.FRAME_RATE_COMPATIBILITY_EXACT, Surface.CHANGE_FRAME_RATE_ALWAYS);
}
}