Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d602aa4d authored by Shane's avatar Shane
Browse files

View should either call setFrameRate or setFrameRateCategory

View should either call setFrameRate or setFrameRateCategory but not
both.

Test: atest ViewRootImplTest
Change-Id: I8de81785f19e44a580b1447cd49eb194043a82b8
parent dd47c034
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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);
            }
        }
    }
+28 −0
Original line number Diff line number Diff line
@@ -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.