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

Commit b973403c authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge changes I7a995415,Idfce2573

* changes:
  SurfaceFlinger: return DisplayStatInfo from getDisplayStatInfo
  SurfaceFlinger: optimize frame rate override
parents 3db5cb6e e90dd52d
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -251,8 +251,7 @@ void RegionSamplingThread::doSample() {
        // If there is relatively little time left for surfaceflinger
        // until the next vsync deadline, defer this sampling work
        // to a later frame, when hopefully there will be more time.
        DisplayStatInfo stats;
        mScheduler.getDisplayStatInfo(&stats, systemTime());
        const DisplayStatInfo stats = mScheduler.getDisplayStatInfo(systemTime());
        if (std::chrono::nanoseconds(stats.vsyncTime) - now < timeForRegionSampling) {
            ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::waitForQuietFrame));
            mDiscardedFrames++;
+14 −1
Original line number Diff line number Diff line
@@ -394,8 +394,9 @@ std::vector<RefreshRateScore> initializeScoresForAllRefreshRates(
RefreshRateConfigs::UidToFrameRateOverride RefreshRateConfigs::getFrameRateOverrides(
        const std::vector<LayerRequirement>& layers, Fps displayFrameRate) const {
    ATRACE_CALL();
    ALOGV("getFrameRateOverrides %zu layers", layers.size());
    if (!mSupportsFrameRateOverride) return {};

    ALOGV("getFrameRateOverrides %zu layers", layers.size());
    std::lock_guard lock(mLock);
    std::vector<RefreshRateScore> scores = initializeScoresForAllRefreshRates(mRefreshRates);
    std::unordered_map<uid_t, std::vector<const LayerRequirement*>> layersByUid =
@@ -552,6 +553,16 @@ RefreshRateConfigs::RefreshRateConfigs(
    mDisplayManagerPolicy.defaultConfig = currentConfigId;
    mMinSupportedRefreshRate = sortedConfigs.front();
    mMaxSupportedRefreshRate = sortedConfigs.back();

    mSupportsFrameRateOverride = false;
    for (const auto& config1 : sortedConfigs) {
        for (const auto& config2 : sortedConfigs) {
            if (getFrameRateDivider(config1->getFps(), config2->getFps()) >= 2) {
                mSupportsFrameRateOverride = true;
                break;
            }
        }
    }
    constructAvailableRefreshRates();
}

@@ -788,6 +799,8 @@ void RefreshRateConfigs::dump(std::string& result) const {
        base::StringAppendF(&result, "\t%s\n", refreshRate->toString().c_str());
    }

    base::StringAppendF(&result, "Supports Frame Rate Override: %s\n",
                        mSupportsFrameRateOverride ? "yes" : "no");
    result.append("\n");
}

+4 −0
Original line number Diff line number Diff line
@@ -318,6 +318,8 @@ public:
    // refresh rates.
    KernelIdleTimerAction getIdleTimerAction() const;

    bool supportsFrameRateOverride() const { return mSupportsFrameRateOverride; }

    // Returns a divider for the current refresh rate
    int getRefreshRateDivider(Fps frameRate) const EXCLUDES(mLock);

@@ -405,6 +407,8 @@ private:
    // A sorted list of known frame rates that a Heuristic layer will choose
    // from based on the closest value.
    const std::vector<Fps> mKnownFrameRates;

    bool mSupportsFrameRateOverride;
};

} // namespace android::scheduler
+23 −6
Original line number Diff line number Diff line
@@ -226,6 +226,10 @@ std::optional<Fps> Scheduler::getFrameRateOverride(uid_t uid) const {
}

