diff options
| author | 2024-03-06 05:09:56 +0000 | |
|---|---|---|
| committer | 2024-03-06 05:23:45 +0000 | |
| commit | dd98160363ef1f2f19ad74f48095336970dd31d4 (patch) | |
| tree | 2486307113d026178d5f313aebc3397da6801ab3 | |
| parent | 2f29168a581cece73f9eaab65950a0863cc0d5e5 (diff) | |
Set frame rate category as HIGH when a View has a velocity
Set frame rate category as HIGH when a View has a velocity
Bug: 296457810
Test: atest ViewRootImplTest
Change-Id: Ia4edbb2a03dcc1c8cbd6a70664157d303640e0a3
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 15 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/view/ViewRootImplTest.java | 33 |
2 files changed, 46 insertions, 2 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 6d8524d5f2e2..fab2db9f2bc1 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -12357,7 +12357,9 @@ public final class ViewRootImpl implements ViewParent, // For now, FRAME_RATE_CATEGORY_HIGH_HINT is used for boosting with user interaction. // FRAME_RATE_CATEGORY_HIGH is for boosting without user interaction // (e.g., Window Initialization). - if (mIsFrameRateBoosting || mInsetsAnimationRunning) { + if (mIsFrameRateBoosting || mInsetsAnimationRunning + || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE + && mPreferredFrameRate > 0)) { frameRateCategory = FRAME_RATE_CATEGORY_HIGH; } @@ -12380,7 +12382,8 @@ public final class ViewRootImpl implements ViewParent, } private void setPreferredFrameRate(float preferredFrameRate) { - if (!shouldSetFrameRate()) { + if (!shouldSetFrameRate() || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE + && preferredFrameRate > 0)) { return; } @@ -12540,6 +12543,14 @@ public final class ViewRootImpl implements ViewParent, } /** + * Get the value of mLastPreferredFrameRate + */ + @VisibleForTesting + public float getLastPreferredFrameRate() { + return mLastPreferredFrameRate; + } + + /** * Returns whether touch boost is currently enabled. */ @VisibleForTesting diff --git a/core/tests/coretests/src/android/view/ViewRootImplTest.java b/core/tests/coretests/src/android/view/ViewRootImplTest.java index 1a242eff73b1..2544fcb81692 100644 --- a/core/tests/coretests/src/android/view/ViewRootImplTest.java +++ b/core/tests/coretests/src/android/view/ViewRootImplTest.java @@ -19,6 +19,7 @@ package android.view; import static android.view.accessibility.Flags.FLAG_FORCE_INVERT_COLOR; import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY; import static android.view.flags.Flags.FLAG_TOOLKIT_FRAME_RATE_BY_SIZE_READ_ONLY; +import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static android.view.Surface.FRAME_RATE_CATEGORY_HIGH; import static android.view.Surface.FRAME_RATE_CATEGORY_HIGH_HINT; import static android.view.Surface.FRAME_RATE_CATEGORY_LOW; @@ -796,6 +797,38 @@ public class ViewRootImplTest { } /** + * When velocity of a View is not equal to 0, we call setFrameRateCategory with HIGH. + * Also, we shouldn't call setFrameRate. + */ + @Test + @RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY, FLAG_VIEW_VELOCITY_API}) + public void votePreferredFrameRate_voteFrameRateCategory_velocityToHigh() { + View view = 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 + wmlp.width = 1; + wmlp.height = 1; + + sInstrumentation.runOnMainSync(() -> { + WindowManager wm = sContext.getSystemService(WindowManager.class); + wm.addView(view, wmlp); + }); + sInstrumentation.waitForIdleSync(); + + ViewRootImpl viewRootImpl = view.getViewRootImpl(); + + sInstrumentation.runOnMainSync(() -> { + assertEquals(viewRootImpl.getPreferredFrameRate(), 0, 0.1); + view.setFrameContentVelocity(100); + view.invalidate(); + assertTrue(viewRootImpl.getPreferredFrameRate() > 0); + }); + sInstrumentation.waitForIdleSync(); + assertEquals(viewRootImpl.getLastPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_HIGH); + assertEquals(viewRootImpl.getLastPreferredFrameRate(), 0 , 0.1); + } + + /** * We should boost the frame rate if the value of mInsetsAnimationRunning is true. */ @Test |