diff options
author | 2021-11-10 01:31:10 +0000 | |
---|---|---|
committer | 2021-11-10 01:31:10 +0000 | |
commit | 0a3ce8e715fbc512b8d87671c7949c3c258a35cf (patch) | |
tree | 3468b183cf5c0aafe888bf1a1c965d03edaacd6d /libs/gui/DisplayEventDispatcher.cpp | |
parent | 4523a48d70a781f812e73e5c3f01764fe2e252cf (diff) | |
parent | a7bcfc53065a10559d7b7271351307f150bab192 (diff) |
Merge "Dispatch vsync when receiving vsync timeout to handle vsync loss." am: 8816376a11 am: c53f121969 am: 15b2ddfad7 am: a7bcfc5306
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1867826
Change-Id: I6492c86df78dc6659cbc0021460a42b7e2e8d240
Diffstat (limited to 'libs/gui/DisplayEventDispatcher.cpp')
-rw-r--r-- | libs/gui/DisplayEventDispatcher.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp index e1b1efc0ed..46800f2f14 100644 --- a/libs/gui/DisplayEventDispatcher.cpp +++ b/libs/gui/DisplayEventDispatcher.cpp @@ -33,10 +33,13 @@ namespace android { // using just a few large reads. static const size_t EVENT_BUFFER_SIZE = 100; +static constexpr nsecs_t WAITING_FOR_VSYNC_TIMEOUT = ms2ns(300); + DisplayEventDispatcher::DisplayEventDispatcher( const sp<Looper>& looper, ISurfaceComposer::VsyncSource vsyncSource, ISurfaceComposer::EventRegistrationFlags eventRegistration) - : mLooper(looper), mReceiver(vsyncSource, eventRegistration), mWaitingForVsync(false) { + : mLooper(looper), mReceiver(vsyncSource, eventRegistration), mWaitingForVsync(false), + mLastVsyncCount(0), mLastScheduleVsyncTime(0) { ALOGV("dispatcher %p ~ Initializing display event dispatcher.", this); } @@ -86,6 +89,7 @@ status_t DisplayEventDispatcher::scheduleVsync() { } mWaitingForVsync = true; + mLastScheduleVsyncTime = systemTime(SYSTEM_TIME_MONOTONIC); } return OK; } @@ -124,9 +128,21 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) { this, ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount, vsyncEventData.id); mWaitingForVsync = false; + mLastVsyncCount = vsyncCount; dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount, vsyncEventData); } + if (mWaitingForVsync) { + const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); + const nsecs_t vsyncScheduleDelay = currentTime - mLastScheduleVsyncTime; + if (vsyncScheduleDelay > WAITING_FOR_VSYNC_TIMEOUT) { + ALOGW("Vsync time out! vsyncScheduleDelay=%" PRId64 "ms", ns2ms(vsyncScheduleDelay)); + mWaitingForVsync = false; + dispatchVsync(currentTime, vsyncDisplayId /* displayId is not used */, + ++mLastVsyncCount, vsyncEventData /* empty data */); + } + } + return 1; // keep the callback } |