Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44d8396d authored by Rachel Lee's avatar Rachel Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topic "flaggedmrr" into main

* changes:
  Add MRR guard logic to SF scheduler
  Add MRR guarding flag frame_rate_category_mrr
parents 19e886cd 45681988
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -40,14 +40,15 @@ namespace android::scheduler {

namespace {

bool isLayerActive(const LayerInfo& info, nsecs_t threshold) {
bool isLayerActive(const LayerInfo& info, nsecs_t threshold, bool isVrrDevice) {
    if (FlagManager::getInstance().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()) {
    const auto frameRate = info.getSetFrameRateVote();
    if (frameRate.isValid() && !frameRate.isNoVote() && frameRate.isVoteValidForMrr(isVrrDevice)) {
        return true;
    }

@@ -194,7 +195,7 @@ auto LayerHistory::summarize(const RefreshRateSelector& selector, nsecs_t now) -

    std::lock_guard lock(mLock);

    partitionLayers(now);
    partitionLayers(now, selector.isVrrDevice());

    for (const auto& [key, value] : mActiveLayerInfos) {
        auto& info = value.second;
@@ -236,7 +237,7 @@ auto LayerHistory::summarize(const RefreshRateSelector& selector, nsecs_t now) -
    return summary;
}

void LayerHistory::partitionLayers(nsecs_t now) {
void LayerHistory::partitionLayers(nsecs_t now, bool isVrrDevice) {
    ATRACE_CALL();
    const nsecs_t threshold = getActiveLayerThreshold(now);

@@ -244,7 +245,7 @@ void LayerHistory::partitionLayers(nsecs_t now) {
    LayerInfos::iterator it = mInactiveLayerInfos.begin();
    while (it != mInactiveLayerInfos.end()) {
        auto& [layerUnsafe, info] = it->second;
        if (isLayerActive(*info, threshold)) {
        if (isLayerActive(*info, threshold, isVrrDevice)) {
            // move this to the active map

            mActiveLayerInfos.insert({it->first, std::move(it->second)});
@@ -262,7 +263,7 @@ void LayerHistory::partitionLayers(nsecs_t now) {
    it = mActiveLayerInfos.begin();
    while (it != mActiveLayerInfos.end()) {
        auto& [layerUnsafe, info] = it->second;
        if (isLayerActive(*info, threshold)) {
        if (isLayerActive(*info, threshold, isVrrDevice)) {
            // Set layer vote if set
            const auto frameRate = info->getSetFrameRateVote();

@@ -305,7 +306,7 @@ void LayerHistory::partitionLayers(nsecs_t now) {
                        trace(*info, gameFrameRateOverrideVoteType,
                              gameModeFrameRateOverride.getIntValue());
                    }
                } else if (frameRate.isValid()) {
                } else if (frameRate.isValid() && frameRate.isVoteValidForMrr(isVrrDevice)) {
                    info->setLayerVote({setFrameRateVoteType, frameRate.vote.rate,
                                        frameRate.vote.seamlessness, frameRate.category});
                    if (CC_UNLIKELY(mTraceEnabled)) {
@@ -321,14 +322,30 @@ void LayerHistory::partitionLayers(nsecs_t now) {
                              gameDefaultFrameRateOverride.getIntValue());
                    }
                } else {
                    if (frameRate.isValid() && !frameRate.isVoteValidForMrr(isVrrDevice)) {
                        ATRACE_FORMAT_INSTANT("Reset layer to ignore explicit vote on MRR %s: %s "
                                              "%s %s",
                                              info->getName().c_str(),
                                              ftl::enum_string(frameRate.vote.type).c_str(),
                                              to_string(frameRate.vote.rate).c_str(),
                                              ftl::enum_string(frameRate.category).c_str());
                    }
                    info->resetLayerVote();
                }
            } else {
                if (frameRate.isValid()) {
                if (frameRate.isValid() && frameRate.isVoteValidForMrr(isVrrDevice)) {
                    const auto type = info->isVisible() ? voteType : LayerVoteType::NoVote;
                    info->setLayerVote({type, frameRate.vote.rate, frameRate.vote.seamlessness,
                                        frameRate.category});
                } else {
                    if (!frameRate.isVoteValidForMrr(isVrrDevice)) {
                        ATRACE_FORMAT_INSTANT("Reset layer to ignore explicit vote on MRR %s: %s "
                                              "%s %s",
                                              info->getName().c_str(),
                                              ftl::enum_string(frameRate.vote.type).c_str(),
                                              to_string(frameRate.vote.rate).c_str(),
                                              ftl::enum_string(frameRate.category).c_str());
                    }
                    info->resetLayerVote();
                }
            }
+5 −2
Original line number Diff line number Diff line
@@ -111,9 +111,12 @@ private:
    std::string dumpGameFrameRateOverridesLocked() const REQUIRES(mLock);

    // Iterates over layers maps moving all active layers to mActiveLayerInfos and all inactive
    // layers to mInactiveLayerInfos.
    // layers to mInactiveLayerInfos. Layer's active state is determined by multiple factors
    // such as update activity, visibility, and frame rate vote.
    // worst case time complexity is O(2 * inactive + active)
    void partitionLayers(nsecs_t now) REQUIRES(mLock);
    // now: the current time (system time) when calling the method
    // isVrrDevice: true if the device has DisplayMode with VrrConfig specified.
    void partitionLayers(nsecs_t now, bool isVrrDevice) REQUIRES(mLock);

    enum class LayerStatus {
        NotFound,
+12 −0
Original line number Diff line number Diff line
@@ -566,6 +566,18 @@ bool LayerInfo::FrameRate::isValid() const {
    return isNoVote() || vote.rate.isValid() || category != FrameRateCategory::Default;
}

bool LayerInfo::FrameRate::isVoteValidForMrr(bool isVrrDevice) const {
    if (isVrrDevice || FlagManager::getInstance().frame_rate_category_mrr()) {
        return true;
    }

    if (category == FrameRateCategory::Default && vote.type != FrameRateCompatibility::Gte) {
        return true;
    }

    return false;
}

std::ostream& operator<<(std::ostream& stream, const LayerInfo::FrameRate& rate) {
    return stream << "{rate=" << rate.vote.rate << " type=" << ftl::enum_string(rate.vote.type)
                  << " seamlessness=" << ftl::enum_string(rate.vote.seamlessness) << '}';
+4 −0
Original line number Diff line number Diff line
@@ -146,6 +146,10 @@ public:
        // selection.
        bool isNoVote() const;

        // Checks whether the given FrameRate's vote specifications is valid for MRR devices
        // given the current flagging.
        bool isVoteValidForMrr(bool isVrrDevice) const;

    private:
        static Seamlessness getSeamlessness(Fps rate, Seamlessness seamlessness) {
            if (!rate.isValid()) {
+9 −1
Original line number Diff line number Diff line
@@ -1246,6 +1246,8 @@ void RefreshRateSelector::setActiveMode(DisplayModeId modeId, Fps renderFrameRat
    LOG_ALWAYS_FATAL_IF(!activeModeOpt);

    mActiveModeOpt.emplace(FrameRateMode{renderFrameRate, ftl::as_non_null(activeModeOpt->get())});
    mIsVrrDevice = FlagManager::getInstance().vrr_config() &&
            activeModeOpt->get()->getVrrConfig().has_value();
}

RefreshRateSelector::RefreshRateSelector(DisplayModes modes, DisplayModeId activeModeId,
@@ -1459,7 +1461,8 @@ void RefreshRateSelector::constructAvailableRefreshRates() {
            }
            return str;
        };
        ALOGV("%s render rates: %s", rangeName, stringifyModes().c_str());
        ALOGV("%s render rates: %s, isVrrDevice? %d", rangeName, stringifyModes().c_str(),
              mIsVrrDevice);

        return frameRateModes;
    };
@@ -1468,6 +1471,11 @@ void RefreshRateSelector::constructAvailableRefreshRates() {
    mAppRequestFrameRates = filterRefreshRates(policy->appRequestRanges, "app request");
}

bool RefreshRateSelector::isVrrDevice() const {
    std::lock_guard lock(mLock);
    return mIsVrrDevice;
}

Fps RefreshRateSelector::findClosestKnownFrameRate(Fps frameRate) const {
    using namespace fps_approx_ops;

Loading