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

Commit 2e1dd89a authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: delete RefreshRate copy constructor

Avoid copying RefreshRate objects

Change-Id: Ic00f14bd03465d163e82ee7f4bf34346f1920ad6
Test: adb shell /data/nativetest64/libsurfaceflinger_unittest/libsurfaceflinger_unittest
Bug: 150887328
parent 10460043
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -168,9 +168,9 @@ bool RefreshRateOverlay::createLayer() {
}

void RefreshRateOverlay::primeCache() {
    auto allRefreshRates = mFlinger.mRefreshRateConfigs->getAllRefreshRates();
    auto& allRefreshRates = mFlinger.mRefreshRateConfigs->getAllRefreshRates();
    if (allRefreshRates.size() == 1) {
        auto fps = allRefreshRates.begin()->second.fps;
        auto fps = allRefreshRates.begin()->second->fps;
        half4 color = {LOW_FPS_COLOR, ALPHA};
        mBufferCache.emplace(fps, SevenSegmentDrawer::drawNumber(fps, color));
        return;
@@ -178,8 +178,8 @@ void RefreshRateOverlay::primeCache() {

    std::vector<uint32_t> supportedFps;
    supportedFps.reserve(allRefreshRates.size());
    for (auto [ignored, refreshRate] : allRefreshRates) {
        supportedFps.push_back(refreshRate.fps);
    for (auto& [ignored, refreshRate] : allRefreshRates) {
        supportedFps.push_back(refreshRate->fps);
    }

    std::sort(supportedFps.begin(), supportedFps.end());
+4 −4
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ std::unordered_map<float, PhaseOffsets::Offsets> PhaseOffsets::initializeOffsets
    std::unordered_map<float, Offsets> offsets;

    for (const auto& [ignored, refreshRate] : refreshRateConfigs.getAllRefreshRates()) {
        if (refreshRate.fps > 65.0f) {
            offsets.emplace(refreshRate.fps, getHighFpsOffsets(refreshRate.vsyncPeriod));
        if (refreshRate->fps > 65.0f) {
            offsets.emplace(refreshRate->fps, getHighFpsOffsets(refreshRate->vsyncPeriod));
        } else {
            offsets.emplace(refreshRate.fps, getDefaultOffsets(refreshRate.vsyncPeriod));
            offsets.emplace(refreshRate->fps, getDefaultOffsets(refreshRate->vsyncPeriod));
        }
    }
    return offsets;
@@ -238,7 +238,7 @@ static std::vector<float> getRefreshRatesFromConfigs(
    refreshRates.reserve(allRefreshRates.size());

    for (const auto& [ignored, refreshRate] : allRefreshRates) {
        refreshRates.emplace_back(refreshRate.fps);
        refreshRates.emplace_back(refreshRate->fps);
    }

    return refreshRates;
+14 −15
Original line number Diff line number Diff line
@@ -286,12 +286,12 @@ const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicyLocked() con
                  mCurrentRefreshRate) != mAvailableRefreshRates.end()) {
        return *mCurrentRefreshRate;
    }
    return mRefreshRates.at(mDefaultConfig);
    return *mRefreshRates.at(mDefaultConfig);
}

void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) {
    std::lock_guard lock(mLock);
    mCurrentRefreshRate = &mRefreshRates.at(configId);
    mCurrentRefreshRate = mRefreshRates.at(configId).get();
}

RefreshRateConfigs::RefreshRateConfigs(const std::vector<InputConfig>& configs,
@@ -326,7 +326,7 @@ status_t RefreshRateConfigs::setPolicy(HwcConfigIndexType defaultConfigId, float
    if (mRefreshRates.count(defaultConfigId) == 0) {
        return BAD_VALUE;
    }
    const RefreshRate& refreshRate = mRefreshRates.at(defaultConfigId);
    const RefreshRate& refreshRate = *mRefreshRates.at(defaultConfigId);
    if (!refreshRate.inPolicy(minRefreshRate, maxRefreshRate)) {
        return BAD_VALUE;
    }
@@ -361,10 +361,10 @@ void RefreshRateConfigs::getSortedRefreshRateList(
    outRefreshRates->clear();
    outRefreshRates->reserve(mRefreshRates.size());
    for (const auto& [type, refreshRate] : mRefreshRates) {
        if (shouldAddRefreshRate(refreshRate)) {
        if (shouldAddRefreshRate(*refreshRate)) {
            ALOGV("getSortedRefreshRateList: config %d added to list policy",
                  refreshRate.configId.value());
            outRefreshRates->push_back(&refreshRate);
                  refreshRate->configId.value());
            outRefreshRates->push_back(refreshRate.get());
        }
    }

@@ -376,7 +376,7 @@ void RefreshRateConfigs::getSortedRefreshRateList(

void RefreshRateConfigs::constructAvailableRefreshRates() {
    // Filter configs based on current policy and sort based on vsync period
    HwcConfigGroupType group = mRefreshRates.at(mDefaultConfig).configGroup;
    HwcConfigGroupType group = mRefreshRates.at(mDefaultConfig)->configGroup;
    ALOGV("constructAvailableRefreshRates: default %d group %d min %.2f max %.2f",
          mDefaultConfig.value(), group.value(), mMinRefreshRateFps, mMaxRefreshRateFps);
    getSortedRefreshRateList(
@@ -403,16 +403,15 @@ void RefreshRateConfigs::init(const std::vector<InputConfig>& configs,
    LOG_ALWAYS_FATAL_IF(configs.empty());
    LOG_ALWAYS_FATAL_IF(currentHwcConfig.value() >= configs.size());

    auto buildRefreshRate = [&](InputConfig config) -> RefreshRate {
        const float fps = 1e9f / config.vsyncPeriod;
        return RefreshRate(config.configId, config.vsyncPeriod, config.configGroup,
                           base::StringPrintf("%2.ffps", fps), fps);
    };

    for (const auto& config : configs) {
        mRefreshRates.emplace(config.configId, buildRefreshRate(config));
        const float fps = 1e9f / config.vsyncPeriod;
        mRefreshRates.emplace(config.configId,
                              std::make_unique<RefreshRate>(config.configId, config.vsyncPeriod,
                                                            config.configGroup,
                                                            base::StringPrintf("%2.ffps", fps),
                                                            fps));
        if (config.configId == currentHwcConfig) {
            mCurrentRefreshRate = &mRefreshRates.at(config.configId);
            mCurrentRefreshRate = mRefreshRates.at(config.configId).get();
        }
    }

+5 −2
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ public:
                configGroup(configGroup),
                name(std::move(name)),
                fps(fps) {}

        RefreshRate(const RefreshRate&) = delete;
        // This config ID corresponds to the position of the config in the vector that is stored
        // on the device.
        const HwcConfigIndexType configId;
@@ -85,7 +87,8 @@ public:
        bool operator==(const RefreshRate& other) const { return !(*this != other); }
    };

    using AllRefreshRatesMapType = std::unordered_map<HwcConfigIndexType, const RefreshRate>;
    using AllRefreshRatesMapType =
            std::unordered_map<HwcConfigIndexType, std::unique_ptr<const RefreshRate>>;

    // Sets the current policy to choose refresh rates. Returns NO_ERROR if the requested policy is
    // valid, or a negative error value otherwise. policyChanged, if non-null, will be set to true
@@ -163,7 +166,7 @@ public:
    // Returns the refresh rate that corresponds to a HwcConfigIndexType. This won't change at
    // runtime.
    const RefreshRate& getRefreshRateFromConfigId(HwcConfigIndexType configId) const {
        return mRefreshRates.at(configId);
        return *mRefreshRates.at(configId);
    };

    // Stores the current configId the device operates at
+2 −2
Original line number Diff line number Diff line
@@ -463,7 +463,7 @@ void Scheduler::chooseRefreshRateForContent() {
            return;
        }
        mFeatures.configId = newConfigId;
        auto newRefreshRate = mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId);
        auto& newRefreshRate = mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId);
        mSchedulerCallback.changeRefreshRate(newRefreshRate, ConfigEvent::Changed);
    }
}
@@ -515,7 +515,7 @@ void Scheduler::kernelIdleTimerCallback(TimerState state) {

    // TODO(145561154): cleanup the kernel idle timer implementation and the refresh rate
    // magic number
    const auto refreshRate = mRefreshRateConfigs.getCurrentRefreshRate();
    const auto& refreshRate = mRefreshRateConfigs.getCurrentRefreshRate();
    constexpr float FPS_THRESHOLD_FOR_KERNEL_TIMER = 65.0f;
    if (state == TimerState::Reset && refreshRate.fps > FPS_THRESHOLD_FOR_KERNEL_TIMER) {
        // If we're not in performance mode then the kernel timer shouldn't do
Loading