Allow ProducerBuffer gain posted buffer.
Say there are 3 buffers allocated in buffer queue or some sort of
containers of the buffers, and all of the three buffers are in
posted state. Consumers are taking their time to do other things.
In this case, the producer who is using the buffers from this buffer
container would not be able to produce image because there is no buffer
available (unless the container of the buffer decide to allocate new
buffers). This change allows the container of the buffer decide whether
to reuse an old posted buffer, or to allocate new buffer, for the
producer side of the buffer container to produce image into.
Bug: 80164475
Test: buffer_hub-test on Taimen and Vega
Change-Id: I8c3d10a3b32ffa4bbf24da176a694b12c4dc3a5d
diff --git a/libs/vr/libbufferhub/producer_buffer.cpp b/libs/vr/libbufferhub/producer_buffer.cpp
index 7b6f77a..8f0e3e3 100644
--- a/libs/vr/libbufferhub/producer_buffer.cpp
+++ b/libs/vr/libbufferhub/producer_buffer.cpp
@@ -134,7 +134,7 @@
}
int ProducerBuffer::LocalGain(DvrNativeBufferMetadata* out_meta,
- LocalHandle* out_fence) {
+ LocalHandle* out_fence, bool gain_posted_buffer) {
uint64_t buffer_state = buffer_state_->load();
ALOGD_IF(TRACE, "ProducerBuffer::LocalGain: buffer=%d, state=%" PRIx64 ".",
id(), buffer_state);
@@ -142,13 +142,14 @@
if (!out_meta)
return -EINVAL;
- if (!BufferHubDefs::IsBufferReleased(buffer_state)) {
- if (BufferHubDefs::IsBufferGained(buffer_state)) {
- // We don't want to log error when gaining a newly allocated
- // buffer.
- ALOGI("ProducerBuffer::LocalGain: already gained id=%d.", id());
- return -EALREADY;
- }
+ if (BufferHubDefs::IsBufferGained(buffer_state)) {
+ // We don't want to log error when gaining a newly allocated
+ // buffer.
+ ALOGI("ProducerBuffer::LocalGain: already gained id=%d.", id());
+ return -EALREADY;
+ }
+ if (BufferHubDefs::IsBufferAcquired(buffer_state) ||
+ (BufferHubDefs::IsBufferPosted(buffer_state) && !gain_posted_buffer)) {
ALOGE("ProducerBuffer::LocalGain: not released id=%d state=%" PRIx64 ".",
id(), buffer_state);
return -EBUSY;
@@ -180,11 +181,11 @@
return 0;
}
-int ProducerBuffer::Gain(LocalHandle* release_fence) {
+int ProducerBuffer::Gain(LocalHandle* release_fence, bool gain_posted_buffer) {
ATRACE_NAME("ProducerBuffer::Gain");
DvrNativeBufferMetadata meta;
- if (const int error = LocalGain(&meta, release_fence))
+ if (const int error = LocalGain(&meta, release_fence, gain_posted_buffer))
return error;
auto status = InvokeRemoteMethod<BufferHubRPC::ProducerGain>();
@@ -194,10 +195,11 @@
}
int ProducerBuffer::GainAsync(DvrNativeBufferMetadata* out_meta,
- LocalHandle* release_fence) {
+ LocalHandle* release_fence,
+ bool gain_posted_buffer) {
ATRACE_NAME("ProducerBuffer::GainAsync");
- if (const int error = LocalGain(out_meta, release_fence))
+ if (const int error = LocalGain(out_meta, release_fence, gain_posted_buffer))
return error;
return ReturnStatusOrError(SendImpulse(BufferHubRPC::ProducerGain::Opcode));