Loading services/surfaceflinger/EventControlThread.h +0 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ namespace android { class SurfaceFlinger; class EventControlThread { public: virtual ~EventControlThread(); Loading services/surfaceflinger/EventThread.cpp +10 −8 Original line number Diff line number Diff line Loading @@ -26,14 +26,12 @@ #include <cutils/sched_policy.h> #include <gui/DisplayEventReceiver.h> #include <gui/IDisplayEventConnection.h> #include <utils/Errors.h> #include <utils/String8.h> #include <utils/Trace.h> #include "EventThread.h" #include "SurfaceFlinger.h" using namespace std::chrono_literals; Loading @@ -47,9 +45,11 @@ EventThread::~EventThread() = default; namespace impl { EventThread::EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs, const char* threadName) : mVSyncSource(src), mFlinger(flinger), mInterceptVSyncs(interceptVSyncs) { EventThread::EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback, InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName) : mVSyncSource(src), mResyncWithRateLimitCallback(resyncWithRateLimitCallback), mInterceptVSyncsCallback(interceptVSyncsCallback) { for (auto& event : mVSyncEvent) { event.header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC; event.header.id = 0; Loading Loading @@ -118,7 +118,9 @@ void EventThread::setVsyncRate(uint32_t count, const sp<EventThread::Connection> void EventThread::requestNextVsync(const sp<EventThread::Connection>& connection) { std::lock_guard<std::mutex> lock(mMutex); mFlinger.resyncWithRateLimit(); if (mResyncWithRateLimitCallback) { mResyncWithRateLimitCallback(); } if (connection->count < 0) { connection->count = 0; Loading Loading @@ -216,8 +218,8 @@ Vector<sp<EventThread::Connection> > EventThread::waitForEventLocked( timestamp = mVSyncEvent[i].header.timestamp; if (timestamp) { // we have a vsync event to dispatch if (mInterceptVSyncs) { mFlinger.mInterceptor->saveVSyncEvent(timestamp); if (mInterceptVSyncsCallback) { mInterceptVSyncsCallback(timestamp); } *event = mVSyncEvent[i]; mVSyncEvent[i].header.timestamp = 0; Loading services/surfaceflinger/EventThread.h +14 −8 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ namespace android { // --------------------------------------------------------------------------- class EventThreadTest; class SurfaceFlinger; class String8; Loading Loading @@ -82,7 +83,9 @@ class EventThread : public android::EventThread, private VSyncSource::Callback { class Connection : public BnDisplayEventConnection { public: explicit Connection(EventThread* eventThread); status_t postEvent(const DisplayEventReceiver::Event& event); virtual ~Connection(); virtual status_t postEvent(const DisplayEventReceiver::Event& event); // count >= 1 : continuous event. count is the vsync rate // count == 0 : one-shot event that has not fired Loading @@ -90,7 +93,6 @@ class EventThread : public android::EventThread, private VSyncSource::Callback { int32_t count; private: virtual ~Connection(); virtual void onFirstRef(); status_t stealReceiveChannel(gui::BitTube* outChannel) override; status_t setVsyncRate(uint32_t count) override; Loading @@ -100,8 +102,11 @@ class EventThread : public android::EventThread, private VSyncSource::Callback { }; public: EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs, const char* threadName); using ResyncWithRateLimitCallback = std::function<void()>; using InterceptVSyncsCallback = std::function<void(nsecs_t)>; EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback, InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName); ~EventThread(); sp<BnDisplayEventConnection> createEventConnection() const override; Loading @@ -124,6 +129,8 @@ public: void setPhaseOffset(nsecs_t phaseOffset) override; private: friend EventThreadTest; void threadMain(); Vector<sp<EventThread::Connection>> waitForEventLocked(std::unique_lock<std::mutex>* lock, DisplayEventReceiver::Event* event) Loading @@ -137,8 +144,9 @@ private: void onVSyncEvent(nsecs_t timestamp) override; // constants VSyncSource* mVSyncSource GUARDED_BY(mMutex) = nullptr; SurfaceFlinger& mFlinger; VSyncSource* const mVSyncSource GUARDED_BY(mMutex) = nullptr; const ResyncWithRateLimitCallback mResyncWithRateLimitCallback; const InterceptVSyncsCallback mInterceptVSyncsCallback; std::thread mThread; mutable std::mutex mMutex; Loading @@ -155,8 +163,6 @@ private: // for debugging bool mDebugVsyncEnabled GUARDED_BY(mMutex) = false; const bool mInterceptVSyncs = false; }; // --------------------------------------------------------------------------- Loading services/surfaceflinger/SurfaceFlinger.cpp +15 −6 Original line number Diff line number Diff line Loading @@ -638,13 +638,20 @@ void SurfaceFlinger::init() { mEventThreadSource = std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::vsyncPhaseOffsetNs, true, "app"); mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(), *this, false, mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(), [this]() { resyncWithRateLimit(); }, impl::EventThread::InterceptVSyncsCallback(), "appEventThread"); mSfEventThreadSource = std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::sfVsyncPhaseOffsetNs, true, "sf"); mSFEventThread = std::make_unique<impl::EventThread>(mSfEventThreadSource.get(), *this, true, mSFEventThread = std::make_unique<impl::EventThread>(mSfEventThreadSource.get(), [this]() { resyncWithRateLimit(); }, [this](nsecs_t timestamp) { mInterceptor->saveVSyncEvent(timestamp); }, "sfEventThread"); mEventQueue->setEventThread(mSFEventThread.get()); mVsyncModulator.setEventThread(mSFEventThread.get()); Loading Loading @@ -1132,8 +1139,10 @@ status_t SurfaceFlinger::enableVSyncInjections(bool enable) { ALOGV("VSync Injections enabled"); if (mVSyncInjector.get() == nullptr) { mVSyncInjector = std::make_unique<InjectVSyncSource>(); mInjectorEventThread = std::make_unique<impl::EventThread>(mVSyncInjector.get(), *this, false, mInjectorEventThread = std::make_unique< impl::EventThread>(mVSyncInjector.get(), [this]() { resyncWithRateLimit(); }, impl::EventThread::InterceptVSyncsCallback(), "injEventThread"); } mEventQueue->setEventThread(mInjectorEventThread.get()); Loading services/surfaceflinger/tests/unittests/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ cc_test { ":libsurfaceflinger_sources", "DisplayIdentificationTest.cpp", "DisplayTransactionTest.cpp", "EventControlThreadTest.cpp", "EventThreadTest.cpp", "mock/DisplayHardware/MockComposer.cpp", "mock/DisplayHardware/MockDisplaySurface.cpp", "mock/gui/MockGraphicBufferConsumer.cpp", Loading Loading
services/surfaceflinger/EventControlThread.h +0 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ namespace android { class SurfaceFlinger; class EventControlThread { public: virtual ~EventControlThread(); Loading
services/surfaceflinger/EventThread.cpp +10 −8 Original line number Diff line number Diff line Loading @@ -26,14 +26,12 @@ #include <cutils/sched_policy.h> #include <gui/DisplayEventReceiver.h> #include <gui/IDisplayEventConnection.h> #include <utils/Errors.h> #include <utils/String8.h> #include <utils/Trace.h> #include "EventThread.h" #include "SurfaceFlinger.h" using namespace std::chrono_literals; Loading @@ -47,9 +45,11 @@ EventThread::~EventThread() = default; namespace impl { EventThread::EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs, const char* threadName) : mVSyncSource(src), mFlinger(flinger), mInterceptVSyncs(interceptVSyncs) { EventThread::EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback, InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName) : mVSyncSource(src), mResyncWithRateLimitCallback(resyncWithRateLimitCallback), mInterceptVSyncsCallback(interceptVSyncsCallback) { for (auto& event : mVSyncEvent) { event.header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC; event.header.id = 0; Loading Loading @@ -118,7 +118,9 @@ void EventThread::setVsyncRate(uint32_t count, const sp<EventThread::Connection> void EventThread::requestNextVsync(const sp<EventThread::Connection>& connection) { std::lock_guard<std::mutex> lock(mMutex); mFlinger.resyncWithRateLimit(); if (mResyncWithRateLimitCallback) { mResyncWithRateLimitCallback(); } if (connection->count < 0) { connection->count = 0; Loading Loading @@ -216,8 +218,8 @@ Vector<sp<EventThread::Connection> > EventThread::waitForEventLocked( timestamp = mVSyncEvent[i].header.timestamp; if (timestamp) { // we have a vsync event to dispatch if (mInterceptVSyncs) { mFlinger.mInterceptor->saveVSyncEvent(timestamp); if (mInterceptVSyncsCallback) { mInterceptVSyncsCallback(timestamp); } *event = mVSyncEvent[i]; mVSyncEvent[i].header.timestamp = 0; Loading
services/surfaceflinger/EventThread.h +14 −8 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ namespace android { // --------------------------------------------------------------------------- class EventThreadTest; class SurfaceFlinger; class String8; Loading Loading @@ -82,7 +83,9 @@ class EventThread : public android::EventThread, private VSyncSource::Callback { class Connection : public BnDisplayEventConnection { public: explicit Connection(EventThread* eventThread); status_t postEvent(const DisplayEventReceiver::Event& event); virtual ~Connection(); virtual status_t postEvent(const DisplayEventReceiver::Event& event); // count >= 1 : continuous event. count is the vsync rate // count == 0 : one-shot event that has not fired Loading @@ -90,7 +93,6 @@ class EventThread : public android::EventThread, private VSyncSource::Callback { int32_t count; private: virtual ~Connection(); virtual void onFirstRef(); status_t stealReceiveChannel(gui::BitTube* outChannel) override; status_t setVsyncRate(uint32_t count) override; Loading @@ -100,8 +102,11 @@ class EventThread : public android::EventThread, private VSyncSource::Callback { }; public: EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs, const char* threadName); using ResyncWithRateLimitCallback = std::function<void()>; using InterceptVSyncsCallback = std::function<void(nsecs_t)>; EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback, InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName); ~EventThread(); sp<BnDisplayEventConnection> createEventConnection() const override; Loading @@ -124,6 +129,8 @@ public: void setPhaseOffset(nsecs_t phaseOffset) override; private: friend EventThreadTest; void threadMain(); Vector<sp<EventThread::Connection>> waitForEventLocked(std::unique_lock<std::mutex>* lock, DisplayEventReceiver::Event* event) Loading @@ -137,8 +144,9 @@ private: void onVSyncEvent(nsecs_t timestamp) override; // constants VSyncSource* mVSyncSource GUARDED_BY(mMutex) = nullptr; SurfaceFlinger& mFlinger; VSyncSource* const mVSyncSource GUARDED_BY(mMutex) = nullptr; const ResyncWithRateLimitCallback mResyncWithRateLimitCallback; const InterceptVSyncsCallback mInterceptVSyncsCallback; std::thread mThread; mutable std::mutex mMutex; Loading @@ -155,8 +163,6 @@ private: // for debugging bool mDebugVsyncEnabled GUARDED_BY(mMutex) = false; const bool mInterceptVSyncs = false; }; // --------------------------------------------------------------------------- Loading
services/surfaceflinger/SurfaceFlinger.cpp +15 −6 Original line number Diff line number Diff line Loading @@ -638,13 +638,20 @@ void SurfaceFlinger::init() { mEventThreadSource = std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::vsyncPhaseOffsetNs, true, "app"); mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(), *this, false, mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(), [this]() { resyncWithRateLimit(); }, impl::EventThread::InterceptVSyncsCallback(), "appEventThread"); mSfEventThreadSource = std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::sfVsyncPhaseOffsetNs, true, "sf"); mSFEventThread = std::make_unique<impl::EventThread>(mSfEventThreadSource.get(), *this, true, mSFEventThread = std::make_unique<impl::EventThread>(mSfEventThreadSource.get(), [this]() { resyncWithRateLimit(); }, [this](nsecs_t timestamp) { mInterceptor->saveVSyncEvent(timestamp); }, "sfEventThread"); mEventQueue->setEventThread(mSFEventThread.get()); mVsyncModulator.setEventThread(mSFEventThread.get()); Loading Loading @@ -1132,8 +1139,10 @@ status_t SurfaceFlinger::enableVSyncInjections(bool enable) { ALOGV("VSync Injections enabled"); if (mVSyncInjector.get() == nullptr) { mVSyncInjector = std::make_unique<InjectVSyncSource>(); mInjectorEventThread = std::make_unique<impl::EventThread>(mVSyncInjector.get(), *this, false, mInjectorEventThread = std::make_unique< impl::EventThread>(mVSyncInjector.get(), [this]() { resyncWithRateLimit(); }, impl::EventThread::InterceptVSyncsCallback(), "injEventThread"); } mEventQueue->setEventThread(mInjectorEventThread.get()); Loading
services/surfaceflinger/tests/unittests/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ cc_test { ":libsurfaceflinger_sources", "DisplayIdentificationTest.cpp", "DisplayTransactionTest.cpp", "EventControlThreadTest.cpp", "EventThreadTest.cpp", "mock/DisplayHardware/MockComposer.cpp", "mock/DisplayHardware/MockDisplaySurface.cpp", "mock/gui/MockGraphicBufferConsumer.cpp", Loading