Loading services/surfaceflinger/Scheduler/PhaseOffsets.cpp +22 −7 Original line number Diff line number Diff line Loading @@ -31,6 +31,11 @@ std::optional<nsecs_t> getProperty(const char* name) { return std::nullopt; } bool fpsEqualsWithMargin(float fpsA, float fpsB) { static constexpr float MARGIN = 0.01f; return std::abs(fpsA - fpsB) <= MARGIN; } } // namespace namespace android::scheduler { Loading Loading @@ -61,16 +66,15 @@ void PhaseOffsets::dump(std::string& result) const { mThresholdForNextVsync); } std::unordered_map<float, PhaseDurations::Offsets> PhaseOffsets::initializeOffsets( std::unordered_map<float, PhaseOffsets::Offsets> PhaseOffsets::initializeOffsets( const scheduler::RefreshRateConfigs& refreshRateConfigs) const { std::unordered_map<float, PhaseDurations::Offsets> offsets; std::unordered_map<float, Offsets> offsets; for (const auto& [ignored, refreshRate] : refreshRateConfigs.getAllRefreshRates()) { const nsecs_t vsyncDuration = static_cast<nsecs_t>(1e9f / refreshRate.fps); if (refreshRate.fps > 65.0f) { offsets.emplace(refreshRate.fps, getHighFpsOffsets(vsyncDuration)); offsets.emplace(refreshRate.fps, getHighFpsOffsets(refreshRate.vsyncPeriod)); } else { offsets.emplace(refreshRate.fps, getDefaultOffsets(vsyncDuration)); offsets.emplace(refreshRate.fps, getDefaultOffsets(refreshRate.vsyncPeriod)); } } return offsets; Loading Loading @@ -150,6 +154,15 @@ PhaseOffsets::Offsets PhaseOffsets::getHighFpsOffsets(nsecs_t vsyncDuration) con }; } PhaseOffsets::Offsets PhaseOffsets::getOffsetsForRefreshRate(float fps) const { const auto iter = std::find_if(mOffsets.begin(), mOffsets.end(), [&fps](const std::pair<float, Offsets>& candidateFps) { return fpsEqualsWithMargin(fps, candidateFps.first); }); LOG_ALWAYS_FATAL_IF(iter == mOffsets.end()); return iter->second; } static void validateSysprops() { const auto validatePropertyBool = [](const char* prop) { LOG_ALWAYS_FATAL_IF(!property_get_bool(prop, false), "%s is false", prop); Loading Loading @@ -207,7 +220,7 @@ static std::vector<float> getRefreshRatesFromConfigs( std::unordered_map<float, PhaseDurations::Offsets> PhaseDurations::initializeOffsets( const std::vector<float>& refreshRates) const { std::unordered_map<float, PhaseDurations::Offsets> offsets; std::unordered_map<float, Offsets> offsets; for (const auto fps : refreshRates) { const nsecs_t vsyncDuration = static_cast<nsecs_t>(1e9f / fps); Loading Loading @@ -275,7 +288,9 @@ PhaseDurations::PhaseDurations(const std::vector<float>& refreshRates, float cur mRefreshRateFps(currentFps) {} PhaseOffsets::Offsets PhaseDurations::getOffsetsForRefreshRate(float fps) const { const auto iter = mOffsets.find(fps); const auto iter = std::find_if(mOffsets.begin(), mOffsets.end(), [=](const auto& candidateFps) { return fpsEqualsWithMargin(fps, candidateFps.first); }); LOG_ALWAYS_FATAL_IF(iter == mOffsets.end()); return iter->second; } Loading services/surfaceflinger/Scheduler/PhaseOffsets.h +3 −8 Original line number Diff line number Diff line Loading @@ -54,11 +54,7 @@ public: PhaseOffsets(const scheduler::RefreshRateConfigs&); // Returns early, early GL, and late offsets for Apps and SF for a given refresh rate. Offsets getOffsetsForRefreshRate(float fps) const override { const auto iter = mOffsets.find(fps); LOG_ALWAYS_FATAL_IF(iter == mOffsets.end()); return iter->second; } Offsets getOffsetsForRefreshRate(float fps) const override; // Returns early, early GL, and late offsets for Apps and SF. Offsets getCurrentOffsets() const override { return getOffsetsForRefreshRate(mRefreshRateFps); } Loading @@ -71,7 +67,7 @@ public: void dump(std::string& result) const override; private: std::unordered_map<float, PhaseOffsets::Offsets> initializeOffsets( std::unordered_map<float, Offsets> initializeOffsets( const scheduler::RefreshRateConfigs&) const; Offsets getDefaultOffsets(nsecs_t vsyncDuration) const; Offsets getHighFpsOffsets(nsecs_t vsyncDuration) const; Loading Loading @@ -111,8 +107,7 @@ protected: nsecs_t sfEarlyGlDuration, nsecs_t appEarlyGlDuration); private: std::unordered_map<float, PhaseDurations::Offsets> initializeOffsets( const std::vector<float>&) const; std::unordered_map<float, Offsets> initializeOffsets(const std::vector<float>&) const; const nsecs_t mSfDuration; const nsecs_t mAppDuration; Loading Loading
services/surfaceflinger/Scheduler/PhaseOffsets.cpp +22 −7 Original line number Diff line number Diff line Loading @@ -31,6 +31,11 @@ std::optional<nsecs_t> getProperty(const char* name) { return std::nullopt; } bool fpsEqualsWithMargin(float fpsA, float fpsB) { static constexpr float MARGIN = 0.01f; return std::abs(fpsA - fpsB) <= MARGIN; } } // namespace namespace android::scheduler { Loading Loading @@ -61,16 +66,15 @@ void PhaseOffsets::dump(std::string& result) const { mThresholdForNextVsync); } std::unordered_map<float, PhaseDurations::Offsets> PhaseOffsets::initializeOffsets( std::unordered_map<float, PhaseOffsets::Offsets> PhaseOffsets::initializeOffsets( const scheduler::RefreshRateConfigs& refreshRateConfigs) const { std::unordered_map<float, PhaseDurations::Offsets> offsets; std::unordered_map<float, Offsets> offsets; for (const auto& [ignored, refreshRate] : refreshRateConfigs.getAllRefreshRates()) { const nsecs_t vsyncDuration = static_cast<nsecs_t>(1e9f / refreshRate.fps); if (refreshRate.fps > 65.0f) { offsets.emplace(refreshRate.fps, getHighFpsOffsets(vsyncDuration)); offsets.emplace(refreshRate.fps, getHighFpsOffsets(refreshRate.vsyncPeriod)); } else { offsets.emplace(refreshRate.fps, getDefaultOffsets(vsyncDuration)); offsets.emplace(refreshRate.fps, getDefaultOffsets(refreshRate.vsyncPeriod)); } } return offsets; Loading Loading @@ -150,6 +154,15 @@ PhaseOffsets::Offsets PhaseOffsets::getHighFpsOffsets(nsecs_t vsyncDuration) con }; } PhaseOffsets::Offsets PhaseOffsets::getOffsetsForRefreshRate(float fps) const { const auto iter = std::find_if(mOffsets.begin(), mOffsets.end(), [&fps](const std::pair<float, Offsets>& candidateFps) { return fpsEqualsWithMargin(fps, candidateFps.first); }); LOG_ALWAYS_FATAL_IF(iter == mOffsets.end()); return iter->second; } static void validateSysprops() { const auto validatePropertyBool = [](const char* prop) { LOG_ALWAYS_FATAL_IF(!property_get_bool(prop, false), "%s is false", prop); Loading Loading @@ -207,7 +220,7 @@ static std::vector<float> getRefreshRatesFromConfigs( std::unordered_map<float, PhaseDurations::Offsets> PhaseDurations::initializeOffsets( const std::vector<float>& refreshRates) const { std::unordered_map<float, PhaseDurations::Offsets> offsets; std::unordered_map<float, Offsets> offsets; for (const auto fps : refreshRates) { const nsecs_t vsyncDuration = static_cast<nsecs_t>(1e9f / fps); Loading Loading @@ -275,7 +288,9 @@ PhaseDurations::PhaseDurations(const std::vector<float>& refreshRates, float cur mRefreshRateFps(currentFps) {} PhaseOffsets::Offsets PhaseDurations::getOffsetsForRefreshRate(float fps) const { const auto iter = mOffsets.find(fps); const auto iter = std::find_if(mOffsets.begin(), mOffsets.end(), [=](const auto& candidateFps) { return fpsEqualsWithMargin(fps, candidateFps.first); }); LOG_ALWAYS_FATAL_IF(iter == mOffsets.end()); return iter->second; } Loading
services/surfaceflinger/Scheduler/PhaseOffsets.h +3 −8 Original line number Diff line number Diff line Loading @@ -54,11 +54,7 @@ public: PhaseOffsets(const scheduler::RefreshRateConfigs&); // Returns early, early GL, and late offsets for Apps and SF for a given refresh rate. Offsets getOffsetsForRefreshRate(float fps) const override { const auto iter = mOffsets.find(fps); LOG_ALWAYS_FATAL_IF(iter == mOffsets.end()); return iter->second; } Offsets getOffsetsForRefreshRate(float fps) const override; // Returns early, early GL, and late offsets for Apps and SF. Offsets getCurrentOffsets() const override { return getOffsetsForRefreshRate(mRefreshRateFps); } Loading @@ -71,7 +67,7 @@ public: void dump(std::string& result) const override; private: std::unordered_map<float, PhaseOffsets::Offsets> initializeOffsets( std::unordered_map<float, Offsets> initializeOffsets( const scheduler::RefreshRateConfigs&) const; Offsets getDefaultOffsets(nsecs_t vsyncDuration) const; Offsets getHighFpsOffsets(nsecs_t vsyncDuration) const; Loading Loading @@ -111,8 +107,7 @@ protected: nsecs_t sfEarlyGlDuration, nsecs_t appEarlyGlDuration); private: std::unordered_map<float, PhaseDurations::Offsets> initializeOffsets( const std::vector<float>&) const; std::unordered_map<float, Offsets> initializeOffsets(const std::vector<float>&) const; const nsecs_t mSfDuration; const nsecs_t mAppDuration; Loading