Loading core/java/android/view/ViewRootImpl.java +12 −3 Original line number Original line Diff line number Diff line Loading @@ -108,6 +108,7 @@ import static android.view.accessibility.Flags.fixMergedContentChangeEventV2; import static android.view.accessibility.Flags.forceInvertColor; import static android.view.accessibility.Flags.forceInvertColor; import static android.view.accessibility.Flags.reduceWindowContentChangedEventThrottle; import static android.view.accessibility.Flags.reduceWindowContentChangedEventThrottle; import static android.view.flags.Flags.toolkitFrameRateTypingReadOnly; import static android.view.flags.Flags.toolkitFrameRateTypingReadOnly; import static android.view.flags.Flags.toolkitFrameRateVelocityMappingReadOnly; import static android.view.flags.Flags.toolkitMetricsForFrameRateDecision; import static android.view.flags.Flags.toolkitMetricsForFrameRateDecision; import static android.view.flags.Flags.toolkitSetFrameRateReadOnly; import static android.view.flags.Flags.toolkitSetFrameRateReadOnly; import static android.view.flags.Flags.toolkitFrameRateFunctionEnablingReadOnly; import static android.view.flags.Flags.toolkitFrameRateFunctionEnablingReadOnly; Loading Loading @@ -1154,6 +1155,8 @@ public final class ViewRootImpl implements ViewParent, private static boolean sToolkitFrameRateFunctionEnablingReadOnlyFlagValue; private static boolean sToolkitFrameRateFunctionEnablingReadOnlyFlagValue; private static boolean sToolkitMetricsForFrameRateDecisionFlagValue; private static boolean sToolkitMetricsForFrameRateDecisionFlagValue; private static boolean sToolkitFrameRateTypingReadOnlyFlagValue; private static boolean sToolkitFrameRateTypingReadOnlyFlagValue; private static boolean sToolkitFrameRateVelocityMappingReadOnlyFlagValue = toolkitFrameRateVelocityMappingReadOnly();; static { static { sToolkitSetFrameRateReadOnlyFlagValue = toolkitSetFrameRateReadOnly(); sToolkitSetFrameRateReadOnlyFlagValue = toolkitSetFrameRateReadOnly(); Loading Loading @@ -12463,7 +12466,9 @@ public final class ViewRootImpl implements ViewParent, } } private void setPreferredFrameRateCategory(int preferredFrameRateCategory) { private void setPreferredFrameRateCategory(int preferredFrameRateCategory) { if (!shouldSetFrameRateCategory()) { if (!shouldSetFrameRateCategory() || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE && sToolkitFrameRateVelocityMappingReadOnlyFlagValue)) { return; return; } } int categoryFromConflictedFrameRates = FRAME_RATE_CATEGORY_NO_PREFERENCE; int categoryFromConflictedFrameRates = FRAME_RATE_CATEGORY_NO_PREFERENCE; Loading Loading @@ -12558,8 +12563,12 @@ public final class ViewRootImpl implements ViewParent, } } private void setPreferredFrameRate(float preferredFrameRate) { private void setPreferredFrameRate(float preferredFrameRate) { if (!shouldSetFrameRate() || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE if (!shouldSetFrameRate()) { && preferredFrameRate > 0)) { return; } if (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE && preferredFrameRate > 0 && !sToolkitFrameRateVelocityMappingReadOnlyFlagValue) { mIsTouchBoosting = false; return; return; } } core/tests/coretests/src/android/view/ViewFrameRateTest.java +40 −0 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ package android.view; import static android.view.Surface.FRAME_RATE_CATEGORY_HIGH; import static android.view.Surface.FRAME_RATE_CATEGORY_HIGH; import static android.view.Surface.FRAME_RATE_CATEGORY_LOW; import static android.view.Surface.FRAME_RATE_CATEGORY_LOW; import static android.view.Surface.FRAME_RATE_CATEGORY_NORMAL; import static android.view.Surface.FRAME_RATE_CATEGORY_NORMAL; import static android.view.Surface.FRAME_RATE_COMPATIBILITY_GTE; import static android.view.flags.Flags.FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY; import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY; import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY; import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static android.view.flags.Flags.toolkitFrameRateBySizeReadOnly; import static android.view.flags.Flags.toolkitFrameRateBySizeReadOnly; Loading Loading @@ -115,6 +117,44 @@ public class ViewFrameRateTest { }); }); } } @Test @RequiresFlagsEnabled({FLAG_VIEW_VELOCITY_API, FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY}) public void lowVelocity60() throws Throwable { mActivityRule.runOnUiThread(() -> { ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; mMovingView.setLayoutParams(layoutParams); }); waitForFrameRateCategoryToSettle(); mActivityRule.runOnUiThread(() -> { mMovingView.setFrameContentVelocity(1f); mMovingView.invalidate(); assertEquals(60f, mViewRoot.getPreferredFrameRate(), 0f); assertEquals(FRAME_RATE_COMPATIBILITY_GTE, mViewRoot.getFrameRateCompatibility()); }); } @Test @RequiresFlagsEnabled({FLAG_VIEW_VELOCITY_API, FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY}) public void highVelocity140() throws Throwable { mActivityRule.runOnUiThread(() -> { ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; mMovingView.setLayoutParams(layoutParams); }); waitForFrameRateCategoryToSettle(); mActivityRule.runOnUiThread(() -> { mMovingView.setFrameContentVelocity(1_000_000_000f); mMovingView.invalidate(); assertEquals(140f, mViewRoot.getPreferredFrameRate(), 0f); assertEquals(FRAME_RATE_COMPATIBILITY_GTE, mViewRoot.getFrameRateCompatibility()); }); } private void waitForFrameRateCategoryToSettle() throws Throwable { private void waitForFrameRateCategoryToSettle() throws Throwable { for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) { final CountDownLatch drawLatch = new CountDownLatch(1); final CountDownLatch drawLatch = new CountDownLatch(1); Loading Loading
core/java/android/view/ViewRootImpl.java +12 −3 Original line number Original line Diff line number Diff line Loading @@ -108,6 +108,7 @@ import static android.view.accessibility.Flags.fixMergedContentChangeEventV2; import static android.view.accessibility.Flags.forceInvertColor; import static android.view.accessibility.Flags.forceInvertColor; import static android.view.accessibility.Flags.reduceWindowContentChangedEventThrottle; import static android.view.accessibility.Flags.reduceWindowContentChangedEventThrottle; import static android.view.flags.Flags.toolkitFrameRateTypingReadOnly; import static android.view.flags.Flags.toolkitFrameRateTypingReadOnly; import static android.view.flags.Flags.toolkitFrameRateVelocityMappingReadOnly; import static android.view.flags.Flags.toolkitMetricsForFrameRateDecision; import static android.view.flags.Flags.toolkitMetricsForFrameRateDecision; import static android.view.flags.Flags.toolkitSetFrameRateReadOnly; import static android.view.flags.Flags.toolkitSetFrameRateReadOnly; import static android.view.flags.Flags.toolkitFrameRateFunctionEnablingReadOnly; import static android.view.flags.Flags.toolkitFrameRateFunctionEnablingReadOnly; Loading Loading @@ -1154,6 +1155,8 @@ public final class ViewRootImpl implements ViewParent, private static boolean sToolkitFrameRateFunctionEnablingReadOnlyFlagValue; private static boolean sToolkitFrameRateFunctionEnablingReadOnlyFlagValue; private static boolean sToolkitMetricsForFrameRateDecisionFlagValue; private static boolean sToolkitMetricsForFrameRateDecisionFlagValue; private static boolean sToolkitFrameRateTypingReadOnlyFlagValue; private static boolean sToolkitFrameRateTypingReadOnlyFlagValue; private static boolean sToolkitFrameRateVelocityMappingReadOnlyFlagValue = toolkitFrameRateVelocityMappingReadOnly();; static { static { sToolkitSetFrameRateReadOnlyFlagValue = toolkitSetFrameRateReadOnly(); sToolkitSetFrameRateReadOnlyFlagValue = toolkitSetFrameRateReadOnly(); Loading Loading @@ -12463,7 +12466,9 @@ public final class ViewRootImpl implements ViewParent, } } private void setPreferredFrameRateCategory(int preferredFrameRateCategory) { private void setPreferredFrameRateCategory(int preferredFrameRateCategory) { if (!shouldSetFrameRateCategory()) { if (!shouldSetFrameRateCategory() || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE && sToolkitFrameRateVelocityMappingReadOnlyFlagValue)) { return; return; } } int categoryFromConflictedFrameRates = FRAME_RATE_CATEGORY_NO_PREFERENCE; int categoryFromConflictedFrameRates = FRAME_RATE_CATEGORY_NO_PREFERENCE; Loading Loading @@ -12558,8 +12563,12 @@ public final class ViewRootImpl implements ViewParent, } } private void setPreferredFrameRate(float preferredFrameRate) { private void setPreferredFrameRate(float preferredFrameRate) { if (!shouldSetFrameRate() || (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE if (!shouldSetFrameRate()) { && preferredFrameRate > 0)) { return; } if (mFrameRateCompatibility == FRAME_RATE_COMPATIBILITY_GTE && preferredFrameRate > 0 && !sToolkitFrameRateVelocityMappingReadOnlyFlagValue) { mIsTouchBoosting = false; return; return; } }
core/tests/coretests/src/android/view/ViewFrameRateTest.java +40 −0 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ package android.view; import static android.view.Surface.FRAME_RATE_CATEGORY_HIGH; import static android.view.Surface.FRAME_RATE_CATEGORY_HIGH; import static android.view.Surface.FRAME_RATE_CATEGORY_LOW; import static android.view.Surface.FRAME_RATE_CATEGORY_LOW; import static android.view.Surface.FRAME_RATE_CATEGORY_NORMAL; import static android.view.Surface.FRAME_RATE_CATEGORY_NORMAL; import static android.view.Surface.FRAME_RATE_COMPATIBILITY_GTE; import static android.view.flags.Flags.FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY; import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY; import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY; import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static android.view.flags.Flags.toolkitFrameRateBySizeReadOnly; import static android.view.flags.Flags.toolkitFrameRateBySizeReadOnly; Loading Loading @@ -115,6 +117,44 @@ public class ViewFrameRateTest { }); }); } } @Test @RequiresFlagsEnabled({FLAG_VIEW_VELOCITY_API, FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY}) public void lowVelocity60() throws Throwable { mActivityRule.runOnUiThread(() -> { ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; mMovingView.setLayoutParams(layoutParams); }); waitForFrameRateCategoryToSettle(); mActivityRule.runOnUiThread(() -> { mMovingView.setFrameContentVelocity(1f); mMovingView.invalidate(); assertEquals(60f, mViewRoot.getPreferredFrameRate(), 0f); assertEquals(FRAME_RATE_COMPATIBILITY_GTE, mViewRoot.getFrameRateCompatibility()); }); } @Test @RequiresFlagsEnabled({FLAG_VIEW_VELOCITY_API, FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY}) public void highVelocity140() throws Throwable { mActivityRule.runOnUiThread(() -> { ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; mMovingView.setLayoutParams(layoutParams); }); waitForFrameRateCategoryToSettle(); mActivityRule.runOnUiThread(() -> { mMovingView.setFrameContentVelocity(1_000_000_000f); mMovingView.invalidate(); assertEquals(140f, mViewRoot.getPreferredFrameRate(), 0f); assertEquals(FRAME_RATE_COMPATIBILITY_GTE, mViewRoot.getFrameRateCompatibility()); }); } private void waitForFrameRateCategoryToSettle() throws Throwable { private void waitForFrameRateCategoryToSettle() throws Throwable { for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) { final CountDownLatch drawLatch = new CountDownLatch(1); final CountDownLatch drawLatch = new CountDownLatch(1); Loading