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

Commit 8fabd068 authored by Christoffer Quist Adamsen's avatar Christoffer Quist Adamsen Committed by Android (Google) Code Review
Browse files

Merge "Revert "Revert "SF: Remove refresh_rate_switching flag."""

parents 011eee1c aa52b007
Loading
Loading
Loading
Loading
+4 −16
Original line number Original line Diff line number Diff line
@@ -216,21 +216,13 @@ const AllRefreshRatesMapType& RefreshRateConfigs::getAllRefreshRates() const {


const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicy() const {
const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicy() const {
    std::lock_guard lock(mLock);
    std::lock_guard lock(mLock);
    if (!mRefreshRateSwitching) {
        return *mCurrentRefreshRate;
    } else {
    return *mAvailableRefreshRates.front();
    return *mAvailableRefreshRates.front();
}
}
}


const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicy() const {
const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicy() const {
    std::lock_guard lock(mLock);
    std::lock_guard lock(mLock);
    if (!mRefreshRateSwitching) {
        return *mCurrentRefreshRate;
    } else {
        return *mAvailableRefreshRates.back();
        return *mAvailableRefreshRates.back();
}
}
}


const RefreshRate& RefreshRateConfigs::getCurrentRefreshRate() const {
const RefreshRate& RefreshRateConfigs::getCurrentRefreshRate() const {
    std::lock_guard lock(mLock);
    std::lock_guard lock(mLock);
@@ -242,18 +234,14 @@ void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) {
    mCurrentRefreshRate = &mRefreshRates.at(configId);
    mCurrentRefreshRate = &mRefreshRates.at(configId);
}
}


RefreshRateConfigs::RefreshRateConfigs(bool refreshRateSwitching,
RefreshRateConfigs::RefreshRateConfigs(const std::vector<InputConfig>& configs,
                                       const std::vector<InputConfig>& configs,
                                       HwcConfigIndexType currentHwcConfig) {
                                       HwcConfigIndexType currentHwcConfig)
      : mRefreshRateSwitching(refreshRateSwitching) {
    init(configs, currentHwcConfig);
    init(configs, currentHwcConfig);
}
}


RefreshRateConfigs::RefreshRateConfigs(
RefreshRateConfigs::RefreshRateConfigs(
        bool refreshRateSwitching,
        const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
        const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
        HwcConfigIndexType currentConfigId)
        HwcConfigIndexType currentConfigId) {
      : mRefreshRateSwitching(refreshRateSwitching) {
    std::vector<InputConfig> inputConfigs;
    std::vector<InputConfig> inputConfigs;
    for (size_t configId = 0; configId < configs.size(); ++configId) {
    for (size_t configId = 0; configId < configs.size(); ++configId) {
        auto configGroup = HwcConfigGroupType(configs[configId]->getConfigGroup());
        auto configGroup = HwcConfigGroupType(configs[configId]->getConfigGroup());
+2 −8
Original line number Original line Diff line number Diff line
@@ -94,9 +94,6 @@ public:
    // Returns true if config is allowed by the current policy.
    // Returns true if config is allowed by the current policy.
    bool isConfigAllowed(HwcConfigIndexType config) const EXCLUDES(mLock);
    bool isConfigAllowed(HwcConfigIndexType config) const EXCLUDES(mLock);


    // Returns true if this device is doing refresh rate switching. This won't change at runtime.
    bool refreshRateSwitchingSupported() const { return mRefreshRateSwitching; }

    // Describes the different options the layer voted for refresh rate
    // Describes the different options the layer voted for refresh rate
    enum class LayerVoteType {
    enum class LayerVoteType {
        NoVote,          // Doesn't care about the refresh rate
        NoVote,          // Doesn't care about the refresh rate
@@ -167,10 +164,9 @@ public:
        nsecs_t vsyncPeriod = 0;
        nsecs_t vsyncPeriod = 0;
    };
    };


    RefreshRateConfigs(bool refreshRateSwitching, const std::vector<InputConfig>& configs,
    RefreshRateConfigs(const std::vector<InputConfig>& configs,
                       HwcConfigIndexType currentHwcConfig);
                       HwcConfigIndexType currentHwcConfig);
    RefreshRateConfigs(bool refreshRateSwitching,
    RefreshRateConfigs(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
                       const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
                       HwcConfigIndexType currentConfigId);
                       HwcConfigIndexType currentConfigId);


private:
private:
@@ -208,8 +204,6 @@ private:
    const RefreshRate* mMinSupportedRefreshRate;
    const RefreshRate* mMinSupportedRefreshRate;
    const RefreshRate* mMaxSupportedRefreshRate;
    const RefreshRate* mMaxSupportedRefreshRate;


    const bool mRefreshRateSwitching;

    mutable std::mutex mLock;
    mutable std::mutex mLock;
};
};


+27 −20
Original line number Original line Diff line number Diff line
@@ -530,8 +530,6 @@ void Scheduler::dump(std::string& result) const {
    using base::StringAppendF;
    using base::StringAppendF;
    const char* const states[] = {"off", "on"};
    const char* const states[] = {"off", "on"};


    const bool supported = mRefreshRateConfigs.refreshRateSwitchingSupported();
    StringAppendF(&result, "+  Refresh rate switching: %s\n", states[supported]);
    StringAppendF(&result, "+  Content detection: %s\n", states[mLayerHistory != nullptr]);
    StringAppendF(&result, "+  Content detection: %s\n", states[mLayerHistory != nullptr]);


    StringAppendF(&result, "+  Idle timer: %s\n",
    StringAppendF(&result, "+  Idle timer: %s\n",
@@ -575,35 +573,44 @@ bool Scheduler::layerHistoryHasClientSpecifiedFrameRate() {
}
}


HwcConfigIndexType Scheduler::calculateRefreshRateType() {
HwcConfigIndexType Scheduler::calculateRefreshRateType() {
    if (!mRefreshRateConfigs.refreshRateSwitchingSupported()) {
    // This block of the code checks whether any layers used the SetFrameRate API. If they have,
        return mRefreshRateConfigs.getCurrentRefreshRate().configId;
    // their request should be honored regardless of whether the device has refresh rate switching
    // turned off.
    if (layerHistoryHasClientSpecifiedFrameRate()) {
        if (!mUseContentDetectionV2) {
            return mRefreshRateConfigs.getRefreshRateForContent(mFeatures.contentRequirements)
                    .configId;
        } else {
            return mRefreshRateConfigs.getRefreshRateForContentV2(mFeatures.contentRequirements)
                    .configId;
        }
    }
    }


    // If the layer history doesn't have the frame rate specified, use the old path. NOTE:
    // 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
    // if we remove the kernel idle timer, and use our internal idle timer, this code will have to
    // be refactored.
    // be refactored.
    if (!layerHistoryHasClientSpecifiedFrameRate()) {
    // If Display Power is not in normal operation we want to be in performance mode.
    // 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
    // When coming back to normal mode, a grace period is given with DisplayPowerTimer
        if (!mFeatures.isDisplayPowerStateNormal ||
    if (mDisplayPowerTimer &&
            mFeatures.displayPowerTimer == TimerState::Reset) {
        (!mFeatures.isDisplayPowerStateNormal ||
         mFeatures.displayPowerTimer == TimerState::Reset)) {
        return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId;
        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 (mFeatures.touch == TouchState::Active) {
    if (mTouchTimer && mFeatures.touch == TouchState::Active) {
        return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId;
        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 (mFeatures.idleTimer == TimerState::Expired) {
    if (mIdleTimer && mFeatures.idleTimer == TimerState::Expired) {
        return mRefreshRateConfigs.getMinRefreshRateByPolicy().configId;
        return mRefreshRateConfigs.getMinRefreshRateByPolicy().configId;
    }
    }
    }


    if (!mUseContentDetectionV2) {
    if (!mUseContentDetectionV2) {
        // If content detection is off we choose performance as we don't know the content fps
        // If content detection is off we choose performance as we don't know the content fps.
        if (mFeatures.contentDetection == ContentDetectionState::Off) {
        if (mFeatures.contentDetection == ContentDetectionState::Off) {
            // TODO(b/148428554): Be careful to not always call this.
            return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId;
            return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId;
        }
        }


+13 −27
Original line number Original line Diff line number Diff line
@@ -555,12 +555,6 @@ void SurfaceFlinger::bootFinished()
        readPersistentProperties();
        readPersistentProperties();
        mBootStage = BootStage::FINISHED;
        mBootStage = BootStage::FINISHED;


        if (mRefreshRateConfigs->refreshRateSwitchingSupported()) {
            // set the refresh rate according to the policy
            const auto& performanceRefreshRate = mRefreshRateConfigs->getMaxRefreshRateByPolicy();
            changeRefreshRateLocked(performanceRefreshRate, Scheduler::ConfigEvent::None);
        }

        if (property_get_bool("sf.debug.show_refresh_rate_overlay", false)) {
        if (property_get_bool("sf.debug.show_refresh_rate_overlay", false)) {
            mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*this);
            mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*this);
            mRefreshRateOverlay->changeRefreshRate(mRefreshRateConfigs->getCurrentRefreshRate());
            mRefreshRateOverlay->changeRefreshRate(mRefreshRateConfigs->getCurrentRefreshRate());
@@ -2719,8 +2713,7 @@ void SurfaceFlinger::initScheduler(DisplayId primaryDisplayId) {


    auto currentConfig = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(primaryDisplayId));
    auto currentConfig = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(primaryDisplayId));
    mRefreshRateConfigs =
    mRefreshRateConfigs =
            std::make_unique<scheduler::RefreshRateConfigs>(refresh_rate_switching(false),
            std::make_unique<scheduler::RefreshRateConfigs>(getHwComposer().getConfigs(
                                                            getHwComposer().getConfigs(
                                                                    primaryDisplayId),
                                                                    primaryDisplayId),
                                                            currentConfig);
                                                            currentConfig);
    mRefreshRateStats =
    mRefreshRateStats =
@@ -5700,26 +5693,19 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal(const sp<DisplayDe
    mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value,
    mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value,
                                display->getActiveConfig(), vsyncPeriod);
                                display->getActiveConfig(), vsyncPeriod);


    if (mRefreshRateConfigs->refreshRateSwitchingSupported()) {
    auto configId = mScheduler->getPreferredConfigId();
    auto configId = mScheduler->getPreferredConfigId();
    auto preferredRefreshRate = configId
    auto preferredRefreshRate = configId
            ? mRefreshRateConfigs->getRefreshRateFromConfigId(*configId)
            ? mRefreshRateConfigs->getRefreshRateFromConfigId(*configId)
                : mRefreshRateConfigs->getMinRefreshRateByPolicy();
            // NOTE: Choose the default config ID, if Scheduler doesn't have one in mind.
            : mRefreshRateConfigs->getRefreshRateFromConfigId(defaultConfig);
    ALOGV("trying to switch to Scheduler preferred config %d (%s)",
    ALOGV("trying to switch to Scheduler preferred config %d (%s)",
          preferredRefreshRate.configId.value(), preferredRefreshRate.name.c_str());
          preferredRefreshRate.configId.value(), preferredRefreshRate.name.c_str());

    if (isDisplayConfigAllowed(preferredRefreshRate.configId)) {
    if (isDisplayConfigAllowed(preferredRefreshRate.configId)) {
            ALOGV("switching to Scheduler preferred config %d",
        ALOGV("switching to Scheduler preferred config %d", preferredRefreshRate.configId.value());
                  preferredRefreshRate.configId.value());
        setDesiredActiveConfig({preferredRefreshRate.configId, Scheduler::ConfigEvent::Changed});
            setDesiredActiveConfig(
                    {preferredRefreshRate.configId, Scheduler::ConfigEvent::Changed});
        } else {
            // Set the highest allowed config
            setDesiredActiveConfig({mRefreshRateConfigs->getMaxRefreshRateByPolicy().configId,
                                    Scheduler::ConfigEvent::Changed});
        }
    } else {
    } else {
        ALOGV("switching to config %d", defaultConfig.value());
        LOG_ALWAYS_FATAL("Desired config not allowed: %d", preferredRefreshRate.configId.value());
        setDesiredActiveConfig({defaultConfig, Scheduler::ConfigEvent::Changed});
    }
    }


    return NO_ERROR;
    return NO_ERROR;
+0 −8
Original line number Original line Diff line number Diff line
@@ -226,14 +226,6 @@ int64_t color_space_agnostic_dataspace(Dataspace defaultValue) {
    return static_cast<int64_t>(defaultValue);
    return static_cast<int64_t>(defaultValue);
}
}


bool refresh_rate_switching(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::refresh_rate_switching();
    if (temp.has_value()) {
        return *temp;
    }
    return defaultValue;
}

int32_t set_idle_timer_ms(int32_t defaultValue) {
int32_t set_idle_timer_ms(int32_t defaultValue) {
    auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
    auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
    if (temp.has_value()) {
    if (temp.has_value()) {
Loading