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

Commit 71b62675 authored by Ady Abraham's avatar Ady Abraham
Browse files

DisplayManagerGlobal: suppress redundant AChoreographer_refreshRateCallback calls


With Frame Rate Override enabled, an app could get an
AChoreographer_refreshRateCallback callbacks which seem redundant.
An example would be:
1. Display changed refresh rate to 60Hz - callback
2. App's frame rate override changed to 60Hz - callback

To avoid sending these redundant callbacks, DisplayManagerGlobal caches
the last DisplayInfo that was reported to the app and based on it, it
decides whether to send the event or not.

Bug: 184588343
Bug: 189174620
Test: atest SetFrameRateTest
Test: atest FrameRateOverrideHostTest
Test: atest ChoreographerNativeTest
Change-Id: Ia0278e98d06bc790810c31dcda8244181e8e1d5d
parent 70dedcf3
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public final class DisplayManagerGlobal {

    // Guarded by mLock
    private boolean mDispatchNativeCallbacks = false;
    private float mNativeCallbackReportedRefreshRate;
    private final Object mLock = new Object();

    @UnsupportedAppUsage
@@ -404,10 +405,11 @@ public final class DisplayManagerGlobal {
                    // We can likely save a binder hop if we attach the refresh rate onto the
                    // listener.
                    DisplayInfo display = getDisplayInfoLocked(displayId);
                    if (display != null) {
                        float refreshRate = display.getRefreshRate();
                    if (display != null
                            && mNativeCallbackReportedRefreshRate != display.getRefreshRate()) {
                        mNativeCallbackReportedRefreshRate = display.getRefreshRate();
                        // Signal native callbacks if we ever set a refresh rate.
                        nSignalNativeCallbacks(refreshRate);
                        nSignalNativeCallbacks(mNativeCallbackReportedRefreshRate);
                    }
                }
            }
@@ -1055,8 +1057,8 @@ public final class DisplayManagerGlobal {
            if (display != null) {
                // We need to tell AChoreographer instances the current refresh rate so that apps
                // can get it for free once a callback first registers.
                float refreshRate = display.getRefreshRate();
                nSignalNativeCallbacks(refreshRate);
                mNativeCallbackReportedRefreshRate = display.getRefreshRate();
                nSignalNativeCallbacks(mNativeCallbackReportedRefreshRate);
            }
        }
    }