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

Commit 42c3aefc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "DisplayEventDispatcher: optimize binder calls"" into sc-dev

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


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


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


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


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


            mVsyncState = VsyncState::RegisteredAndWaitingForVsync;
        mWaitingForVsync = true;
            break;
        }
        case VsyncState::Registered: {
            mVsyncState = VsyncState::RegisteredAndWaitingForVsync;
            break;
        }
        case VsyncState::RegisteredAndWaitingForVsync: {
            break;
        }
    }
    }
    return OK;
    return OK;
}
}
@@ -136,23 +123,8 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) {
              ", displayId=%s, count=%d, vsyncId=%" PRId64,
              ", displayId=%s, count=%d, vsyncId=%" PRId64,
              this, ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount,
              this, ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount,
              vsyncEventData.id);
              vsyncEventData.id);
        switch (mVsyncState) {
        mWaitingForVsync = false;
            case VsyncState::Unregistered:
                ALOGW("Received unexpected VSYNC event");
                break;
            case VsyncState::RegisteredAndWaitingForVsync:
                mVsyncState = VsyncState::Registered;
        dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount, vsyncEventData);
        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
    return 1; // keep the callback
+1 −14
Original line number Original line Diff line number Diff line
@@ -52,20 +52,7 @@ protected:
private:
private:
    sp<Looper> mLooper;
    sp<Looper> mLooper;
    DisplayEventReceiver mReceiver;
    DisplayEventReceiver mReceiver;
    // The state of vsync event registration and whether the client is expecting
    bool mWaitingForVsync;
    // 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;
    std::vector<FrameRateOverride> mFrameRateOverrides;


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


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

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