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

Commit f64a8975 authored by Shane's avatar Shane
Browse files

Use applyAsyncUnsafe() instead of apply() to apply a transaction

As suggested, applyAsyncUnsafe() can be more efficient than apply() when
apply a transaction. This CL makes the corresponding changes to
setFrameRateCateogry and setFrameRate call

Also, I reduce the frequency of the API calls by comparing the previous
frame rate (category) with the current one. We only make an API call
when they are different.

Bug: 310966165
Test: Manual Test, atest ViewRootImplTest
Change-Id: I3f0752da8d088edff4f19725dabd75bd6d11a28f
parent ee7eea32
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -3991,9 +3991,7 @@ public final class ViewRootImpl implements ViewParent,
        // when the values are applicable.
        setPreferredFrameRate(mPreferredFrameRate);
        setPreferredFrameRateCategory(mPreferredFrameRateCategory);
        mLastPreferredFrameRateCategory = mPreferredFrameRateCategory;
        mPreferredFrameRateCategory = FRAME_RATE_CATEGORY_NO_PREFERENCE;
        mLastPreferredFrameRate = mPreferredFrameRate;
        mPreferredFrameRate = 0;
    }

@@ -11982,8 +11980,11 @@ public final class ViewRootImpl implements ViewParent,
                ? FRAME_RATE_CATEGORY_HIGH : preferredFrameRateCategory;

        try {
            if (mLastPreferredFrameRateCategory != frameRateCategory) {
                mFrameRateTransaction.setFrameRateCategory(mSurfaceControl,
                    frameRateCategory, false).apply();
                    frameRateCategory, false).applyAsyncUnsafe();
                mLastPreferredFrameRateCategory = frameRateCategory;
            }
        } catch (Exception e) {
            Log.e(mTag, "Unable to set frame rate category", e);
        }
@@ -12003,8 +12004,11 @@ public final class ViewRootImpl implements ViewParent,
        }

        try {
            mFrameRateTransaction.setFrameRate(mSurfaceControl,
                    preferredFrameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT).apply();
            if (mLastPreferredFrameRate != preferredFrameRate) {
                mFrameRateTransaction.setFrameRate(mSurfaceControl, preferredFrameRate,
                    Surface.FRAME_RATE_COMPATIBILITY_DEFAULT).applyAsyncUnsafe();
                mLastPreferredFrameRate = preferredFrameRate;
            }
        } catch (Exception e) {
            Log.e(mTag, "Unable to set frame rate", e);
        }