SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::addTransactionCallback(
TransactionCompletedCallbackTakesContext callback, void* callbackContext,
CallbackId::Type callbackType) {
auto listener = TransactionCompletedListener::getInstance();
auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
const auto& surfaceControls =
mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
CallbackId callbackId =
listener->addCallbackFunction(callbackWithContext, surfaceControls, callbackType);
mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
callbackId);
return *this;
}
TransactionCompletedCallbackTakesContext 是一个函数类型。
using TransactionCompletedCallbackTakesContext =
std::function<void(void* /*context*/, nsecs_t /*latchTime*/,
const sp<Fence>& /*presentFence*/,
const std::vector<SurfaceControlStats>& /*stats*/)>;
绑定 TransactionCompletedCallbackTakesContext 函数的第一个参数 callbackContext
,这样其余 3 个参数正好和 TransactionCompletedCallback 函数一致。
TransactionCompletedCallback 是函数类型。
using TransactionCompletedCallback =
std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
const std::vector<SurfaceControlStats>& /*stats*/)>;
如果是从 BLASTBufferQueue::acquireNextBufferLocked() 调用的,则 callbackContext
是 BLASTBufferQueue 指针。
用 TransactionCompletedListener::addCallbackFunction() 设置 surfaceControls
、callbackType
和 callbackFunction
,返回 CallbackId。
把新的 callbackId
写入 Transaction::mListenerCallbacks。
通过 Transaction::apply() 把 callback 传给 SurafceFlinger。