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

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

Merge "SurfaceFlinger: Some fixes to DispSync" into qt-r1-dev

parents a834dd6d 45e4e363
Loading
Loading
Loading
Loading
+8 −20
Original line number Original line Diff line number Diff line
@@ -92,7 +92,6 @@ public:
        mPeriod = period;
        mPeriod = period;
        if (!mModelLocked && referenceTimeChanged) {
        if (!mModelLocked && referenceTimeChanged) {
            for (auto& eventListener : mEventListeners) {
            for (auto& eventListener : mEventListeners) {
                eventListener.mHasFired = false;
                eventListener.mLastEventTime =
                eventListener.mLastEventTime =
                        mReferenceTime - mPeriod + mPhase + eventListener.mPhase;
                        mReferenceTime - mPeriod + mPhase + eventListener.mPhase;
            }
            }
@@ -123,13 +122,6 @@ public:


    void unlockModel() {
    void unlockModel() {
        Mutex::Autolock lock(mMutex);
        Mutex::Autolock lock(mMutex);
        if (mModelLocked) {
            for (auto& eventListener : mEventListeners) {
                if (eventListener.mLastEventTime > mReferenceTime) {
                    eventListener.mHasFired = true;
                }
            }
        }
        mModelLocked = false;
        mModelLocked = false;
        ATRACE_INT("DispSync:ModelLocked", mModelLocked);
        ATRACE_INT("DispSync:ModelLocked", mModelLocked);
    }
    }
@@ -259,10 +251,6 @@ public:
            listener.mLastCallbackTime = lastCallbackTime;
            listener.mLastCallbackTime = lastCallbackTime;
        }
        }


        if (!mModelLocked && listener.mLastEventTime > mReferenceTime) {
            listener.mHasFired = true;
        }

        mEventListeners.push_back(listener);
        mEventListeners.push_back(listener);


        mCond.signal();
        mCond.signal();
@@ -305,7 +293,14 @@ public:
                } else if (diff < -mPeriod / 2) {
                } else if (diff < -mPeriod / 2) {
                    diff += mPeriod;
                    diff += mPeriod;
                }
                }

                if (phase < 0 && oldPhase > 0) {
                    diff += mPeriod;
                } else if (phase > 0 && oldPhase < 0) {
                    diff -= mPeriod;
                }
                eventListener.mLastEventTime -= diff;
                eventListener.mLastEventTime -= diff;
                eventListener.mLastCallbackTime -= diff;
                mCond.signal();
                mCond.signal();
                return NO_ERROR;
                return NO_ERROR;
            }
            }
@@ -320,7 +315,6 @@ private:
        nsecs_t mLastEventTime;
        nsecs_t mLastEventTime;
        nsecs_t mLastCallbackTime;
        nsecs_t mLastCallbackTime;
        DispSync::Callback* mCallback;
        DispSync::Callback* mCallback;
        bool mHasFired = false;
    };
    };


    struct CallbackInvocation {
    struct CallbackInvocation {
@@ -368,12 +362,7 @@ private:
                          eventListener.mName);
                          eventListener.mName);
                    continue;
                    continue;
                }
                }
                if (eventListener.mHasFired && !mModelLocked) {

                    eventListener.mLastEventTime = t;
                    ALOGV("[%s] [%s] Skipping event due to already firing", mName,
                          eventListener.mName);
                    continue;
                }
                CallbackInvocation ci;
                CallbackInvocation ci;
                ci.mCallback = eventListener.mCallback;
                ci.mCallback = eventListener.mCallback;
                ci.mEventTime = t;
                ci.mEventTime = t;
@@ -382,7 +371,6 @@ private:
                callbackInvocations.push_back(ci);
                callbackInvocations.push_back(ci);
                eventListener.mLastEventTime = t;
                eventListener.mLastEventTime = t;
                eventListener.mLastCallbackTime = now;
                eventListener.mLastCallbackTime = now;
                eventListener.mHasFired = true;
            }
            }
        }
        }


