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

Commit 0fcde1b2 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

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
parent 2ee3957e
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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
+31 −8
Original line number Diff line number Diff line
@@ -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
+13 −11
Original line number Diff line number Diff line
@@ -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 {
+5 −1
Original line number Diff line number Diff line
@@ -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;