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

Commit 229b9349 authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge changes Ie2df1f34,Ia906a7f0

* changes:
  surfaceflinger: use std::vector for mDisplayEventConnections
  surfaceflinger: use std::queue for mPendingEvents
parents 1b097780 98cd38f9
Loading
Loading
Loading
Loading
+28 −14
Original line number Diff line number Diff line
@@ -111,14 +111,28 @@ sp<BnDisplayEventConnection> EventThread::createEventConnection() const {
status_t EventThread::registerDisplayEventConnection(
        const sp<EventThread::Connection>& connection) {
    std::lock_guard<std::mutex> lock(mMutex);
    mDisplayEventConnections.add(connection);

    // this should never happen
    auto it = std::find(mDisplayEventConnections.cbegin(),
            mDisplayEventConnections.cend(), connection);
    if (it != mDisplayEventConnections.cend()) {
        ALOGW("DisplayEventConnection %p already exists", connection.get());
        mCondition.notify_all();
        return ALREADY_EXISTS;
    }

    mDisplayEventConnections.push_back(connection);
    mCondition.notify_all();
    return NO_ERROR;
}

void EventThread::removeDisplayEventConnectionLocked(
        const wp<EventThread::Connection>& connection) {
    mDisplayEventConnections.remove(connection);
    auto it = std::find(mDisplayEventConnections.cbegin(),
            mDisplayEventConnections.cend(), connection);
    if (it != mDisplayEventConnections.cend()) {
        mDisplayEventConnections.erase(it);
    }
}

void EventThread::setVsyncRate(uint32_t count, const sp<EventThread::Connection>& connection) {
@@ -181,7 +195,7 @@ void EventThread::onHotplugReceived(DisplayType displayType, bool connected) {
    event.header.timestamp = systemTime();
    event.hotplug.connected = connected;

    mPendingEvents.add(event);
    mPendingEvents.push(event);
    mCondition.notify_all();
}

@@ -244,18 +258,18 @@ Vector<sp<EventThread::Connection> > EventThread::waitForEventLocked(

        if (!timestamp) {
            // no vsync event, see if there are some other event
            eventPending = !mPendingEvents.isEmpty();
            eventPending = !mPendingEvents.empty();
            if (eventPending) {
                // we have some other event to dispatch
                *outEvent = mPendingEvents[0];
                mPendingEvents.removeAt(0);
                *outEvent = mPendingEvents.front();
                mPendingEvents.pop();
            }
        }

        // find out connections waiting for events
        size_t count = mDisplayEventConnections.size();
        for (size_t i = 0; i < count;) {
            sp<Connection> connection(mDisplayEventConnections[i].promote());
        auto it = mDisplayEventConnections.begin();
        while (it != mDisplayEventConnections.end()) {
            sp<Connection> connection(it->promote());
            if (connection != nullptr) {
                bool added = false;
                if (connection->count >= 0) {
@@ -285,12 +299,11 @@ Vector<sp<EventThread::Connection> > EventThread::waitForEventLocked(
                    // messages.
                    signalConnections.add(connection);
                }
                ++i;
                ++it;
            } else {
                // we couldn't promote this reference, the connection has
                // died, so clean-up!
                mDisplayEventConnections.removeAt(i);
                --count;
                it = mDisplayEventConnections.erase(it);
            }
        }

@@ -379,11 +392,12 @@ void EventThread::dump(String8& result) const {
    result.appendFormat("  soft-vsync: %s\n", mUseSoftwareVSync ? "enabled" : "disabled");
    result.appendFormat("  numListeners=%zu,\n  events-delivered: %u\n",
                        mDisplayEventConnections.size(), mVSyncEvent[0].vsync.count);
    for (size_t i = 0; i < mDisplayEventConnections.size(); i++) {
        sp<Connection> connection = mDisplayEventConnections.itemAt(i).promote();
    for (const wp<Connection>& weak : mDisplayEventConnections) {
        sp<Connection> connection = weak.promote();
        result.appendFormat("    %p: count=%d\n", connection.get(),
                            connection != nullptr ? connection->count : 0);
    }
    result.appendFormat("  other-events-pending: %zu\n", mPendingEvents.size());
}

// ---------------------------------------------------------------------------
+6 −4
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@
#include <condition_variable>
#include <cstdint>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>

#include <android-base/thread_annotations.h>

@@ -31,7 +33,6 @@
#include <private/gui/BitTube.h>

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

// ---------------------------------------------------------------------------
namespace android {
@@ -117,7 +118,6 @@ public:
    ~EventThread();

    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);
@@ -143,6 +143,8 @@ private:
                ResyncWithRateLimitCallback resyncWithRateLimitCallback,
                InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName);

    status_t registerDisplayEventConnection(const sp<Connection>& connection);

    void threadMain();
    Vector<sp<EventThread::Connection>> waitForEventLocked(std::unique_lock<std::mutex>* lock,
                                                           DisplayEventReceiver::Event* event)
@@ -167,8 +169,8 @@ private:
    mutable std::condition_variable mCondition;

    // protected by mLock
    SortedVector<wp<Connection>> mDisplayEventConnections GUARDED_BY(mMutex);
    Vector<DisplayEventReceiver::Event> mPendingEvents GUARDED_BY(mMutex);
    std::vector<wp<Connection>> mDisplayEventConnections GUARDED_BY(mMutex);
    std::queue<DisplayEventReceiver::Event> mPendingEvents GUARDED_BY(mMutex);
    std::array<DisplayEventReceiver::Event, 2> mVSyncEvent GUARDED_BY(mMutex);
    bool mUseSoftwareVSync GUARDED_BY(mMutex) = false;
    bool mVsyncEnabled GUARDED_BY(mMutex) = false;