SF: Register resync callback per event connection
This CL ties the resync callback to an EventThreadConnection instead
of an EventThread. This is a step towards having IDisplayEventConnection
subscribe to a given display rather than the primary display implicitly.
Each display will then have SurfaceFlinger::VsyncState that resyncs
independently at potentially different rates. Callbacks have weak
references to the per-display VsyncState owned by SurfaceFlinger.
Bug: 74619554
Test: Boot and turn display on/off repeatedly
Change-Id: Ic7cc64e2004fa07a5d54431fc330995048a4ed20
diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp
index bf925b2..7b25adb 100644
--- a/services/surfaceflinger/Scheduler/EventThread.cpp
+++ b/services/surfaceflinger/Scheduler/EventThread.cpp
@@ -43,8 +43,12 @@
// ---------------------------------------------------------------------------
-EventThreadConnection::EventThreadConnection(EventThread* eventThread)
- : count(-1), mEventThread(eventThread), mChannel(gui::BitTube::DefaultSize) {}
+EventThreadConnection::EventThreadConnection(EventThread* eventThread,
+ ResyncCallback resyncCallback)
+ : resyncCallback(std::move(resyncCallback)),
+ count(-1),
+ mEventThread(eventThread),
+ mChannel(gui::BitTube::DefaultSize) {}
EventThreadConnection::~EventThreadConnection() {
// do nothing here -- clean-up will happen automatically
@@ -88,26 +92,21 @@
namespace impl {
EventThread::EventThread(std::unique_ptr<VSyncSource> src,
- const ResyncWithRateLimitCallback& resyncWithRateLimitCallback,
const InterceptVSyncsCallback& interceptVSyncsCallback,
const ResetIdleTimerCallback& resetIdleTimerCallback,
const char* threadName)
- : EventThread(nullptr, std::move(src), resyncWithRateLimitCallback, interceptVSyncsCallback,
- threadName) {
+ : EventThread(nullptr, std::move(src), interceptVSyncsCallback, threadName) {
mResetIdleTimer = resetIdleTimerCallback;
}
-EventThread::EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback,
- InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName)
- : EventThread(src, nullptr, resyncWithRateLimitCallback, interceptVSyncsCallback,
- threadName) {}
+EventThread::EventThread(VSyncSource* src, InterceptVSyncsCallback interceptVSyncsCallback,
+ const char* threadName)
+ : EventThread(src, nullptr, interceptVSyncsCallback, threadName) {}
EventThread::EventThread(VSyncSource* src, std::unique_ptr<VSyncSource> uniqueSrc,
- ResyncWithRateLimitCallback resyncWithRateLimitCallback,
InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName)
: mVSyncSource(src),
mVSyncSourceUnique(std::move(uniqueSrc)),
- mResyncWithRateLimitCallback(resyncWithRateLimitCallback),
mInterceptVSyncsCallback(interceptVSyncsCallback) {
if (src == nullptr) {
mVSyncSource = mVSyncSourceUnique.get();
@@ -150,8 +149,8 @@
mVSyncSource->setPhaseOffset(phaseOffset);
}
-sp<EventThreadConnection> EventThread::createEventConnection() const {
- return new EventThreadConnection(const_cast<EventThread*>(this));
+sp<EventThreadConnection> EventThread::createEventConnection(ResyncCallback resyncCallback) const {
+ return new EventThreadConnection(const_cast<EventThread*>(this), std::move(resyncCallback));
}
status_t EventThread::registerDisplayEventConnection(const sp<EventThreadConnection>& connection) {
@@ -195,8 +194,9 @@
ATRACE_NAME("resetIdleTimer");
mResetIdleTimer();
}
- if (mResyncWithRateLimitCallback) {
- mResyncWithRateLimitCallback();
+
+ if (connection->resyncCallback) {
+ connection->resyncCallback();
}
std::lock_guard<std::mutex> lock(mMutex);