bool Scheduler::isVsyncValid(nsecs_t expectedVsyncTimestamp, uid_t uid) const {
    if (!mRefreshRateConfigs.supportsFrameRateOverride()) {
        return true;
    }

    const auto frameRate = getFrameRateOverride(uid);
    if (!frameRate.has_value()) {
        return true;
@@ -239,14 +243,22 @@ bool Scheduler::isVsyncValid(nsecs_t expectedVsyncTimestamp, uid_t uid) const {
    return mVsyncSchedule.tracker->isVSyncInPhase(expectedVsyncTimestamp, divider);
}

impl::EventThread::ThrottleVsyncCallback Scheduler::makeThrottleVsyncCallback() const {
    if (!mRefreshRateConfigs.supportsFrameRateOverride()) {
        return {};
    }

    return [this](nsecs_t expectedVsyncTimestamp, uid_t uid) {
        return !isVsyncValid(expectedVsyncTimestamp, uid);
    };
}

Scheduler::ConnectionHandle Scheduler::createConnection(
        const char* connectionName, frametimeline::TokenManager* tokenManager,
        std::chrono::nanoseconds workDuration, std::chrono::nanoseconds readyDuration,
        impl::EventThread::InterceptVSyncsCallback interceptCallback) {
    auto vsyncSource = makePrimaryDispSyncSource(connectionName, workDuration, readyDuration);
    auto throttleVsync = [this](nsecs_t expectedVsyncTimestamp, uid_t uid) {
        return !isVsyncValid(expectedVsyncTimestamp, uid);
    };
    auto throttleVsync = makeThrottleVsyncCallback();
    auto eventThread = std::make_unique<impl::EventThread>(std::move(vsyncSource), tokenManager,
                                                           std::move(interceptCallback),
                                                           std::move(throttleVsync));
@@ -414,9 +426,10 @@ void Scheduler::setDuration(ConnectionHandle handle, std::chrono::nanoseconds wo
    thread->setDuration(workDuration, readyDuration);
}

void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats, nsecs_t now) {
    stats->vsyncTime = mVsyncSchedule.tracker->nextAnticipatedVSyncTimeFrom(now);
    stats->vsyncPeriod = mVsyncSchedule.tracker->currentPeriod();
DisplayStatInfo Scheduler::getDisplayStatInfo(nsecs_t now) {
    const auto vsyncTime = mVsyncSchedule.tracker->nextAnticipatedVSyncTimeFrom(now);
    const auto vsyncPeriod = mVsyncSchedule.tracker->currentPeriod();
    return DisplayStatInfo{.vsyncTime = vsyncTime, .vsyncPeriod = vsyncPeriod};
}

Scheduler::ConnectionHandle Scheduler::enableVSyncInjection(bool enable) {
@@ -744,6 +757,10 @@ void Scheduler::dumpVsync(std::string& s) const {

bool Scheduler::updateFrameRateOverrides(
        scheduler::RefreshRateConfigs::GlobalSignals consideredSignals, Fps displayRefreshRate) {
    if (!mRefreshRateConfigs.supportsFrameRateOverride()) {
        return false;
    }

    if (consideredSignals.touch) {
        std::lock_guard lock(mFrameRateOverridesMutex);
        const bool changed = !mFrameRateOverridesByContent.empty();
+2 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ public:
    void setDuration(ConnectionHandle, std::chrono::nanoseconds workDuration,
                     std::chrono::nanoseconds readyDuration);

    void getDisplayStatInfo(DisplayStatInfo* stats, nsecs_t now);
    DisplayStatInfo getDisplayStatInfo(nsecs_t now);

    // Returns injector handle if injection has toggled, or an invalid handle otherwise.
    ConnectionHandle enableVSyncInjection(bool enable);
@@ -238,6 +238,7 @@ private:
            EXCLUDES(mFrameRateOverridesMutex);

    std::optional<Fps> getFrameRateOverride(uid_t uid) const EXCLUDES(mFrameRateOverridesMutex);
    impl::EventThread::ThrottleVsyncCallback makeThrottleVsyncCallback() const;

    // Stores EventThread associated with a given VSyncSource, and an initial EventThreadConnection.
    struct Connection {
Loading