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

Commit 5a6640e8 authored by Ana Krulec's avatar Ana Krulec Committed by Android (Google) Code Review
Browse files

Merge "SF: Round the min/max checking to the closest int"

parents ec104634 72f0d6e0
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ status_t RefreshRateConfigs::setPolicy(HwcConfigIndexType defaultConfigId, float
        return BAD_VALUE;
    }
    const RefreshRate& refreshRate = mRefreshRates.at(defaultConfigId);
    if (refreshRate.fps < minRefreshRate || refreshRate.fps > maxRefreshRate) {
    if (!refreshRate.inPolicy(minRefreshRate, maxRefreshRate)) {
        return BAD_VALUE;
    }
    mDefaultConfig = defaultConfigId;
@@ -180,8 +180,8 @@ void RefreshRateConfigs::constructAvailableRefreshRates() {
          group.value(), mMinRefreshRateFps, mMaxRefreshRateFps);
    getSortedRefreshRateList(
            [&](const RefreshRate& refreshRate) REQUIRES(mLock) {
                return refreshRate.configGroup == group && refreshRate.fps >= mMinRefreshRateFps &&
                        refreshRate.fps <= mMaxRefreshRateFps;
                return refreshRate.configGroup == group &&
                        refreshRate.inPolicy(mMinRefreshRateFps, mMaxRefreshRateFps);
            },
            &mAvailableRefreshRates);
    LOG_ALWAYS_FATAL_IF(mAvailableRefreshRates.empty(),
+9 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ inline RefreshRateConfigEvent operator|(RefreshRateConfigEvent lhs, RefreshRateC
class RefreshRateConfigs {
public:
    struct RefreshRate {
        // The tolerance within which we consider FPS approximately equals.
        static constexpr float FPS_EPSILON = 0.001f;

        RefreshRate(HwcConfigIndexType configId, nsecs_t vsyncPeriod,
                    HwcConfigGroupType configGroup, std::string name, float fps)
              : configId(configId),
@@ -63,6 +66,12 @@ public:
        // Refresh rate in frames per second
        const float fps = 0;

        // Checks whether the fps of this RefreshRate struct is within a given min and max refresh
        // rate passed in. FPS_EPSILON is applied to the boundaries for approximation.
        bool inPolicy(float minRefreshRate, float maxRefreshRate) const {
            return (fps >= (minRefreshRate - FPS_EPSILON) && fps <= (maxRefreshRate + FPS_EPSILON));
        }

        bool operator!=(const RefreshRate& other) const {
            return configId != other.configId || vsyncPeriod != other.vsyncPeriod ||
                    configGroup != other.configGroup;
+11 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ protected:
    static inline const HwcConfigGroupType HWC_GROUP_ID_0 = HwcConfigGroupType(0);
    static inline const HwcConfigGroupType HWC_GROUP_ID_1 = HwcConfigGroupType(1);
    static constexpr int64_t VSYNC_60 = 16666667;
    static constexpr int64_t VSYNC_60_POINT_4 = 16666665;
    static constexpr int64_t VSYNC_90 = 11111111;

    RefreshRateConfigsTest();
@@ -238,6 +239,16 @@ TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContent) {
    ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(24.0f));
}

TEST_F(RefreshRateConfigsTest, testInPolicy) {
    RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60_POINT_4, HWC_GROUP_ID_0,
                                         "60fps", 60};
    ASSERT_TRUE(expectedDefaultConfig.inPolicy(60.000004, 60.000004));
    ASSERT_TRUE(expectedDefaultConfig.inPolicy(59.0f, 60.1f));
    ASSERT_FALSE(expectedDefaultConfig.inPolicy(75.0, 90.0));
    ASSERT_FALSE(expectedDefaultConfig.inPolicy(60.0011, 90.0));
    ASSERT_FALSE(expectedDefaultConfig.inPolicy(50.0, 59.998));
}

} // namespace
} // namespace scheduler
} // namespace android