Loading services/surfaceflinger/Scheduler/LayerHistory.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -46,11 +46,13 @@ LayerHistory::LayerHistory() { LayerHistory::~LayerHistory() = default; std::unique_ptr<LayerHistory::LayerHandle> LayerHistory::createLayer(const std::string name, float minRefreshRate, float maxRefreshRate) { const int64_t id = sNextId++; std::lock_guard lock(mLock); mInactiveLayerInfos.emplace(id, std::make_shared<LayerInfo>(name, maxRefreshRate)); mInactiveLayerInfos.emplace(id, std::make_shared<LayerInfo>(name, minRefreshRate, maxRefreshRate)); return std::make_unique<LayerHistory::LayerHandle>(*this, id); } Loading services/surfaceflinger/Scheduler/LayerHistory.h +2 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ public: ~LayerHistory(); // When the layer is first created, register it. std::unique_ptr<LayerHandle> createLayer(const std::string name, float maxRefreshRate); std::unique_ptr<LayerHandle> createLayer(const std::string name, float minRefreshRate, float maxRefreshRate); // Method for inserting layers and their requested present time into the unordered map. void insert(const std::unique_ptr<LayerHandle>& layerHandle, nsecs_t presentTime, bool isHdr); Loading services/surfaceflinger/Scheduler/LayerInfo.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -24,9 +24,10 @@ namespace android { namespace scheduler { LayerInfo::LayerInfo(const std::string name, float maxRefreshRate) LayerInfo::LayerInfo(const std::string name, float minRefreshRate, float maxRefreshRate) : mName(name), mMinRefreshDuration(1e9f / maxRefreshRate), mLowActivityRefreshDuration(1e9f / minRefreshRate), mRefreshRateHistory(mMinRefreshDuration) {} LayerInfo::~LayerInfo() = default; Loading @@ -47,7 +48,7 @@ void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime) { const nsecs_t timeDiff = lastPresentTime - mLastPresentTime; mLastPresentTime = lastPresentTime; // Ignore time diff that are too high - those are stale values if (timeDiff > TIME_EPSILON_NS.count()) return; if (timeDiff > OBSOLETE_TIME_EPSILON_NS.count()) return; const nsecs_t refreshDuration = (timeDiff > 0) ? timeDiff : mMinRefreshDuration; mRefreshRateHistory.insertRefreshRate(refreshDuration); } Loading services/surfaceflinger/Scheduler/LayerInfo.h +28 −3 Original line number Diff line number Diff line Loading @@ -96,8 +96,9 @@ class LayerInfo { return false; } // The last update should not be older than TIME_EPSILON_NS nanoseconds. const int64_t obsoleteEpsilon = systemTime() - scheduler::TIME_EPSILON_NS.count(); // The last update should not be older than OBSOLETE_TIME_EPSILON_NS nanoseconds. const int64_t obsoleteEpsilon = systemTime() - scheduler::OBSOLETE_TIME_EPSILON_NS.count(); if (mElements.at(mElements.size() - 1) < obsoleteEpsilon) { return false; } Loading @@ -105,6 +106,25 @@ class LayerInfo { return true; } bool isLowActivityLayer() const { // We want to make sure that we received more than two frames from the layer // in order to check low activity. if (mElements.size() < 2) { return false; } const int64_t obsoleteEpsilon = systemTime() - scheduler::LOW_ACTIVITY_EPSILON_NS.count(); // Check the frame before last to determine whether there is low activity. // If that frame is older than LOW_ACTIVITY_EPSILON_NS, the layer is sending // infrequent updates. if (mElements.at(mElements.size() - 2) < obsoleteEpsilon) { return true; } return false; } void clearHistory() { mElements.clear(); } private: Loading @@ -114,7 +134,7 @@ class LayerInfo { }; public: LayerInfo(const std::string name, float maxRefreshRate); LayerInfo(const std::string name, float minRefreshRate, float maxRefreshRate); ~LayerInfo(); LayerInfo(const LayerInfo&) = delete; Loading Loading @@ -144,6 +164,10 @@ public: // Calculate the average refresh rate. float getDesiredRefreshRate() const { std::lock_guard lock(mLock); if (mPresentTimeHistory.isLowActivityLayer()) { return 1e9f / mLowActivityRefreshDuration; } return mRefreshRateHistory.getRefreshRateAvg(); } Loading Loading @@ -175,6 +199,7 @@ public: private: const std::string mName; const nsecs_t mMinRefreshDuration; const nsecs_t mLowActivityRefreshDuration; mutable std::mutex mLock; nsecs_t mLastUpdatedTime GUARDED_BY(mLock) = 0; nsecs_t mLastPresentTime GUARDED_BY(mLock) = 0; Loading services/surfaceflinger/Scheduler/Scheduler.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -330,8 +330,11 @@ std::unique_ptr<scheduler::LayerHistory::LayerHandle> Scheduler::registerLayer( : RefreshRateType::PERFORMANCE; const auto refreshRate = mRefreshRateConfigs.getRefreshRate(refreshRateType); const uint32_t fps = (refreshRate) ? refreshRate->fps : 0; return mLayerHistory.createLayer(name, fps); const uint32_t performanceFps = (refreshRate) ? refreshRate->fps : 0; const auto defaultRefreshRate = mRefreshRateConfigs.getRefreshRate(RefreshRateType::DEFAULT); const uint32_t defaultFps = (defaultRefreshRate) ? defaultRefreshRate->fps : 0; return mLayerHistory.createLayer(name, defaultFps, performanceFps); } void Scheduler::addLayerPresentTimeAndHDR( Loading Loading
services/surfaceflinger/Scheduler/LayerHistory.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -46,11 +46,13 @@ LayerHistory::LayerHistory() { LayerHistory::~LayerHistory() = default; std::unique_ptr<LayerHistory::LayerHandle> LayerHistory::createLayer(const std::string name, float minRefreshRate, float maxRefreshRate) { const int64_t id = sNextId++; std::lock_guard lock(mLock); mInactiveLayerInfos.emplace(id, std::make_shared<LayerInfo>(name, maxRefreshRate)); mInactiveLayerInfos.emplace(id, std::make_shared<LayerInfo>(name, minRefreshRate, maxRefreshRate)); return std::make_unique<LayerHistory::LayerHandle>(*this, id); } Loading
services/surfaceflinger/Scheduler/LayerHistory.h +2 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ public: ~LayerHistory(); // When the layer is first created, register it. std::unique_ptr<LayerHandle> createLayer(const std::string name, float maxRefreshRate); std::unique_ptr<LayerHandle> createLayer(const std::string name, float minRefreshRate, float maxRefreshRate); // Method for inserting layers and their requested present time into the unordered map. void insert(const std::unique_ptr<LayerHandle>& layerHandle, nsecs_t presentTime, bool isHdr); Loading
services/surfaceflinger/Scheduler/LayerInfo.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -24,9 +24,10 @@ namespace android { namespace scheduler { LayerInfo::LayerInfo(const std::string name, float maxRefreshRate) LayerInfo::LayerInfo(const std::string name, float minRefreshRate, float maxRefreshRate) : mName(name), mMinRefreshDuration(1e9f / maxRefreshRate), mLowActivityRefreshDuration(1e9f / minRefreshRate), mRefreshRateHistory(mMinRefreshDuration) {} LayerInfo::~LayerInfo() = default; Loading @@ -47,7 +48,7 @@ void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime) { const nsecs_t timeDiff = lastPresentTime - mLastPresentTime; mLastPresentTime = lastPresentTime; // Ignore time diff that are too high - those are stale values if (timeDiff > TIME_EPSILON_NS.count()) return; if (timeDiff > OBSOLETE_TIME_EPSILON_NS.count()) return; const nsecs_t refreshDuration = (timeDiff > 0) ? timeDiff : mMinRefreshDuration; mRefreshRateHistory.insertRefreshRate(refreshDuration); } Loading
services/surfaceflinger/Scheduler/LayerInfo.h +28 −3 Original line number Diff line number Diff line Loading @@ -96,8 +96,9 @@ class LayerInfo { return false; } // The last update should not be older than TIME_EPSILON_NS nanoseconds. const int64_t obsoleteEpsilon = systemTime() - scheduler::TIME_EPSILON_NS.count(); // The last update should not be older than OBSOLETE_TIME_EPSILON_NS nanoseconds. const int64_t obsoleteEpsilon = systemTime() - scheduler::OBSOLETE_TIME_EPSILON_NS.count(); if (mElements.at(mElements.size() - 1) < obsoleteEpsilon) { return false; } Loading @@ -105,6 +106,25 @@ class LayerInfo { return true; } bool isLowActivityLayer() const { // We want to make sure that we received more than two frames from the layer // in order to check low activity. if (mElements.size() < 2) { return false; } const int64_t obsoleteEpsilon = systemTime() - scheduler::LOW_ACTIVITY_EPSILON_NS.count(); // Check the frame before last to determine whether there is low activity. // If that frame is older than LOW_ACTIVITY_EPSILON_NS, the layer is sending // infrequent updates. if (mElements.at(mElements.size() - 2) < obsoleteEpsilon) { return true; } return false; } void clearHistory() { mElements.clear(); } private: Loading @@ -114,7 +134,7 @@ class LayerInfo { }; public: LayerInfo(const std::string name, float maxRefreshRate); LayerInfo(const std::string name, float minRefreshRate, float maxRefreshRate); ~LayerInfo(); LayerInfo(const LayerInfo&) = delete; Loading Loading @@ -144,6 +164,10 @@ public: // Calculate the average refresh rate. float getDesiredRefreshRate() const { std::lock_guard lock(mLock); if (mPresentTimeHistory.isLowActivityLayer()) { return 1e9f / mLowActivityRefreshDuration; } return mRefreshRateHistory.getRefreshRateAvg(); } Loading Loading @@ -175,6 +199,7 @@ public: private: const std::string mName; const nsecs_t mMinRefreshDuration; const nsecs_t mLowActivityRefreshDuration; mutable std::mutex mLock; nsecs_t mLastUpdatedTime GUARDED_BY(mLock) = 0; nsecs_t mLastPresentTime GUARDED_BY(mLock) = 0; Loading
services/surfaceflinger/Scheduler/Scheduler.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -330,8 +330,11 @@ std::unique_ptr<scheduler::LayerHistory::LayerHandle> Scheduler::registerLayer( : RefreshRateType::PERFORMANCE; const auto refreshRate = mRefreshRateConfigs.getRefreshRate(refreshRateType); const uint32_t fps = (refreshRate) ? refreshRate->fps : 0; return mLayerHistory.createLayer(name, fps); const uint32_t performanceFps = (refreshRate) ? refreshRate->fps : 0; const auto defaultRefreshRate = mRefreshRateConfigs.getRefreshRate(RefreshRateType::DEFAULT); const uint32_t defaultFps = (defaultRefreshRate) ? defaultRefreshRate->fps : 0; return mLayerHistory.createLayer(name, defaultFps, performanceFps); } void Scheduler::addLayerPresentTimeAndHDR( Loading