Loading core/java/android/view/View.java +8 −6 Original line number Original line Diff line number Diff line Loading @@ -33942,7 +33942,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return; // can't vote if not connected return; // can't vote if not connected } } float velocity = mFrameContentVelocity; float velocity = mFrameContentVelocity; float frameRate = mPreferredFrameRate; final float frameRate = mPreferredFrameRate; ViewParent parent = mParent; ViewParent parent = mParent; if (velocity <= 0 && Float.isNaN(frameRate)) { if (velocity <= 0 && Float.isNaN(frameRate)) { // The most common case is when nothing is set, so this special case is called // The most common case is when nothing is set, so this special case is called Loading Loading @@ -33982,13 +33982,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } if (velocityFrameRate > 0f || frameRate > 0f) { if (velocityFrameRate > 0f || frameRate > 0f) { int compatibility; int compatibility; float frameRateToSet; if (frameRate >= velocityFrameRate) { if (frameRate >= velocityFrameRate) { compatibility = FRAME_RATE_COMPATIBILITY_FIXED_SOURCE; compatibility = FRAME_RATE_COMPATIBILITY_FIXED_SOURCE; frameRateToSet = frameRate; } else { } else { compatibility = FRAME_RATE_COMPATIBILITY_GTE; compatibility = FRAME_RATE_COMPATIBILITY_GTE; frameRate = velocityFrameRate; frameRateToSet = velocityFrameRate; } } viewRootImpl.votePreferredFrameRate(frameRate, compatibility); viewRootImpl.votePreferredFrameRate(frameRateToSet, compatibility); } } } } Loading Loading @@ -34052,7 +34054,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ @FlaggedApi(FLAG_VIEW_VELOCITY_API) @FlaggedApi(FLAG_VIEW_VELOCITY_API) public void setFrameContentVelocity(float pixelsPerSecond) { public void setFrameContentVelocity(float pixelsPerSecond) { if (viewVelocityApi()) { if (mAttachInfo != null && mAttachInfo.mViewVelocityApi) { mFrameContentVelocity = Math.abs(pixelsPerSecond); mFrameContentVelocity = Math.abs(pixelsPerSecond); if (sToolkitMetricsForFrameRateDecisionFlagValue) { if (sToolkitMetricsForFrameRateDecisionFlagValue) { Loading @@ -34070,8 +34072,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ @FlaggedApi(FLAG_VIEW_VELOCITY_API) @FlaggedApi(FLAG_VIEW_VELOCITY_API) public float getFrameContentVelocity() { public float getFrameContentVelocity() { if (viewVelocityApi()) { if (mAttachInfo != null && mAttachInfo.mViewVelocityApi) { return (mFrameContentVelocity < 0f) ? 0f : mFrameContentVelocity; return Math.max(mFrameContentVelocity, 0f); } } return 0; return 0; } } core/tests/coretests/src/android/view/ViewFrameRateTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -183,6 +183,7 @@ public class ViewFrameRateTest { mActivityRule.runOnUiThread(() -> { mActivityRule.runOnUiThread(() -> { frameLayout.setFrameContentVelocity(1f); frameLayout.setFrameContentVelocity(1f); mMovingView.offsetTopAndBottom(100); mMovingView.offsetTopAndBottom(100); frameLayout.invalidate(); runAfterDraw(() -> assertEquals(60f, mViewRoot.getLastPreferredFrameRate(), 0f)); runAfterDraw(() -> assertEquals(60f, mViewRoot.getLastPreferredFrameRate(), 0f)); }); }); waitForAfterDraw(); waitForAfterDraw(); Loading Loading
core/java/android/view/View.java +8 −6 Original line number Original line Diff line number Diff line Loading @@ -33942,7 +33942,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return; // can't vote if not connected return; // can't vote if not connected } } float velocity = mFrameContentVelocity; float velocity = mFrameContentVelocity; float frameRate = mPreferredFrameRate; final float frameRate = mPreferredFrameRate; ViewParent parent = mParent; ViewParent parent = mParent; if (velocity <= 0 && Float.isNaN(frameRate)) { if (velocity <= 0 && Float.isNaN(frameRate)) { // The most common case is when nothing is set, so this special case is called // The most common case is when nothing is set, so this special case is called Loading Loading @@ -33982,13 +33982,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } if (velocityFrameRate > 0f || frameRate > 0f) { if (velocityFrameRate > 0f || frameRate > 0f) { int compatibility; int compatibility; float frameRateToSet; if (frameRate >= velocityFrameRate) { if (frameRate >= velocityFrameRate) { compatibility = FRAME_RATE_COMPATIBILITY_FIXED_SOURCE; compatibility = FRAME_RATE_COMPATIBILITY_FIXED_SOURCE; frameRateToSet = frameRate; } else { } else { compatibility = FRAME_RATE_COMPATIBILITY_GTE; compatibility = FRAME_RATE_COMPATIBILITY_GTE; frameRate = velocityFrameRate; frameRateToSet = velocityFrameRate; } } viewRootImpl.votePreferredFrameRate(frameRate, compatibility); viewRootImpl.votePreferredFrameRate(frameRateToSet, compatibility); } } } } Loading Loading @@ -34052,7 +34054,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ @FlaggedApi(FLAG_VIEW_VELOCITY_API) @FlaggedApi(FLAG_VIEW_VELOCITY_API) public void setFrameContentVelocity(float pixelsPerSecond) { public void setFrameContentVelocity(float pixelsPerSecond) { if (viewVelocityApi()) { if (mAttachInfo != null && mAttachInfo.mViewVelocityApi) { mFrameContentVelocity = Math.abs(pixelsPerSecond); mFrameContentVelocity = Math.abs(pixelsPerSecond); if (sToolkitMetricsForFrameRateDecisionFlagValue) { if (sToolkitMetricsForFrameRateDecisionFlagValue) { Loading @@ -34070,8 +34072,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ @FlaggedApi(FLAG_VIEW_VELOCITY_API) @FlaggedApi(FLAG_VIEW_VELOCITY_API) public float getFrameContentVelocity() { public float getFrameContentVelocity() { if (viewVelocityApi()) { if (mAttachInfo != null && mAttachInfo.mViewVelocityApi) { return (mFrameContentVelocity < 0f) ? 0f : mFrameContentVelocity; return Math.max(mFrameContentVelocity, 0f); } } return 0; return 0; } }
core/tests/coretests/src/android/view/ViewFrameRateTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -183,6 +183,7 @@ public class ViewFrameRateTest { mActivityRule.runOnUiThread(() -> { mActivityRule.runOnUiThread(() -> { frameLayout.setFrameContentVelocity(1f); frameLayout.setFrameContentVelocity(1f); mMovingView.offsetTopAndBottom(100); mMovingView.offsetTopAndBottom(100); frameLayout.invalidate(); runAfterDraw(() -> assertEquals(60f, mViewRoot.getLastPreferredFrameRate(), 0f)); runAfterDraw(() -> assertEquals(60f, mViewRoot.getLastPreferredFrameRate(), 0f)); }); }); waitForAfterDraw(); waitForAfterDraw(); Loading