Add Window Infos state to dumpsys
Update SurfaceFlinger and InputDispatcher dumpsys output to include
the vsync id and timestamp of Window Infos changes.
Bug: 279792237
Test: presubmits
Change-Id: I17fba2d09972467cfdd452e5041666ffbeabddc9
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index d406aff..0e3c47b 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2533,7 +2533,7 @@
}
updateCursorAsync();
- updateInputFlinger();
+ updateInputFlinger(vsyncId);
if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) {
// This will block and tracing should only be enabled for debugging.
@@ -3718,7 +3718,7 @@
doCommitTransactions();
}
-void SurfaceFlinger::updateInputFlinger() {
+void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId) {
if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) {
return;
}
@@ -3730,6 +3730,8 @@
if (mUpdateInputInfo) {
mUpdateInputInfo = false;
updateWindowInfo = true;
+ mLastInputFlingerUpdateVsyncId = vsyncId;
+ mLastInputFlingerUpdateTimestamp = systemTime();
buildWindowInfos(windowInfos, displayInfos);
}
@@ -3759,7 +3761,9 @@
std::move(
inputWindowCommands.windowInfosReportedListeners),
/* forceImmediateCall= */ visibleWindowsChanged ||
- !inputWindowCommands.focusRequests.empty());
+ !inputWindowCommands.focusRequests.empty(),
+ mLastInputFlingerUpdateVsyncId,
+ mLastInputFlingerUpdateTimestamp);
} else {
// If there are listeners but no changes to input windows, call the listeners
// immediately.
@@ -6105,6 +6109,29 @@
result.append(mTimeStats->miniDump());
result.append("\n");
+
+ result.append("Window Infos:\n");
+ StringAppendF(&result, " input flinger update vsync id: %" PRId64 "\n",
+ mLastInputFlingerUpdateVsyncId.value);
+ StringAppendF(&result, " input flinger update timestamp (ns): %" PRId64 "\n",
+ mLastInputFlingerUpdateTimestamp);
+ result.append("\n");
+
+ if (int64_t unsentVsyncId = mWindowInfosListenerInvoker->getUnsentMessageVsyncId().value;
+ unsentVsyncId != -1) {
+ StringAppendF(&result, " unsent input flinger update vsync id: %" PRId64 "\n",
+ unsentVsyncId);
+ StringAppendF(&result, " unsent input flinger update timestamp (ns): %" PRId64 "\n",
+ mWindowInfosListenerInvoker->getUnsentMessageTimestamp());
+ result.append("\n");
+ }
+
+ if (uint32_t pendingMessages = mWindowInfosListenerInvoker->getPendingMessageCount();
+ pendingMessages != 0) {
+ StringAppendF(&result, " pending input flinger calls: %" PRIu32 "\n",
+ mWindowInfosListenerInvoker->getPendingMessageCount());
+ result.append("\n");
+ }
}
mat4 SurfaceFlinger::calculateColorMatrix(float saturation) {
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index cd7659b..8eaa1c7 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -717,7 +717,7 @@
void updateLayerHistory(const frontend::LayerSnapshot& snapshot);
frontend::Update flushLifecycleUpdates() REQUIRES(kMainThreadContext);
- void updateInputFlinger();
+ void updateInputFlinger(VsyncId);
void persistDisplayBrightness(bool needsComposite) REQUIRES(kMainThreadContext);
void buildWindowInfos(std::vector<gui::WindowInfo>& outWindowInfos,
std::vector<gui::DisplayInfo>& outDisplayInfos);
@@ -1248,6 +1248,9 @@
VsyncId mLastCommittedVsyncId;
+ VsyncId mLastInputFlingerUpdateVsyncId;
+ nsecs_t mLastInputFlingerUpdateTimestamp;
+
// If blurs should be enabled on this device.
bool mSupportsBlur = false;
std::atomic<uint32_t> mFrameMissedCount = 0;
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.cpp b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
index 856fbbb..2b62638 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.cpp
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
@@ -16,6 +16,7 @@
#include <ftl/small_vector.h>
#include <gui/ISurfaceComposer.h>
+#include <gui/WindowInfosUpdate.h>
#include "WindowInfosListenerInvoker.h"
@@ -86,11 +87,12 @@
void WindowInfosListenerInvoker::windowInfosChanged(
std::vector<WindowInfo> windowInfos, std::vector<DisplayInfo> displayInfos,
- WindowInfosReportedListenerSet reportedListeners, bool forceImmediateCall) {
+ WindowInfosReportedListenerSet reportedListeners, bool forceImmediateCall, VsyncId vsyncId,
+ nsecs_t timestamp) {
reportedListeners.insert(sp<WindowInfosListenerInvoker>::fromExisting(this));
auto callListeners = [this, windowInfos = std::move(windowInfos),
- displayInfos = std::move(displayInfos)](
- WindowInfosReportedListenerSet reportedListeners) mutable {
+ displayInfos = std::move(displayInfos), vsyncId,
+ timestamp](WindowInfosReportedListenerSet reportedListeners) mutable {
WindowInfosListenerVector windowInfosListeners;
{
std::scoped_lock lock(mListenersMutex);
@@ -103,6 +105,9 @@
sp<WindowInfosReportedListenerInvoker>::make(windowInfosListeners,
std::move(reportedListeners));
+ gui::WindowInfosUpdate update(std::move(windowInfos), std::move(displayInfos),
+ vsyncId.value, timestamp);
+
for (const auto& listener : windowInfosListeners) {
sp<IBinder> asBinder = IInterface::asBinder(listener);
@@ -111,8 +116,7 @@
// calling onWindowInfosReported.
asBinder->linkToDeath(reportedInvoker);
- auto status =
- listener->onWindowInfosChanged(windowInfos, displayInfos, reportedInvoker);
+ auto status = listener->onWindowInfosChanged(update, reportedInvoker);
if (!status.isOk()) {
reportedInvoker->onWindowInfosReported();
}
@@ -129,11 +133,15 @@
// to reduce the amount of binder memory used.
if (mActiveMessageCount > 0 && !forceImmediateCall) {
mWindowInfosChangedDelayed = std::move(callListeners);
+ mUnsentVsyncId = vsyncId;
+ mUnsentTimestamp = timestamp;
mReportedListenersDelayed.merge(reportedListeners);
return;
}
mWindowInfosChangedDelayed = nullptr;
+ mUnsentVsyncId = {-1};
+ mUnsentTimestamp = -1;
reportedListeners.merge(mReportedListenersDelayed);
mActiveMessageCount++;
}
@@ -154,6 +162,8 @@
mActiveMessageCount++;
callListeners = std::move(mWindowInfosChangedDelayed);
mWindowInfosChangedDelayed = nullptr;
+ mUnsentVsyncId = {-1};
+ mUnsentTimestamp = -1;
reportedListeners = std::move(mReportedListenersDelayed);
mReportedListenersDelayed.clear();
}
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.h b/services/surfaceflinger/WindowInfosListenerInvoker.h
index 4da9828..e35d056 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.h
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.h
@@ -26,6 +26,8 @@
#include <gui/SpHash.h>
#include <utils/Mutex.h>
+#include "scheduler/VsyncId.h"
+
namespace android {
using WindowInfosReportedListenerSet =
@@ -40,10 +42,25 @@
void windowInfosChanged(std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>,
WindowInfosReportedListenerSet windowInfosReportedListeners,
- bool forceImmediateCall);
+ bool forceImmediateCall, VsyncId vsyncId, nsecs_t timestamp);
binder::Status onWindowInfosReported() override;
+ VsyncId getUnsentMessageVsyncId() {
+ std::scoped_lock lock(mMessagesMutex);
+ return mUnsentVsyncId;
+ }
+
+ nsecs_t getUnsentMessageTimestamp() {
+ std::scoped_lock lock(mMessagesMutex);
+ return mUnsentTimestamp;
+ }
+
+ uint32_t getPendingMessageCount() {
+ std::scoped_lock lock(mMessagesMutex);
+ return mActiveMessageCount;
+ }
+
protected:
void binderDied(const wp<IBinder>& who) override;
@@ -58,6 +75,8 @@
uint32_t mActiveMessageCount GUARDED_BY(mMessagesMutex) = 0;
std::function<void(WindowInfosReportedListenerSet)> mWindowInfosChangedDelayed
GUARDED_BY(mMessagesMutex);
+ VsyncId mUnsentVsyncId GUARDED_BY(mMessagesMutex) = {-1};
+ nsecs_t mUnsentTimestamp GUARDED_BY(mMessagesMutex) = -1;
WindowInfosReportedListenerSet mReportedListenersDelayed;
};
diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
index c1bab0e..4d13aca 100644
--- a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
+++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
@@ -590,7 +590,7 @@
mFlinger->binderDied(display);
mFlinger->onFirstRef();
- mFlinger->updateInputFlinger();
+ mFlinger->updateInputFlinger(VsyncId{0});
mFlinger->updateCursorAsync();
mutableScheduler().setVsyncConfig({.sfOffset = mFdp.ConsumeIntegral<nsecs_t>(),
diff --git a/services/surfaceflinger/tests/WindowInfosListener_test.cpp b/services/surfaceflinger/tests/WindowInfosListener_test.cpp
index f4a8f03..3f27360 100644
--- a/services/surfaceflinger/tests/WindowInfosListener_test.cpp
+++ b/services/surfaceflinger/tests/WindowInfosListener_test.cpp
@@ -16,6 +16,7 @@
#include <gtest/gtest.h>
#include <gui/SurfaceComposerClient.h>
+#include <gui/WindowInfosUpdate.h>
#include <private/android_filesystem_config.h>
#include <cstdint>
#include <future>
@@ -41,9 +42,8 @@
WindowInfosListener(WindowInfosPredicate predicate, std::promise<void>& promise)
: mPredicate(std::move(predicate)), mPromise(promise) {}
- void onWindowInfosChanged(const std::vector<WindowInfo>& windowInfos,
- const std::vector<DisplayInfo>&) override {
- if (mPredicate(windowInfos)) {
+ void onWindowInfosChanged(const gui::WindowInfosUpdate& update) override {
+ if (mPredicate(update.windowInfos)) {
mPromise.set_value();
}
}