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

Commit e5991f5f authored by Patrick Williams's avatar Patrick Williams
Browse files

Replace syncInputWindows with addWindowInfosReportedListener

Bug: 222421815
Change-Id: Ica0b6aa0f4c2c0405cc34acf0147b0fffe439076
Test: manual
parent e2e8ef2b
Loading
Loading
Loading
Loading
+5 −42
Original line number Diff line number Diff line
@@ -636,8 +636,7 @@ SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
        mDesiredPresentTime(other.mDesiredPresentTime),
        mIsAutoTimestamp(other.mIsAutoTimestamp),
        mFrameTimelineInfo(other.mFrameTimelineInfo),
        mApplyToken(other.mApplyToken),
        mWindowInfosReportedEvent(other.mWindowInfosReportedEvent) {
        mApplyToken(other.mApplyToken) {
    mDisplayStates = other.mDisplayStates;
    mComposerStates = other.mComposerStates;
    mInputWindowCommands = other.mInputWindowCommands;
@@ -881,9 +880,6 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
    mEarlyWakeupStart = mEarlyWakeupStart || other.mEarlyWakeupStart;
    mEarlyWakeupEnd = mEarlyWakeupEnd || other.mEarlyWakeupEnd;
    mApplyToken = other.mApplyToken;
    if (other.mWindowInfosReportedEvent) {
        mWindowInfosReportedEvent = std::move(other.mWindowInfosReportedEvent);
    }

    mergeFrameTimelineInfo(mFrameTimelineInfo, other.mFrameTimelineInfo);

@@ -906,7 +902,6 @@ void SurfaceComposerClient::Transaction::clear() {
    mIsAutoTimestamp = true;
    clearFrameTimelineInfo(mFrameTimelineInfo);
    mApplyToken = nullptr;
    mWindowInfosReportedEvent = nullptr;
}

uint64_t SurfaceComposerClient::Transaction::getId() {
@@ -1053,10 +1048,6 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
                            hasListenerCallbacks, listenerCallbacks, mId);
    mId = generateId();

    if (mWindowInfosReportedEvent && !mWindowInfosReportedEvent->wait()) {
        ALOGE("Timed out waiting for window infos to be reported.");
    }

    // Clear the current states and flags
    clear();

@@ -1743,25 +1734,10 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocus
    return *this;
}

class NotifyWindowInfosReported : public gui::BnWindowInfosReportedListener {
public:
    NotifyWindowInfosReported(
            std::shared_ptr<SurfaceComposerClient::Event> windowInfosReportedEvent)
          : mWindowInfosReportedEvent(windowInfosReportedEvent) {}

    binder::Status onWindowInfosReported() {
        mWindowInfosReportedEvent->set();
        return binder::Status::ok();
    }

private:
    std::shared_ptr<SurfaceComposerClient::Event> mWindowInfosReportedEvent;
};

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
    mWindowInfosReportedEvent = std::make_shared<Event>();
    mInputWindowCommands.windowInfosReportedListeners.insert(
            sp<NotifyWindowInfosReported>::make(mWindowInfosReportedEvent));
SurfaceComposerClient::Transaction&
SurfaceComposerClient::Transaction::addWindowInfosReportedListener(
        sp<gui::IWindowInfosReportedListener> windowInfosReportedListener) {
    mInputWindowCommands.windowInfosReportedListeners.insert(windowInfosReportedListener);
    return *this;
}

@@ -2849,17 +2825,4 @@ void ReleaseCallbackThread::threadMain() {
    }
}

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

void SurfaceComposerClient::Event::set() {
    std::lock_guard<std::mutex> lock(mMutex);
    mComplete = true;
    mConditionVariable.notify_all();
}

bool SurfaceComposerClient::Event::wait() {
    std::unique_lock<std::mutex> lock(mMutex);
    return mConditionVariable.wait_for(lock, sTimeout, [this] { return mComplete; });
}

} // namespace android
+3 −19
Original line number Diff line number Diff line
@@ -387,22 +387,6 @@ public:
        std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls;
    };

    // TODO(b/222421815) this class should be removed when
    // SurfaceComposerClient::Transaction::syncInputWindows is removed and replaced with a method
    // for adding callbacks to InputWindowCommands.
    class Event {
    private:
        static constexpr std::chrono::seconds sTimeout{5};

        bool mComplete = false;
        std::condition_variable mConditionVariable;
        std::mutex mMutex;

    public:
        void set();
        bool wait();
    };

    class Transaction : public Parcelable {
    private:
        void releaseBufferIfOverwriting(const layer_state_t& state);
@@ -452,8 +436,6 @@ public:
        InputWindowCommands mInputWindowCommands;
        int mStatus = NO_ERROR;

        std::shared_ptr<Event> mWindowInfosReportedEvent = nullptr;

        layer_state_t* getLayerState(const sp<SurfaceControl>& sc);
        DisplayState& getDisplayState(const sp<IBinder>& token);

@@ -588,7 +570,9 @@ public:

        Transaction& setInputWindowInfo(const sp<SurfaceControl>& sc, const gui::WindowInfo& info);
        Transaction& setFocusedWindow(const gui::FocusRequest& request);
        Transaction& syncInputWindows();

        Transaction& addWindowInfosReportedListener(
                sp<gui::IWindowInfosReportedListener> windowInfosReportedListener);

        // Set a color transform matrix on the given layer on the built-in display.
        Transaction& setColorTransform(const sp<SurfaceControl>& sc, const mat3& matrix,