Loading services/bufferhub/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ cc_library_shared { "BufferClient.cpp", "BufferHubService.cpp", "BufferNode.cpp", "UniqueIdGenerator.cpp", ], header_libs: [ "libbufferhub_headers", Loading services/bufferhub/BufferHubService.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& d std::shared_ptr<BufferNode> node = std::make_shared<BufferNode>(desc.width, desc.height, desc.layers, desc.format, desc.usage, userMetadataSize); desc.usage, userMetadataSize, nodeIdGenerator.getId()); if (node == nullptr || !node->IsValid()) { ALOGE("%s: creating BufferNode failed.", __FUNCTION__); _hidl_cb(/*bufferClient=*/nullptr, /*status=*/BufferHubStatus::ALLOCATION_FAILED); Loading services/bufferhub/BufferNode.cpp +13 −2 Original line number Diff line number Diff line #include <errno.h> #include <bufferhub/BufferHubService.h> #include <bufferhub/BufferNode.h> #include <private/dvr/buffer_hub_defs.h> #include <ui/GraphicBufferAllocator.h> Loading @@ -22,7 +23,8 @@ void BufferNode::InitializeMetadata() { // Allocates a new BufferNode. BufferNode::BufferNode(uint32_t width, uint32_t height, uint32_t layer_count, uint32_t format, uint64_t usage, size_t user_metadata_size) { uint64_t usage, size_t user_metadata_size, uint32_t id) : mId(id) { uint32_t out_stride = 0; // graphicBufferId is not used in GraphicBufferAllocator::allocate // TODO(b/112338294) After move to the service folder, stop using the Loading Loading @@ -54,14 +56,23 @@ BufferNode::BufferNode(uint32_t width, uint32_t height, uint32_t layer_count, ui InitializeMetadata(); } // Free the handle BufferNode::~BufferNode() { // Free the handle if (buffer_handle_ != nullptr) { status_t ret = GraphicBufferAllocator::get().free(buffer_handle_); if (ret != OK) { ALOGE("%s: Failed to free handle; Got error: %d", __FUNCTION__, ret); } } // Free the id, if valid if (id() != UniqueIdGenerator::kInvalidId) { if (nodeIdGenerator.freeId(id())) { ALOGI("%s: id #%u is freed.", __FUNCTION__, id()); } else { ALOGE("%s: Cannot free nonexistent id #%u", __FUNCTION__, id()); } } } uint64_t BufferNode::GetActiveClientsBitMask() const { Loading services/bufferhub/UniqueIdGenerator.cpp 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * 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. */ #include <bufferhub/UniqueIdGenerator.h> namespace android { namespace frameworks { namespace bufferhub { namespace V1_0 { namespace implementation { constexpr uint32_t UniqueIdGenerator::kInvalidId; uint32_t UniqueIdGenerator::getId() { std::lock_guard<std::mutex> lock(mIdsInUseMutex); do { if (++mLastId >= std::numeric_limits<uint32_t>::max()) { mLastId = kInvalidId + 1; } } while (mIdsInUse.find(mLastId) != mIdsInUse.end()); mIdsInUse.insert(mLastId); return mLastId; } bool UniqueIdGenerator::freeId(uint32_t id) { std::lock_guard<std::mutex> lock(mIdsInUseMutex); auto iter = mIdsInUse.find(id); if (iter != mIdsInUse.end()) { mIdsInUse.erase(iter); return true; } return false; } } // namespace implementation } // namespace V1_0 } // namespace bufferhub } // namespace frameworks } // namespace android services/bufferhub/include/bufferhub/BufferHubService.h +3 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <android/frameworks/bufferhub/1.0/IBufferHub.h> #include <bufferhub/BufferClient.h> #include <bufferhub/UniqueIdGenerator.h> #include <utils/Mutex.h> namespace android { Loading @@ -34,6 +35,8 @@ using hardware::hidl_handle; using hardware::Return; using hardware::graphics::common::V1_2::HardwareBufferDescription; static UniqueIdGenerator nodeIdGenerator; class BufferHubService : public IBufferHub { public: Return<void> allocateBuffer(const HardwareBufferDescription& description, Loading Loading
services/bufferhub/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ cc_library_shared { "BufferClient.cpp", "BufferHubService.cpp", "BufferNode.cpp", "UniqueIdGenerator.cpp", ], header_libs: [ "libbufferhub_headers", Loading
services/bufferhub/BufferHubService.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& d std::shared_ptr<BufferNode> node = std::make_shared<BufferNode>(desc.width, desc.height, desc.layers, desc.format, desc.usage, userMetadataSize); desc.usage, userMetadataSize, nodeIdGenerator.getId()); if (node == nullptr || !node->IsValid()) { ALOGE("%s: creating BufferNode failed.", __FUNCTION__); _hidl_cb(/*bufferClient=*/nullptr, /*status=*/BufferHubStatus::ALLOCATION_FAILED); Loading
services/bufferhub/BufferNode.cpp +13 −2 Original line number Diff line number Diff line #include <errno.h> #include <bufferhub/BufferHubService.h> #include <bufferhub/BufferNode.h> #include <private/dvr/buffer_hub_defs.h> #include <ui/GraphicBufferAllocator.h> Loading @@ -22,7 +23,8 @@ void BufferNode::InitializeMetadata() { // Allocates a new BufferNode. BufferNode::BufferNode(uint32_t width, uint32_t height, uint32_t layer_count, uint32_t format, uint64_t usage, size_t user_metadata_size) { uint64_t usage, size_t user_metadata_size, uint32_t id) : mId(id) { uint32_t out_stride = 0; // graphicBufferId is not used in GraphicBufferAllocator::allocate // TODO(b/112338294) After move to the service folder, stop using the Loading Loading @@ -54,14 +56,23 @@ BufferNode::BufferNode(uint32_t width, uint32_t height, uint32_t layer_count, ui InitializeMetadata(); } // Free the handle BufferNode::~BufferNode() { // Free the handle if (buffer_handle_ != nullptr) { status_t ret = GraphicBufferAllocator::get().free(buffer_handle_); if (ret != OK) { ALOGE("%s: Failed to free handle; Got error: %d", __FUNCTION__, ret); } } // Free the id, if valid if (id() != UniqueIdGenerator::kInvalidId) { if (nodeIdGenerator.freeId(id())) { ALOGI("%s: id #%u is freed.", __FUNCTION__, id()); } else { ALOGE("%s: Cannot free nonexistent id #%u", __FUNCTION__, id()); } } } uint64_t BufferNode::GetActiveClientsBitMask() const { Loading
services/bufferhub/UniqueIdGenerator.cpp 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * 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. */ #include <bufferhub/UniqueIdGenerator.h> namespace android { namespace frameworks { namespace bufferhub { namespace V1_0 { namespace implementation { constexpr uint32_t UniqueIdGenerator::kInvalidId; uint32_t UniqueIdGenerator::getId() { std::lock_guard<std::mutex> lock(mIdsInUseMutex); do { if (++mLastId >= std::numeric_limits<uint32_t>::max()) { mLastId = kInvalidId + 1; } } while (mIdsInUse.find(mLastId) != mIdsInUse.end()); mIdsInUse.insert(mLastId); return mLastId; } bool UniqueIdGenerator::freeId(uint32_t id) { std::lock_guard<std::mutex> lock(mIdsInUseMutex); auto iter = mIdsInUse.find(id); if (iter != mIdsInUse.end()) { mIdsInUse.erase(iter); return true; } return false; } } // namespace implementation } // namespace V1_0 } // namespace bufferhub } // namespace frameworks } // namespace android
services/bufferhub/include/bufferhub/BufferHubService.h +3 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <android/frameworks/bufferhub/1.0/IBufferHub.h> #include <bufferhub/BufferClient.h> #include <bufferhub/UniqueIdGenerator.h> #include <utils/Mutex.h> namespace android { Loading @@ -34,6 +35,8 @@ using hardware::hidl_handle; using hardware::Return; using hardware::graphics::common::V1_2::HardwareBufferDescription; static UniqueIdGenerator nodeIdGenerator; class BufferHubService : public IBufferHub { public: Return<void> allocateBuffer(const HardwareBufferDescription& description, Loading