Loading services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(), Loading services/surfaceflinger/Scheduler/RefreshRateConfigs.h +9 −0 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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; Loading services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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 Loading
services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(), Loading
services/surfaceflinger/Scheduler/RefreshRateConfigs.h +9 −0 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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; Loading
services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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