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

Commit 00eb127e authored by Ady Abraham's avatar Ady Abraham
Browse files

Don't call setFrameRate if refresh rate switching is disabled

When refresh rate switching is set to SWITCHING_TYPE_NONE, DisplayManager
limits the refresh rate to a single value. Calling setFrameRate to SF
is redundant and causes unnecessary duplicate events.

Bug: 189174620
Bug: 189191861
Test: atest SetFrameRateTest
Test: atest FrameRateOverrideHostTest
Test: atest ChoreographerNativeTest
Test: atest FrameRateSelectionPriorityTests
Change-Id: I77ca430555c57c13a6e36707b344537deee5c2d7
parent 71b62675
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -286,6 +286,12 @@ public abstract class DisplayManagerInternal {
     */
    public abstract void ignoreProximitySensorUntilChanged();

    /**
     * Returns the refresh rate switching type.
     */
    @DisplayManager.SwitchingType
    public abstract int getRefreshRateSwitchingType();

    /**
     * Describes the requested power state of the display.
     *
+5 −0
Original line number Diff line number Diff line
@@ -3250,6 +3250,11 @@ public final class DisplayManagerService extends SystemService {
            mDisplayPowerControllers.get(Display.DEFAULT_DISPLAY)
                    .ignoreProximitySensorUntilChanged();
        }

        @Override
        public int getRefreshRateSwitchingType() {
            return getRefreshRateSwitchingTypeInternal();
        }
    }

    class DesiredDisplayModeSpecsObserver
+13 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.isSplitScreenWindowingMode;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.graphics.GraphicsProtos.dumpPointProto;
import static android.hardware.display.DisplayManager.SWITCHING_TYPE_NONE;
import static android.hardware.input.InputManager.BLOCK_UNTRUSTED_TOUCHES;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.os.PowerManager.DRAW_WAKE_LOCK;
@@ -5448,6 +5449,11 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                    mFrameRateSelectionPriority);
        }

        // If refresh rate switching is disabled there is no point to set the frame rate on the
        // surface as the refresh rate will be limited by display manager to a single value
        // and SurfaceFlinger wouldn't be able to change it anyways.
        if (mWmService.mDisplayManagerInternal.getRefreshRateSwitchingType()
                != SWITCHING_TYPE_NONE) {
            final float refreshRate = refreshRatePolicy.getPreferredRefreshRate(this);
            if (mAppPreferredFrameRate != refreshRate) {
                mAppPreferredFrameRate = refreshRate;
@@ -5456,6 +5462,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                        Surface.FRAME_RATE_COMPATIBILITY_EXACT, Surface.CHANGE_FRAME_RATE_ALWAYS);
            }
        }
    }

    private void updateScaleIfNeeded() {
        float newHScale = mHScale * mGlobalScale * mWallpaperScale;
+43 −8
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.hardware.display.DisplayManager;
import android.platform.test.annotations.Presubmit;
import android.view.Display.Mode;
import android.view.DisplayInfo;
@@ -56,6 +57,13 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {
    private RefreshRatePolicy mRefreshRatePolicy;
    private HighRefreshRateDenylist mDenylist = mock(HighRefreshRateDenylist.class);

    WindowState createWindow(String name) {
        WindowState window = createWindow(null, TYPE_APPLICATION, name);
        when(window.mWmService.mDisplayManagerInternal.getRefreshRateSwitchingType())
                .thenReturn(DisplayManager.SWITCHING_TYPE_WITHIN_GROUPS);
        return window;
    }

    @Before
    public void setUp() {
        DisplayInfo di = new DisplayInfo(mDisplayInfo);
@@ -73,7 +81,7 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {

    @Test
    public void basicTest() {
        final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
        final WindowState appWindow = createWindow("appWindow");
        assertNotNull("Window state is created", appWindow);

        assertEquals(appWindow.mFrameRateSelectionPriority, RefreshRatePolicy.LAYER_PRIORITY_UNSET);
@@ -97,7 +105,7 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {

    @Test
    public void testApplicationInFocusWithoutModeId() {
        final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
        final WindowState appWindow = createWindow("appWindow");
        assertEquals(appWindow.mFrameRateSelectionPriority, RefreshRatePolicy.LAYER_PRIORITY_UNSET);
        assertEquals(appWindow.getDisplayContent().getDisplayPolicy().getRefreshRatePolicy()
                .getPreferredModeId(appWindow), 0);
@@ -128,7 +136,7 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {

    @Test
    public void testApplicationInFocusWithModeId() {
        final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
        final WindowState appWindow = createWindow("appWindow");
        assertEquals(appWindow.mFrameRateSelectionPriority, RefreshRatePolicy.LAYER_PRIORITY_UNSET);
        assertEquals(appWindow.mAppPreferredFrameRate, 0, FLOAT_TOLERANCE);

@@ -165,11 +173,11 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {

    @Test
    public void testApplicationNotInFocusWithModeId() {
        final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
        final WindowState appWindow = createWindow("appWindow");
        assertEquals(appWindow.mFrameRateSelectionPriority, RefreshRatePolicy.LAYER_PRIORITY_UNSET);
        assertEquals(appWindow.mAppPreferredFrameRate, 0, FLOAT_TOLERANCE);

        final WindowState inFocusWindow = createWindow(null, TYPE_APPLICATION, "inFocus");
        final WindowState inFocusWindow = createWindow("inFocus");
        appWindow.mToken.mDisplayContent.mCurrentFocus = inFocusWindow;

        appWindow.updateFrameRateSelectionPriorityIfNeeded();
@@ -194,11 +202,11 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {

    @Test
    public void testApplicationNotInFocusWithoutModeId() {
        final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
        final WindowState appWindow = createWindow("appWindow");
        assertEquals(appWindow.mFrameRateSelectionPriority, RefreshRatePolicy.LAYER_PRIORITY_UNSET);
        assertEquals(appWindow.mAppPreferredFrameRate, 0, FLOAT_TOLERANCE);

        final WindowState inFocusWindow = createWindow(null, TYPE_APPLICATION, "inFocus");
        final WindowState inFocusWindow = createWindow("inFocus");
        appWindow.mToken.mDisplayContent.mCurrentFocus = inFocusWindow;

        appWindow.updateFrameRateSelectionPriorityIfNeeded();
@@ -221,7 +229,7 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {

    @Test
    public void testPreferredRefreshRate() {
        final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
        final WindowState appWindow = createWindow("appWindow");
        assertNotNull("Window state is created", appWindow);
        when(appWindow.getDisplayContent().getDisplayPolicy()).thenReturn(mDisplayPolicy);

@@ -246,4 +254,31 @@ public class FrameRateSelectionPriorityTests extends WindowTestsBase {
                appWindow.getSurfaceControl(), 60,
                Surface.FRAME_RATE_COMPATIBILITY_EXACT, Surface.CHANGE_FRAME_RATE_ALWAYS);
    }

    @Test
    public void testSwitchingTypeNone() {
        final WindowState appWindow = createWindow("appWindow");
        when(appWindow.mWmService.mDisplayManagerInternal.getRefreshRateSwitchingType())
                .thenReturn(DisplayManager.SWITCHING_TYPE_NONE);

        assertEquals(appWindow.mFrameRateSelectionPriority, RefreshRatePolicy.LAYER_PRIORITY_UNSET);
        assertEquals(appWindow.mAppPreferredFrameRate, 0, FLOAT_TOLERANCE);

        // Update the mode ID to a requested number.
        appWindow.mAttrs.preferredDisplayModeId = 1;
        appWindow.updateFrameRateSelectionPriorityIfNeeded();

        assertEquals(appWindow.mAppPreferredFrameRate, 0, FLOAT_TOLERANCE);

        // Remove the mode ID request.
        appWindow.mAttrs.preferredDisplayModeId = 0;
        appWindow.updateFrameRateSelectionPriorityIfNeeded();

        assertEquals(appWindow.mAppPreferredFrameRate, 0, FLOAT_TOLERANCE);

        verify(appWindow.getPendingTransaction()).setFrameRateSelectionPriority(
                appWindow.getSurfaceControl(), RefreshRatePolicy.LAYER_PRIORITY_UNSET);
        verify(appWindow.getPendingTransaction(), never()).setFrameRate(
                any(SurfaceControl.class), anyInt(), anyInt(), anyInt());
    }
}