EventThread的threadMain方法无限循环处理pendingEvents,对Vsync类型的Event分发到消费者,通过往消费者的FD写数据,通知APP有Vsync信号到来。pendingEvents中的消息处理完了,分发线程等待mCondition的通知,EventThread的threadMain方法代码如下:
//frameworks/native/services/surfaceflinger/Scheduler/EventThread.cpp
std::vector<DisplayEventReceiver::Event> mPendingEvents;
void EventThread::threadMain(std::unique_lock<std::mutex>& lock) {
// consumers 表示即将消费事件的 connection 集合
DisplayEventConsumers consumers;
// 状态值不等于 State::Quit 则一直循环遍历,死循环
while (mState != State::Quit) {
std::optional<DisplayEventReceiver::Event> event;
// Determine next event to dispatch.
// 确定下一个要调度的 Event
if (!mPendingEvents.empty()) {
event = mPendingEvents.front(); // 获取头部 Event
mPendingEvents.pop_front(); // 将头部 Event 弹出
switch (event->header.type) { // 根据 Event 类型分别对应处理
case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: //Event类型为DISPLAY_EVENT_HOTPLUG,即当显示设备(如显示器)被插入或拔出时产生
if (event->hotplug.connected && !mVSyncState) {
mVSyncState.emplace(event->header.displayId);
} else if (!event->hotplug.connected && mVSyncState &&
mVSyncState->displayId == event->header.displayId) {
mVSyncState.reset();
}
break;
case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: //Event类型为DISPLAY_EVENT_VSYNC,即Vsync( 垂直同步)事件
if (mInterceptVSyncsCallback) {
mInterceptVSyncsCallback(event->header.timestamp);
}
break;
}
}
// 标志位:是否有 VSync 请求,默认 false
bool vsyncRequested = false;
// Find connections that should consume this event.
// 循环遍历存储 EventThreadConnection 的 vector 容器 mDisplayEventConnections,查找要消费事件的连接
// begin()函数用于返回指向向量容器的第一个元素的迭代器
auto it = mDisplayEventConnections.begin();
while (it != mDisplayEventConnections.end()) {
if (const auto c

最低0.47元/天 解锁文章
1869

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



