summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/WindowInfosListenerInvoker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger/WindowInfosListenerInvoker.cpp')
-rw-r--r--services/surfaceflinger/WindowInfosListenerInvoker.cpp93
1 files changed, 20 insertions, 73 deletions
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.cpp b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
index 023402f747..30b9d8f1cb 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.cpp
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
@@ -28,26 +28,19 @@ using gui::WindowInfo;
struct WindowInfosListenerInvoker::WindowInfosReportedListener
: gui::BnWindowInfosReportedListener {
- explicit WindowInfosReportedListener(WindowInfosListenerInvoker& invoker, size_t callbackCount,
- bool shouldSync)
- : mInvoker(invoker), mCallbacksPending(callbackCount), mShouldSync(shouldSync) {}
+ explicit WindowInfosReportedListener(WindowInfosListenerInvoker& invoker) : mInvoker(invoker) {}
binder::Status onWindowInfosReported() override {
- mCallbacksPending--;
- if (mCallbacksPending == 0) {
- mInvoker.windowInfosReported(mShouldSync);
- }
+ mInvoker.windowInfosReported();
return binder::Status::ok();
}
-private:
WindowInfosListenerInvoker& mInvoker;
- std::atomic<size_t> mCallbacksPending;
- bool mShouldSync;
};
WindowInfosListenerInvoker::WindowInfosListenerInvoker(SurfaceFlinger& flinger)
- : mFlinger(flinger) {}
+ : mFlinger(flinger),
+ mWindowInfosReportedListener(sp<WindowInfosReportedListener>::make(*this)) {}
void WindowInfosListenerInvoker::addWindowInfosListener(sp<IWindowInfosListener> listener) {
sp<IBinder> asBinder = IInterface::asBinder(listener);
@@ -71,76 +64,30 @@ void WindowInfosListenerInvoker::binderDied(const wp<IBinder>& who) {
mWindowInfosListeners.erase(who);
}
-void WindowInfosListenerInvoker::windowInfosChanged(std::vector<WindowInfo> windowInfos,
- std::vector<DisplayInfo> displayInfos,
- bool shouldSync, bool forceImmediateCall) {
- auto callListeners = [this, windowInfos = std::move(windowInfos),
- displayInfos = std::move(displayInfos)](bool shouldSync) mutable {
- ftl::SmallVector<const sp<IWindowInfosListener>, kStaticCapacity> windowInfosListeners;
- {
- std::scoped_lock lock(mListenersMutex);
- for (const auto& [_, listener] : mWindowInfosListeners) {
- windowInfosListeners.push_back(listener);
- }
- }
-
- auto reportedListener =
- sp<WindowInfosReportedListener>::make(*this, windowInfosListeners.size(),
- shouldSync);
-
- for (const auto& listener : windowInfosListeners) {
- auto status =
- listener->onWindowInfosChanged(windowInfos, displayInfos, reportedListener);
- if (!status.isOk()) {
- reportedListener->onWindowInfosReported();
- }
- }
- };
-
+void WindowInfosListenerInvoker::windowInfosChanged(const std::vector<WindowInfo>& windowInfos,
+ const std::vector<DisplayInfo>& displayInfos,
+ bool shouldSync) {
+ ftl::SmallVector<const sp<IWindowInfosListener>, kStaticCapacity> windowInfosListeners;
{
- std::scoped_lock lock(mMessagesMutex);
- // If there are unacked messages and this isn't a forced call, then return immediately.
- // If a forced window infos change doesn't happen first, the update will be sent after
- // the WindowInfosReportedListeners are called. If a forced window infos change happens or
- // if there are subsequent delayed messages before this update is sent, then this message
- // will be dropped and the listeners will only be called with the latest info. This is done
- // to reduce the amount of binder memory used.
- if (mActiveMessageCount > 0 && !forceImmediateCall) {
- mWindowInfosChangedDelayed = std::move(callListeners);
- mShouldSyncDelayed |= shouldSync;
- return;
+ std::scoped_lock lock(mListenersMutex);
+ for (const auto& [_, listener] : mWindowInfosListeners) {
+ windowInfosListeners.push_back(listener);
}
+ }
- mWindowInfosChangedDelayed = nullptr;
- shouldSync |= mShouldSyncDelayed;
- mShouldSyncDelayed = false;
- mActiveMessageCount++;
+ mCallbacksPending = windowInfosListeners.size();
+
+ for (const auto& listener : windowInfosListeners) {
+ listener->onWindowInfosChanged(windowInfos, displayInfos,
+ shouldSync ? mWindowInfosReportedListener : nullptr);
}
- callListeners(shouldSync);
}
-void WindowInfosListenerInvoker::windowInfosReported(bool shouldSync) {
- if (shouldSync) {
+void WindowInfosListenerInvoker::windowInfosReported() {
+ mCallbacksPending--;
+ if (mCallbacksPending == 0) {
mFlinger.windowInfosReported();
}
-
- std::function<void(bool)> callListeners;
- bool shouldSyncDelayed;
- {
- std::scoped_lock lock{mMessagesMutex};
- mActiveMessageCount--;
- if (!mWindowInfosChangedDelayed || mActiveMessageCount > 0) {
- return;
- }
-
- mActiveMessageCount++;
- callListeners = std::move(mWindowInfosChangedDelayed);
- mWindowInfosChangedDelayed = nullptr;
- shouldSyncDelayed = mShouldSyncDelayed;
- mShouldSyncDelayed = false;
- }
-
- callListeners(shouldSyncDelayed);
}
} // namespace android