releaseBuffer(bufferItem, Fence::NO_FENCE); BQA_LOGE("Buffer was empty"); return; } if (rejectBuffer(bufferItem)) { BQA_LOGE("rejecting buffer:active_size=%dx%d, requested_size=%dx%d " "buffer{size=%dx%d transform=%d}", mSize.width, mSi"> releaseBuffer(bufferItem, Fence::NO_FENCE); BQA_LOGE("Buffer was empty"); return; } if (rejectBuffer(bufferItem)) { BQA_LOGE("rejecting buffer:active_size=%dx%d, requested_size=%dx%d " "buffer{size=%dx%d transform=%d}", mSize.width, mSi"> releaseBuffer(bufferItem, Fence::NO_FENCE); BQA_LOGE("Buffer was empty"); return; } if (rejectBuffer(bufferItem)) { BQA_LOGE("rejecting buffer:active_size=%dx%d, requested_size=%dx%d " "buffer{size=%dx%d transform=%d}", mSize.width, mSi">
void BLASTBufferQueue::acquireNextBufferLocked(
const std::optional<SurfaceComposerClient::Transaction*> transaction) {
...
BufferItem bufferItem;
status_t status =
mBufferItemConsumer->acquireBuffer(&bufferItem, 0 /* expectedPresent */, false);
if (status == BufferQueue::NO_BUFFER_AVAILABLE) {
BQA_LOGV("Failed to acquire a buffer, err=NO_BUFFER_AVAILABLE");
return;
} else if (status != OK) {
BQA_LOGE("Failed to acquire a buffer, err=%s", statusToString(status).c_str());
return;
}
auto buffer = bufferItem.mGraphicBuffer;
mNumFrameAvailable--;
if (buffer == nullptr) {
mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE);
BQA_LOGE("Buffer was empty");
return;
}
if (rejectBuffer(bufferItem)) {
BQA_LOGE("rejecting buffer:active_size=%dx%d, requested_size=%dx%d "
"buffer{size=%dx%d transform=%d}",
mSize.width, mSize.height, mRequestedSize.width, mRequestedSize.height,
buffer->getWidth(), buffer->getHeight(), bufferItem.mTransform);
mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE);
acquireNextBufferLocked(transaction);
return;
}
mNumAcquired++;
mLastAcquiredFrameNumber = bufferItem.mFrameNumber;
ReleaseCallbackId releaseCallbackId(buffer->getId(), mLastAcquiredFrameNumber);
mSubmitted[releaseCallbackId] = bufferItem;
incStrong()
增加 this 的引用计数,即 BLASTBufferQueue。在 BLASTBufferQueue::transactionCallback() 中引用计数减一。acquireBuffer()
获取 bufferItem,它最终会调用 BufferQueueConsumer::acquireBuffer()。它是在 BufferQueueProducer::queueBuffer() 中加入到 buffer queue 中的。acquireBuffer()
返回错误,则 return。releaseBuffer()
释放 buffer slot。rejectBuffer()
返回 true 表示 buffer 的宽高不符,所以调用 releaseBuffer()
,再次调用该函数。mNumAcquired
加一,在 BLASTBufferQueue::releaseBufferCallbackLocked() 中减一。mLastAcquiredFrameNumber
。mSubmitted
。 // Ensure BLASTBufferQueue stays alive until we receive the transaction complete callback.
incStrong((void*)transactionCallbackThunk);
...
auto releaseBufferCallback =
std::bind(releaseBufferCallbackThunk, wp<BLASTBufferQueue>(this) /* callbackContext */,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4);
t->setBuffer(mSurfaceControl, buffer, releaseCallbackId, releaseBufferCallback);
t->setAcquireFence(mSurfaceControl,
bufferItem.mFence ? new Fence(bufferItem.mFence->dup()) : Fence::NO_FENCE);
t->addTransactionCompletedCallback(transactionCallbackThunk, static_cast<void*>(this));
...
}
incStrong()
增加 this 的引用计数,即 BLASTBufferQueue。在 BLASTBufferQueue::transactionCallback() 中引用计数减一。releaseBufferCallback
是 releaseBufferCallbackThunk()。acquireBuffer()
获取 bufferItem,它最终会调用 BufferQueueConsumer::acquireBuffer()。它是在 BufferQueueProducer::queueBuffer() 中加入到 buffer queue 中的。setAcquireFence()
把 fence 存到 layer_state_t 中。