diff options
| author | 2024-03-07 16:07:59 +0000 | |
|---|---|---|
| committer | 2024-03-07 16:07:59 +0000 | |
| commit | 9facd3ac6e4db8f059d5a4fe0bb8fc637514ba4f (patch) | |
| tree | 1395f0043723bb1b6027b804a772061ccd623856 | |
| parent | a14ab6642f89084e9a6dc8f12ab0fdbc18e16cc3 (diff) | |
| parent | dd98160363ef1f2f19ad74f48095336970dd31d4 (diff) | |
Merge "Set frame rate category as HIGH when a View has a velocity" into main
| -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 42f64052d987..69f16572585d 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -12360,7 +12360,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; } @@ -12383,7 +12385,8 @@ public final class ViewRootImpl implements ViewParent, } private void setPreferredFrameRate(float preferredFrameRate) { - if (!shouldSetFrameRate()) { + if (!shouldSetFrameRate() || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE + && preferredFrameRate > 0)) { return; } @@ -12543,6 +12546,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 |