关键流程
shouldConsumeEvent
它充当了一个过滤器:虽然系统产生了一个事件,但并不是所有的 App 都需要接收它,或者都需要在这一刻接收它(例如 App 运行在 60Hz,而屏幕是 120Hz,App 就需要跳过一半的 VSync 信号)。
// frameworks/native/services/surfaceflinger/Scheduler/EventThread.cpp
bool EventThread::shouldConsumeEvent(const DisplayEventReceiver::Event& event,
const sp<EventThreadConnection>& connection) const {
const auto throttleVsync = [&]() REQUIRES(mMutex) {
const auto& vsyncData = event.vsync.vsyncData;
if (connection->frameRate.isValid()) {
return !mVsyncSchedule->getTracker()
.isVSyncInPhase(vsyncData.preferredExpectedPresentationTime(),
connection->frameRate);
}
const auto expectedPresentTime =
TimePoint::fromNs(event.vsync.vsyncData.preferredExpectedPresentationTime());
return mCallback.throttleVsync(expectedPresentTime, connection->mOwnerUid);
};
switch (event.header.type) {
case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG:
return true;
case DisplayEventReceiver::DISPLAY_EVENT_HDCP_LEVELS_CHANGE:
return true;
case DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE: {
return connection->mEventRegistration.test(
gui::ISurfaceComposer::EventRegistration::modeChanged);
}
case DisplayEventReceiver::DISPLAY_EVENT_VSYNC:
switch (connection->vsyncRequest) {
case VSyncRequest::None:
return false;
case VSyncRequest::SingleSuppressCallback:为
connection->vsyncRequest = VSyncRequest::None;
return false;
case VSyncRequest::Single: {
if (throttleVsync()) {
return false;
}
connection->vsyncRequest = VSyncRequest::SingleSuppressCallback;
return true;
}
case VSyncRequest::Periodic:
if (throttleVsync()) {
return false;
}
return true;
default:
// We don't throttle vsync if the app set a vsync request rate
// since there is no easy way to do that and this is a very
// rare case
return event.vsync.count % vsyncPeriod(connection->vsyncRequest) == 0;
}
case DisplayEventReceiver::DISPLAY_EVENT_FRAME_RATE_OVERRIDE:
[[fallthrough]];
case DisplayEventReceiver::DISPLAY_EVENT_FRAME_RATE_OVERRIDE_FLUSH:
return connection->mEventRegistration.test(
gui::ISurfaceComposer::EventRegistration
273



被折叠的 条评论
为什么被折叠?



