Loading core/java/android/view/View.java +18 −16 Original line number Diff line number Diff line Loading @@ -5543,7 +5543,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // The preferred frame rate of the view that is mainly used for // touch boosting, view velocity handling, and TextureView. private float mPreferredFrameRate = REQUESTED_FRAME_RATE_CATEGORY_DEFAULT; private float mPreferredFrameRate = Float.NaN; private int mInfrequentUpdateCount = 0; private long mLastUpdateTimeMillis = 0; Loading Loading @@ -33186,6 +33186,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, float sizePercentage = getSizePercentage(); int frameRateCateogry = calculateFrameRateCategory(sizePercentage); if (viewRootImpl != null && sizePercentage > 0) { if (sToolkitMetricsForFrameRateDecisionFlagValue) { viewRootImpl.recordViewPercentage(sizePercentage); } if (!Float.isNaN(mPreferredFrameRate)) { if (mPreferredFrameRate < 0) { if (mPreferredFrameRate == REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE) { frameRateCateogry = FRAME_RATE_CATEGORY_NO_PREFERENCE; Loading @@ -33198,13 +33202,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } else { viewRootImpl.votePreferredFrameRate(mPreferredFrameRate); return; } } viewRootImpl.votePreferredFrameRateCategory(frameRateCateogry); mLastFrameRateCategory = frameRateCateogry; if (sToolkitMetricsForFrameRateDecisionFlagValue) { viewRootImpl.recordViewPercentage(sizePercentage); } } } core/tests/coretests/src/android/view/ViewRootImplTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -828,6 +828,34 @@ public class ViewRootImplTest { assertEquals(viewRootImpl.getPreferredFrameRate(), 0, 0.1); } /** * A View should either vote a frame rate or a frame rate category instead of both. */ @Test @RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY) public void votePreferredFrameRate_voteFrameRateOnly() { View view = new View(sContext); float frameRate = 20; attachViewToWindow(view); sInstrumentation.waitForIdleSync(); ViewRootImpl viewRootImpl = view.getViewRootImpl(); sInstrumentation.runOnMainSync(() -> { assertEquals(viewRootImpl.getPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_NO_PREFERENCE); view.setRequestedFrameRate(frameRate); view.invalidate(); assertEquals(viewRootImpl.getPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_NO_PREFERENCE); assertEquals(viewRootImpl.getPreferredFrameRate(), frameRate, 0.1); view.setRequestedFrameRate(view.REQUESTED_FRAME_RATE_CATEGORY_LOW); view.invalidate(); assertEquals(viewRootImpl.getPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_LOW); }); } /** * Test the logic of infrequent layer: * - NORMAL for infrequent update: FT2-FT1 > 100 && FT3-FT2 > 100. Loading Loading
core/java/android/view/View.java +18 −16 Original line number Diff line number Diff line Loading @@ -5543,7 +5543,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // The preferred frame rate of the view that is mainly used for // touch boosting, view velocity handling, and TextureView. private float mPreferredFrameRate = REQUESTED_FRAME_RATE_CATEGORY_DEFAULT; private float mPreferredFrameRate = Float.NaN; private int mInfrequentUpdateCount = 0; private long mLastUpdateTimeMillis = 0; Loading Loading @@ -33186,6 +33186,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, float sizePercentage = getSizePercentage(); int frameRateCateogry = calculateFrameRateCategory(sizePercentage); if (viewRootImpl != null && sizePercentage > 0) { if (sToolkitMetricsForFrameRateDecisionFlagValue) { viewRootImpl.recordViewPercentage(sizePercentage); } if (!Float.isNaN(mPreferredFrameRate)) { if (mPreferredFrameRate < 0) { if (mPreferredFrameRate == REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE) { frameRateCateogry = FRAME_RATE_CATEGORY_NO_PREFERENCE; Loading @@ -33198,13 +33202,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } else { viewRootImpl.votePreferredFrameRate(mPreferredFrameRate); return; } } viewRootImpl.votePreferredFrameRateCategory(frameRateCateogry); mLastFrameRateCategory = frameRateCateogry; if (sToolkitMetricsForFrameRateDecisionFlagValue) { viewRootImpl.recordViewPercentage(sizePercentage); } } }
core/tests/coretests/src/android/view/ViewRootImplTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -828,6 +828,34 @@ public class ViewRootImplTest { assertEquals(viewRootImpl.getPreferredFrameRate(), 0, 0.1); } /** * A View should either vote a frame rate or a frame rate category instead of both. */ @Test @RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY) public void votePreferredFrameRate_voteFrameRateOnly() { View view = new View(sContext); float frameRate = 20; attachViewToWindow(view); sInstrumentation.waitForIdleSync(); ViewRootImpl viewRootImpl = view.getViewRootImpl(); sInstrumentation.runOnMainSync(() -> { assertEquals(viewRootImpl.getPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_NO_PREFERENCE); view.setRequestedFrameRate(frameRate); view.invalidate(); assertEquals(viewRootImpl.getPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_NO_PREFERENCE); assertEquals(viewRootImpl.getPreferredFrameRate(), frameRate, 0.1); view.setRequestedFrameRate(view.REQUESTED_FRAME_RATE_CATEGORY_LOW); view.invalidate(); assertEquals(viewRootImpl.getPreferredFrameRateCategory(), FRAME_RATE_CATEGORY_LOW); }); } /** * Test the logic of infrequent layer: * - NORMAL for infrequent update: FT2-FT1 > 100 && FT3-FT2 > 100. Loading