diff options
| author | 2018-11-08 16:29:13 -0800 | |
|---|---|---|
| committer | 2018-11-14 10:42:21 -0800 | |
| commit | ffde786ffce1afcd7ee574e7b45026d651ac1779 (patch) | |
| tree | c6ee2a9f13c21b0125653b897402b8f7ec72606b /services/bufferhub/BufferNode.cpp | |
| parent | 18d90eaf05d8b3a21a68d84ebf23ea2326067aad (diff) | |
Add a service-unique ID to BufferNode
All the BufferNode allocated by bufferhub hwservice now will have a
unique ID generated and managed by the UniqueIdGenerator.
The idGenerator is placed in global static namespace because 1)
therefore it is process-unique 2) BufferNode could still access it
without a reference to the service instance.
Added UniqueIdGenerator_test.
Test: UniqueIdGenerator_test, BufferNode_test, buffer_hub-test,
BufferHubBuffer_test passed.
Fix: 118844348
Change-Id: I9c9adebab3af7b9de71dbe8728d3f24ed231338d
Diffstat (limited to 'services/bufferhub/BufferNode.cpp')
| -rw-r--r-- | services/bufferhub/BufferNode.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/services/bufferhub/BufferNode.cpp b/services/bufferhub/BufferNode.cpp index 53dd702792..715d0a1f67 100644 --- a/services/bufferhub/BufferNode.cpp +++ b/services/bufferhub/BufferNode.cpp @@ -1,5 +1,6 @@ #include <errno.h> +#include <bufferhub/BufferHubService.h> #include <bufferhub/BufferNode.h> #include <private/dvr/buffer_hub_defs.h> #include <ui/GraphicBufferAllocator.h> @@ -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 @@ -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 { |