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

Commit 8c6f3f6b authored by Ana Krulec's avatar Ana Krulec
Browse files

SF: Remove refresh_rate_switching flag.

ag/9294789 introduce a flag to only allow refresh rate switching on the
devices that have that flag set to true, because it broke devices that
didn't support multiple refresh rates, and Android TV.

LocalDisplayAdapter sets the refresh rate to default when booting the
phone, so no need for that in SF anymore.

Test: Install on devices that doesn't have multiple refresh rates.
Test: Run SF unittests.
Test: Turn on all the flags, and run through set of examples:
      Video playback stays at 60.
      Camera stays at 60.
      Maps play at 60.
      Low brightness stays at 90.
      Swappy successfully switches between 60 & 90.
Test: Turn off all the flags, and rerun the examples from previous.
      If applications requested the change, the change is honored,
      otherwise we stay at default (set by DM).
Test: Ask Android TV team to test the patch.
Bug: 148427603
Change-Id: I44085e91a74902d102bcf9f1491164cdb50650cc
parent 5ca59db0
Loading
Loading
Loading
Loading
+4 −16
Original line number Diff line number Diff line
@@ -199,21 +199,13 @@ const AllRefreshRatesMapType& RefreshRateConfigs::getAllRefreshRates() const {

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

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

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

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

RefreshRateConfigs::RefreshRateConfigs(
        bool refreshRateSwitching,
        const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
        HwcConfigIndexType currentConfigId)
      : mRefreshRateSwitching(refreshRateSwitching) {
        HwcConfigIndexType currentConfigId) {
    std::vector<InputConfig> inputConfigs;
    for (size_t configId = 0; configId < configs.size(); ++configId) {
        auto configGroup = HwcConfigGroupType(configs[configId]->getConfigGroup());
+2 −8
Original line number Diff line number Diff line
@@ -94,9 +94,6 @@ public:
    // Returns true if config is allowed by the current policy.
    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
    enum class LayerVoteType {
        NoVote,    // Doesn't care about the refresh rate
@@ -164,10 +161,9 @@ public:
        nsecs_t vsyncPeriod = 0;
    };

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

private:
@@ -205,8 +201,6 @@ private:
    const RefreshRate* mMinSupportedRefreshRate;
    const RefreshRate* mMaxSupportedRefreshRate;

    const bool mRefreshRateSwitching;

    mutable std::mutex mLock;
};

+27 −20
Original line number Diff line number Diff line
@@ -529,8 +529,6 @@ void Scheduler::dump(std::string& result) const {
    using base::StringAppendF;
    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, "+  Idle timer: %s\n",
@@ -573,35 +571,44 @@ bool Scheduler::layerHistoryHasClientSpecifiedFrameRate() {
}

HwcConfigIndexType Scheduler::calculateRefreshRateType() {
    if (!mRefreshRateConfigs.refreshRateSwitchingSupported()) {
        return mRefreshRateConfigs.getCurrentRefreshRate().configId;
    // 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.
    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 we remove the kernel idle timer, and use our internal idle timer, this code will have to
    // be refactored.
    if (!layerHistoryHasClientSpecifiedFrameRate()) {
    // 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 (!mFeatures.isDisplayPowerStateNormal ||
            mFeatures.displayPowerTimer == TimerState::Reset) {
    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
        if (mFeatures.touch == TouchState::Active) {
    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 (mFeatures.idleTimer == TimerState::Expired) {
    if (mIdleTimer && mFeatures.idleTimer == TimerState::Expired) {
        return mRefreshRateConfigs.getMinRefreshRateByPolicy().configId;
    }
    }

    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) {
            // TODO(b/148428554): Be careful to not always call this.
            return mRefreshRateConfigs.getMaxRefreshRateByPolicy().configId;
        }

+13 −27
Original line number Diff line number Diff line
@@ -538,12 +538,6 @@ void SurfaceFlinger::bootFinished()
        readPersistentProperties();
        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)) {
            mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*this);
            mRefreshRateOverlay->changeRefreshRate(mRefreshRateConfigs->getCurrentRefreshRate());
@@ -2699,8 +2693,7 @@ void SurfaceFlinger::initScheduler(DisplayId primaryDisplayId) {

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

    if (mRefreshRateConfigs->refreshRateSwitchingSupported()) {
    auto configId = mScheduler->getPreferredConfigId();
    auto preferredRefreshRate = 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)",
          preferredRefreshRate.configId.value(), preferredRefreshRate.name.c_str());

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

    return NO_ERROR;
+0 −8
Original line number Diff line number Diff line
@@ -226,14 +226,6 @@ int64_t color_space_agnostic_dataspace(Dataspace 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) {
    auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
    if (temp.has_value()) {
Loading