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

Commit 933f8ded authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Extract VsyncConfig to its own header

...such that VsyncConfiguration does not depend on VsyncModulator.

Bug: 241285475
Bug: 241285191
Test: Build
Change-Id: I05b66a4ed2e6721b10ae90bdc6af2e49c22f2a59
parent f44c51c0
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -196,7 +196,7 @@ Layer::Layer(const LayerCreationArgs& args)
        mDrawingState.color.b = -1.0_hf;
        mDrawingState.color.b = -1.0_hf;
    }
    }


    mFrameTracker.setDisplayRefreshPeriod(args.flinger->mScheduler->getLeaderVsyncPeriod());
    mFrameTracker.setDisplayRefreshPeriod(args.flinger->mScheduler->getLeaderVsyncPeriod().ns());


    mOwnerUid = args.ownerUid;
    mOwnerUid = args.ownerUid;
    mOwnerPid = args.ownerPid;
    mOwnerPid = args.ownerPid;
+2 −2
Original line number Original line Diff line number Diff line
@@ -239,8 +239,8 @@ public:
    // Retrieves the overridden refresh rate for a given uid.
    // Retrieves the overridden refresh rate for a given uid.
    std::optional<Fps> getFrameRateOverride(uid_t) const EXCLUDES(mDisplayLock);
    std::optional<Fps> getFrameRateOverride(uid_t) const EXCLUDES(mDisplayLock);


    nsecs_t getLeaderVsyncPeriod() const EXCLUDES(mDisplayLock) {
    Period getLeaderVsyncPeriod() const EXCLUDES(mDisplayLock) {
        return leaderSelectorPtr()->getActiveMode().fps.getPeriodNsecs();
        return leaderSelectorPtr()->getActiveMode().fps.getPeriod();
    }
    }


    // Returns the framerate of the layer with the given sequence ID
    // Returns the framerate of the layer with the given sequence ID
