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

Commit b7d2f2b5 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Restore flicker votes" into main

parents 64d21aea 8f8b5679
Loading
Loading
Loading
Loading
+27 −17
Original line number Diff line number Diff line
@@ -465,6 +465,7 @@ public class DisplayModeDirector {
    }

    // TODO(b/372019752) Rename all the occurrences of the VRR with ARR.
    @GuardedBy("mLock")
    private boolean isVrrSupportedLocked(int displayId) {
        if (mHasArrSupportFlagEnabled) {
            Boolean hasArrSupport = mHasArrSupport.get(displayId);
@@ -642,6 +643,7 @@ public class DisplayModeDirector {
        return maxRefreshRate;
    }

    @GuardedBy("mLock")
    private void notifyDesiredDisplayModeSpecsChangedLocked() {
        if (mDesiredDisplayModeSpecsListener != null
                && !mHandler.hasMessages(MSG_REFRESH_RATE_RANGE_CHANGED)) {
@@ -655,6 +657,7 @@ public class DisplayModeDirector {
        }
    }

    @GuardedBy("mLock")
    boolean isExternalDisplayLocked(int displayId) {
        return mExternalDisplaysConnected.contains(displayId);
    }
@@ -1139,6 +1142,7 @@ public class DisplayModeDirector {
            mDefaultPeakRefreshRate = defaultPeakRefreshRate;
        }

        @GuardedBy("mLock")
        private void updateLowPowerModeSettingLocked() {
            mIsLowPower = Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.LOW_POWER_MODE, 0 /*default*/) != 0;
@@ -1153,6 +1157,7 @@ public class DisplayModeDirector {
            updateLowPowerModeAllowedModesLocked();
        }

        @GuardedBy("mLock")
        private void updateLowPowerModeAllowedModesLocked() {
            if (!mVsyncLowPowerVoteEnabled) {
                return;
@@ -1286,6 +1291,7 @@ public class DisplayModeDirector {
            mVotesStorage.updateVote(displayId, Vote.PRIORITY_DEFAULT_RENDER_FRAME_RATE, null);
        }

        @GuardedBy("mLock")
        private void updateModeSwitchingTypeSettingLocked() {
            final ContentResolver cr = mContext.getContentResolver();
            int switchingType = Settings.Secure.getIntForUser(cr,
@@ -1297,6 +1303,7 @@ public class DisplayModeDirector {
            }
        }

        @GuardedBy("mLock")
        public void dumpLocked(PrintWriter pw) {
            pw.println("  SettingsObserver");
            pw.println("    mDefaultRefreshRate: " + mDefaultRefreshRate);
@@ -1341,6 +1348,7 @@ public class DisplayModeDirector {
            }
        }

        @GuardedBy("mLock")
        private Display.Mode findModeLocked(int displayId, int modeId, float requestedRefreshRate) {
            Display.Mode mode = null;
            if (modeId != 0) {
@@ -1392,6 +1400,7 @@ public class DisplayModeDirector {
        }

        @Nullable
        @GuardedBy("mLock")
        private Display.Mode findDefaultModeByRefreshRateLocked(int displayId, float refreshRate) {
            Display.Mode[] modes = mAppSupportedModesByDisplay.get(displayId);
            Display.Mode defaultMode = mDefaultModeByDisplay.get(displayId);
@@ -1404,6 +1413,7 @@ public class DisplayModeDirector {
            return null;
        }

        @GuardedBy("mLock")
        private Display.Mode findAppModeByIdLocked(int displayId, int modeId) {
            Display.Mode[] modes = mAppSupportedModesByDisplay.get(displayId);
            if (modes == null) {
@@ -1417,6 +1427,7 @@ public class DisplayModeDirector {
            return null;
        }

        @GuardedBy("mLock")
        private void dumpLocked(PrintWriter pw) {
            pw.println("  AppRequestObserver");
            pw.println("    mIgnorePreferredRefreshRate: " + mIgnorePreferredRefreshRate);
@@ -1811,7 +1822,7 @@ public class DisplayModeDirector {
                            if (mThermalStatus != currentStatus) {
                                mThermalStatus = currentStatus;
                            }
                            onBrightnessChangedLocked();
                            updateFlickerRefreshRateVotes();
                        }
                    }
                };
@@ -2108,34 +2119,26 @@ public class DisplayModeDirector {
        }

        @VisibleForTesting
        @GuardedBy("mLock")
        public void onRefreshRateSettingChangedLocked(float min, float max) {
            boolean changeable = (max - min > 1f && max > 60f);
            if (mRefreshRateChangeable != changeable) {
                mRefreshRateChangeable = changeable;
                updateSensorStatus();
                if (!changeable) {
                    removeFlickerRefreshRateVotes();
                }
                updateFlickerRefreshRateVotes();
            }
        }

        @VisibleForTesting
        @GuardedBy("mLock")
        void onLowPowerModeEnabledLocked(boolean enabled) {
            if (mLowPowerModeEnabled != enabled) {
                mLowPowerModeEnabled = enabled;
                updateSensorStatus();
                if (enabled) {
                    removeFlickerRefreshRateVotes();
                }
                updateFlickerRefreshRateVotes();
            }
        }

        private void removeFlickerRefreshRateVotes() {
            // Revoke previous vote from BrightnessObserver
            mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE, null);
            mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH, null);
        }

        private void onDeviceConfigLowBrightnessThresholdsChanged(float[] displayThresholds,
                float[] ambientThresholds) {
            if (displayThresholds != null && ambientThresholds != null
@@ -2228,6 +2231,7 @@ public class DisplayModeDirector {
            }
        }

        @GuardedBy("mLock")
        void dumpLocked(PrintWriter pw) {
            pw.println("  BrightnessObserver");
            pw.println("    mAmbientLux: " + mAmbientLux);
@@ -2288,7 +2292,7 @@ public class DisplayModeDirector {
                synchronized (mLock) {
                    if (!BrightnessSynchronizer.floatEquals(brightness, mBrightness)) {
                        mBrightness = brightness;
                        onBrightnessChangedLocked();
                        updateFlickerRefreshRateVotes();
                    }
                }
            }
@@ -2341,7 +2345,7 @@ public class DisplayModeDirector {

            updateSensorStatus();
            synchronized (mLock) {
                onBrightnessChangedLocked();
                updateFlickerRefreshRateVotes();
            }
        }

@@ -2448,8 +2452,11 @@ public class DisplayModeDirector {
        }

        @GuardedBy("mLock")
        private void onBrightnessChangedLocked() {
        private void updateFlickerRefreshRateVotes() {
            if (!mRefreshRateChangeable || mLowPowerModeEnabled) {
                // Revoke previous vote from BrightnessObserver
                mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE, null);
                mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH, null);
                return;
            }
            Vote refreshRateVote = null;
@@ -2637,6 +2644,7 @@ public class DisplayModeDirector {
            private long mTimestamp;
            private boolean mLoggingEnabled;

            @GuardedBy("mLock")
            public void dumpLocked(PrintWriter pw) {
                pw.println("    mLastSensorData: " + mLastSensorData);
                pw.println("    mTimestamp: " + formatTimestamp(mTimestamp));
@@ -2715,7 +2723,7 @@ public class DisplayModeDirector {
                }

                synchronized (mLock) {
                    onBrightnessChangedLocked();
                    updateFlickerRefreshRateVotes();
                }
            }

@@ -2832,6 +2840,7 @@ public class DisplayModeDirector {
            mVotesStorage.updateVote(displayId, votePriority, vote);
        }

        @GuardedBy("mLock")
        void dumpLocked(PrintWriter pw) {
            pw.println("  UdfpsObserver");
            pw.println("    mUdfpsRefreshRateEnabled: ");
@@ -3011,6 +3020,7 @@ public class DisplayModeDirector {
            mVotesStorage.updateVote(displayId, Vote.PRIORITY_HIGH_BRIGHTNESS_MODE, vote);
        }

        @GuardedBy("mLock")
        void dumpLocked(PrintWriter pw) {
            pw.println("   HbmObserver");
            pw.println("     mHbmMode: " + mHbmMode);
+66 −18
Original line number Diff line number Diff line
@@ -867,24 +867,6 @@ public class DisplayModeDirectorTest {
        verifyBrightnessObserverCall(director, 120, 90, 0, 120, 90);
    }

    @Test
    public void testBrightnessObserver_LowPowerModeRemovesFlickerVotes() {
        float[] refreshRates = {60.f, 90.f, 120.f};
        DisplayModeDirector director =
                createDirectorFromRefreshRateArray(refreshRates, /*baseModeId=*/0);
        SparseArray<Vote> votes = new SparseArray<>();
        SparseArray<SparseArray<Vote>> votesByDisplay = new SparseArray<>();
        votesByDisplay.put(-1, votes); // Global Vote
        votes.put(Vote.PRIORITY_FLICKER_REFRESH_RATE, Vote.forPhysicalRefreshRates(0, 60));
        votes.put(Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH, Vote.forRenderFrameRates(60, 90));
        director.injectVotesByDisplay(votesByDisplay);

        director.getBrightnessObserver().onLowPowerModeEnabledLocked(true);

        assertNull(director.getVote(-1, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(-1, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));
    }

    @Test
    public void testVotingWithAlwaysRespectAppRequest() {
        Display.Mode[] modes = new Display.Mode[3];
@@ -1304,6 +1286,7 @@ public class DisplayModeDirectorTest {
    }

    @Test
    @SuppressWarnings("GuardedBy")
    public void testLockFpsForLowZone() throws Exception {
        DisplayModeDirector director =
                createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
@@ -1351,6 +1334,38 @@ public class DisplayModeDirectorTest {
        DisableRefreshRateSwitchingVote disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Disabling Smooth Display should remove the vote
        setPeakRefreshRate(60);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-enabling Smooth Display should restore the vote
        setPeakRefreshRate(90);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 90 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Enabling low power mode should remove the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(true);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-disabling low power mode should restore the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(false);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 90 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // We expect DisplayModeDirector to act on BrightnessInfo.adjustedBrightness; set only this
        // parameter to the necessary threshold
        setBrightness(10, 125, displayListener);
@@ -1443,6 +1458,7 @@ public class DisplayModeDirectorTest {
    }

    @Test
    @SuppressWarnings("GuardedBy")
    public void testLockFpsForHighZone() throws Exception {
        DisplayModeDirector director =
                createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
@@ -1500,6 +1516,38 @@ public class DisplayModeDirectorTest {
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        DisableRefreshRateSwitchingVote disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Disabling Smooth Display should remove the vote
        setPeakRefreshRate(60);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-enabling Smooth Display should restore the vote
        setPeakRefreshRate(90);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 60 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Enabling low power mode should remove the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(true);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-disabling low power mode should restore the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(false);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 60 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();
    }

    @Test