Loading libs/gui/WindowInfosListenerReporter.cpp +28 −30 Original line number Original line Diff line number Diff line Loading @@ -54,49 +54,47 @@ android::base::Result<gui::WindowInfosUpdate> WindowInfosListenerReporter::addWi status_t WindowInfosListenerReporter::removeWindowInfosListener( status_t WindowInfosListenerReporter::removeWindowInfosListener( const sp<WindowInfosListener>& windowInfosListener, const sp<WindowInfosListener>& windowInfosListener, const sp<gui::ISurfaceComposer>& surfaceComposer) { const sp<gui::ISurfaceComposer>& surfaceComposer) { status_t status = OK; { std::scoped_lock lock(mListenersMutex); std::scoped_lock lock(mListenersMutex); if (mWindowInfosListeners.find(windowInfosListener) == mWindowInfosListeners.end()) { mWindowInfosListeners.erase(windowInfosListener); return status; if (!mWindowInfosListeners.empty()) { return OK; } if (binder::Status status = surfaceComposer->removeWindowInfosListener(this); !status.isOk()) { ALOGW("Failed to remove window infos listener from SurfaceFlinger"); return statusTFromBinderStatus(status); } } if (mWindowInfosListeners.size() == 1) { binder::Status s = surfaceComposer->removeWindowInfosListener(this); status = statusTFromBinderStatus(s); // Clear the last stored state since we're disabling updates and don't want to hold // Clear the last stored state since we're disabling updates and don't want to hold // stale values // stale values mLastUpdate = gui::WindowInfosUpdate(); mLastUpdate = gui::WindowInfosUpdate(); } mWindowInfosPublisher.clear(); mListenerId = UNASSIGNED_LISTENER_ID; if (status == OK) { mWindowInfosListeners.erase(windowInfosListener); } } return status; return OK; } } binder::Status WindowInfosListenerReporter::onWindowInfosChanged( binder::Status WindowInfosListenerReporter::onWindowInfosChanged( const gui::WindowInfosUpdate& update) { const gui::WindowInfosUpdate& update) { std::unordered_set<sp<WindowInfosListener>, gui::SpHash<WindowInfosListener>> ListenerSet listeners; windowInfosListeners; int64_t id; sp<gui::IWindowInfosPublisher> publisher; { { std::scoped_lock lock(mListenersMutex); std::scoped_lock lock(mListenersMutex); for (auto listener : mWindowInfosListeners) { listeners = mWindowInfosListeners; windowInfosListeners.insert(listener); publisher = mWindowInfosPublisher; } id = mListenerId; mLastUpdate = update; mLastUpdate = update; } } // Publisher may be null if we've removed the last window infos listener before handling all for (auto listener : windowInfosListeners) { // in-flight onWindowInfosChanged calls. if (!publisher) { return binder::Status::ok(); } for (auto listener : listeners) { listener->onWindowInfosChanged(update); listener->onWindowInfosChanged(update); } } publisher->ackWindowInfosReceived(update.vsyncId, id); mWindowInfosPublisher->ackWindowInfosReceived(update.vsyncId, mListenerId); return binder::Status::ok(); return binder::Status::ok(); } } Loading libs/gui/include/gui/WindowInfosListenerReporter.h +8 −6 Original line number Original line Diff line number Diff line Loading @@ -42,13 +42,15 @@ private: WindowInfosListenerReporter() = default; WindowInfosListenerReporter() = default; friend class sp<WindowInfosListenerReporter>; friend class sp<WindowInfosListenerReporter>; std::mutex mListenersMutex; using ListenerSet = std::unordered_set<sp<gui::WindowInfosListener>, gui::SpHash<gui::WindowInfosListener>> std::unordered_set<sp<gui::WindowInfosListener>, gui::SpHash<gui::WindowInfosListener>>; mWindowInfosListeners GUARDED_BY(mListenersMutex); gui::WindowInfosUpdate mLastUpdate GUARDED_BY(mListenersMutex); static constexpr int64_t UNASSIGNED_LISTENER_ID = -1; sp<gui::IWindowInfosPublisher> mWindowInfosPublisher; std::mutex mListenersMutex; int64_t mListenerId; ListenerSet mWindowInfosListeners GUARDED_BY(mListenersMutex); gui::WindowInfosUpdate mLastUpdate GUARDED_BY(mListenersMutex); sp<gui::IWindowInfosPublisher> mWindowInfosPublisher GUARDED_BY(mListenersMutex); int64_t mListenerId GUARDED_BY(mListenersMutex); }; }; } // namespace android } // namespace android Loading
libs/gui/WindowInfosListenerReporter.cpp +28 −30 Original line number Original line Diff line number Diff line Loading @@ -54,49 +54,47 @@ android::base::Result<gui::WindowInfosUpdate> WindowInfosListenerReporter::addWi status_t WindowInfosListenerReporter::removeWindowInfosListener( status_t WindowInfosListenerReporter::removeWindowInfosListener( const sp<WindowInfosListener>& windowInfosListener, const sp<WindowInfosListener>& windowInfosListener, const sp<gui::ISurfaceComposer>& surfaceComposer) { const sp<gui::ISurfaceComposer>& surfaceComposer) { status_t status = OK; { std::scoped_lock lock(mListenersMutex); std::scoped_lock lock(mListenersMutex); if (mWindowInfosListeners.find(windowInfosListener) == mWindowInfosListeners.end()) { mWindowInfosListeners.erase(windowInfosListener); return status; if (!mWindowInfosListeners.empty()) { return OK; } if (binder::Status status = surfaceComposer->removeWindowInfosListener(this); !status.isOk()) { ALOGW("Failed to remove window infos listener from SurfaceFlinger"); return statusTFromBinderStatus(status); } } if (mWindowInfosListeners.size() == 1) { binder::Status s = surfaceComposer->removeWindowInfosListener(this); status = statusTFromBinderStatus(s); // Clear the last stored state since we're disabling updates and don't want to hold // Clear the last stored state since we're disabling updates and don't want to hold // stale values // stale values mLastUpdate = gui::WindowInfosUpdate(); mLastUpdate = gui::WindowInfosUpdate(); } mWindowInfosPublisher.clear(); mListenerId = UNASSIGNED_LISTENER_ID; if (status == OK) { mWindowInfosListeners.erase(windowInfosListener); } } return status; return OK; } } binder::Status WindowInfosListenerReporter::onWindowInfosChanged( binder::Status WindowInfosListenerReporter::onWindowInfosChanged( const gui::WindowInfosUpdate& update) { const gui::WindowInfosUpdate& update) { std::unordered_set<sp<WindowInfosListener>, gui::SpHash<WindowInfosListener>> ListenerSet listeners; windowInfosListeners; int64_t id; sp<gui::IWindowInfosPublisher> publisher; { { std::scoped_lock lock(mListenersMutex); std::scoped_lock lock(mListenersMutex); for (auto listener : mWindowInfosListeners) { listeners = mWindowInfosListeners; windowInfosListeners.insert(listener); publisher = mWindowInfosPublisher; } id = mListenerId; mLastUpdate = update; mLastUpdate = update; } } // Publisher may be null if we've removed the last window infos listener before handling all for (auto listener : windowInfosListeners) { // in-flight onWindowInfosChanged calls. if (!publisher) { return binder::Status::ok(); } for (auto listener : listeners) { listener->onWindowInfosChanged(update); listener->onWindowInfosChanged(update); } } publisher->ackWindowInfosReceived(update.vsyncId, id); mWindowInfosPublisher->ackWindowInfosReceived(update.vsyncId, mListenerId); return binder::Status::ok(); return binder::Status::ok(); } } Loading
libs/gui/include/gui/WindowInfosListenerReporter.h +8 −6 Original line number Original line Diff line number Diff line Loading @@ -42,13 +42,15 @@ private: WindowInfosListenerReporter() = default; WindowInfosListenerReporter() = default; friend class sp<WindowInfosListenerReporter>; friend class sp<WindowInfosListenerReporter>; std::mutex mListenersMutex; using ListenerSet = std::unordered_set<sp<gui::WindowInfosListener>, gui::SpHash<gui::WindowInfosListener>> std::unordered_set<sp<gui::WindowInfosListener>, gui::SpHash<gui::WindowInfosListener>>; mWindowInfosListeners GUARDED_BY(mListenersMutex); gui::WindowInfosUpdate mLastUpdate GUARDED_BY(mListenersMutex); static constexpr int64_t UNASSIGNED_LISTENER_ID = -1; sp<gui::IWindowInfosPublisher> mWindowInfosPublisher; std::mutex mListenersMutex; int64_t mListenerId; ListenerSet mWindowInfosListeners GUARDED_BY(mListenersMutex); gui::WindowInfosUpdate mLastUpdate GUARDED_BY(mListenersMutex); sp<gui::IWindowInfosPublisher> mWindowInfosPublisher GUARDED_BY(mListenersMutex); int64_t mListenerId GUARDED_BY(mListenersMutex); }; }; } // namespace android } // namespace android