Loading services/surfaceflinger/Layer.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,6 @@ Layer::Layer(const LayerCreationArgs& args) mName(args.name), mClientRef(args.client), mWindowType(args.metadata.getInt32(METADATA_WINDOW_TYPE, 0)) { uint32_t layerFlags = 0; if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; Loading Loading @@ -1264,6 +1263,9 @@ bool Layer::setShadowRadius(float shadowRadius) { } bool Layer::setFrameRate(FrameRate frameRate) { if (!mFlinger->useFrameRateApi) { return false; } if (mCurrentState.frameRate == frameRate) { return false; } Loading services/surfaceflinger/Scheduler/LayerHistory.cpp +0 −19 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ void trace(const wp<Layer>& weak, int fps) { ATRACE_INT(tag.c_str(), fps); ALOGD("%s: %s @ %d Hz", __FUNCTION__, name.c_str(), fps); } } // namespace LayerHistory::LayerHistory() Loading Loading @@ -102,23 +101,6 @@ LayerHistory::Summary LayerHistory::summarize(nsecs_t now) { partitionLayers(now); // Find the maximum refresh rate among recently active layers. for (const auto& [activeLayer, info] : activeLayers()) { const bool recent = info->isRecentlyActive(now); if (recent || CC_UNLIKELY(mTraceEnabled)) { const float refreshRate = info->getRefreshRate(now); if (recent && refreshRate > 0.0f) { if (const auto layer = activeLayer.promote(); layer) { const int32_t priority = layer->getFrameRateSelectionPriority(); // TODO(b/142507166): This is where the scoring algorithm should live. // Layers should be organized by priority ALOGD("Layer has priority: %d", priority); } } } } LayerHistory::Summary summary; for (const auto& [weakLayer, info] : activeLayers()) { const bool recent = info->isRecentlyActive(now); Loading Loading @@ -196,6 +178,5 @@ void LayerHistory::clear() { mActiveLayersEnd = 0; } } // namespace android::scheduler::impl services/surfaceflinger/Scheduler/LayerHistoryV2.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ void trace(const wp<Layer>& weak, LayerHistory::LayerVoteType type, int fps) { ALOGD("%s: %s @ %d Hz", __FUNCTION__, name.c_str(), fps); } } // namespace LayerHistoryV2::LayerHistoryV2() Loading Loading @@ -124,6 +123,10 @@ LayerHistoryV2::Summary LayerHistoryV2::summarize(nsecs_t now) { continue; } // TODO(b/144307188): This needs to be plugged into layer summary as // an additional parameter. ALOGV("Layer has priority: %d", strong->getFrameRateSelectionPriority()); const bool recent = info->isRecentlyActive(now); if (recent) { const auto [type, refreshRate] = info->getRefreshRate(now); Loading Loading @@ -212,5 +215,4 @@ void LayerHistoryV2::clear() { mActiveLayersEnd = 0; } } // namespace android::scheduler::impl services/surfaceflinger/Scheduler/Scheduler.cpp +18 −23 Original line number Diff line number Diff line Loading @@ -108,14 +108,11 @@ Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function, mUseContentDetectionV2(useContentDetectionV2) { using namespace sysprop; if (property_get_bool("debug.sf.use_content_detection_for_refresh_rate", 0) || use_content_detection_for_refresh_rate(false)) { if (mUseContentDetectionV2) { mLayerHistory = std::make_unique<scheduler::impl::LayerHistoryV2>(); } else { mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>(); } } const int setIdleTimerMs = property_get_int32("debug.sf.set_idle_timer_ms", 0); Loading Loading @@ -438,7 +435,7 @@ void Scheduler::chooseRefreshRateForContent() { mFeatures.contentDetection = !summary.empty() ? ContentDetectionState::On : ContentDetectionState::Off; newConfigId = calculateRefreshRateType(); newConfigId = calculateRefreshRateConfigIndexType(); if (mFeatures.configId == newConfigId) { return; } Loading Loading @@ -531,8 +528,6 @@ void Scheduler::dump(std::string& result) const { using base::StringAppendF; const char* const states[] = {"off", "on"}; StringAppendF(&result, "+ Content detection: %s\n", states[mLayerHistory != nullptr]); StringAppendF(&result, "+ Idle timer: %s\n", mIdleTimer ? mIdleTimer->dump().c_str() : states[0]); StringAppendF(&result, "+ Touch timer: %s\n\n", Loading @@ -549,7 +544,7 @@ void Scheduler::handleTimerStateChanged(T* currentState, T newState, bool eventO return; } *currentState = newState; newConfigId = calculateRefreshRateType(); newConfigId = calculateRefreshRateConfigIndexType(); if (mFeatures.configId == newConfigId) { return; } Loading @@ -563,6 +558,7 @@ void Scheduler::handleTimerStateChanged(T* currentState, T newState, bool eventO } bool Scheduler::layerHistoryHasClientSpecifiedFrameRate() { // Traverse all the layers to see if any of them requested frame rate. for (const auto& layer : mFeatures.contentRequirements) { if (layer.vote == scheduler::RefreshRateConfigs::LayerVoteType::ExplicitDefault || layer.vote == scheduler::RefreshRateConfigs::LayerVoteType::ExplicitExactOrMultiple) { Loading @@ -573,10 +569,9 @@ bool Scheduler::layerHistoryHasClientSpecifiedFrameRate() { return false; } HwcConfigIndexType Scheduler::calculateRefreshRateType() { HwcConfigIndexType Scheduler::calculateRefreshRateConfigIndexType() { // This block of the code checks whether any layers used the SetFrameRate API. If they have, // their request should be honored regardless of whether the device has refresh rate switching // turned off. // their request should be honored depending on other active layers. if (layerHistoryHasClientSpecifiedFrameRate()) { if (!mUseContentDetectionV2) { return mRefreshRateConfigs.getRefreshRateForContent(mFeatures.contentRequirements) Loading @@ -587,23 +582,23 @@ HwcConfigIndexType Scheduler::calculateRefreshRateType() { } } // If the layer history doesn't have the frame rate specified, use the old path. NOTE: // if we remove the kernel idle timer, and use our internal idle timer, this code will have to // be refactored. // If Display Power is not in normal operation we want to be in performance mode. // When coming back to normal mode, a grace period is given with DisplayPowerTimer // If the layer history doesn't have the frame rate specified, check for other features and // honor them. NOTE: If we remove the kernel idle timer, and use our internal idle timer, this // code will have to be refactored. If Display Power is not in normal operation we want to be in // performance mode. When coming back to normal mode, a grace period is given with // DisplayPowerTimer. if (mDisplayPowerTimer && (!mFeatures.isDisplayPowerStateNormal || mFeatures.displayPowerTimer == TimerState::Reset)) { return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId; } // As long as touch is active we want to be in performance mode // As long as touch is active we want to be in performance mode. if (mTouchTimer && mFeatures.touch == TouchState::Active) { return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId; } // If timer has expired as it means there is no new content on the screen // If timer has expired as it means there is no new content on the screen. if (mIdleTimer && mFeatures.idleTimer == TimerState::Expired) { return mRefreshRateConfigs.getMinRefreshRateByPolicy().configId; } Loading @@ -611,7 +606,7 @@ HwcConfigIndexType Scheduler::calculateRefreshRateType() { if (!mUseContentDetectionV2) { // If content detection is off we choose performance as we don't know the content fps. if (mFeatures.contentDetection == ContentDetectionState::Off) { // TODO(b/148428554): Be careful to not always call this. // NOTE: V1 always calls this, but this is not a default behavior for V2. return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId; } Loading @@ -633,7 +628,7 @@ std::optional<HwcConfigIndexType> Scheduler::getPreferredConfigId() { std::lock_guard<std::mutex> lock(mFeatureStateLock); // Make sure that the default config ID is first updated, before returned. if (mFeatures.configId.has_value()) { mFeatures.configId = calculateRefreshRateType(); mFeatures.configId = calculateRefreshRateConfigIndexType(); } return mFeatures.configId; } Loading services/surfaceflinger/Scheduler/Scheduler.h +4 −1 Original line number Diff line number Diff line Loading @@ -177,7 +177,10 @@ private: void setVsyncPeriod(nsecs_t period); HwcConfigIndexType calculateRefreshRateType() REQUIRES(mFeatureStateLock); // This function checks whether individual features that are affecting the refresh rate // selection were initialized, prioritizes them, and calculates the HwcConfigIndexType // for the suggested refresh rate. HwcConfigIndexType calculateRefreshRateConfigIndexType() REQUIRES(mFeatureStateLock); bool layerHistoryHasClientSpecifiedFrameRate() REQUIRES(mFeatureStateLock); Loading Loading
services/surfaceflinger/Layer.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,6 @@ Layer::Layer(const LayerCreationArgs& args) mName(args.name), mClientRef(args.client), mWindowType(args.metadata.getInt32(METADATA_WINDOW_TYPE, 0)) { uint32_t layerFlags = 0; if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; Loading Loading @@ -1264,6 +1263,9 @@ bool Layer::setShadowRadius(float shadowRadius) { } bool Layer::setFrameRate(FrameRate frameRate) { if (!mFlinger->useFrameRateApi) { return false; } if (mCurrentState.frameRate == frameRate) { return false; } Loading
services/surfaceflinger/Scheduler/LayerHistory.cpp +0 −19 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ void trace(const wp<Layer>& weak, int fps) { ATRACE_INT(tag.c_str(), fps); ALOGD("%s: %s @ %d Hz", __FUNCTION__, name.c_str(), fps); } } // namespace LayerHistory::LayerHistory() Loading Loading @@ -102,23 +101,6 @@ LayerHistory::Summary LayerHistory::summarize(nsecs_t now) { partitionLayers(now); // Find the maximum refresh rate among recently active layers. for (const auto& [activeLayer, info] : activeLayers()) { const bool recent = info->isRecentlyActive(now); if (recent || CC_UNLIKELY(mTraceEnabled)) { const float refreshRate = info->getRefreshRate(now); if (recent && refreshRate > 0.0f) { if (const auto layer = activeLayer.promote(); layer) { const int32_t priority = layer->getFrameRateSelectionPriority(); // TODO(b/142507166): This is where the scoring algorithm should live. // Layers should be organized by priority ALOGD("Layer has priority: %d", priority); } } } } LayerHistory::Summary summary; for (const auto& [weakLayer, info] : activeLayers()) { const bool recent = info->isRecentlyActive(now); Loading Loading @@ -196,6 +178,5 @@ void LayerHistory::clear() { mActiveLayersEnd = 0; } } // namespace android::scheduler::impl
services/surfaceflinger/Scheduler/LayerHistoryV2.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ void trace(const wp<Layer>& weak, LayerHistory::LayerVoteType type, int fps) { ALOGD("%s: %s @ %d Hz", __FUNCTION__, name.c_str(), fps); } } // namespace LayerHistoryV2::LayerHistoryV2() Loading Loading @@ -124,6 +123,10 @@ LayerHistoryV2::Summary LayerHistoryV2::summarize(nsecs_t now) { continue; } // TODO(b/144307188): This needs to be plugged into layer summary as // an additional parameter. ALOGV("Layer has priority: %d", strong->getFrameRateSelectionPriority()); const bool recent = info->isRecentlyActive(now); if (recent) { const auto [type, refreshRate] = info->getRefreshRate(now); Loading Loading @@ -212,5 +215,4 @@ void LayerHistoryV2::clear() { mActiveLayersEnd = 0; } } // namespace android::scheduler::impl
services/surfaceflinger/Scheduler/Scheduler.cpp +18 −23 Original line number Diff line number Diff line Loading @@ -108,14 +108,11 @@ Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function, mUseContentDetectionV2(useContentDetectionV2) { using namespace sysprop; if (property_get_bool("debug.sf.use_content_detection_for_refresh_rate", 0) || use_content_detection_for_refresh_rate(false)) { if (mUseContentDetectionV2) { mLayerHistory = std::make_unique<scheduler::impl::LayerHistoryV2>(); } else { mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>(); } } const int setIdleTimerMs = property_get_int32("debug.sf.set_idle_timer_ms", 0); Loading Loading @@ -438,7 +435,7 @@ void Scheduler::chooseRefreshRateForContent() { mFeatures.contentDetection = !summary.empty() ? ContentDetectionState::On : ContentDetectionState::Off; newConfigId = calculateRefreshRateType(); newConfigId = calculateRefreshRateConfigIndexType(); if (mFeatures.configId == newConfigId) { return; } Loading Loading @@ -531,8 +528,6 @@ void Scheduler::dump(std::string& result) const { using base::StringAppendF; const char* const states[] = {"off", "on"}; StringAppendF(&result, "+ Content detection: %s\n", states[mLayerHistory != nullptr]); StringAppendF(&result, "+ Idle timer: %s\n", mIdleTimer ? mIdleTimer->dump().c_str() : states[0]); StringAppendF(&result, "+ Touch timer: %s\n\n", Loading @@ -549,7 +544,7 @@ void Scheduler::handleTimerStateChanged(T* currentState, T newState, bool eventO return; } *currentState = newState; newConfigId = calculateRefreshRateType(); newConfigId = calculateRefreshRateConfigIndexType(); if (mFeatures.configId == newConfigId) { return; } Loading @@ -563,6 +558,7 @@ void Scheduler::handleTimerStateChanged(T* currentState, T newState, bool eventO } bool Scheduler::layerHistoryHasClientSpecifiedFrameRate() { // Traverse all the layers to see if any of them requested frame rate. for (const auto& layer : mFeatures.contentRequirements) { if (layer.vote == scheduler::RefreshRateConfigs::LayerVoteType::ExplicitDefault || layer.vote == scheduler::RefreshRateConfigs::LayerVoteType::ExplicitExactOrMultiple) { Loading @@ -573,10 +569,9 @@ bool Scheduler::layerHistoryHasClientSpecifiedFrameRate() { return false; } HwcConfigIndexType Scheduler::calculateRefreshRateType() { HwcConfigIndexType Scheduler::calculateRefreshRateConfigIndexType() { // This block of the code checks whether any layers used the SetFrameRate API. If they have, // their request should be honored regardless of whether the device has refresh rate switching // turned off. // their request should be honored depending on other active layers. if (layerHistoryHasClientSpecifiedFrameRate()) { if (!mUseContentDetectionV2) { return mRefreshRateConfigs.getRefreshRateForContent(mFeatures.contentRequirements) Loading @@ -587,23 +582,23 @@ HwcConfigIndexType Scheduler::calculateRefreshRateType() { } } // If the layer history doesn't have the frame rate specified, use the old path. NOTE: // if we remove the kernel idle timer, and use our internal idle timer, this code will have to // be refactored. // If Display Power is not in normal operation we want to be in performance mode. // When coming back to normal mode, a grace period is given with DisplayPowerTimer // If the layer history doesn't have the frame rate specified, check for other features and // honor them. NOTE: If we remove the kernel idle timer, and use our internal idle timer, this // code will have to be refactored. If Display Power is not in normal operation we want to be in // performance mode. When coming back to normal mode, a grace period is given with // DisplayPowerTimer. if (mDisplayPowerTimer && (!mFeatures.isDisplayPowerStateNormal || mFeatures.displayPowerTimer == TimerState::Reset)) { return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId; } // As long as touch is active we want to be in performance mode // As long as touch is active we want to be in performance mode. if (mTouchTimer && mFeatures.touch == TouchState::Active) { return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId; } // If timer has expired as it means there is no new content on the screen // If timer has expired as it means there is no new content on the screen. if (mIdleTimer && mFeatures.idleTimer == TimerState::Expired) { return mRefreshRateConfigs.getMinRefreshRateByPolicy().configId; } Loading @@ -611,7 +606,7 @@ HwcConfigIndexType Scheduler::calculateRefreshRateType() { if (!mUseContentDetectionV2) { // If content detection is off we choose performance as we don't know the content fps. if (mFeatures.contentDetection == ContentDetectionState::Off) { // TODO(b/148428554): Be careful to not always call this. // NOTE: V1 always calls this, but this is not a default behavior for V2. return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId; } Loading @@ -633,7 +628,7 @@ std::optional<HwcConfigIndexType> Scheduler::getPreferredConfigId() { std::lock_guard<std::mutex> lock(mFeatureStateLock); // Make sure that the default config ID is first updated, before returned. if (mFeatures.configId.has_value()) { mFeatures.configId = calculateRefreshRateType(); mFeatures.configId = calculateRefreshRateConfigIndexType(); } return mFeatures.configId; } Loading
services/surfaceflinger/Scheduler/Scheduler.h +4 −1 Original line number Diff line number Diff line Loading @@ -177,7 +177,10 @@ private: void setVsyncPeriod(nsecs_t period); HwcConfigIndexType calculateRefreshRateType() REQUIRES(mFeatureStateLock); // This function checks whether individual features that are affecting the refresh rate // selection were initialized, prioritizes them, and calculates the HwcConfigIndexType // for the suggested refresh rate. HwcConfigIndexType calculateRefreshRateConfigIndexType() REQUIRES(mFeatureStateLock); bool layerHistoryHasClientSpecifiedFrameRate() REQUIRES(mFeatureStateLock); Loading