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

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

Merge "[ARR] Inogre frame rate boost heuristic when flinging" into main

parents e7072c24 7a9a8ffc
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -34199,7 +34199,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                && viewRootImpl.shouldCheckFrameRateCategory()
                && parent instanceof View
                && ((View) parent).getFrameContentVelocity() <= 0
                && !isInputMethodWindowType) {
                && !isInputMethodWindowType
                && viewRootImpl.getFrameRateCompatibility() != FRAME_RATE_COMPATIBILITY_AT_LEAST) {
            return FRAME_RATE_CATEGORY_HIGH_HINT | FRAME_RATE_CATEGORY_REASON_BOOST;
        }
+82 −0
Original line number Diff line number Diff line
@@ -1171,6 +1171,88 @@ public class ViewFrameRateTest {
        waitForAfterDraw();
    }

    @Test
    public void ignoreHeuristicWhenFling() throws Throwable {
        if (!ViewProperties.vrr_enabled().orElse(true)) {
            return;
        }

        waitForFrameRateCategoryToSettle();
        FrameLayout host = new FrameLayout(mActivity);
        View childView = new View(mActivity);
        float velocity = 1000;

        TranslateAnimation translateAnimation = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0f, // fromXDelta
                Animation.RELATIVE_TO_PARENT, 0f, // toXDelta
                Animation.RELATIVE_TO_PARENT, 1f, // fromYDelta (100%p)
                Animation.RELATIVE_TO_PARENT, 0f  // toYDelta
        );
        translateAnimation.setDuration(100);

        mActivityRule.runOnUiThread(() -> {
            ViewGroup.LayoutParams fullSize = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
            mActivity.setContentView(host, fullSize);
            host.setFrameContentVelocity(velocity);
            ViewGroupOverlay overlay = host.getOverlay();
            overlay.add(childView);
            assertEquals(velocity, host.getFrameContentVelocity());
            assertEquals(host.getFrameContentVelocity(),
                    ((View) childView.getParent()).getFrameContentVelocity());

            mMovingView.startAnimation(translateAnimation);

            // The frame rate should be "Normal" during fling gestures,
            // even if there's a moving View.
            assertEquals(FRAME_RATE_CATEGORY_NORMAL,
                    mViewRoot.getLastPreferredFrameRateCategory());
        });
        waitForAfterDraw();
    }

    @Test
    public void ignoreHeuristicWhenFlingMovementFirst() throws Throwable {
        if (!ViewProperties.vrr_enabled().orElse(true)) {
            return;
        }

        waitForFrameRateCategoryToSettle();
        FrameLayout host = new FrameLayout(mActivity);
        View childView = new View(mActivity);
        float velocity = 1000;

        TranslateAnimation translateAnimation = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0f, // fromXDelta
                Animation.RELATIVE_TO_PARENT, 0f, // toXDelta
                Animation.RELATIVE_TO_PARENT, 1f, // fromYDelta (100%p)
                Animation.RELATIVE_TO_PARENT, 0f  // toYDelta
        );
        translateAnimation.setDuration(100);

        mActivityRule.runOnUiThread(() -> {
            mMovingView.startAnimation(translateAnimation);

            ViewGroup.LayoutParams fullSize = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
            mActivity.setContentView(host, fullSize);
            host.setFrameContentVelocity(velocity);
            ViewGroupOverlay overlay = host.getOverlay();
            overlay.add(childView);
            assertEquals(velocity, host.getFrameContentVelocity());
            assertEquals(host.getFrameContentVelocity(),
                    ((View) childView.getParent()).getFrameContentVelocity());

            // The frame rate should be "Normal" during fling gestures,
            // even if there's a moving View.
            assertEquals(FRAME_RATE_CATEGORY_NORMAL,
                    mViewRoot.getLastPreferredFrameRateCategory());
        });
        waitForAfterDraw();
    }

    private void runAfterDraw(@NonNull Runnable runnable) {
        Handler handler = new Handler(Looper.getMainLooper());
        mAfterDrawLatch = new CountDownLatch(1);