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

Commit 148994e5 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

We now report hotplug events to the framework

Change-Id: I2d6b7787d39e5929485a551e4982498c5053c211
parent 1604f777
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -40,7 +40,8 @@ class IDisplayEventConnection;
class DisplayEventReceiver {
public:
    enum {
        DISPLAY_EVENT_VSYNC = 'vsyn'
        DISPLAY_EVENT_VSYNC = 'vsyn',
        DISPLAY_EVENT_HOTPLUG = 'plug'
    };

    struct Event {
@@ -54,9 +55,15 @@ public:
            uint32_t count;
        };

        struct Hotplug {
            int32_t id;
            bool connected;
        };

        Header header;
        union {
            VSync vsync;
            Hotplug hotplug;
        };
    };

+1 −1
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ void HWComposer::hotplug(int disp, int connected) {
    if (connected)
        queryDisplayProperties(disp);

    // TODO: tell someone else about this
    mEventHandler.onHotplugReceived(disp, bool(connected));
}

static const uint32_t DISPLAY_ATTRIBUTES[] = {
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public:
    class EventHandler {
        friend class HWComposer;
        virtual void onVSyncReceived(int disp, nsecs_t timestamp) = 0;
        virtual void onHotplugReceived(int disp, bool connected) = 0;
    protected:
        virtual ~EventHandler() {}
    };
+36 −15
Original line number Diff line number Diff line
@@ -106,19 +106,30 @@ void EventThread::onScreenAcquired() {
}


void EventThread::onVSyncReceived(const wp<IBinder>&, nsecs_t timestamp) {
void EventThread::onVSyncReceived(int type, nsecs_t timestamp) {
    Mutex::Autolock _l(mLock);
    mVSyncTimestamp = timestamp;
    mVSyncCount++;
    mCondition.broadcast();
}

void EventThread::onHotplugReceived(int type, bool connected) {
    Mutex::Autolock _l(mLock);
    DisplayEventReceiver::Event event;
    event.header.type = DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG;
    event.header.timestamp = systemTime();
    event.hotplug.id = type;
    event.hotplug.connected = connected;
    mPendingEvents.add(event);
    mCondition.broadcast();
}

bool EventThread::threadLoop() {
    DisplayEventReceiver::Event vsync;
    Vector< sp<EventThread::Connection> > signalConnections;
    signalConnections = waitForEvent(&vsync);

    // dispatch vsync events to listeners...
    // dispatch events to listeners...
    const size_t count = signalConnections.size();
    for (size_t i=0 ; i<count ; i++) {
        const sp<Connection>& conn(signalConnections[i]);
@@ -146,18 +157,29 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
        DisplayEventReceiver::Event* event)
{
    Mutex::Autolock _l(mLock);

    size_t vsyncCount;
    nsecs_t timestamp;
    Vector< sp<EventThread::Connection> > signalConnections;

    do {
        // latch VSYNC event if any
        bool eventPending = false;
        bool waitForVSync = false;
        vsyncCount = mVSyncCount;
        timestamp = mVSyncTimestamp;
        size_t vsyncCount = mVSyncCount;
        nsecs_t timestamp = mVSyncTimestamp;
        mVSyncTimestamp = 0;

        if (timestamp) {
            // we have a vsync event to dispatch
            event->header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
            event->header.timestamp = timestamp;
            event->vsync.count = vsyncCount;
        } else {
            eventPending = !mPendingEvents.isEmpty();
            if (eventPending) {
                // we have some other event to dispatch
                *event = mPendingEvents[0];
                mPendingEvents.removeAt(0);
            }
        }

        // find out connections waiting for events
        size_t count = mDisplayEventConnections.size();
        for (size_t i=0 ; i<count ; i++) {
@@ -179,6 +201,11 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
                            // continuous event, and time to report it
                            signalConnections.add(connection);
                        }
                    } else if (eventPending) {
                        // we don't have a vsync event to process
                        // (timestamp==0), but we have some pending
                        // messages.
                        signalConnections.add(connection);
                    }
                }
            } else {
@@ -206,7 +233,7 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(

        // note: !timestamp implies signalConnections.isEmpty(), because we
        // don't populate signalConnections if there's no vsync pending
        if (!timestamp) {
        if (!timestamp && !eventPending) {
            // wait for something to happen
            if (waitForVSync) {
                // This is where we spend most of our time, waiting
@@ -241,12 +268,6 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
    // here we're guaranteed to have a timestamp and some connections to signal
    // (The connections might have dropped out of mDisplayEventConnections
    // while we were asleep, but we'll still have strong references to them.)

    // fill in vsync event info
    event->header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
    event->header.timestamp = timestamp;
    event->vsync.count = vsyncCount;

    return signalConnections;
}

+3 −1
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ public:
    void onScreenAcquired();

    // called when receiving a vsync event
    void onVSyncReceived(const wp<IBinder>& display, nsecs_t timestamp);
    void onVSyncReceived(int type, nsecs_t timestamp);
    void onHotplugReceived(int type, bool connected);

    Vector< sp<EventThread::Connection> > waitForEvent(
            DisplayEventReceiver::Event* event);
@@ -100,6 +101,7 @@ private:

    // protected by mLock
    SortedVector< wp<Connection> > mDisplayEventConnections;
    Vector< DisplayEventReceiver::Event > mPendingEvents;
    nsecs_t mVSyncTimestamp;
    bool mUseSoftwareVSync;
    size_t mVSyncCount;
Loading