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

Commit e83f9315 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Cleanup EventThread Part 2

De-refbase EventThread and a bunch of related classes. Convert from
usign StrongPointer to std::unique_ptr to hold owned references, or bare
pointers for unowned references.

I did not see any need for using std::shared_ptr, or anything else, as
SurfaceFlinger appeared to own all the objects, and they were created
once and not really destroyed afterwards.

Test: Things seem to still work on a Pixel XL
Bug: None

Change-Id: Ifff32118d31bc1bb51e38df695ebe5cf86d2bb6d
parent 46a46b31
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -168,8 +168,7 @@ public:
        return false;
    }

    status_t addEventListener(const char* name, nsecs_t phase,
                              const sp<DispSync::Callback>& callback) {
    status_t addEventListener(const char* name, nsecs_t phase, DispSync::Callback* callback) {
        if (kTraceDetailedInfo) ATRACE_CALL();
        Mutex::Autolock lock(mMutex);

@@ -195,7 +194,7 @@ public:
        return NO_ERROR;
    }

    status_t removeEventListener(const sp<DispSync::Callback>& callback) {
    status_t removeEventListener(DispSync::Callback* callback) {
        if (kTraceDetailedInfo) ATRACE_CALL();
        Mutex::Autolock lock(mMutex);

@@ -223,11 +222,11 @@ private:
        const char* mName;
        nsecs_t mPhase;
        nsecs_t mLastEventTime;
        sp<DispSync::Callback> mCallback;
        DispSync::Callback* mCallback;
    };

    struct CallbackInvocation {
        sp<DispSync::Callback> mCallback;
        DispSync::Callback* mCallback;
        nsecs_t mEventTime;
    };

@@ -388,7 +387,8 @@ void DispSync::init(bool hasSyncFramework, int64_t dispSyncPresentTimeOffset) {
        // not needed because any time there is an event registered we will
        // turn on the HW vsync events.
        if (!mIgnorePresentFences && kEnableZeroPhaseTracer) {
            addEventListener("ZeroPhaseTracer", 0, new ZeroPhaseTracer());
            mZeroPhaseTracer = std::make_unique<ZeroPhaseTracer>();
            addEventListener("ZeroPhaseTracer", 0, mZeroPhaseTracer.get());
        }
    }
}
@@ -470,7 +470,7 @@ bool DispSync::addResyncSample(nsecs_t timestamp) {

void DispSync::endResync() {}

status_t DispSync::addEventListener(const char* name, nsecs_t phase, const sp<Callback>& callback) {
status_t DispSync::addEventListener(const char* name, nsecs_t phase, Callback* callback) {
    Mutex::Autolock lock(mMutex);
    return mThread->addEventListener(name, phase, callback);
}
@@ -482,7 +482,7 @@ void DispSync::setRefreshSkipCount(int count) {
    updateModelLocked();
}

status_t DispSync::removeEventListener(const sp<Callback>& callback) {
status_t DispSync::removeEventListener(Callback* callback) {
    Mutex::Autolock lock(mMutex);
    return mThread->removeEventListener(callback);
}
+5 −3
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ class DispSyncThread;
// needed.
class DispSync {
public:
    class Callback : public virtual RefBase {
    class Callback {
    public:
        virtual ~Callback(){};
        virtual void onDispSyncEvent(nsecs_t when) = 0;
@@ -106,12 +106,12 @@ public:
    // 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).
    status_t addEventListener(const char* name, nsecs_t phase, const sp<Callback>& callback);
    status_t addEventListener(const char* name, nsecs_t phase, Callback* callback);

    // removeEventListener removes an already-registered event callback.  Once
    // this method returns that callback will no longer be called by the
    // DispSync object.
    status_t removeEventListener(const sp<Callback>& callback);
    status_t removeEventListener(Callback* callback);

    // computeNextRefresh computes when the next refresh is expected to begin.
    // The periodOffset value can be used to move forward or backward; an
@@ -188,6 +188,8 @@ private:
    // Ignore present (retire) fences if the device doesn't have support for the
    // sync framework
    bool mIgnorePresentFences;

    std::unique_ptr<Callback> mZeroPhaseTracer;
};

} // namespace android
+3 −3
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ namespace android {

// ---------------------------------------------------------------------------

EventThread::EventThread(const sp<VSyncSource>& src, SurfaceFlinger& flinger, bool interceptVSyncs,
EventThread::EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs,
                         const char* threadName)
      : mVSyncSource(src), mFlinger(flinger), mInterceptVSyncs(interceptVSyncs) {
    for (auto& event : mVSyncEvent) {
@@ -339,7 +339,7 @@ void EventThread::enableVSyncLocked() {
        // never enable h/w VSYNC when screen is off
        if (!mVsyncEnabled) {
            mVsyncEnabled = true;
            mVSyncSource->setCallback(static_cast<VSyncSource::Callback*>(this));
            mVSyncSource->setCallback(this);
            mVSyncSource->setVSyncEnabled(true);
        }
    }
@@ -370,7 +370,7 @@ void EventThread::dump(String8& result) const {

// ---------------------------------------------------------------------------

EventThread::Connection::Connection(const sp<EventThread>& eventThread)
EventThread::Connection::Connection(EventThread* eventThread)
      : count(-1), mEventThread(eventThread), mChannel(gui::BitTube::DefaultSize) {}

EventThread::Connection::~Connection() {
+8 −9
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
#include <private/gui/BitTube.h>

#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <utils/SortedVector.h>

#include "DisplayDevice.h"
@@ -43,9 +42,9 @@ class String8;

// ---------------------------------------------------------------------------

class VSyncSource : public virtual RefBase {
class VSyncSource {
public:
    class Callback : public virtual RefBase {
    class Callback {
    public:
        virtual ~Callback() {}
        virtual void onVSyncEvent(nsecs_t when) = 0;
@@ -53,14 +52,14 @@ public:

    virtual ~VSyncSource() {}
    virtual void setVSyncEnabled(bool enable) = 0;
    virtual void setCallback(const sp<Callback>& callback) = 0;
    virtual void setCallback(Callback* callback) = 0;
    virtual void setPhaseOffset(nsecs_t phaseOffset) = 0;
};

class EventThread : public virtual RefBase, private VSyncSource::Callback {
class EventThread : private VSyncSource::Callback {
    class Connection : public BnDisplayEventConnection {
    public:
        explicit Connection(const sp<EventThread>& eventThread);
        explicit Connection(EventThread* eventThread);
        status_t postEvent(const DisplayEventReceiver::Event& event);

        // count >= 1 : continuous event. count is the vsync rate
@@ -74,12 +73,12 @@ class EventThread : public virtual RefBase, private VSyncSource::Callback {
        status_t stealReceiveChannel(gui::BitTube* outChannel) override;
        status_t setVsyncRate(uint32_t count) override;
        void requestNextVsync() override; // asynchronous
        sp<EventThread> const mEventThread;
        EventThread* const mEventThread;
        gui::BitTube mChannel;
    };

public:
    EventThread(const sp<VSyncSource>& src, SurfaceFlinger& flinger, bool interceptVSyncs,
    EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs,
                const char* threadName);
    ~EventThread();

@@ -116,7 +115,7 @@ private:
    void onVSyncEvent(nsecs_t timestamp) override;

    // constants
    sp<VSyncSource> mVSyncSource GUARDED_BY(mMutex);
    VSyncSource* mVSyncSource GUARDED_BY(mMutex) = nullptr;
    SurfaceFlinger& mFlinger;

    std::thread mThread;
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ void MessageQueue::init(const sp<SurfaceFlinger>& flinger) {
    mHandler = new Handler(*this);
}

void MessageQueue::setEventThread(const sp<EventThread>& eventThread) {
void MessageQueue::setEventThread(EventThread* eventThread) {
    if (mEventThread == eventThread) {
        return;
    }
Loading