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

Commit 41b63789 authored by Shane's avatar Shane
Browse files

[VRR] Reset relevant values when destroying surface

Reset relevant values when destroying surface

Flag: EXEMPT bugfix
Bug: 356875545
Test: atest ViewFrameRateTest / ViewRootImplTest
Change-Id: I4630dd6298097383011ab23e4c59e6678ab16135
parent 99d9db2c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2822,6 +2822,12 @@ public final class ViewRootImpl implements ViewParent,
        if (mAttachInfo.mThreadedRenderer != null) {
            mAttachInfo.mThreadedRenderer.setSurfaceControl(null, null);
        }
        // Also reset the VRR relevant values.
        mPreferredFrameRateCategory = FRAME_RATE_CATEGORY_DEFAULT;
        mLastPreferredFrameRateCategory = FRAME_RATE_CATEGORY_DEFAULT;
        mPreferredFrameRate = 0;
        mLastPreferredFrameRate = 0;
    }
    /**
+40 −1
Original line number Diff line number Diff line
@@ -1418,9 +1418,48 @@ public class ViewRootImplTest {
        waitForAfterDraw();
    }

    @Test
    @RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
            FLAG_TOOLKIT_FRAME_RATE_FUNCTION_ENABLING_READ_ONLY,
            FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
    public void votePreferredFrameRate_resetWhenDestroyingSurface()
            throws Throwable {
        if (!ViewProperties.vrr_enabled().orElse(true)) {
            return;
        }
        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

        sInstrumentation.runOnMainSync(() -> {
            WindowManager wm = sContext.getSystemService(WindowManager.class);
            wm.addView(mView, wmlp);
        });
        sInstrumentation.waitForIdleSync();

        mViewRootImpl = mView.getViewRootImpl();

        waitForFrameRateCategoryToSettle(mView);

        sInstrumentation.runOnMainSync(() -> {
            mViewRootImpl.getView().setVisibility(View.INVISIBLE);
            mViewRootImpl.mSurface.release();
            mView.invalidate();
        });
        sInstrumentation.waitForIdleSync();

        assertEquals(false, mViewRootImpl.mSurface.isValid());
        assertEquals(FRAME_RATE_CATEGORY_DEFAULT,
                mViewRootImpl.getLastPreferredFrameRateCategory());
        assertEquals(FRAME_RATE_CATEGORY_DEFAULT,
                mViewRootImpl.getPreferredFrameRateCategory());
        assertEquals(0, mViewRootImpl.getLastPreferredFrameRate(), 0.1);
        assertEquals(0, mViewRootImpl.getPreferredFrameRate(), 0.1);
    }

    @Test
    @RequiresFlagsEnabled(FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY)
    public void votePreferredFrameRate_velocityVotedAfterOnDraw() throws Throwable {
    public void votePreferredFrameRate_reset() throws Throwable {
        if (!ViewProperties.vrr_enabled().orElse(true)) {
            return;
        }