summaryrefslogtreecommitdiff
path: root/libs/gui/DisplayEventDispatcher.cpp
diff options
context:
space:
mode:
author Ady Abraham <adyabr@google.com> 2020-12-21 19:14:30 -0800
committer Ady Abraham <adyabr@google.com> 2021-02-01 21:28:52 +0000
commit981787535c543cf82ef6f92ad17e9d15b6dc032f (patch)
tree1f4a91421c40cd51265b32fac5e714e7bf46a7d0 /libs/gui/DisplayEventDispatcher.cpp
parent87eb2c419ef230366ccbdbe980c4f49b7a70f372 (diff)
DisplayEventDispatcher: optimize binder calls
Use DisplayEventReciever::setVsyncRate instead of DisplayEventReciever::requestNextVsync to accommodate a one-time registration to vsync events when the app registers back to back callbacks. With this approach we can save all the binder calls during a running animation. Test: run TouchLatency test app and observe systrace Bug: 162096692 Change-Id: Ib415f2aade40a3d23a2b4c77e5746e5e13666d23
Diffstat (limited to 'libs/gui/DisplayEventDispatcher.cpp')
-rw-r--r--libs/gui/DisplayEventDispatcher.cpp70
1 files changed, 49 insertions, 21 deletions
diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp
index c6c9a8f7a7..2ad484add3 100644
--- a/libs/gui/DisplayEventDispatcher.cpp
+++ b/libs/gui/DisplayEventDispatcher.cpp
@@ -36,7 +36,9 @@ static const size_t EVENT_BUFFER_SIZE = 100;
DisplayEventDispatcher::DisplayEventDispatcher(
const sp<Looper>& looper, ISurfaceComposer::VsyncSource vsyncSource,
ISurfaceComposer::EventRegistrationFlags eventRegistration)
- : mLooper(looper), mReceiver(vsyncSource, eventRegistration), mWaitingForVsync(false) {
+ : mLooper(looper),
+ mReceiver(vsyncSource, eventRegistration),
+ mVsyncState(VsyncState::Unregistered) {
ALOGV("dispatcher %p ~ Initializing display event dispatcher.", this);
}
@@ -66,26 +68,37 @@ void DisplayEventDispatcher::dispose() {
}
status_t DisplayEventDispatcher::scheduleVsync() {
- if (!mWaitingForVsync) {
- ALOGV("dispatcher %p ~ Scheduling vsync.", this);
-
- // Drain all pending events.
- nsecs_t vsyncTimestamp;
- PhysicalDisplayId vsyncDisplayId;
- uint32_t vsyncCount;
- VsyncEventData vsyncEventData;
- if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount, &vsyncEventData)) {
- ALOGE("dispatcher %p ~ last event processed while scheduling was for %" PRId64 "", this,
- ns2ms(static_cast<nsecs_t>(vsyncTimestamp)));
- }
+ switch (mVsyncState) {
+ case VsyncState::Unregistered: {
+ ALOGV("dispatcher %p ~ Scheduling vsync.", this);
+
+ // Drain all pending events.
+ nsecs_t vsyncTimestamp;
+ PhysicalDisplayId vsyncDisplayId;
+ uint32_t vsyncCount;
+ VsyncEventData vsyncEventData;
+ if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount,
+ &vsyncEventData)) {
+ ALOGE("dispatcher %p ~ last event processed while scheduling was for %" PRId64 "",
+ this, ns2ms(static_cast<nsecs_t>(vsyncTimestamp)));
+ }
- status_t status = mReceiver.requestNextVsync();
- if (status) {
- ALOGW("Failed to request next vsync, status=%d", status);
- return status;
- }
+ status_t status = mReceiver.setVsyncRate(1);
+ if (status) {
+ ALOGW("Failed to set vsync rate, status=%d", status);
+ return status;
+ }
- mWaitingForVsync = true;
+ mVsyncState = VsyncState::RegisteredAndWaitingForVsync;
+ break;
+ }
+ case VsyncState::Registered: {
+ mVsyncState = VsyncState::RegisteredAndWaitingForVsync;
+ break;
+ }
+ case VsyncState::RegisteredAndWaitingForVsync: {
+ break;
+ }
}
return OK;
}
@@ -123,8 +136,23 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) {
", displayId=%s, count=%d, vsyncId=%" PRId64,
this, ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount,
vsyncEventData.id);
- mWaitingForVsync = false;
- dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount, vsyncEventData);
+ switch (mVsyncState) {
+ case VsyncState::Unregistered:
+ ALOGW("Received unexpected VSYNC event");
+ break;
+ case VsyncState::RegisteredAndWaitingForVsync:
+ mVsyncState = VsyncState::Registered;
+ 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