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

Commit 6d2bcfed authored by Ady Abraham's avatar Ady Abraham Committed by Automerger Merge Worker
Browse files

Merge "DisplayEventDispatcher: optimize binder calls" into sc-dev am: ffbab789

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/13419554

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I378e0592678328a04dab377d6c16bace8f66bf4d
parents 86c58983 ffbab789
Loading
Loading
Loading
Loading
+49 −21
Original line number Diff line number Diff line
@@ -36,7 +36,9 @@ static const size_t EVENT_BUFFER_SIZE = 100;
DisplayEventDispatcher::DisplayEventDispatcher(
        const sp<Looper>& looper, ISurfaceComposer::VsyncSource vsyncSource,
        ISurfaceComposer::EventRegistrationFlags eventRegistration)
      : mLooper(looper), mReceiver(vsyncSource, eventRegistration), mWaitingForVsync(false) {
      : mLooper(looper),
        mReceiver(vsyncSource, eventRegistration),
        mVsyncState(VsyncState::Unregistered) {
    ALOGV("dispatcher %p ~ Initializing display event dispatcher.", this);
}

@@ -66,7 +68,8 @@ void DisplayEventDispatcher::dispose() {
}

status_t DisplayEventDispatcher::scheduleVsync() {
    if (!mWaitingForVsync) {
    switch (mVsyncState) {
        case VsyncState::Unregistered: {
            ALOGV("dispatcher %p ~ Scheduling vsync.", this);

            // Drain all pending events.
@@ -74,18 +77,28 @@ status_t DisplayEventDispatcher::scheduleVsync() {
            PhysicalDisplayId vsyncDisplayId;
            uint32_t vsyncCount;
            VsyncEventData vsyncEventData;
        if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount, &vsyncEventData)) {
            ALOGE("dispatcher %p ~ last event processed while scheduling was for %" PRId64 "", this,
                  ns2ms(static_cast<nsecs_t>(vsyncTimestamp)));
            if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount,
                                     &vsyncEventData)) {
                ALOGE("dispatcher %p ~ last event processed while scheduling was for %" PRId64 "",
                      this, ns2ms(static_cast<nsecs_t>(vsyncTimestamp)));
            }

        status_t status = mReceiver.requestNextVsync();
            status_t status = mReceiver.setVsyncRate(1);
            if (status) {
            ALOGW("Failed to request next vsync, status=%d", status);
                ALOGW("Failed to set vsync rate, status=%d", status);
                return status;
            }

        mWaitingForVsync = true;
            mVsyncState = VsyncState::RegisteredAndWaitingForVsync;
            break;
        }
        case VsyncState::Registered: {
            mVsyncState = VsyncState::RegisteredAndWaitingForVsync;
            break;
        }
        case VsyncState::RegisteredAndWaitingForVsync: {
            break;
        }
    }
    return OK;
}
@@ -123,8 +136,23 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) {
              ", displayId=%s, count=%d, vsyncId=%" PRId64,
              this, ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount,
              vsyncEventData.id);
        mWaitingForVsync = false;
        switch (mVsyncState) {
            case VsyncState::Unregistered:
                ALOGW("Received unexpected VSYNC event");
                break;
            case VsyncState::RegisteredAndWaitingForVsync:
                mVsyncState = VsyncState::Registered;
                dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount, vsyncEventData);
                break;
            case VsyncState::Registered:
                status_t status = mReceiver.setVsyncRate(0);
                if (status) {
                    ALOGW("Failed to reset vsync rate, status=%d", status);
                    return status;
                }
                mVsyncState = VsyncState::Unregistered;
                break;
        }
    }

    return 1; // keep the callback
+14 −1
Original line number Diff line number Diff line
@@ -52,7 +52,20 @@ protected:
private:
    sp<Looper> mLooper;
    DisplayEventReceiver mReceiver;
    bool mWaitingForVsync;
    // The state of vsync event registration and whether the client is expecting
    // an event or not.
    enum class VsyncState {
        // The dispatcher is not registered for vsync events.
        Unregistered,
        // The dispatcher is registered to receive vsync events but should not dispatch it to the
        // client as the client is not expecting a vsync event.
        Registered,

        // The dispatcher is registered to receive vsync events and supposed to dispatch it to
        // the client.
        RegisteredAndWaitingForVsync,
    };
    VsyncState mVsyncState;

    std::vector<FrameRateOverride> mFrameRateOverrides;

+4 −0
Original line number Diff line number Diff line
@@ -303,6 +303,10 @@ void EventThread::setVsyncRate(uint32_t rate, const sp<EventThreadConnection>& c
    std::lock_guard<std::mutex> lock(mMutex);

    const auto request = rate == 0 ? VSyncRequest::None : static_cast<VSyncRequest>(rate);
    if (request != VSyncRequest::None && connection->resyncCallback) {
        connection->resyncCallback();
    }

    if (connection->vsyncRequest != request) {
        connection->vsyncRequest = request;
        mCondition.notify_all();