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

Commit 267b4c49 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "b:140112642:5" into qt-surfaceflinger-dev

* changes:
  SurfaceFlinger: correct negative offset when refresh rate changes
  SurfaceFlinger: add allowed display configs to dumpsys
  Surfaceflinger: adjust content detection fps selection
parents 3264ef9a 5c08044a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) {
    // Normalize phaseOffset to [-period, period)
    const int numPeriods = phaseOffset / period;
    phaseOffset -= numPeriods * period;
    if (mPhaseOffset == phaseOffset) {
        return;
    }

    mPhaseOffset = phaseOffset;
    tracePhaseOffset();

+9 −12
Original line number Diff line number Diff line
@@ -523,22 +523,19 @@ Scheduler::RefreshRateType Scheduler::calculateRefreshRateType() {
        return RefreshRateType::PERFORMANCE;
    }

    // Content detection is on, find the appropriate refresh rate
    // Start with the smallest refresh rate which is within a margin of the content
    RefreshRateType currRefreshRateType = RefreshRateType::PERFORMANCE;
    constexpr float MARGIN = 0.05f;
    auto iter = mRefreshRateConfigs.getRefreshRates().cbegin();
    while (iter != mRefreshRateConfigs.getRefreshRates().cend()) {
        if (iter->second->fps >= mContentRefreshRate * (1 - MARGIN)) {
            currRefreshRateType = iter->first;
            break;
        }
        ++iter;
    }
    // Content detection is on, find the appropriate refresh rate with minimal error
    auto iter = min_element(mRefreshRateConfigs.getRefreshRates().cbegin(),
                            mRefreshRateConfigs.getRefreshRates().cend(),
                            [rate = mContentRefreshRate](const auto& l, const auto& r) -> bool {
                                return std::abs(l.second->fps - static_cast<float>(rate)) <
                                        std::abs(r.second->fps - static_cast<float>(rate));
                            });
    RefreshRateType currRefreshRateType = iter->first;

    // Some content aligns better on higher refresh rate. For example for 45fps we should choose
    // 90Hz config. However we should still prefer a lower refresh rate if the content doesn't
    // align well with both
    constexpr float MARGIN = 0.05f;
    float ratio = mRefreshRateConfigs.getRefreshRate(currRefreshRateType)->fps /
            float(mContentRefreshRate);
    if (std::abs(std::round(ratio) - ratio) > MARGIN) {
+7 −20
Original line number Diff line number Diff line
@@ -129,30 +129,17 @@ void VSyncModulator::updateOffsets() {

void VSyncModulator::updateOffsetsLocked() {
    const Offsets desired = getNextOffsets();
    const Offsets current = mOffsets;

    bool changed = false;
    if (desired.sf != current.sf) {
    if (mSfConnectionHandle != nullptr) {
        mScheduler->setPhaseOffset(mSfConnectionHandle, desired.sf);
        } else if (mSfEventThread != nullptr) {
            mSfEventThread->setPhaseOffset(desired.sf);
    }
        changed = true;
    }
    if (desired.app != current.app) {

    if (mAppConnectionHandle != nullptr) {
        mScheduler->setPhaseOffset(mAppConnectionHandle, desired.app);
        } else if (mAppEventThread != nullptr) {
            mAppEventThread->setPhaseOffset(desired.app);
        }
        changed = true;
    }

    if (changed) {
    flushOffsets();
}
}

void VSyncModulator::flushOffsets() {
    OffsetType type = getNextOffsetType();
+0 −9
Original line number Diff line number Diff line
@@ -68,12 +68,6 @@ public:
    void setPhaseOffsets(Offsets early, Offsets earlyGl, Offsets late,
                         nsecs_t thresholdForNextVsync) EXCLUDES(mMutex);

    // Sets handles to the SF and app event threads.
    void setEventThreads(EventThread* sfEventThread, EventThread* appEventThread) {
        mSfEventThread = sfEventThread;
        mAppEventThread = appEventThread;
    }

    // Sets the scheduler and vsync connection handlers.
    void setSchedulerAndHandles(Scheduler* scheduler,
                                Scheduler::ConnectionHandle* appConnectionHandle,
@@ -121,9 +115,6 @@ private:
    std::unordered_map<OffsetType, Offsets> mOffsetMap GUARDED_BY(mMutex);
    nsecs_t mThresholdForNextVsync;

    EventThread* mSfEventThread = nullptr;
    EventThread* mAppEventThread = nullptr;

    Scheduler* mScheduler = nullptr;
    Scheduler::ConnectionHandle* mAppConnectionHandle = nullptr;
    Scheduler::ConnectionHandle* mSfConnectionHandle = nullptr;
+10 −0
Original line number Diff line number Diff line
@@ -4704,6 +4704,16 @@ void SurfaceFlinger::dumpVSync(std::string& result) const {
    StringAppendF(&result, "Scheduler enabled.");
    StringAppendF(&result, "+  Smart 90 for video detection: %s\n\n",
                  mUseSmart90ForVideo ? "on" : "off");
    StringAppendF(&result, "Allowed Display Configs: ");
    for (int32_t configId : mAllowedDisplayConfigs) {
        for (auto refresh : mRefreshRateConfigs.getRefreshRates()) {
            if (refresh.second && refresh.second->configId == configId) {
                StringAppendF(&result, "%dHz, ", refresh.second->fps);
            }
        }
    }
    StringAppendF(&result, "(config override by backdoor: %s)\n\n",
                  mDebugDisplayConfigSetByBackdoor ? "yes" : "no");
    mScheduler->dump(mAppConnectionHandle, result);
}