上一篇文章我们介绍了 SurfaceFlinger 发送 Vsync 信号的流程以及信号的相关处理,这里我们来看一下 Vsync 信号的监听回调逻辑。
一、Vsync监听
1、EventThread.cpp
源码位置:/frameworks/native/services/surfaceflinger/Scheduler/EventThread.cpp
EventThread::EventThread(std::unique_ptr<VSyncSource> vsyncSource,
android::frametimeline::TokenManager* tokenManager, InterceptVSyncsCallback interceptVSyncsCallback,
ThrottleVsyncCallback throttleVsyncCallback, GetVsyncPeriodFunction getVsyncPeriodFunction)
: mVSyncSource(std::move(vsyncSource)),
mTokenManager(tokenManager),
mInterceptVSyncsCallback(std::move(interceptVSyncsCallback)),
mThrottleVsyncCallback(std::move(throttleVsyncCallback)),
mGetVsyncPeriodFunction(std::move(getVsyncPeriodFunction)),
mThreadName(mVSyncSource->getName()) {
……
// 将当前EventThread对象设置为VSync源的回调目标。
mVSyncSource->setCallback(this);
// 创建线程
mThread &