diff options
-rw-r--r-- | libs/ui/BufferHubBuffer.cpp | 25 | ||||
-rw-r--r-- | libs/ui/include/ui/BufferHubBuffer.h | 2 | ||||
-rw-r--r-- | libs/ui/include/ui/BufferHubDefs.h | 66 | ||||
-rw-r--r-- | libs/ui/tests/BufferHubMetadata_test.cpp | 4 | ||||
-rw-r--r-- | libs/vr/libbufferhub/buffer_hub_base.cpp | 6 | ||||
-rw-r--r-- | libs/vr/libbufferhub/include/private/dvr/buffer_hub_base.h | 4 | ||||
-rw-r--r-- | services/bufferhub/BufferHubService.cpp | 4 | ||||
-rw-r--r-- | services/bufferhub/BufferNode.cpp | 6 | ||||
-rw-r--r-- | services/vr/bufferhubd/producer_channel.cpp | 13 |
9 files changed, 64 insertions, 66 deletions
diff --git a/libs/ui/BufferHubBuffer.cpp b/libs/ui/BufferHubBuffer.cpp index 604665bc91..da91a979fe 100644 --- a/libs/ui/BufferHubBuffer.cpp +++ b/libs/ui/BufferHubBuffer.cpp @@ -78,15 +78,14 @@ BufferHubBuffer::BufferHubBuffer(uint32_t width, uint32_t height, uint32_t layer BufferHubStatus ret; sp<IBufferClient> client; BufferTraits bufferTraits; - IBufferHub::allocateBuffer_cb alloc_cb = [&](const auto& status, const auto& outClient, - const auto& outTraits) { + IBufferHub::allocateBuffer_cb allocCb = [&](const auto& status, const auto& outClient, + const auto& outTraits) { ret = status; client = std::move(outClient); bufferTraits = std::move(outTraits); }; - if (!bufferhub->allocateBuffer(desc, static_cast<uint32_t>(userMetadataSize), alloc_cb) - .isOk()) { + if (!bufferhub->allocateBuffer(desc, static_cast<uint32_t>(userMetadataSize), allocCb).isOk()) { ALOGE("%s: allocateBuffer transaction failed!", __FUNCTION__); return; } else if (ret != BufferHubStatus::NO_ERROR) { @@ -115,8 +114,8 @@ BufferHubBuffer::BufferHubBuffer(const sp<NativeHandle>& token) { BufferHubStatus ret; sp<IBufferClient> client; BufferTraits bufferTraits; - IBufferHub::importBuffer_cb import_cb = [&](const auto& status, const auto& outClient, - const auto& outTraits) { + IBufferHub::importBuffer_cb importCb = [&](const auto& status, const auto& outClient, + const auto& outTraits) { ret = status; client = std::move(outClient); bufferTraits = std::move(outTraits); @@ -124,7 +123,7 @@ BufferHubBuffer::BufferHubBuffer(const sp<NativeHandle>& token) { // hidl_handle(native_handle_t*) simply creates a raw pointer reference withouth ownership // transfer. - if (!bufferhub->importBuffer(hidl_handle(token.get()->handle()), import_cb).isOk()) { + if (!bufferhub->importBuffer(hidl_handle(token.get()->handle()), importCb).isOk()) { ALOGE("%s: importBuffer transaction failed!", __FUNCTION__); return; } else if (ret != BufferHubStatus::NO_ERROR) { @@ -210,9 +209,9 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) { // Populate shortcuts to the atomics in metadata. auto metadataHeader = mMetadata.metadataHeader(); - mBufferState = &metadataHeader->buffer_state; - mFenceState = &metadataHeader->fence_state; - mActiveClientsBitMask = &metadataHeader->active_clients_bit_mask; + mBufferState = &metadataHeader->bufferState; + mFenceState = &metadataHeader->fenceState; + mActiveClientsBitMask = &metadataHeader->activeClientsBitMask; // The C++ standard recommends (but does not require) that lock-free atomic operations are // also address-free, that is, suitable for communication between processes using shared // memory. @@ -230,7 +229,7 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) { mClientStateMask = clientBitMask; // TODO(b/112012161) Set up shared fences. - ALOGD("%s: id=%d, buffer_state=%" PRIx32 ".", __FUNCTION__, mId, + ALOGD("%s: id=%d, mBufferState=%" PRIx32 ".", __FUNCTION__, mId, mBufferState->load(std::memory_order_acquire)); return 0; } @@ -336,12 +335,12 @@ sp<NativeHandle> BufferHubBuffer::duplicate() { hidl_handle token; BufferHubStatus ret; - IBufferClient::duplicate_cb dup_cb = [&](const auto& outToken, const auto& status) { + IBufferClient::duplicate_cb dupCb = [&](const auto& outToken, const auto& status) { token = std::move(outToken); ret = status; }; - if (!mBufferClient->duplicate(dup_cb).isOk()) { + if (!mBufferClient->duplicate(dupCb).isOk()) { ALOGE("%s: duplicate transaction failed!", __FUNCTION__); return nullptr; } else if (ret != BufferHubStatus::NO_ERROR) { diff --git a/libs/ui/include/ui/BufferHubBuffer.h b/libs/ui/include/ui/BufferHubBuffer.h index 5c0903251a..5ba189c2c3 100644 --- a/libs/ui/include/ui/BufferHubBuffer.h +++ b/libs/ui/include/ui/BufferHubBuffer.h @@ -57,7 +57,7 @@ public: const BufferHubEventFd& eventFd() const { return mEventFd; } - // Returns the current value of MetadataHeader::buffer_state. + // Returns the current value of MetadataHeader::bufferState. uint32_t bufferState() const { return mBufferState->load(std::memory_order_acquire); } // A state mask which is unique to a buffer hub client among all its siblings sharing the same diff --git a/libs/ui/include/ui/BufferHubDefs.h b/libs/ui/include/ui/BufferHubDefs.h index 722a060597..10f274f569 100644 --- a/libs/ui/include/ui/BufferHubDefs.h +++ b/libs/ui/include/ui/BufferHubDefs.h @@ -32,7 +32,7 @@ namespace BufferHubDefs { // Single buffer clients (up to 16) ownership signal. // 32-bit atomic unsigned int. // Each client takes 2 bits. The first bit locates in the first 16 bits of -// buffer_state; the second bit locates in the last 16 bits of buffer_state. +// bufferState; the second bit locates in the last 16 bits of bufferState. // Client states: // Gained state 11. Exclusive write state. // Posted state 10. @@ -64,9 +64,9 @@ static constexpr uint32_t kFirstClientBitMask = (1U << kMaxNumberOfClients) + 1U // Returns true if any of the client is in gained state. static inline bool isAnyClientGained(uint32_t state) { - uint32_t high_bits = state >> kMaxNumberOfClients; - uint32_t low_bits = state & kLowbitsMask; - return high_bits == low_bits && low_bits != 0U; + uint32_t highBits = state >> kMaxNumberOfClients; + uint32_t lowBits = state & kLowbitsMask; + return highBits == lowBits && lowBits != 0U; } // Returns true if the input client is in gained state. @@ -76,34 +76,34 @@ static inline bool isClientGained(uint32_t state, uint32_t client_bit_mask) { // Returns true if any of the client is in posted state. static inline bool isAnyClientPosted(uint32_t state) { - uint32_t high_bits = state >> kMaxNumberOfClients; - uint32_t low_bits = state & kLowbitsMask; - uint32_t posted_or_acquired = high_bits ^ low_bits; - return posted_or_acquired & high_bits; + uint32_t highBits = state >> kMaxNumberOfClients; + uint32_t lowBits = state & kLowbitsMask; + uint32_t postedOrAcquired = highBits ^ lowBits; + return postedOrAcquired & highBits; } // Returns true if the input client is in posted state. static inline bool isClientPosted(uint32_t state, uint32_t client_bit_mask) { - uint32_t client_bits = state & client_bit_mask; - if (client_bits == 0U) return false; - uint32_t low_bits = client_bits & kLowbitsMask; - return low_bits == 0U; + uint32_t clientBits = state & client_bit_mask; + if (clientBits == 0U) return false; + uint32_t lowBits = clientBits & kLowbitsMask; + return lowBits == 0U; } // Return true if any of the client is in acquired state. static inline bool isAnyClientAcquired(uint32_t state) { - uint32_t high_bits = state >> kMaxNumberOfClients; - uint32_t low_bits = state & kLowbitsMask; - uint32_t posted_or_acquired = high_bits ^ low_bits; - return posted_or_acquired & low_bits; + uint32_t highBits = state >> kMaxNumberOfClients; + uint32_t lowBits = state & kLowbitsMask; + uint32_t postedOrAcquired = highBits ^ lowBits; + return postedOrAcquired & lowBits; } // Return true if the input client is in acquired state. static inline bool isClientAcquired(uint32_t state, uint32_t client_bit_mask) { - uint32_t client_bits = state & client_bit_mask; - if (client_bits == 0U) return false; - uint32_t high_bits = client_bits & kHighBitsMask; - return high_bits == 0U; + uint32_t clientBits = state & client_bit_mask; + if (clientBits == 0U) return false; + uint32_t highBits = clientBits & kHighBitsMask; + return highBits == 0U; } // Returns true if the input client is in released state. @@ -114,12 +114,12 @@ static inline bool isClientReleased(uint32_t state, uint32_t client_bit_mask) { // Returns the next available buffer client's client_state_masks. // @params union_bits. Union of all existing clients' client_state_masks. static inline uint32_t findNextAvailableClientStateMask(uint32_t union_bits) { - uint32_t low_union = union_bits & kLowbitsMask; - if (low_union == kLowbitsMask) return 0U; - uint32_t incremented = low_union + 1U; - uint32_t difference = incremented ^ low_union; - uint32_t new_low_bit = (difference + 1U) >> 1; - return new_low_bit + (new_low_bit << kMaxNumberOfClients); + uint32_t lowUnion = union_bits & kLowbitsMask; + if (lowUnion == kLowbitsMask) return 0U; + uint32_t incremented = lowUnion + 1U; + uint32_t difference = incremented ^ lowUnion; + uint32_t newLowBit = (difference + 1U) >> 1; + return newLowBit + (newLowBit << kMaxNumberOfClients); } struct __attribute__((aligned(8))) MetadataHeader { @@ -129,22 +129,22 @@ struct __attribute__((aligned(8))) MetadataHeader { // platform (include Apps and vendor HAL). // Every client takes up one bit from the higher 32 bits and one bit from the lower 32 bits in - // buffer_state. - std::atomic<uint32_t> buffer_state; + // bufferState. + std::atomic<uint32_t> bufferState; - // Every client takes up one bit in fence_state. Only the lower 32 bits are valid. The upper 32 + // Every client takes up one bit in fenceState. Only the lower 32 bits are valid. The upper 32 // bits are there for easier manipulation, but the value should be ignored. - std::atomic<uint32_t> fence_state; + std::atomic<uint32_t> fenceState; // Every client takes up one bit from the higher 32 bits and one bit from the lower 32 bits in - // active_clients_bit_mask. - std::atomic<uint32_t> active_clients_bit_mask; + // activeClientsBitMask. + std::atomic<uint32_t> activeClientsBitMask; // Explicit padding 4 bytes. uint32_t padding; // The index of the buffer queue where the buffer belongs to. - uint64_t queue_index; + uint64_t queueIndex; // Public data format, which should be updated with caution. See more details in dvr_api.h DvrNativeBufferMetadata metadata; diff --git a/libs/ui/tests/BufferHubMetadata_test.cpp b/libs/ui/tests/BufferHubMetadata_test.cpp index f02c4fc178..eb978cabc6 100644 --- a/libs/ui/tests/BufferHubMetadata_test.cpp +++ b/libs/ui/tests/BufferHubMetadata_test.cpp @@ -51,7 +51,7 @@ TEST_F(BufferHubMetadataTest, Import_Success) { // Check if the newly allocated buffer is initialized in released state (i.e. // state equals to 0U). - EXPECT_TRUE(mh1->buffer_state.load() == 0U); + EXPECT_TRUE(mh1->bufferState.load() == 0U); EXPECT_TRUE(m2.isValid()); BufferHubDefs::MetadataHeader* mh2 = m2.metadataHeader(); @@ -59,7 +59,7 @@ TEST_F(BufferHubMetadataTest, Import_Success) { // Check if the newly allocated buffer is initialized in released state (i.e. // state equals to 0U). - EXPECT_TRUE(mh2->buffer_state.load() == 0U); + EXPECT_TRUE(mh2->bufferState.load() == 0U); } TEST_F(BufferHubMetadataTest, MoveMetadataInvalidatesOldOne) { diff --git a/libs/vr/libbufferhub/buffer_hub_base.cpp b/libs/vr/libbufferhub/buffer_hub_base.cpp index b28d10147b..17930b4405 100644 --- a/libs/vr/libbufferhub/buffer_hub_base.cpp +++ b/libs/vr/libbufferhub/buffer_hub_base.cpp @@ -122,15 +122,15 @@ int BufferHubBase::ImportBuffer() { // are mapped from shared memory as an atomic object. The std::atomic's // constructor will not be called so that the original value stored in the // memory region will be preserved. - buffer_state_ = &metadata_header_->buffer_state; + buffer_state_ = &metadata_header_->bufferState; ALOGD_IF(TRACE, "BufferHubBase::ImportBuffer: id=%d, buffer_state=%" PRIx32 ".", id(), buffer_state_->load(std::memory_order_acquire)); - fence_state_ = &metadata_header_->fence_state; + fence_state_ = &metadata_header_->fenceState; ALOGD_IF(TRACE, "BufferHubBase::ImportBuffer: id=%d, fence_state=%" PRIx32 ".", id(), fence_state_->load(std::memory_order_acquire)); - active_clients_bit_mask_ = &metadata_header_->active_clients_bit_mask; + active_clients_bit_mask_ = &metadata_header_->activeClientsBitMask; ALOGD_IF( TRACE, "BufferHubBase::ImportBuffer: id=%d, active_clients_bit_mask=%" PRIx32 diff --git a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_base.h b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_base.h index fa39d081e1..8a490d9983 100644 --- a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_base.h +++ b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_base.h @@ -97,8 +97,8 @@ class BufferHubBase : public pdx::Client { uint32_t usage() const { return buffer_.usage(); } uint32_t layer_count() const { return buffer_.layer_count(); } - uint64_t GetQueueIndex() const { return metadata_header_->queue_index; } - void SetQueueIndex(uint64_t index) { metadata_header_->queue_index = index; } + uint64_t GetQueueIndex() const { return metadata_header_->queueIndex; } + void SetQueueIndex(uint64_t index) { metadata_header_->queueIndex = index; } protected: explicit BufferHubBase(LocalChannelHandle channel); diff --git a/services/bufferhub/BufferHubService.cpp b/services/bufferhub/BufferHubService.cpp index ade08e7d17..7a3472fa7e 100644 --- a/services/bufferhub/BufferHubService.cpp +++ b/services/bufferhub/BufferHubService.cpp @@ -241,8 +241,8 @@ Return<void> BufferHubService::debug(const hidl_handle& fd, const hidl_vec<hidl_ MetadataHeader* metadataHeader = const_cast<BufferHubMetadata*>(&node->metadata())->metadataHeader(); - const uint32_t state = metadataHeader->buffer_state.load(std::memory_order_acquire); - const uint64_t index = metadataHeader->queue_index; + const uint32_t state = metadataHeader->bufferState.load(std::memory_order_acquire); + const uint64_t index = metadataHeader->queueIndex; stream << std::right; stream << std::setw(6) << /*Id=*/node->id(); diff --git a/services/bufferhub/BufferNode.cpp b/services/bufferhub/BufferNode.cpp index 1efb27ee0a..04ca6493f7 100644 --- a/services/bufferhub/BufferNode.cpp +++ b/services/bufferhub/BufferNode.cpp @@ -15,9 +15,9 @@ void BufferNode::initializeMetadata() { // Using placement new here to reuse shared memory instead of new allocation // Initialize the atomic variables to zero. BufferHubDefs::MetadataHeader* metadataHeader = mMetadata.metadataHeader(); - mBufferState = new (&metadataHeader->buffer_state) std::atomic<uint32_t>(0); - mFenceState = new (&metadataHeader->fence_state) std::atomic<uint32_t>(0); - mActiveClientsBitMask = new (&metadataHeader->active_clients_bit_mask) std::atomic<uint32_t>(0); + mBufferState = new (&metadataHeader->bufferState) std::atomic<uint32_t>(0); + mFenceState = new (&metadataHeader->fenceState) std::atomic<uint32_t>(0); + mActiveClientsBitMask = new (&metadataHeader->activeClientsBitMask) std::atomic<uint32_t>(0); // The C++ standard recommends (but does not require) that lock-free atomic operations are // also address-free, that is, suitable for communication between processes using shared // memory. diff --git a/services/vr/bufferhubd/producer_channel.cpp b/services/vr/bufferhubd/producer_channel.cpp index f3e54a0ed2..b49d89470f 100644 --- a/services/vr/bufferhubd/producer_channel.cpp +++ b/services/vr/bufferhubd/producer_channel.cpp @@ -91,11 +91,10 @@ int ProducerChannel::InitializeBuffer() { // Using placement new here to reuse shared memory instead of new allocation // and also initialize the value to zero. - buffer_state_ = - new (&metadata_header_->buffer_state) std::atomic<uint32_t>(0); - fence_state_ = new (&metadata_header_->fence_state) std::atomic<uint32_t>(0); + buffer_state_ = new (&metadata_header_->bufferState) std::atomic<uint32_t>(0); + fence_state_ = new (&metadata_header_->fenceState) std::atomic<uint32_t>(0); active_clients_bit_mask_ = - new (&metadata_header_->active_clients_bit_mask) std::atomic<uint32_t>(0); + new (&metadata_header_->activeClientsBitMask) std::atomic<uint32_t>(0); // Producer channel is never created after consumer channel, and one buffer // only have one fixed producer for now. Thus, it is correct to assume @@ -183,7 +182,7 @@ BufferHubChannel::BufferInfo ProducerChannel::GetBufferInfo() const { buffer_.height(), buffer_.layer_count(), buffer_.format(), buffer_.usage(), buffer_state_->load(std::memory_order_acquire), - signaled_mask, metadata_header_->queue_index); + signaled_mask, metadata_header_->queueIndex); } void ProducerChannel::HandleImpulse(Message& message) { @@ -547,7 +546,7 @@ Status<void> ProducerChannel::OnConsumerRelease(Message&, "%s: orphaned buffer detected during the this acquire/release cycle: " "id=%d orphaned=0x%" PRIx32 " queue_index=%" PRId64 ".", __FUNCTION__, buffer_id(), orphaned_consumer_bit_mask_, - metadata_header_->queue_index); + metadata_header_->queueIndex); orphaned_consumer_bit_mask_ = 0; } } @@ -581,7 +580,7 @@ void ProducerChannel::OnConsumerOrphaned(const uint32_t& consumer_state_mask) { "consumer_state_mask=%" PRIx32 " queue_index=%" PRId64 " buffer_state=%" PRIx32 " fence_state=%" PRIx32 ".", __FUNCTION__, buffer_id(), consumer_state_mask, - metadata_header_->queue_index, + metadata_header_->queueIndex, buffer_state_->load(std::memory_order_acquire), fence_state_->load(std::memory_order_acquire)); } |