+12 −10
Original line number Original line Diff line number Diff line
@@ -27,14 +27,16 @@


namespace android {
namespace android {


DispSyncSource::DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync,
DispSyncSource::DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset,
                               nsecs_t offsetThresholdForNextVsync, bool traceVsync,
                               const char* name)
                               const char* name)
      : mName(name),
      : mName(name),
        mTraceVsync(traceVsync),
        mTraceVsync(traceVsync),
        mVsyncOnLabel(base::StringPrintf("VsyncOn-%s", name)),
        mVsyncOnLabel(base::StringPrintf("VsyncOn-%s", name)),
        mVsyncEventLabel(base::StringPrintf("VSYNC-%s", name)),
        mVsyncEventLabel(base::StringPrintf("VSYNC-%s", name)),
        mDispSync(dispSync),
        mDispSync(dispSync),
        mPhaseOffset(phaseOffset) {}
        mPhaseOffset(phaseOffset),
        mOffsetThresholdForNextVsync(offsetThresholdForNextVsync) {}


void DispSyncSource::setVSyncEnabled(bool enable) {
void DispSyncSource::setVSyncEnabled(bool enable) {
    std::lock_guard lock(mVsyncMutex);
    std::lock_guard lock(mVsyncMutex);
@@ -64,15 +66,15 @@ void DispSyncSource::setCallback(VSyncSource::Callback* callback) {


void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) {
void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) {
    std::lock_guard lock(mVsyncMutex);
    std::lock_guard lock(mVsyncMutex);

    const nsecs_t period = mDispSync->getPeriod();
    // Normalize phaseOffset to [0, period)
    // Check if offset should be handled as negative
    auto period = mDispSync->getPeriod();
    if (phaseOffset >= mOffsetThresholdForNextVsync) {
    phaseOffset %= period;
        phaseOffset -= period;
    if (phaseOffset < 0) {
        // If we're here, then phaseOffset is in (-period, 0). After this
        // operation, it will be in (0, period)
        phaseOffset += period;
    }
    }

    // Normalize phaseOffset to [-period, period)
    const int numPeriods = phaseOffset / period;
    phaseOffset -= numPeriods * period;
    mPhaseOffset = phaseOffset;
    mPhaseOffset = phaseOffset;


    // If we're not enabled, we don't need to mess with the listeners
    // If we're not enabled, we don't need to mess with the listeners
+3 −1
Original line number Original line Diff line number Diff line
@@ -25,7 +25,8 @@ namespace android {


class DispSyncSource final : public VSyncSource, private DispSync::Callback {
class DispSyncSource final : public VSyncSource, private DispSync::Callback {
public:
public:
    DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync, const char* name);
    DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, nsecs_t offsetThresholdForNextVsync,
                   bool traceVsync, const char* name);


    ~DispSyncSource() override = default;
    ~DispSyncSource() override = default;


@@ -53,6 +54,7 @@ private:


    std::mutex mVsyncMutex;
    std::mutex mVsyncMutex;
    nsecs_t mPhaseOffset GUARDED_BY(mVsyncMutex);
    nsecs_t mPhaseOffset GUARDED_BY(mVsyncMutex);
    const nsecs_t mOffsetThresholdForNextVsync;
    bool mEnabled GUARDED_BY(mVsyncMutex) = false;
    bool mEnabled GUARDED_BY(mVsyncMutex) = false;
};
};


+7 −4
Original line number Original line Diff line number Diff line
@@ -119,14 +119,15 @@ Scheduler::~Scheduler() {
}
}


sp<Scheduler::ConnectionHandle> Scheduler::createConnection(
sp<Scheduler::ConnectionHandle> Scheduler::createConnection(
        const char* connectionName, int64_t phaseOffsetNs, ResyncCallback resyncCallback,
        const char* connectionName, nsecs_t phaseOffsetNs, nsecs_t offsetThresholdForNextVsync,
        ResyncCallback resyncCallback,
        impl::EventThread::InterceptVSyncsCallback interceptCallback) {
        impl::EventThread::InterceptVSyncsCallback interceptCallback) {
    const int64_t id = sNextId++;
    const int64_t id = sNextId++;
    ALOGV("Creating a connection handle with ID: %" PRId64 "\n", id);
    ALOGV("Creating a connection handle with ID: %" PRId64 "\n", id);


    std::unique_ptr<EventThread> eventThread =
    std::unique_ptr<EventThread> eventThread =
            makeEventThread(connectionName, mPrimaryDispSync.get(), phaseOffsetNs,
            makeEventThread(connectionName, mPrimaryDispSync.get(), phaseOffsetNs,
                            std::move(interceptCallback));
                            offsetThresholdForNextVsync, std::move(interceptCallback));


    auto eventThreadConnection =
    auto eventThreadConnection =
            createConnectionInternal(eventThread.get(), std::move(resyncCallback),
            createConnectionInternal(eventThread.get(), std::move(resyncCallback),
@@ -139,10 +140,12 @@ sp<Scheduler::ConnectionHandle> Scheduler::createConnection(
}
}


std::unique_ptr<EventThread> Scheduler::makeEventThread(
std::unique_ptr<EventThread> Scheduler::makeEventThread(
        const char* connectionName, DispSync* dispSync, int64_t phaseOffsetNs,
        const char* connectionName, DispSync* dispSync, nsecs_t phaseOffsetNs,
        nsecs_t offsetThresholdForNextVsync,
        impl::EventThread::InterceptVSyncsCallback interceptCallback) {
        impl::EventThread::InterceptVSyncsCallback interceptCallback) {
    std::unique_ptr<VSyncSource> eventThreadSource =
    std::unique_ptr<VSyncSource> eventThreadSource =
            std::make_unique<DispSyncSource>(dispSync, phaseOffsetNs, true, connectionName);
            std::make_unique<DispSyncSource>(dispSync, phaseOffsetNs, offsetThresholdForNextVsync,
                                             true, connectionName);
    return std::make_unique<impl::EventThread>(std::move(eventThreadSource),
    return std::make_unique<impl::EventThread>(std::move(eventThreadSource),
                                               std::move(interceptCallback), connectionName);
                                               std::move(interceptCallback), connectionName);
}
}
+4 −3
Original line number Original line Diff line number Diff line
@@ -96,8 +96,8 @@ public:
    virtual ~Scheduler();
    virtual ~Scheduler();


    /** Creates an EventThread connection. */
    /** Creates an EventThread connection. */
    sp<ConnectionHandle> createConnection(const char* connectionName, int64_t phaseOffsetNs,
    sp<ConnectionHandle> createConnection(const char* connectionName, nsecs_t phaseOffsetNs,
                                          ResyncCallback,
                                          nsecs_t offsetThresholdForNextVsync, ResyncCallback,
                                          impl::EventThread::InterceptVSyncsCallback);
                                          impl::EventThread::InterceptVSyncsCallback);


    sp<IDisplayEventConnection> createDisplayEventConnection(
    sp<IDisplayEventConnection> createDisplayEventConnection(
@@ -185,7 +185,8 @@ public:


protected:
protected:
    virtual std::unique_ptr<EventThread> makeEventThread(
    virtual std::unique_ptr<EventThread> makeEventThread(
            const char* connectionName, DispSync* dispSync, int64_t phaseOffsetNs,
            const char* connectionName, DispSync* dispSync, nsecs_t phaseOffsetNs,
            nsecs_t offsetThresholdForNextVsync,
            impl::EventThread::InterceptVSyncsCallback interceptCallback);
            impl::EventThread::InterceptVSyncsCallback interceptCallback);


private:
private:
Loading