diff options
author | 2017-12-20 16:50:21 -0800 | |
---|---|---|
committer | 2018-02-07 14:45:06 -0800 | |
commit | 0fcde1b23edcb8105b944df70bf1113cac8f0c15 (patch) | |
tree | 2b6f8f8959026896b32055d61fa766f37c7a0852 | |
parent | 2ee3957ebc063ee770e6fcc1c28fef40709e0f48 (diff) |
SF: Separate EventThread into interface and impl
This allows the normal EventThread to be substituted by a GMock for unit
tests.
The EventThread is now the abstract interface. impl::EventThread is the
normal implementation.
Test: Builds
Bug: None
Change-Id: I2c6234a10849f7d34a215d53e5f601895738a5ae
-rw-r--r-- | services/surfaceflinger/EventThread.cpp | 7 | ||||
-rw-r--r-- | services/surfaceflinger/EventThread.h | 39 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 24 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 6 |
4 files changed, 55 insertions, 21 deletions
diff --git a/services/surfaceflinger/EventThread.cpp b/services/surfaceflinger/EventThread.cpp index 53d95e21ec..90aab506c8 100644 --- a/services/surfaceflinger/EventThread.cpp +++ b/services/surfaceflinger/EventThread.cpp @@ -43,6 +43,10 @@ namespace android { // --------------------------------------------------------------------------- +EventThread::~EventThread() = default; + +namespace impl { + EventThread::EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs, const char* threadName) : mVSyncSource(src), mFlinger(flinger), mInterceptVSyncs(interceptVSyncs) { @@ -84,7 +88,7 @@ void EventThread::setPhaseOffset(nsecs_t phaseOffset) { mVSyncSource->setPhaseOffset(phaseOffset); } -sp<EventThread::Connection> EventThread::createEventConnection() const { +sp<BnDisplayEventConnection> EventThread::createEventConnection() const { return new Connection(const_cast<EventThread*>(this)); } @@ -404,4 +408,5 @@ status_t EventThread::Connection::postEvent(const DisplayEventReceiver::Event& e // --------------------------------------------------------------------------- +} // namespace impl } // namespace android diff --git a/services/surfaceflinger/EventThread.h b/services/surfaceflinger/EventThread.h index 9ae8fb25b0..708806a22d 100644 --- a/services/surfaceflinger/EventThread.h +++ b/services/surfaceflinger/EventThread.h @@ -56,7 +56,29 @@ public: virtual void setPhaseOffset(nsecs_t phaseOffset) = 0; }; -class EventThread : private VSyncSource::Callback { +class EventThread { +public: + virtual ~EventThread(); + + virtual sp<BnDisplayEventConnection> createEventConnection() const = 0; + + // called before the screen is turned off from main thread + virtual void onScreenReleased() = 0; + + // called after the screen is turned on from main thread + virtual void onScreenAcquired() = 0; + + // called when receiving a hotplug event + virtual void onHotplugReceived(int type, bool connected) = 0; + + virtual void dump(String8& result) const = 0; + + virtual void setPhaseOffset(nsecs_t phaseOffset) = 0; +}; + +namespace impl { + +class EventThread : public android::EventThread, private VSyncSource::Callback { class Connection : public BnDisplayEventConnection { public: explicit Connection(EventThread* eventThread); @@ -82,24 +104,24 @@ public: const char* threadName); ~EventThread(); - sp<Connection> createEventConnection() const; + sp<BnDisplayEventConnection> createEventConnection() const override; status_t registerDisplayEventConnection(const sp<Connection>& connection); void setVsyncRate(uint32_t count, const sp<Connection>& connection); void requestNextVsync(const sp<Connection>& connection); // called before the screen is turned off from main thread - void onScreenReleased(); + void onScreenReleased() override; // called after the screen is turned on from main thread - void onScreenAcquired(); + void onScreenAcquired() override; // called when receiving a hotplug event - void onHotplugReceived(int type, bool connected); + void onHotplugReceived(int type, bool connected) override; - void dump(String8& result) const; + void dump(String8& result) const override; - void setPhaseOffset(nsecs_t phaseOffset); + void setPhaseOffset(nsecs_t phaseOffset) override; private: void threadMain(); @@ -139,4 +161,5 @@ private: // --------------------------------------------------------------------------- -}; // namespace android +} // namespace impl +} // namespace android diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 7ad13e3ef2..03f6bdc583 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -574,15 +574,16 @@ void SurfaceFlinger::init() { Mutex::Autolock _l(mStateLock); // start the EventThread - - mEventThreadSource = std::make_unique<DispSyncSource>( - &mPrimaryDispSync, SurfaceFlinger::vsyncPhaseOffsetNs, true, "app"); - mEventThread = std::make_unique<EventThread>( - mEventThreadSource.get(), *this, false, "sfEventThread"); - mSfEventThreadSource = std::make_unique<DispSyncSource>( - &mPrimaryDispSync, SurfaceFlinger::sfVsyncPhaseOffsetNs, true, "sf"); - mSFEventThread = std::make_unique<EventThread>( - mSfEventThreadSource.get(), *this, true, "appEventThread"); + mEventThreadSource = + std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::vsyncPhaseOffsetNs, + true, "app"); + mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(), *this, false, + "appEventThread"); + mSfEventThreadSource = + std::make_unique<DispSyncSource>(&mPrimaryDispSync, + SurfaceFlinger::sfVsyncPhaseOffsetNs, true, "sf"); + mSFEventThread = std::make_unique<impl::EventThread>(mSfEventThreadSource.get(), *this, true, + "sfEventThread"); mEventQueue.setEventThread(mSFEventThread.get()); // Get a RenderEngine for the given display / config (can't fail) @@ -1068,8 +1069,9 @@ status_t SurfaceFlinger::enableVSyncInjections(bool enable) { ALOGV("VSync Injections enabled"); if (mVSyncInjector.get() == nullptr) { mVSyncInjector = std::make_unique<InjectVSyncSource>(); - mInjectorEventThread = std::make_unique<EventThread>( - mVSyncInjector.get(), *this, false, "injEvThread"); + mInjectorEventThread = + std::make_unique<impl::EventThread>(mVSyncInjector.get(), *this, false, + "injEventThread"); } mEventQueue.setEventThread(mInjectorEventThread.get()); } else { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index a17eb70882..b7ebb1bcf3 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -93,6 +93,10 @@ class Surface; class SurfaceFlingerBE; class VSyncSource; +namespace impl { +class EventThread; +} // namespace impl + namespace RE { class RenderEngine; } @@ -312,7 +316,7 @@ public: private: friend class Client; friend class DisplayEventConnection; - friend class EventThread; + friend class impl::EventThread; friend class Layer; friend class BufferLayer; friend class MonitoredProducer; |