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

Commit 9facd3ac authored by Jian-Syuan (Shane) Wong's avatar Jian-Syuan (Shane) Wong Committed by Android (Google) Code Review
Browse files

Merge "Set frame rate category as HIGH when a View has a velocity" into main

parents a14ab664 dd981603
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -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;
        }
@@ -12542,6 +12545,14 @@ public final class ViewRootImpl implements ViewParent,
        return mPreferredFrameRate >= 0 ? mPreferredFrameRate : mLastPreferredFrameRate;
    }
    /**
     * Get the value of mLastPreferredFrameRate
     */
    @VisibleForTesting
    public float getLastPreferredFrameRate() {
        return mLastPreferredFrameRate;
    }
    /**
     * Returns whether touch boost is currently enabled.
     */
+33 −0
Original line number Diff line number Diff line
@@ -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;
@@ -795,6 +796,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.
     */