+6 −6
Original line number Original line Diff line number Diff line
@@ -42,12 +42,12 @@ namespace android::scheduler::impl {


VsyncConfiguration::VsyncConfiguration(Fps currentFps) : mRefreshRateFps(currentFps) {}
VsyncConfiguration::VsyncConfiguration(Fps currentFps) : mRefreshRateFps(currentFps) {}


PhaseOffsets::VsyncConfigSet VsyncConfiguration::getConfigsForRefreshRate(Fps fps) const {
VsyncConfigSet VsyncConfiguration::getConfigsForRefreshRate(Fps fps) const {
    std::lock_guard lock(mLock);
    std::lock_guard lock(mLock);
    return getConfigsForRefreshRateLocked(fps);
    return getConfigsForRefreshRateLocked(fps);
}
}


PhaseOffsets::VsyncConfigSet VsyncConfiguration::getConfigsForRefreshRateLocked(Fps fps) const {
VsyncConfigSet VsyncConfiguration::getConfigsForRefreshRateLocked(Fps fps) const {
    if (const auto offsets = mOffsetsCache.get(fps)) {
    if (const auto offsets = mOffsetsCache.get(fps)) {
        return offsets->get();
        return offsets->get();
    }
    }
@@ -134,7 +134,7 @@ PhaseOffsets::PhaseOffsets(Fps currentFps, nsecs_t vsyncPhaseOffsetNs, nsecs_t s
        mThresholdForNextVsync(thresholdForNextVsync),
        mThresholdForNextVsync(thresholdForNextVsync),
        mHwcMinWorkDuration(hwcMinWorkDuration) {}
        mHwcMinWorkDuration(hwcMinWorkDuration) {}


PhaseOffsets::VsyncConfigSet PhaseOffsets::constructOffsets(nsecs_t vsyncDuration) const {
VsyncConfigSet PhaseOffsets::constructOffsets(nsecs_t vsyncDuration) const {
    if (vsyncDuration < std::chrono::nanoseconds(15ms).count()) {
    if (vsyncDuration < std::chrono::nanoseconds(15ms).count()) {
        return getHighFpsOffsets(vsyncDuration);
        return getHighFpsOffsets(vsyncDuration);
    } else {
    } else {
@@ -158,7 +158,7 @@ std::chrono::nanoseconds appOffsetToDuration(nsecs_t appOffset, nsecs_t sfOffset
}
}
} // namespace
} // namespace


PhaseOffsets::VsyncConfigSet PhaseOffsets::getDefaultOffsets(nsecs_t vsyncDuration) const {
VsyncConfigSet PhaseOffsets::getDefaultOffsets(nsecs_t vsyncDuration) const {
    const auto earlySfOffset =
    const auto earlySfOffset =
            mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) < mThresholdForNextVsync
            mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) < mThresholdForNextVsync


@@ -196,7 +196,7 @@ PhaseOffsets::VsyncConfigSet PhaseOffsets::getDefaultOffsets(nsecs_t vsyncDurati
    };
    };
}
}


PhaseOffsets::VsyncConfigSet PhaseOffsets::getHighFpsOffsets(nsecs_t vsyncDuration) const {
VsyncConfigSet PhaseOffsets::getHighFpsOffsets(nsecs_t vsyncDuration) const {
    const auto earlySfOffset =
    const auto earlySfOffset =
            mHighFpsEarlySfOffsetNs.value_or(mHighFpsSfVSyncPhaseOffsetNs) < mThresholdForNextVsync
            mHighFpsEarlySfOffsetNs.value_or(mHighFpsSfVSyncPhaseOffsetNs) < mThresholdForNextVsync
            ? mHighFpsEarlySfOffsetNs.value_or(mHighFpsSfVSyncPhaseOffsetNs)
            ? mHighFpsEarlySfOffsetNs.value_or(mHighFpsSfVSyncPhaseOffsetNs)
@@ -286,7 +286,7 @@ nsecs_t appDurationToOffset(std::chrono::nanoseconds appDuration,
}
}
} // namespace
} // namespace


WorkDuration::VsyncConfigSet WorkDuration::constructOffsets(nsecs_t vsyncDuration) const {
VsyncConfigSet WorkDuration::constructOffsets(nsecs_t vsyncDuration) const {
    const auto sfDurationFixup = [vsyncDuration](nsecs_t duration) {
    const auto sfDurationFixup = [vsyncDuration](nsecs_t duration) {
        return duration == -1 ? std::chrono::nanoseconds(vsyncDuration) - 1ms
        return duration == -1 ? std::chrono::nanoseconds(vsyncDuration) - 1ms
                              : std::chrono::nanoseconds(duration);
                              : std::chrono::nanoseconds(duration);
+5 −7
Original line number Original line Diff line number Diff line
@@ -20,12 +20,12 @@
#include <optional>
#include <optional>
#include <string>
#include <string>


#include <android-base/thread_annotations.h>
#include <ftl/small_map.h>
#include <ftl/small_map.h>
#include <utils/Timers.h>
#include <utils/Timers.h>


#include <scheduler/Fps.h>
#include <scheduler/Fps.h>

#include <scheduler/VsyncConfig.h>
#include "VsyncModulator.h"


namespace android::scheduler {
namespace android::scheduler {


@@ -37,8 +37,6 @@ namespace android::scheduler {
 */
 */
class VsyncConfiguration {
class VsyncConfiguration {
public:
public:
    using VsyncConfigSet = VsyncModulator::VsyncConfigSet;

    virtual ~VsyncConfiguration() = default;
    virtual ~VsyncConfiguration() = default;
    virtual VsyncConfigSet getCurrentConfigs() const = 0;
    virtual VsyncConfigSet getCurrentConfigs() const = 0;
    virtual VsyncConfigSet getConfigsForRefreshRate(Fps fps) const = 0;
    virtual VsyncConfigSet getConfigsForRefreshRate(Fps fps) const = 0;
@@ -85,7 +83,7 @@ public:
    void dump(std::string& result) const override;
    void dump(std::string& result) const override;


protected:
protected:
    virtual VsyncConfiguration::VsyncConfigSet constructOffsets(nsecs_t vsyncDuration) const = 0;
    virtual VsyncConfigSet constructOffsets(nsecs_t vsyncDuration) const = 0;


    VsyncConfigSet getConfigsForRefreshRateLocked(Fps fps) const REQUIRES(mLock);
    VsyncConfigSet getConfigsForRefreshRateLocked(Fps fps) const REQUIRES(mLock);


@@ -115,7 +113,7 @@ protected:
                 nsecs_t hwcMinWorkDuration);
                 nsecs_t hwcMinWorkDuration);


private:
private:
    VsyncConfiguration::VsyncConfigSet constructOffsets(nsecs_t vsyncDuration) const override;
    VsyncConfigSet constructOffsets(nsecs_t vsyncDuration) const override;


    VsyncConfigSet getDefaultOffsets(nsecs_t vsyncPeriod) const;
    VsyncConfigSet getDefaultOffsets(nsecs_t vsyncPeriod) const;
    VsyncConfigSet getHighFpsOffsets(nsecs_t vsyncPeriod) const;
    VsyncConfigSet getHighFpsOffsets(nsecs_t vsyncPeriod) const;
@@ -154,7 +152,7 @@ protected:
                 nsecs_t hwcMinWorkDuration);
                 nsecs_t hwcMinWorkDuration);


private:
private:
    VsyncConfiguration::VsyncConfigSet constructOffsets(nsecs_t vsyncDuration) const override;
    VsyncConfigSet constructOffsets(nsecs_t vsyncDuration) const override;


    const nsecs_t mSfDuration;
    const nsecs_t mSfDuration;
    const nsecs_t mAppDuration;
    const nsecs_t mAppDuration;
+5 −5
Original line number Original line Diff line number Diff line
@@ -40,7 +40,7 @@ VsyncModulator::VsyncModulator(const VsyncConfigSet& config, Now now)
        mNow(now),
        mNow(now),
        mTraceDetailedInfo(base::GetBoolProperty("debug.sf.vsync_trace_detailed_info", false)) {}
        mTraceDetailedInfo(base::GetBoolProperty("debug.sf.vsync_trace_detailed_info", false)) {}


VsyncModulator::VsyncConfig VsyncModulator::setVsyncConfigSet(const VsyncConfigSet& config) {
VsyncConfig VsyncModulator::setVsyncConfigSet(const VsyncConfigSet& config) {
    std::lock_guard<std::mutex> lock(mMutex);
    std::lock_guard<std::mutex> lock(mMutex);
    mVsyncConfigSet = config;
    mVsyncConfigSet = config;
    return updateVsyncConfigLocked();
    return updateVsyncConfigLocked();
@@ -129,7 +129,7 @@ VsyncModulator::VsyncConfigOpt VsyncModulator::onDisplayRefresh(bool usedGpuComp
    return updateVsyncConfig();
    return updateVsyncConfig();
}
}


VsyncModulator::VsyncConfig VsyncModulator::getVsyncConfig() const {
VsyncConfig VsyncModulator::getVsyncConfig() const {
    std::lock_guard<std::mutex> lock(mMutex);
    std::lock_guard<std::mutex> lock(mMutex);
    return mVsyncConfig;
    return mVsyncConfig;
}
}
@@ -147,7 +147,7 @@ auto VsyncModulator::getNextVsyncConfigType() const -> VsyncConfigType {
    }
    }
}
}


const VsyncModulator::VsyncConfig& VsyncModulator::getNextVsyncConfig() const {
const VsyncConfig& VsyncModulator::getNextVsyncConfig() const {
    switch (getNextVsyncConfigType()) {
    switch (getNextVsyncConfigType()) {
        case VsyncConfigType::Early:
        case VsyncConfigType::Early:
            return mVsyncConfigSet.early;
            return mVsyncConfigSet.early;
@@ -158,12 +158,12 @@ const VsyncModulator::VsyncConfig& VsyncModulator::getNextVsyncConfig() const {
    }
    }
}
}


VsyncModulator::VsyncConfig VsyncModulator::updateVsyncConfig() {
VsyncConfig VsyncModulator::updateVsyncConfig() {
    std::lock_guard<std::mutex> lock(mMutex);
    std::lock_guard<std::mutex> lock(mMutex);
    return updateVsyncConfigLocked();
    return updateVsyncConfigLocked();
}
}


VsyncModulator::VsyncConfig VsyncModulator::updateVsyncConfigLocked() {
VsyncConfig VsyncModulator::updateVsyncConfigLocked() {
    const VsyncConfig& offsets = getNextVsyncConfig();
    const VsyncConfig& offsets = getNextVsyncConfig();
    mVsyncConfig = offsets;
    mVsyncConfig = offsets;


Loading