CallbackId TransactionCompletedListener::addCallbackFunction(
const TransactionCompletedCallback& callbackFunction,
const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
surfaceControls,
CallbackId::Type callbackType) {
std::lock_guard<std::mutex> lock(mMutex);
startListeningLocked();
CallbackId callbackId(getNextIdLocked(), callbackType);
mCallbacks[callbackId].callbackFunction = callbackFunction;
auto& callbackSurfaceControls = mCallbacks[callbackId].surfaceControls;
for (const auto& surfaceControl : surfaceControls) {
callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
}
return callbackId;
}
TransactionCompletedCallback 是函数类型。
using TransactionCompletedCallback =
std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
const std::vector<SurfaceControlStats>& /*stats*/)>;
TransactionCompletedListener::startListeningLocked() 开启 binder 线程。
新建一个 CallbackId,调用 TransactionCompletedListener::getNextIdLocked() 分配一个 id。
callbackId
加入 TransactionCompletedListener::mCallbacks,同时 callbackFunction
和 surfaceControls
存入 value,类型是 TransactionCompletedListener::CallbackTranslation。
TransactionCompletedListener 是一个进程一个对象,mCallbacks
中存着 CallbackId。当 SurfaceFlinger 回调 ITransactionCompletedListener 接口时,通过 CallbackId 来找到 callbackFunction
。例如,对于 BLASTBufferQueue::acquireNextBufferLocked() 中调用 Transaction::setBuffer() 的事务,callbackFunction
是 transactionCallbackThunk()。