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

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

Merge "SurfaceFlinger: remove old DispSync implementation"

parents 7ba5971e 49cb7d58
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -160,7 +160,6 @@ filegroup {
        "RefreshRateOverlay.cpp",
        "RegionSamplingThread.cpp",
        "RenderArea.cpp",
        "Scheduler/DispSync.cpp",
        "Scheduler/DispSyncSource.cpp",
        "Scheduler/EventThread.cpp",
        "Scheduler/OneShotTimer.cpp",
+0 −877

File deleted.

Preview size limit exceeded, changes collapsed.

+2 −197
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ public:
    class Callback {
    public:
        Callback() = default;
        virtual ~Callback();
        virtual ~Callback() = default;
        virtual void onDispSyncEvent(nsecs_t when, nsecs_t expectedVSyncTimestamp) = 0;

    protected:
@@ -44,7 +44,7 @@ public:
    };

    DispSync() = default;
    virtual ~DispSync();
    virtual ~DispSync() = default;

    virtual void reset() = 0;
    virtual bool addPresentFence(const std::shared_ptr<FenceTime>&) = 0;
@@ -69,199 +69,4 @@ protected:
    DispSync& operator=(DispSync const&) = delete;
};

namespace impl {

class DispSyncThread;

// DispSync maintains a model of the periodic hardware-based vsync events of a
// display and uses that model to execute period callbacks at specific phase
// offsets from the hardware vsync events.  The model is constructed by
// feeding consecutive hardware event timestamps to the DispSync object via
// the addResyncSample method.
//
// The model is validated using timestamps from Fence objects that are passed
// to the DispSync object via the addPresentFence method.  These fence
// timestamps should correspond to a hardware vsync event, but they need not
// be consecutive hardware vsync times.  If this method determines that the
// current model accurately represents the hardware event times it will return
// false to indicate that a resynchronization (via addResyncSample) is not
// needed.
class DispSync : public android::DispSync {
public:
    // hasSyncFramework specifies whether the platform supports present fences.
    DispSync(const char* name, bool hasSyncFramework);
    ~DispSync() override;

    // reset clears the resync samples and error value.
    void reset() override;

    // addPresentFence adds a fence for use in validating the current vsync
    // event model.  The fence need not be signaled at the time
    // addPresentFence is called.  When the fence does signal, its timestamp
    // should correspond to a hardware vsync event.  Unlike the
    // addResyncSample method, the timestamps of consecutive fences need not
    // correspond to consecutive hardware vsync events.
    //
    // This method should be called with the retire fence from each HWComposer
    // set call that affects the display.
    bool addPresentFence(const std::shared_ptr<FenceTime>& fenceTime) override;

    // The beginResync, addResyncSample, and endResync methods are used to re-
    // synchronize the DispSync's model to the hardware vsync events.  The re-
    // synchronization process involves first calling beginResync, then
    // calling addResyncSample with a sequence of consecutive hardware vsync
    // event timestamps, and finally calling endResync when addResyncSample
    // indicates that no more samples are needed by returning false.
    //
    // This resynchronization process should be performed whenever the display
    // is turned on (i.e. once immediately after it's turned on) and whenever
    // addPresentFence returns true indicating that the model has drifted away
    // from the hardware vsync events.
    void beginResync() override;
    // Adds a vsync sample to the dispsync model. The timestamp is the time
    // of the vsync event that fired. periodFlushed will return true if the
    // vsync period was detected to have changed to mPendingPeriod.
    //
    // This method will return true if more vsync samples are needed to lock
    // down the DispSync model, and false otherwise.
    // periodFlushed will be set to true if mPendingPeriod is flushed to
    // mIntendedPeriod, and false otherwise.
    bool addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod,
                         bool* periodFlushed) override;
    void endResync() override;

    // The setPeriod method sets the vsync event model's period to a specific
    // value. This should be used to prime the model when a display is first
    // turned on, or when a refresh rate change is requested.
    void setPeriod(nsecs_t period) override;

    // The getPeriod method returns the current vsync period.
    nsecs_t getPeriod() override;

    // addEventListener registers a callback to be called repeatedly at the
    // given phase offset from the hardware vsync events.  The callback is
    // called from a separate thread and it should return reasonably quickly
    // (i.e. within a few hundred microseconds).
    // If the callback was previously registered, and the last clock time the
    // callback was invoked was known to the caller (e.g. via removeEventListener),
    // then the caller may pass that through to lastCallbackTime, so that
    // callbacks do not accidentally double-fire if they are unregistered and
    // reregistered in rapid succession.
    status_t addEventListener(const char* name, nsecs_t phase, Callback* callback,
                              nsecs_t lastCallbackTime) override;

    // removeEventListener removes an already-registered event callback.  Once
    // this method returns that callback will no longer be called by the
    // DispSync object.
    // outLastCallbackTime will contain the last time that the callback was invoked.
    // If the caller wishes to reregister the same callback, they should pass the
    // callback time back into lastCallbackTime (see addEventListener).
    status_t removeEventListener(Callback* callback, nsecs_t* outLastCallbackTime) override;

    // changePhaseOffset changes the phase offset of an already-registered event callback. The
    // method will make sure that there is no skipping or double-firing on the listener per frame,
    // even when changing the offsets multiple times.
    status_t changePhaseOffset(Callback* callback, nsecs_t phase) override;

