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

Commit d810a617 authored by Shane's avatar Shane Committed by Jian-Syuan (Shane) Wong
Browse files

[dVRR] Call updateInfrequentCount after setCategoryFromCategoryCounts

In some use cases, the intermittent update state could be updated right after Views vote that causes inconsistency between the voted category and the category that is sent to SurfaceFlinger.

This Cl moves updateInfrequentCount after setCategoryFromCategoryCounts to avoid that. Although we need one more frame to change the intermittent update state, we can now ensure the consistency.

Fixes: 338173334
Test: atest ViewRootImplTest / atest ViewFrameRateTest`
Change-Id: I8eb775a45eb7bc5d3cb4a0f759525228296203dd
parent e11d5f30
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4257,8 +4257,8 @@ public final class ViewRootImpl implements ViewParent,
        // when the values are applicable.
        if (mDrawnThisFrame) {
            mDrawnThisFrame = false;
            updateInfrequentCount();
            setCategoryFromCategoryCounts();
            updateInfrequentCount();
            setPreferredFrameRate(mPreferredFrameRate);
            setPreferredFrameRateCategory(mPreferredFrameRateCategory);
            if (!mIsFrameRateConflicted) {
+17 −5
Original line number Diff line number Diff line
@@ -1138,6 +1138,8 @@ public class ViewRootImplTest {
        mView = 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
        int expected = toolkitFrameRateDefaultNormalReadOnly()
                    ? FRAME_RATE_CATEGORY_NORMAL : FRAME_RATE_CATEGORY_HIGH;

        sInstrumentation.runOnMainSync(() -> {
            WindowManager wm = sContext.getSystemService(WindowManager.class);
@@ -1157,8 +1159,6 @@ public class ViewRootImplTest {
        Thread.sleep(delay);
        sInstrumentation.runOnMainSync(() -> {
            mView.invalidate();
            int expected = toolkitFrameRateDefaultNormalReadOnly()
                    ? FRAME_RATE_CATEGORY_NORMAL : FRAME_RATE_CATEGORY_HIGH;
            runAfterDraw(() -> assertEquals(expected,
                    mViewRootImpl.getLastPreferredFrameRateCategory()));
        });
@@ -1168,8 +1168,6 @@ public class ViewRootImplTest {
        Thread.sleep(delay);
        sInstrumentation.runOnMainSync(() -> {
            mView.invalidate();
            int expected = toolkitFrameRateDefaultNormalReadOnly()
                    ? FRAME_RATE_CATEGORY_NORMAL : FRAME_RATE_CATEGORY_HIGH;
            runAfterDraw(() -> assertEquals(expected,
                    mViewRootImpl.getLastPreferredFrameRateCategory()));
        });
@@ -1177,12 +1175,26 @@ public class ViewRootImplTest {
        // Infrequent update
        Thread.sleep(delay);
        sInstrumentation.runOnMainSync(() -> {
            mView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_DEFAULT);
            mView.invalidate();
            runAfterDraw(() -> assertEquals(FRAME_RATE_CATEGORY_NORMAL,
                    mViewRootImpl.getLastPreferredFrameRateCategory()));
        });
        waitForAfterDraw();

        // When the View vote, it's still considered as intermittent update state
        sInstrumentation.runOnMainSync(() -> {
            mView.invalidate();
            runAfterDraw(() -> assertEquals(FRAME_RATE_CATEGORY_NORMAL,
                    mViewRootImpl.getLastPreferredFrameRateCategory()));
        });
        waitForAfterDraw();

        // Becomes frequent update state
        sInstrumentation.runOnMainSync(() -> {
            mView.invalidate();
            runAfterDraw(() -> assertEquals(expected,
                    mViewRootImpl.getLastPreferredFrameRateCategory()));
        });
    }

    /**