SF: Remove display config functions from HWC2
HWC2 is unnecessary stateful stopgap between HWComposer and
ComposerHal. In this CL the following functions are removed from HWC2
* getActiveConfig
* getActiveConfigIndex
* getDisplayVsyncPeriod
and ComposerHal is called directly from HWComposer. This way display
configs are stored only in HWComposer.
Additionally HWC2::Display::Config is renamed to DisplayMode and
it's extracted in its own file.
From the perspective of SurfaceFlinger this CL is not modifying
behaviour.
Bug: 159590486
Bug: 175678215
Test: atest libsurfaceflinger_unittest
Change-Id: I8cb450209adf038d891cff00d1c2690c8e6d94f7
diff --git a/services/surfaceflinger/Scheduler/HwcStrongTypes.h b/services/surfaceflinger/Scheduler/HwcStrongTypes.h
index 8ba4f20..b6a33a2 100644
--- a/services/surfaceflinger/Scheduler/HwcStrongTypes.h
+++ b/services/surfaceflinger/Scheduler/HwcStrongTypes.h
@@ -18,9 +18,11 @@
#include "StrongTyping.h"
+#include <cstddef>
+
namespace android {
// Strong types for the different indexes as they are referring to a different base.
-using HwcConfigIndexType = StrongTyping<int, struct HwcConfigIndexTypeTag, Compare, Add, Hash>;
+using HwcConfigIndexType = StrongTyping<size_t, struct HwcConfigIndexTypeTag, Compare, Add, Hash>;
} // namespace android
\ No newline at end of file
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
index 975754b..b02596a 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
@@ -40,8 +40,7 @@
to_string(layer.desiredRefreshRate).c_str());
}
-std::vector<Fps> constructKnownFrameRates(
- const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs) {
+std::vector<Fps> constructKnownFrameRates(const DisplayModes& configs) {
std::vector<Fps> knownFrameRates = {Fps(24.0f), Fps(30.0f), Fps(45.0f), Fps(60.0f), Fps(72.0f)};
knownFrameRates.reserve(knownFrameRates.size() + configs.size());
@@ -65,8 +64,8 @@
using RefreshRate = RefreshRateConfigs::RefreshRate;
std::string RefreshRate::toString() const {
- return base::StringPrintf("{id=%d, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}",
- getConfigId().value(), hwcConfig->getId(), getFps().getValue(),
+ return base::StringPrintf("{id=%zu, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}",
+ getConfigId().value(), hwcConfig->getHwcId(), getFps().getValue(),
hwcConfig->getWidth(), hwcConfig->getHeight(), getConfigGroup());
}
@@ -88,7 +87,7 @@
}
std::string RefreshRateConfigs::Policy::toString() const {
- return base::StringPrintf("default config ID: %d, allowGroupSwitching = %d"
+ return base::StringPrintf("default config ID: %zu, allowGroupSwitching = %d"
", primary range: %s, app request range: %s",
defaultConfig.value(), allowGroupSwitching,
primaryRange.toString().c_str(), appRequestRange.toString().c_str());
@@ -560,19 +559,16 @@
mCurrentRefreshRate = mRefreshRates.at(configId).get();
}
-RefreshRateConfigs::RefreshRateConfigs(
- const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
- HwcConfigIndexType currentConfigId)
+RefreshRateConfigs::RefreshRateConfigs(const DisplayModes& configs,
+ HwcConfigIndexType currentConfigId)
: mKnownFrameRates(constructKnownFrameRates(configs)) {
updateDisplayConfigs(configs, currentConfigId);
}
-void RefreshRateConfigs::updateDisplayConfigs(
- const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
- HwcConfigIndexType currentConfigId) {
+void RefreshRateConfigs::updateDisplayConfigs(const DisplayModes& configs,
+ HwcConfigIndexType currentConfigId) {
std::lock_guard lock(mLock);
LOG_ALWAYS_FATAL_IF(configs.empty());
- LOG_ALWAYS_FATAL_IF(currentConfigId.value() < 0);
LOG_ALWAYS_FATAL_IF(currentConfigId.value() >= configs.size());
mRefreshRates.clear();
@@ -684,7 +680,7 @@
outRefreshRates->reserve(mRefreshRates.size());
for (const auto& [type, refreshRate] : mRefreshRates) {
if (shouldAddRefreshRate(*refreshRate)) {
- ALOGV("getSortedRefreshRateListLocked: config %d added to list policy",
+ ALOGV("getSortedRefreshRateListLocked: config %zu added to list policy",
refreshRate->configId.value());
outRefreshRates->push_back(refreshRate.get());
}
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
index 4b99145..a5d37c2 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
@@ -24,6 +24,7 @@
#include <optional>
#include <type_traits>
+#include "DisplayHardware/DisplayMode.h"
#include "DisplayHardware/HWComposer.h"
#include "Fps.h"
#include "HwcStrongTypes.h"
@@ -64,8 +65,7 @@
};
public:
- RefreshRate(HwcConfigIndexType configId,
- std::shared_ptr<const HWC2::Display::Config> config, Fps fps, ConstructorTag)
+ RefreshRate(HwcConfigIndexType configId, DisplayModePtr config, Fps fps, ConstructorTag)
: configId(configId), hwcConfig(config), fps(std::move(fps)) {}
HwcConfigIndexType getConfigId() const { return configId; }
@@ -101,7 +101,7 @@
// on the device.
const HwcConfigIndexType configId;
// The config itself
- std::shared_ptr<const HWC2::Display::Config> hwcConfig;
+ DisplayModePtr hwcConfig;
// Refresh rate in frames per second
const Fps fps{0.0f};
};
@@ -296,12 +296,10 @@
// Returns a known frame rate that is the closest to frameRate
Fps findClosestKnownFrameRate(Fps frameRate) const;
- RefreshRateConfigs(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
- HwcConfigIndexType currentConfigId);
+ RefreshRateConfigs(const DisplayModes& configs, HwcConfigIndexType currentConfigId);
- void updateDisplayConfigs(
- const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
- HwcConfigIndexType currentConfig) EXCLUDES(mLock);
+ void updateDisplayConfigs(const DisplayModes& configs, HwcConfigIndexType currentConfig)
+ EXCLUDES(mLock);
// Returns whether switching configs (refresh rate or resolution) is possible.
// TODO(b/158780872): Consider HAL support, and skip frame rate detection if the configs only
diff --git a/services/surfaceflinger/Scheduler/StrongTyping.h b/services/surfaceflinger/Scheduler/StrongTyping.h
index 6a60257..a05c123 100644
--- a/services/surfaceflinger/Scheduler/StrongTyping.h
+++ b/services/surfaceflinger/Scheduler/StrongTyping.h
@@ -62,8 +62,8 @@
template <typename T, typename W, template <typename> class... Ability>
struct StrongTyping : Ability<StrongTyping<T, W, Ability...>>... {
- StrongTyping() : mValue(0) {}
- explicit StrongTyping(T const& value) : mValue(value) {}
+ constexpr StrongTyping() = default;
+ constexpr explicit StrongTyping(T const& value) : mValue(value) {}
StrongTyping(StrongTyping const&) = default;
StrongTyping& operator=(StrongTyping const&) = default;
explicit inline operator T() const { return mValue; }
@@ -75,7 +75,7 @@
}
private:
- T mValue;
+ T mValue{0};
};
} // namespace android