    // computeNextRefresh computes when the next refresh is expected to begin.
    // The periodOffset value can be used to move forward or backward; an
    // offset of zero is the next refresh, -1 is the previous refresh, 1 is
    // the refresh after next. etc.
    nsecs_t computeNextRefresh(int periodOffset, nsecs_t now) const override;

    // In certain situations the present fences aren't a good indicator of vsync
    // time, e.g. when vr flinger is active, or simply aren't available,
    // e.g. when the sync framework isn't present. Use this method to toggle
    // whether or not DispSync ignores present fences. If present fences are
    // ignored, DispSync will always ask for hardware vsync events by returning
    // true from addPresentFence() and addResyncSample().
    void setIgnorePresentFences(bool ignore) override;

    // Determine the expected present time when a buffer acquired now will be displayed.
    nsecs_t expectedPresentTime(nsecs_t now);

    // dump appends human-readable debug info to the result string.
    void dump(std::string& result) const override;

private:
    void updateModelLocked();
    void updateErrorLocked();
    void resetLocked();
    void resetErrorLocked();

    enum { MAX_RESYNC_SAMPLES = 32 };
    enum { MIN_RESYNC_SAMPLES_FOR_UPDATE = 6 };
    enum { NUM_PRESENT_SAMPLES = 8 };
    enum { MAX_RESYNC_SAMPLES_WITHOUT_PRESENT = 4 };
    enum { ACCEPTABLE_ZERO_ERR_SAMPLES_COUNT = 64 };

    const char* const mName;

    // mPeriod is the computed period of the modeled vsync events in
    // nanoseconds.
    nsecs_t mPeriod;

    // mIntendedPeriod is the intended period of the modeled vsync events in
    // nanoseconds. Under ideal conditions this should be similar if not the
    // same as mPeriod, plus or minus an observed error.
    nsecs_t mIntendedPeriod = 0;

    // mPendingPeriod is the proposed period change in nanoseconds.
    // If mPendingPeriod differs from mPeriod and is nonzero, it will
    // be flushed to mPeriod when we detect that the hardware switched
    // vsync frequency.
    nsecs_t mPendingPeriod = 0;

    // mPhase is the phase offset of the modeled vsync events.  It is the
    // number of nanoseconds from time 0 to the first vsync event.
    nsecs_t mPhase;

    // mReferenceTime is the reference time of the modeled vsync events.
    // It is the nanosecond timestamp of the first vsync event after a resync.
    nsecs_t mReferenceTime;

    // mError is the computed model error.  It is based on the difference
    // between the estimated vsync event times and those observed in the
    // mPresentFences array.
    nsecs_t mError;

    // mZeroErrSamplesCount keeps track of how many times in a row there were
    // zero timestamps available in the mPresentFences array.
    // Used to check that we are able to calculate the model error.
    size_t mZeroErrSamplesCount;

    // Whether we have updated the vsync event model since the last resync.
    bool mModelUpdated;

    // These member variables are the state used during the resynchronization
    // process to store information about the hardware vsync event times used
    // to compute the model.
    nsecs_t mResyncSamples[MAX_RESYNC_SAMPLES] = {0};
    size_t mFirstResyncSample = 0;
    size_t mNumResyncSamples = 0;
    int mNumResyncSamplesSincePresent;

    // These member variables store information about the present fences used
    // to validate the currently computed model.
    std::shared_ptr<FenceTime> mPresentFences[NUM_PRESENT_SAMPLES]{FenceTime::NO_FENCE};
    size_t mPresentSampleOffset;

    // mThread is the thread from which all the callbacks are called.
    sp<DispSyncThread> mThread;

    // mMutex is used to protect access to all member variables.
    mutable Mutex mMutex;

    // Ignore present (retire) fences if the device doesn't have support for the
    // sync framework
    bool mIgnorePresentFences;

    std::unique_ptr<Callback> mZeroPhaseTracer;

    // Flag to turn on logging in systrace.
    bool mTraceDetailedInfo = false;
};

} // namespace impl

} // namespace android
+1 −9
Original line number Diff line number Diff line
@@ -100,9 +100,7 @@ Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCal
                  {.supportKernelTimer = sysprop::support_kernel_idle_timer(false),
                   .useContentDetection = sysprop::use_content_detection_for_refresh_rate(false),
                   .useContentDetectionV2 =
                           base::GetBoolProperty("debug.sf.use_content_detection_v2"s, true),
                   // TODO(b/140302863): Remove this and use the vsync_reactor system.
                   .useVsyncPredictor = base::GetBoolProperty("debug.sf.vsync_reactor"s, true)}) {}
                           base::GetBoolProperty("debug.sf.use_content_detection_v2"s, true)}) {}

Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCallback& callback,
                     Options options)
@@ -159,12 +157,6 @@ Scheduler::~Scheduler() {
}

Scheduler::VsyncSchedule Scheduler::createVsyncSchedule(Options options) {
    if (!options.useVsyncPredictor) {
        auto sync = std::make_unique<impl::DispSync>("SchedulerDispSync",
                                                     sysprop::running_without_sync_framework(true));
        return {std::move(sync), nullptr, nullptr};
    }

    auto clock = std::make_unique<scheduler::SystemClock>();
    auto tracker = createVSyncTracker();
    auto dispatch = createVSyncDispatch(*tracker);
+0 −2
Original line number Diff line number Diff line
@@ -167,8 +167,6 @@ private:
        bool useContentDetection;
        // Whether to use improved content detection.
        bool useContentDetectionV2;
        // Whether to use improved DispSync implementation.
        bool useVsyncPredictor;
    };

    struct VsyncSchedule {
Loading