SF: Pull FpsRange to scheduler/Fps.h
Bug: 185535769
Test: libsurfaceflinger_unittest
Change-Id: Iec0696d752e7cd071f68a9c15be5f28e3b7f5c07
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
index 3b9cfa6..eeeaac1 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
@@ -69,11 +69,6 @@
using AllRefreshRatesMapType = RefreshRateConfigs::AllRefreshRatesMapType;
using RefreshRate = RefreshRateConfigs::RefreshRate;
-bool RefreshRate::inPolicy(Fps minRefreshRate, Fps maxRefreshRate) const {
- using fps_approx_ops::operator<=;
- return minRefreshRate <= getFps() && getFps() <= maxRefreshRate;
-}
-
std::string RefreshRate::toString() const {
return base::StringPrintf("{id=%d, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}",
getModeId().value(), mode->getHwcId(), getFps().getValue(),
@@ -84,7 +79,7 @@
return base::StringPrintf("default mode ID: %d, allowGroupSwitching = %d"
", primary range: %s, app request range: %s",
defaultMode.value(), allowGroupSwitching,
- primaryRange.toString().c_str(), appRequestRange.toString().c_str());
+ to_string(primaryRange).c_str(), to_string(appRequestRange).c_str());
}
std::pair<nsecs_t, nsecs_t> RefreshRateConfigs::getDisplayFrames(nsecs_t layerPeriod,
@@ -396,8 +391,9 @@
continue;
}
- bool inPrimaryRange = scores[i].refreshRate->inPolicy(policy->primaryRange.min,
- policy->primaryRange.max);
+ const bool inPrimaryRange =
+ policy->primaryRange.includes(scores[i].refreshRate->getFps());
+
if ((primaryRangeIsSingleRate || !inPrimaryRange) &&
!(layer.focused &&
(layer.vote == LayerVoteType::ExplicitDefault ||
@@ -746,7 +742,7 @@
return false;
}
const RefreshRate& refreshRate = *iter->second;
- if (!refreshRate.inPolicy(policy.primaryRange.min, policy.primaryRange.max)) {
+ if (!policy.primaryRange.includes(refreshRate.getFps())) {
ALOGE("Default mode is not in the primary range.");
return false;
}
@@ -843,7 +839,7 @@
ALOGV("constructAvailableRefreshRates: %s ", policy->toString().c_str());
auto filterRefreshRates =
- [&](Fps min, Fps max, const char* listName,
+ [&](FpsRange range, const char* rangeName,
std::vector<const RefreshRate*>* outRefreshRates) REQUIRES(mLock) {
getSortedRefreshRateListLocked(
[&](const RefreshRate& refreshRate) REQUIRES(mLock) {
@@ -855,13 +851,13 @@
mode->getDpiY() == defaultMode->getDpiY() &&
(policy->allowGroupSwitching ||
mode->getGroup() == defaultMode->getGroup()) &&
- refreshRate.inPolicy(min, max);
+ range.includes(mode->getFps());
},
outRefreshRates);
- LOG_ALWAYS_FATAL_IF(outRefreshRates->empty(),
- "No matching modes for %s range: min=%s max=%s", listName,
- to_string(min).c_str(), to_string(max).c_str());
+ LOG_ALWAYS_FATAL_IF(outRefreshRates->empty(), "No matching modes for %s range %s",
+ rangeName, to_string(range).c_str());
+
auto stringifyRefreshRates = [&]() -> std::string {
std::string str;
for (auto refreshRate : *outRefreshRates) {
@@ -869,13 +865,11 @@
}
return str;
};
- ALOGV("%s refresh rates: %s", listName, stringifyRefreshRates().c_str());
+ ALOGV("%s refresh rates: %s", rangeName, stringifyRefreshRates().c_str());
};
- filterRefreshRates(policy->primaryRange.min, policy->primaryRange.max, "primary",
- &mPrimaryRefreshRates);
- filterRefreshRates(policy->appRequestRange.min, policy->appRequestRange.max, "app request",
- &mAppRequestRefreshRates);
+ filterRefreshRates(policy->primaryRange, "primary", &mPrimaryRefreshRates);
+ filterRefreshRates(policy->appRequestRange, "app request", &mAppRequestRefreshRates);
}
Fps RefreshRateConfigs::findClosestKnownFrameRate(Fps frameRate) const {
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
index ade1787..f5b97c2 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
@@ -22,7 +22,6 @@
#include <type_traits>
#include <utility>
-#include <android-base/stringprintf.h>
#include <gui/DisplayEventReceiver.h>
#include <scheduler/Fps.h>
@@ -101,21 +100,6 @@
using AllRefreshRatesMapType =
std::unordered_map<DisplayModeId, std::unique_ptr<const RefreshRate>>;
- struct FpsRange {
- Fps min = Fps::fromValue(0.f);
- Fps max = Fps::fromValue(std::numeric_limits<float>::max());
-
- bool operator==(const FpsRange& other) const {
- return isApproxEqual(min, other.min) && isApproxEqual(max, other.max);
- }
-
- bool operator!=(const FpsRange& other) const { return !(*this == other); }
-
- std::string toString() const {
- return base::StringPrintf("[%s %s]", to_string(min).c_str(), to_string(max).c_str());
- }
- };
-
struct Policy {
private:
static constexpr int kAllowGroupSwitchingDefault = false;
@@ -140,24 +124,24 @@
Policy() = default;
- Policy(DisplayModeId defaultMode, const FpsRange& range)
+ Policy(DisplayModeId defaultMode, FpsRange range)
: Policy(defaultMode, kAllowGroupSwitchingDefault, range, range) {}
- Policy(DisplayModeId defaultMode, bool allowGroupSwitching, const FpsRange& range)
+ Policy(DisplayModeId defaultMode, bool allowGroupSwitching, FpsRange range)
: Policy(defaultMode, allowGroupSwitching, range, range) {}
- Policy(DisplayModeId defaultMode, const FpsRange& primaryRange,
- const FpsRange& appRequestRange)
+ Policy(DisplayModeId defaultMode, FpsRange primaryRange, FpsRange appRequestRange)
: Policy(defaultMode, kAllowGroupSwitchingDefault, primaryRange, appRequestRange) {}
- Policy(DisplayModeId defaultMode, bool allowGroupSwitching, const FpsRange& primaryRange,
- const FpsRange& appRequestRange)
+ Policy(DisplayModeId defaultMode, bool allowGroupSwitching, FpsRange primaryRange,
+ FpsRange appRequestRange)
: defaultMode(defaultMode),
allowGroupSwitching(allowGroupSwitching),
primaryRange(primaryRange),
appRequestRange(appRequestRange) {}
bool operator==(const Policy& other) const {
+ using namespace fps_approx_ops;
return defaultMode == other.defaultMode && primaryRange == other.primaryRange &&
appRequestRange == other.appRequestRange &&
allowGroupSwitching == other.allowGroupSwitching;
diff --git a/services/surfaceflinger/Scheduler/include/scheduler/Fps.h b/services/surfaceflinger/Scheduler/include/scheduler/Fps.h
index 639b3e5..bd4f409 100644
--- a/services/surfaceflinger/Scheduler/include/scheduler/Fps.h
+++ b/services/surfaceflinger/Scheduler/include/scheduler/Fps.h
@@ -17,6 +17,7 @@
#pragma once
#include <cmath>
+#include <limits>
#include <ostream>
#include <string>
#include <type_traits>
@@ -60,6 +61,13 @@
nsecs_t mPeriod = 0;
};
+struct FpsRange {
+ Fps min = Fps::fromValue(0.f);
+ Fps max = Fps::fromValue(std::numeric_limits<float>::max());
+
+ bool includes(Fps) const;
+};
+
static_assert(std::is_trivially_copyable_v<Fps>);
constexpr Fps operator""_Hz(unsigned long long frequency) {
@@ -111,8 +119,21 @@
return !isApproxLess(lhs, rhs);
}
+inline bool operator==(FpsRange lhs, FpsRange rhs) {
+ return isApproxEqual(lhs.min, rhs.min) && isApproxEqual(lhs.max, rhs.max);
+}
+
+inline bool operator!=(FpsRange lhs, FpsRange rhs) {
+ return !(lhs == rhs);
+}
+
} // namespace fps_approx_ops
+inline bool FpsRange::includes(Fps fps) const {
+ using fps_approx_ops::operator<=;
+ return min <= fps && fps <= max;
+}
+
struct FpsApproxEqual {
bool operator()(Fps lhs, Fps rhs) const { return isApproxEqual(lhs, rhs); }
};
@@ -125,4 +146,9 @@
return stream << to_string(fps);
}
+inline std::string to_string(FpsRange range) {
+ const auto [min, max] = range;
+ return base::StringPrintf("[%s, %s]", to_string(min).c_str(), to_string(max).c_str());
+}
+
} // namespace android