该函数中并没有处理 mDrawingState.buffer
,只是给 client 发送 release,说明 layer 的 buffer 是一直存在的,直到 layer 销毁。
void BufferStateLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
ATRACE_CALL();
ATRACE_NAME(getName().c_str());
for (const auto& handle : mDrawingState.callbackHandles) {
handle->transformHint = mTransformHint;
handle->dequeueReadyTime = dequeueReadyTime;
handle->currentMaxAcquiredBufferCount =
mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid);
}
for (auto& handle : mDrawingState.callbackHandles) {
if (handle->releasePreviousBuffer &&
mDrawingState.releaseBufferEndpoint == handle->listener) {
handle->previousReleaseCallbackId = mPreviousReleaseCallbackId;
break;
}
}
mDrawingState.callbackHandles
,更新 CallbackHandle 的成员。mDrawingState.callbackHandles
,如果 releasePreviousBuffer
是 true,且 mDrawingState.releaseBufferEndpoint
和 handle->listener
相同,则设置 previousReleaseCallbackId
。listener
与 releaseBufferEndpoint
相同表示它是生产 buffer 的应用设置的,因为 Transaction 可以跨进程传递,所以 callbackHandles
有可能由多个应用设置。
releasePreviousBuffer
是在 BufferStateLayer::setTransactionCompletedListeners() 中设置的。releaseBufferEndpoint
是在 BufferStateLayer::setBuffer() 中设置的。mPreviousReleaseCallbackId
是在 BufferStateLayer::updateActiveBuffer() 中设置的。 std::vector<JankData> jankData;
jankData.reserve(mPendingJankClassifications.size());
while (!mPendingJankClassifications.empty()
&& mPendingJankClassifications.front()->getJankType()) {
std::shared_ptr<frametimeline::SurfaceFrame> surfaceFrame =
mPendingJankClassifications.front();
mPendingJankClassifications.pop_front();
jankData.emplace_back(
JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value()));
}
mFlinger->getTransactionCallbackInvoker().finalizePendingCallbackHandles(
mDrawingState.callbackHandles, jankData);
mDrawingState.callbackHandles = {};
callbackHandles
,用 CallbackHandle 成员更新 mCompletedTransactions
中相关的 TransactionStats 成员。callbackHandles
。 const sp<Fence>& releaseFence(mPreviousReleaseFence);
std::shared_ptr<FenceTime> releaseFenceTime = std::make_shared<FenceTime>(releaseFence);
{
Mutex::Autolock lock(mFrameEventHistoryMutex);
if (mPreviousFrameNumber != 0) {
mFrameEventHistory.addRelease(mPreviousFrameNumber, dequeueReadyTime,
std::move(releaseFenceTime));
}
}
}
mPreviousReleaseFence
是在 BufferStateLayer::onLayerDisplayed() 中设置的。