diff options
| author | 2018-12-04 11:32:39 -0800 | |
|---|---|---|
| committer | 2018-12-12 14:59:56 -0800 | |
| commit | d34a80a63b47dd6c046afb2be47fa55e6ca7a284 (patch) | |
| tree | 95b09b6fcb64b9a56ed1679d95487d9145b31a9f | |
| parent | cfbe07453ebd7cde74a7ed75568ee2c81d726049 (diff) | |
Move BufferHubDefs namespace to ui/BufferHubDefs.h
And move libbufferhubservice off libbufferhub_headers and libpdx_headers
dependency.
Test: build passed, including all the tests under libui and
libbufferhubservice
Bug: 118893702
Change-Id: I8163a7524c6078f9fbb264cf5253d8cbe05dd1c4
| -rw-r--r-- | libs/ui/include/ui/BufferHubDefs.h | 98 | ||||
| -rw-r--r-- | libs/ui/tests/Android.bp | 6 | ||||
| -rw-r--r-- | libs/ui/tests/BufferHubMetadata_test.cpp | 4 | ||||
| -rw-r--r-- | libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h | 88 | ||||
| -rw-r--r-- | services/bufferhub/Android.bp | 4 | ||||
| -rw-r--r-- | services/bufferhub/BufferNode.cpp | 10 | ||||
| -rw-r--r-- | services/bufferhub/tests/Android.bp | 4 | ||||
| -rw-r--r-- | services/bufferhub/tests/BufferNode_test.cpp | 5 |
8 files changed, 124 insertions, 95 deletions
diff --git a/libs/ui/include/ui/BufferHubDefs.h b/libs/ui/include/ui/BufferHubDefs.h index a1948256f5..ef6668bd76 100644 --- a/libs/ui/include/ui/BufferHubDefs.h +++ b/libs/ui/include/ui/BufferHubDefs.h @@ -29,6 +29,104 @@ namespace android { namespace BufferHubDefs { +// Single buffer clients (up to 32) ownership signal. +// 64-bit atomic unsigned int. +// Each client takes 2 bits. The first bit locates in the first 32 bits of +// buffer_state; the second bit locates in the last 32 bits of buffer_state. +// Client states: +// Gained state 11. Exclusive write state. +// Posted state 10. +// Acquired state 01. Shared read state. +// Released state 00. +// +// MSB LSB +// | | +// v v +// [C31|...|C1|C0|C31| ... |C1|C0] + +// Maximum number of clients a buffer can have. +static constexpr int kMaxNumberOfClients = 32; + +// Definition of bit masks. +// MSB LSB +// | kHighBitsMask | kLowbitsMask | +// v v v +// [b63| ... |b32|b31| ... |b0] + +// The location of lower 32 bits in the 64-bit buffer state. +static constexpr uint64_t kLowbitsMask = (1ULL << kMaxNumberOfClients) - 1ULL; + +// The location of higher 32 bits in the 64-bit buffer state. +static constexpr uint64_t kHighBitsMask = ~kLowbitsMask; + +// The client bit mask of the first client. +static constexpr uint64_t kFirstClientBitMask = (1ULL << kMaxNumberOfClients) + 1ULL; + +// Returns true if any of the client is in gained state. +static inline bool AnyClientGained(uint64_t state) { + uint64_t high_bits = state >> kMaxNumberOfClients; + uint64_t low_bits = state & kLowbitsMask; + return high_bits == low_bits && low_bits != 0ULL; +} + +// Returns true if the input client is in gained state. +static inline bool IsClientGained(uint64_t state, uint64_t client_bit_mask) { + return state == client_bit_mask; +} + +// Returns true if any of the client is in posted state. +static inline bool AnyClientPosted(uint64_t state) { + uint64_t high_bits = state >> kMaxNumberOfClients; + uint64_t low_bits = state & kLowbitsMask; + uint64_t posted_or_acquired = high_bits ^ low_bits; + return posted_or_acquired & high_bits; +} + +// Returns true if the input client is in posted state. +static inline bool IsClientPosted(uint64_t state, uint64_t client_bit_mask) { + uint64_t client_bits = state & client_bit_mask; + if (client_bits == 0ULL) return false; + uint64_t low_bits = client_bits & kLowbitsMask; + return low_bits == 0ULL; +} + +// Return true if any of the client is in acquired state. +static inline bool AnyClientAcquired(uint64_t state) { + uint64_t high_bits = state >> kMaxNumberOfClients; + uint64_t low_bits = state & kLowbitsMask; + uint64_t posted_or_acquired = high_bits ^ low_bits; + return posted_or_acquired & low_bits; +} + +// Return true if the input client is in acquired state. +static inline bool IsClientAcquired(uint64_t state, uint64_t client_bit_mask) { + uint64_t client_bits = state & client_bit_mask; + if (client_bits == 0ULL) return false; + uint64_t high_bits = client_bits & kHighBitsMask; + return high_bits == 0ULL; +} + +// Returns true if all clients are in released state. +static inline bool IsBufferReleased(uint64_t state) { + return state == 0ULL; +} + +// Returns true if the input client is in released state. +static inline bool IsClientReleased(uint64_t state, uint64_t client_bit_mask) { + return (state & client_bit_mask) == 0ULL; +} + +// Returns the next available buffer client's client_state_masks. +// @params union_bits. Union of all existing clients' client_state_masks. +static inline uint64_t FindNextAvailableClientStateMask(uint64_t union_bits) { + uint64_t low_union = union_bits & kLowbitsMask; + if (low_union == kLowbitsMask) return 0ULL; + uint64_t incremented = low_union + 1ULL; + uint64_t difference = incremented ^ low_union; + uint64_t new_low_bit = (difference + 1ULL) >> 1; + return new_low_bit + (new_low_bit << kMaxNumberOfClients); +} + struct __attribute__((aligned(8))) MetadataHeader { // Internal data format, which can be updated as long as the size, padding and field alignment // of the struct is consistent within the same ABI. As this part is subject for future updates, diff --git a/libs/ui/tests/Android.bp b/libs/ui/tests/Android.bp index ca73be79d1..c0f4c8916c 100644 --- a/libs/ui/tests/Android.bp +++ b/libs/ui/tests/Android.bp @@ -73,11 +73,7 @@ cc_test { cc_test { name: "BufferHubMetadata_test", - header_libs: [ - "libbufferhub_headers", - "libdvr_headers", - "libpdx_headers", - ], + header_libs: ["libdvr_headers"], shared_libs: [ "libbase", "libui", diff --git a/libs/ui/tests/BufferHubMetadata_test.cpp b/libs/ui/tests/BufferHubMetadata_test.cpp index 2265336c30..11f8e57adc 100644 --- a/libs/ui/tests/BufferHubMetadata_test.cpp +++ b/libs/ui/tests/BufferHubMetadata_test.cpp @@ -15,11 +15,9 @@ */ #include <gtest/gtest.h> -#include <private/dvr/buffer_hub_defs.h> #include <ui/BufferHubMetadata.h> -// TODO(b/118893702): move this function to ui/BufferHubDefs.h after ag/5483995 is landed -using android::dvr::BufferHubDefs::IsBufferReleased; +using android::BufferHubDefs::IsBufferReleased; namespace android { namespace dvr { diff --git a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h index 62ef475f16..2de36f26a6 100644 --- a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h +++ b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h @@ -19,104 +19,50 @@ static constexpr uint32_t kMetadataFormat = HAL_PIXEL_FORMAT_BLOB; static constexpr uint32_t kMetadataUsage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; -// Single buffer clients (up to 32) ownership signal. -// 64-bit atomic unsigned int. -// Each client takes 2 bits. The first bit locates in the first 32 bits of -// buffer_state; the second bit locates in the last 32 bits of buffer_state. -// Client states: -// Gained state 11. Exclusive write state. -// Posted state 10. -// Acquired state 01. Shared read state. -// Released state 00. -// -// MSB LSB -// | | -// v v -// [C31|...|C1|C0|C31| ... |C1|C0] - -// Maximum number of clients a buffer can have. -static constexpr int kMaxNumberOfClients = 32; - -// Definition of bit masks. -// MSB LSB -// | kHighBitsMask | kLowbitsMask | -// v v v -// [b63| ... |b32|b31| ... |b0] - -// The location of lower 32 bits in the 64-bit buffer state. -static constexpr uint64_t kLowbitsMask = (1ULL << kMaxNumberOfClients) - 1ULL; - -// The location of higher 32 bits in the 64-bit buffer state. -static constexpr uint64_t kHighBitsMask = ~kLowbitsMask; - -// The client bit mask of the first client. +// See more details in libs/ui/include/ui/BufferHubDefs.h +static constexpr int kMaxNumberOfClients = + android::BufferHubDefs::kMaxNumberOfClients; +static constexpr uint64_t kLowbitsMask = android::BufferHubDefs::kLowbitsMask; +static constexpr uint64_t kHighBitsMask = android::BufferHubDefs::kHighBitsMask; static constexpr uint64_t kFirstClientBitMask = - (1ULL << kMaxNumberOfClients) + 1ULL; + android::BufferHubDefs::kFirstClientBitMask; -// Returns true if any of the client is in gained state. static inline bool AnyClientGained(uint64_t state) { - uint64_t high_bits = state >> kMaxNumberOfClients; - uint64_t low_bits = state & kLowbitsMask; - return high_bits == low_bits && low_bits != 0ULL; + return android::BufferHubDefs::AnyClientGained(state); } -// Returns true if the input client is in gained state. static inline bool IsClientGained(uint64_t state, uint64_t client_bit_mask) { - return state == client_bit_mask; + return android::BufferHubDefs::IsClientGained(state, client_bit_mask); } -// Returns true if any of the client is in posted state. static inline bool AnyClientPosted(uint64_t state) { - uint64_t high_bits = state >> kMaxNumberOfClients; - uint64_t low_bits = state & kLowbitsMask; - uint64_t posted_or_acquired = high_bits ^ low_bits; - return posted_or_acquired & high_bits; + return android::BufferHubDefs::AnyClientPosted(state); } -// Returns true if the input client is in posted state. static inline bool IsClientPosted(uint64_t state, uint64_t client_bit_mask) { - uint64_t client_bits = state & client_bit_mask; - if (client_bits == 0ULL) - return false; - uint64_t low_bits = client_bits & kLowbitsMask; - return low_bits == 0ULL; + return android::BufferHubDefs::IsClientPosted(state, client_bit_mask); } -// Return true if any of the client is in acquired state. static inline bool AnyClientAcquired(uint64_t state) { - uint64_t high_bits = state >> kMaxNumberOfClients; - uint64_t low_bits = state & kLowbitsMask; - uint64_t posted_or_acquired = high_bits ^ low_bits; - return posted_or_acquired & low_bits; + return android::BufferHubDefs::AnyClientAcquired(state); } -// Return true if the input client is in acquired state. static inline bool IsClientAcquired(uint64_t state, uint64_t client_bit_mask) { - uint64_t client_bits = state & client_bit_mask; - if (client_bits == 0ULL) - return false; - uint64_t high_bits = client_bits & kHighBitsMask; - return high_bits == 0ULL; + return android::BufferHubDefs::IsClientAcquired(state, client_bit_mask); } -// Returns true if all clients are in released state. -static inline bool IsBufferReleased(uint64_t state) { return state == 0ULL; } +static inline bool IsBufferReleased(uint64_t state) { + return android::BufferHubDefs::IsBufferReleased(state); +} -// Returns true if the input client is in released state. static inline bool IsClientReleased(uint64_t state, uint64_t client_bit_mask) { - return (state & client_bit_mask) == 0ULL; + return android::BufferHubDefs::IsClientReleased(state, 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 uint64_t FindNextAvailableClientStateMask(uint64_t union_bits) { - uint64_t low_union = union_bits & kLowbitsMask; - if (low_union == kLowbitsMask) - return 0ULL; - uint64_t incremented = low_union + 1ULL; - uint64_t difference = incremented ^ low_union; - uint64_t new_low_bit = (difference + 1ULL) >> 1; - return new_low_bit + (new_low_bit << kMaxNumberOfClients); + return android::BufferHubDefs::FindNextAvailableClientStateMask(union_bits); } using MetadataHeader = android::BufferHubDefs::MetadataHeader; diff --git a/services/bufferhub/Android.bp b/services/bufferhub/Android.bp index f9aaa2050f..72d210cbb0 100644 --- a/services/bufferhub/Android.bp +++ b/services/bufferhub/Android.bp @@ -29,10 +29,8 @@ cc_library_shared { "BufferNode.cpp", ], header_libs: [ - "libbufferhub_headers", "libdvr_headers", "libnativewindow_headers", - "libpdx_headers", ], shared_libs: [ "android.frameworks.bufferhub@1.0", @@ -56,10 +54,8 @@ cc_binary { "main_bufferhub.cpp" ], header_libs: [ - "libbufferhub_headers", "libdvr_headers", "libnativewindow_headers", - "libpdx_headers", ], shared_libs: [ "android.frameworks.bufferhub@1.0", diff --git a/services/bufferhub/BufferNode.cpp b/services/bufferhub/BufferNode.cpp index ec84849e22..4bad829210 100644 --- a/services/bufferhub/BufferNode.cpp +++ b/services/bufferhub/BufferNode.cpp @@ -2,7 +2,6 @@ #include <bufferhub/BufferHubService.h> #include <bufferhub/BufferNode.h> -#include <private/dvr/buffer_hub_defs.h> #include <ui/GraphicBufferAllocator.h> namespace android { @@ -14,7 +13,7 @@ namespace implementation { void BufferNode::InitializeMetadata() { // Using placement new here to reuse shared memory instead of new allocation // Initialize the atomic variables to zero. - dvr::BufferHubDefs::MetadataHeader* metadata_header = metadata_.metadata_header(); + BufferHubDefs::MetadataHeader* metadata_header = metadata_.metadata_header(); buffer_state_ = new (&metadata_header->buffer_state) std::atomic<uint64_t>(0); fence_state_ = new (&metadata_header->fence_state) std::atomic<uint64_t>(0); active_clients_bit_mask_ = @@ -84,10 +83,11 @@ uint64_t BufferNode::AddNewActiveClientsBitToMask() { uint64_t client_state_mask = 0ULL; uint64_t updated_active_clients_bit_mask = 0ULL; do { - client_state_mask = dvr::BufferHubDefs::FindNextAvailableClientStateMask( - current_active_clients_bit_mask); + client_state_mask = + BufferHubDefs::FindNextAvailableClientStateMask(current_active_clients_bit_mask); if (client_state_mask == 0ULL) { - ALOGE("%s: reached the maximum number of channels per buffer node: 32.", __FUNCTION__); + ALOGE("%s: reached the maximum number of channels per buffer node: %d.", __FUNCTION__, + BufferHubDefs::kMaxNumberOfClients); errno = E2BIG; return 0ULL; } diff --git a/services/bufferhub/tests/Android.bp b/services/bufferhub/tests/Android.bp index 39678865cb..bf65469784 100644 --- a/services/bufferhub/tests/Android.bp +++ b/services/bufferhub/tests/Android.bp @@ -7,10 +7,8 @@ cc_test { "-DATRACE_TAG=ATRACE_TAG_GRAPHICS", ], header_libs: [ - "libbufferhub_headers", "libdvr_headers", "libnativewindow_headers", - "libpdx_headers", ], shared_libs: [ "libbufferhubservice", @@ -19,8 +17,6 @@ cc_test { static_libs: [ "libgmock", ], - // TODO(b/117568153): Temporarily opt out using libcrt. - no_libcrt: true, } cc_test { diff --git a/services/bufferhub/tests/BufferNode_test.cpp b/services/bufferhub/tests/BufferNode_test.cpp index 3358c87eb8..8555eb7800 100644 --- a/services/bufferhub/tests/BufferNode_test.cpp +++ b/services/bufferhub/tests/BufferNode_test.cpp @@ -3,7 +3,7 @@ #include <bufferhub/BufferNode.h> #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <private/dvr/buffer_hub_defs.h> +#include <ui/BufferHubDefs.h> #include <ui/GraphicBufferMapper.h> namespace android { @@ -22,7 +22,6 @@ const uint32_t kLayerCount = 1; const uint32_t kFormat = 1; const uint64_t kUsage = 0; const size_t kUserMetadataSize = 0; -const size_t kMaxClientsCount = dvr::BufferHubDefs::kMaxNumberOfClients; class BufferNodeTest : public ::testing::Test { protected: @@ -73,7 +72,7 @@ TEST_F(BufferNodeTest, TestAddNewActiveClientsBitToMask_32NewClients) { uint64_t current_mask = 0ULL; uint64_t expected_mask = 0ULL; - for (int i = 0; i < kMaxClientsCount; ++i) { + for (int i = 0; i < BufferHubDefs::kMaxNumberOfClients; ++i) { new_client_state_mask = buffer_node->AddNewActiveClientsBitToMask(); EXPECT_NE(new_client_state_mask, 0); EXPECT_FALSE(new_client_state_mask & current_mask); |