Non-visible layers are now "inactive"
When setting "explicit_refresh_rate_hints", we saw the perfetto trace is
very noisy in LayerHistory/RefreshRateSelector. This change fixes this
in a few ways:
- Non-visible layers should now be inactive in LayerHistory. This should
be safe because non-visible layers were treated as NoVote,
and does not affect the refresh rate chosen.
- LayerInfo for ExplicitCategory now considers NoVote (from non-visible
layer).
- RefreshRateSelector::calculateLayerScoreLocked does not have any
interesting trace calls itself, so remove its ATRACE_CALL.
Bug: 305008279
Test: atest libsurfaceflinger_unittest
Test: atest SetFrameRateTest
Test: perfetto trace not noisy
Change-Id: I40056ea48b8323b7be0936e7717706bf9a0926f9
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index 069d89b..ff82914 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -21,6 +21,7 @@
#include "LayerHistory.h"
#include <android-base/stringprintf.h>
+#include <com_android_graphics_surfaceflinger_flags.h>
#include <cutils/properties.h>
#include <gui/TraceUtils.h>
#include <utils/Log.h>
@@ -39,8 +40,14 @@
namespace {
+using namespace com::android::graphics::surfaceflinger;
+
bool isLayerActive(const LayerInfo& info, nsecs_t threshold) {
- // Layers with an explicit frame rate or frame rate category are always kept active,
+ if (flags::misc1() && !info.isVisible()) {
+ return false;
+ }
+
+ // Layers with an explicit frame rate or frame rate category are kept active,
// but ignore NoVote.
if (info.getSetFrameRateVote().isValid() && !info.getSetFrameRateVote().isNoVote()) {
return true;
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp
index 36f2475..54e9022 100644
--- a/services/surfaceflinger/Scheduler/LayerInfo.cpp
+++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp
@@ -304,19 +304,22 @@
if (mLayerVote.type != LayerHistory::LayerVoteType::Heuristic) {
if (mLayerVote.category != FrameRateCategory::Default) {
- ATRACE_FORMAT_INSTANT("ExplicitCategory (%s)",
+ const auto voteType = mLayerVote.type == LayerHistory::LayerVoteType::NoVote
+ ? LayerHistory::LayerVoteType::NoVote
+ : LayerHistory::LayerVoteType::ExplicitCategory;
+ ATRACE_FORMAT_INSTANT("Vote %s (category=%s)", ftl::enum_string(voteType).c_str(),
ftl::enum_string(mLayerVote.category).c_str());
- ALOGV("%s uses frame rate category: %d", mName.c_str(),
- static_cast<int>(mLayerVote.category));
- votes.push_back({LayerHistory::LayerVoteType::ExplicitCategory, Fps(),
- Seamlessness::Default, mLayerVote.category,
+ ALOGV("%s voted %s with category: %s", mName.c_str(),
+ ftl::enum_string(voteType).c_str(),
+ ftl::enum_string(mLayerVote.category).c_str());
+ votes.push_back({voteType, Fps(), Seamlessness::Default, mLayerVote.category,
mLayerVote.categorySmoothSwitchOnly});
}
if (mLayerVote.fps.isValid() ||
mLayerVote.type != LayerHistory::LayerVoteType::ExplicitDefault) {
ATRACE_FORMAT_INSTANT("Vote %s", ftl::enum_string(mLayerVote.type).c_str());
- ALOGV("%s voted %d ", mName.c_str(), static_cast<int>(mLayerVote.type));
+ ALOGV("%s voted %d", mName.c_str(), static_cast<int>(mLayerVote.type));
votes.push_back(mLayerVote);
}
diff --git a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp
index 1d23fb5..eb69d0b 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp
+++ b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp
@@ -401,7 +401,6 @@
float RefreshRateSelector::calculateLayerScoreLocked(const LayerRequirement& layer, Fps refreshRate,
bool isSeamlessSwitch) const {
- ATRACE_CALL();
// Slightly prefer seamless switches.
constexpr float kSeamedSwitchPenalty = 0.95f;
const float seamlessness = isSeamlessSwitch ? 1.0f : kSeamedSwitchPenalty;