diff options
author | 2018-11-21 15:03:32 -0800 | |
---|---|---|
committer | 2018-12-12 14:35:50 -0800 | |
commit | cfbe07453ebd7cde74a7ed75568ee2c81d726049 (patch) | |
tree | ca279be9a83a1a78a93eaeed646fa38b49ee3071 | |
parent | faba0dc129e2d73bb8fc313bfa337baddb2582d6 (diff) |
Move MetadataHeader to libui
To remove BufferHubMetadata off pdx dependency.
Note that the __attribute__(packed) is removed as part of this CL, as
it's not really needed and is triggering clang warnings.
Test: build passed. Not test needed as no behavior changes.
Bug: 118893702
Change-Id: Ifae94a143a2bedef68a653c57f089b95d166e6d7
-rw-r--r-- | libs/ui/BufferHubBuffer.cpp | 4 | ||||
-rw-r--r-- | libs/ui/BufferHubMetadata.cpp | 5 | ||||
-rw-r--r-- | libs/ui/include/ui/BufferHubDefs.h | 64 | ||||
-rw-r--r-- | libs/ui/include/ui/BufferHubMetadata.h | 30 | ||||
-rw-r--r-- | libs/ui/tests/Android.bp | 7 | ||||
-rw-r--r-- | libs/ui/tests/BufferHubMetadata_test.cpp | 2 | ||||
-rw-r--r-- | libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h | 36 | ||||
-rw-r--r-- | libs/vr/libdvr/include/dvr/dvr_api.h | 1 | ||||
-rw-r--r-- | services/bufferhub/BufferClient.cpp | 1 | ||||
-rw-r--r-- | services/bufferhub/include/bufferhub/BufferNode.h | 1 | ||||
-rw-r--r-- | services/bufferhub/tests/BufferNode_test.cpp | 4 |
11 files changed, 91 insertions, 64 deletions
diff --git a/libs/ui/BufferHubBuffer.cpp b/libs/ui/BufferHubBuffer.cpp index 3816c1bc4f..36eaed93ad 100644 --- a/libs/ui/BufferHubBuffer.cpp +++ b/libs/ui/BufferHubBuffer.cpp @@ -40,6 +40,7 @@ #include <android-base/unique_fd.h> #include <ui/BufferHubBuffer.h> +#include <ui/BufferHubDefs.h> using android::base::unique_fd; using android::dvr::BufferTraits; @@ -69,7 +70,6 @@ using dvr::BufferHubDefs::IsClientGained; using dvr::BufferHubDefs::IsClientPosted; using dvr::BufferHubDefs::IsClientReleased; using dvr::BufferHubDefs::kHighBitsMask; -using dvr::BufferHubDefs::kMetadataHeaderSize; } // namespace @@ -161,7 +161,7 @@ int BufferHubBuffer::ImportGraphicBuffer() { } size_t metadataSize = static_cast<size_t>(bufferTraits.metadata_size()); - if (metadataSize < kMetadataHeaderSize) { + if (metadataSize < BufferHubDefs::kMetadataHeaderSize) { ALOGE("BufferHubBuffer::ImportGraphicBuffer: metadata too small: %zu", metadataSize); return -EINVAL; } diff --git a/libs/ui/BufferHubMetadata.cpp b/libs/ui/BufferHubMetadata.cpp index 18d9a2c963..816707db9d 100644 --- a/libs/ui/BufferHubMetadata.cpp +++ b/libs/ui/BufferHubMetadata.cpp @@ -16,6 +16,7 @@ #include <errno.h> #include <sys/mman.h> +#include <limits> #include <cutils/ashmem.h> #include <log/log.h> @@ -29,8 +30,8 @@ static const int kAshmemProt = PROT_READ | PROT_WRITE; } // namespace -using dvr::BufferHubDefs::kMetadataHeaderSize; -using dvr::BufferHubDefs::MetadataHeader; +using BufferHubDefs::kMetadataHeaderSize; +using BufferHubDefs::MetadataHeader; /* static */ BufferHubMetadata BufferHubMetadata::Create(size_t userMetadataSize) { diff --git a/libs/ui/include/ui/BufferHubDefs.h b/libs/ui/include/ui/BufferHubDefs.h new file mode 100644 index 0000000000..a1948256f5 --- /dev/null +++ b/libs/ui/include/ui/BufferHubDefs.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_BUFFER_HUB_DEFS_H_ +#define ANDROID_BUFFER_HUB_DEFS_H_ + +#include <atomic> + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" +// TODO(b/118893702): remove dependency once DvrNativeBufferMetadata moved out of libdvr +#include <dvr/dvr_api.h> +#pragma clang diagnostic pop + +namespace android { + +namespace BufferHubDefs { + +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, + // it's not stable cross Android version, so don't have it visible from outside of the Android + // 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<uint64_t> buffer_state; + + // Every client takes up one bit in fence_state. Only the lower 32 bits are valid. The upper 32 + // bits are there for easier manipulation, but the value should be ignored. + std::atomic<uint64_t> fence_state; + + // 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<uint64_t> active_clients_bit_mask; + + // The index of the buffer queue where the buffer belongs to. + uint64_t queue_index; + + // Public data format, which should be updated with caution. See more details in dvr_api.h + DvrNativeBufferMetadata metadata; +}; + +static_assert(sizeof(MetadataHeader) == 136, "Unexpected MetadataHeader size"); +static constexpr size_t kMetadataHeaderSize = sizeof(MetadataHeader); + +} // namespace BufferHubDefs + +} // namespace android + +#endif // ANDROID_BUFFER_HUB_DEFS_H_ diff --git a/libs/ui/include/ui/BufferHubMetadata.h b/libs/ui/include/ui/BufferHubMetadata.h index 4261971f55..212189497a 100644 --- a/libs/ui/include/ui/BufferHubMetadata.h +++ b/libs/ui/include/ui/BufferHubMetadata.h @@ -17,26 +17,8 @@ #ifndef ANDROID_BUFFER_HUB_METADATA_H_ #define ANDROID_BUFFER_HUB_METADATA_H_ -// We would eliminate the clang warnings introduced by libdpx. -// TODO(b/112338294): Remove those once BufferHub moved to use Binder -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wconversion" -#pragma clang diagnostic ignored "-Wdouble-promotion" -#pragma clang diagnostic ignored "-Wgnu-case-range" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#pragma clang diagnostic ignored "-Winconsistent-missing-destructor-override" -#pragma clang diagnostic ignored "-Wnested-anon-types" -#pragma clang diagnostic ignored "-Wpacked" -#pragma clang diagnostic ignored "-Wshadow" -#pragma clang diagnostic ignored "-Wsign-conversion" -#pragma clang diagnostic ignored "-Wswitch-enum" -#pragma clang diagnostic ignored "-Wundefined-func-template" -#pragma clang diagnostic ignored "-Wunused-template" -#pragma clang diagnostic ignored "-Wweak-vtables" -#include <private/dvr/buffer_hub_defs.h> -#pragma clang diagnostic pop - #include <android-base/unique_fd.h> +#include <ui/BufferHubDefs.h> namespace android { @@ -84,23 +66,21 @@ public: bool IsValid() const { return mAshmemFd.get() != -1 && mMetadataHeader != nullptr; } size_t user_metadata_size() const { return mUserMetadataSize; } - size_t metadata_size() const { - return mUserMetadataSize + dvr::BufferHubDefs::kMetadataHeaderSize; - } + size_t metadata_size() const { return mUserMetadataSize + BufferHubDefs::kMetadataHeaderSize; } const unique_fd& ashmem_fd() const { return mAshmemFd; } - dvr::BufferHubDefs::MetadataHeader* metadata_header() { return mMetadataHeader; } + BufferHubDefs::MetadataHeader* metadata_header() { return mMetadataHeader; } private: BufferHubMetadata(size_t userMetadataSize, unique_fd ashmemFd, - dvr::BufferHubDefs::MetadataHeader* metadataHeader); + BufferHubDefs::MetadataHeader* metadataHeader); BufferHubMetadata(const BufferHubMetadata&) = delete; void operator=(const BufferHubMetadata&) = delete; size_t mUserMetadataSize = 0; unique_fd mAshmemFd; - dvr::BufferHubDefs::MetadataHeader* mMetadataHeader = nullptr; + BufferHubDefs::MetadataHeader* mMetadataHeader = nullptr; }; } // namespace android diff --git a/libs/ui/tests/Android.bp b/libs/ui/tests/Android.bp index 18bbb3e876..ca73be79d1 100644 --- a/libs/ui/tests/Android.bp +++ b/libs/ui/tests/Android.bp @@ -73,10 +73,13 @@ cc_test { cc_test { name: "BufferHubMetadata_test", - header_libs: ["libbufferhub_headers", "libdvr_headers"], + header_libs: [ + "libbufferhub_headers", + "libdvr_headers", + "libpdx_headers", + ], shared_libs: [ "libbase", - "libpdx_default_transport", "libui", "libutils", ], diff --git a/libs/ui/tests/BufferHubMetadata_test.cpp b/libs/ui/tests/BufferHubMetadata_test.cpp index 14422bf987..2265336c30 100644 --- a/libs/ui/tests/BufferHubMetadata_test.cpp +++ b/libs/ui/tests/BufferHubMetadata_test.cpp @@ -15,8 +15,10 @@ */ #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; namespace android { 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 400def7341..62ef475f16 100644 --- a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h +++ b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h @@ -8,8 +8,7 @@ #include <pdx/rpc/remote_method.h> #include <pdx/rpc/serializable.h> #include <private/dvr/native_handle_wrapper.h> - -#include <atomic> +#include <ui/BufferHubDefs.h> namespace android { namespace dvr { @@ -120,36 +119,9 @@ static inline uint64_t FindNextAvailableClientStateMask(uint64_t union_bits) { return new_low_bit + (new_low_bit << kMaxNumberOfClients); } -struct __attribute__((packed, 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, it's not stable cross Android version, - // so don't have it visible from outside of the Android 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<uint64_t> buffer_state; - - // Every client takes up one bit in fence_state. Only the lower 32 bits are - // valid. The upper 32 bits are there for easier manipulation, but the value - // should be ignored. - std::atomic<uint64_t> fence_state; - - // 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<uint64_t> active_clients_bit_mask; - - // The index of the buffer queue where the buffer belongs to. - uint64_t queue_index; - - // Public data format, which should be updated with caution. See more details - // in dvr_api.h - DvrNativeBufferMetadata metadata; -}; - -static_assert(sizeof(MetadataHeader) == 136, "Unexpected MetadataHeader size"); -static constexpr size_t kMetadataHeaderSize = sizeof(MetadataHeader); +using MetadataHeader = android::BufferHubDefs::MetadataHeader; +static constexpr size_t kMetadataHeaderSize = + android::BufferHubDefs::kMetadataHeaderSize; } // namespace BufferHubDefs diff --git a/libs/vr/libdvr/include/dvr/dvr_api.h b/libs/vr/libdvr/include/dvr/dvr_api.h index fef8512266..a204f62fff 100644 --- a/libs/vr/libdvr/include/dvr/dvr_api.h +++ b/libs/vr/libdvr/include/dvr/dvr_api.h @@ -412,6 +412,7 @@ typedef int (*DvrTrackingSensorsStopPtr)(DvrTrackingSensors* sensors); // existing data members. If new fields need to be added, please take extra care // to make sure that new data field is padded properly the size of the struct // stays same. +// TODO(b/118893702): move the definition to libnativewindow or libui struct ALIGNED_DVR_STRUCT(8) DvrNativeBufferMetadata { #ifdef __cplusplus DvrNativeBufferMetadata() diff --git a/services/bufferhub/BufferClient.cpp b/services/bufferhub/BufferClient.cpp index 745951745a..e312011696 100644 --- a/services/bufferhub/BufferClient.cpp +++ b/services/bufferhub/BufferClient.cpp @@ -17,6 +17,7 @@ #include <bufferhub/BufferClient.h> #include <bufferhub/BufferHubService.h> #include <hidl/HidlSupport.h> +#include <log/log.h> namespace android { namespace frameworks { diff --git a/services/bufferhub/include/bufferhub/BufferNode.h b/services/bufferhub/include/bufferhub/BufferNode.h index 94ef505d41..02bb5af0e0 100644 --- a/services/bufferhub/include/bufferhub/BufferNode.h +++ b/services/bufferhub/include/bufferhub/BufferNode.h @@ -3,6 +3,7 @@ #include <android/hardware_buffer.h> #include <bufferhub/BufferHubIdGenerator.h> +#include <cutils/native_handle.h> #include <ui/BufferHubMetadata.h> namespace android { diff --git a/services/bufferhub/tests/BufferNode_test.cpp b/services/bufferhub/tests/BufferNode_test.cpp index df31d78b89..3358c87eb8 100644 --- a/services/bufferhub/tests/BufferNode_test.cpp +++ b/services/bufferhub/tests/BufferNode_test.cpp @@ -1,7 +1,9 @@ -#include <bufferhub/BufferNode.h> #include <errno.h> + +#include <bufferhub/BufferNode.h> #include <gmock/gmock.h> #include <gtest/gtest.h> +#include <private/dvr/buffer_hub_defs.h> #include <ui/GraphicBufferMapper.h> namespace android { |