Loading services/bufferhub/BufferHubService.cpp +29 −19 Original line number Diff line number Diff line Loading @@ -65,15 +65,20 @@ Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& d std::lock_guard<std::mutex> lock(mClientSetMutex); mClientSet.emplace(client); hidl_handle bufferInfo = buildBufferInfo(node->id(), node->AddNewActiveClientsBitToMask(), node->user_metadata_size(), node->eventFd().get(), node->metadata().ashmem_fd()); // Allocate memory for bufferInfo of type hidl_handle on the stack. See // http://aosp/286282 for the usage of NATIVE_HANDLE_DECLARE_STORAGE. NATIVE_HANDLE_DECLARE_STORAGE(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds, BufferHubDefs::kBufferInfoNumInts); hidl_handle bufferInfo = buildBufferInfo(bufferInfoStorage, node->id(), node->AddNewActiveClientsBitToMask(), node->user_metadata_size(), node->metadata().ashmem_fd(), node->eventFd().get()); BufferTraits bufferTraits = {/*bufferDesc=*/description, /*bufferHandle=*/hidl_handle(node->buffer_handle()), /*bufferInfo=*/bufferInfo}; /*bufferInfo=*/std::move(bufferInfo)}; _hidl_cb(/*status=*/BufferHubStatus::NO_ERROR, /*bufferClient=*/client, /*bufferTraits=*/bufferTraits); /*bufferTraits=*/std::move(bufferTraits)); return Void(); } Loading Loading @@ -154,15 +159,19 @@ Return<void> BufferHubService::importBuffer(const hidl_handle& tokenHandle, HardwareBufferDescription bufferDesc; memcpy(&bufferDesc, &node->buffer_desc(), sizeof(HardwareBufferDescription)); hidl_handle bufferInfo = buildBufferInfo(node->id(), clientStateMask, node->user_metadata_size(), node->eventFd().get(), node->metadata().ashmem_fd()); // Allocate memory for bufferInfo of type hidl_handle on the stack. See // http://aosp/286282 for the usage of NATIVE_HANDLE_DECLARE_STORAGE. NATIVE_HANDLE_DECLARE_STORAGE(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds, BufferHubDefs::kBufferInfoNumInts); hidl_handle bufferInfo = buildBufferInfo(bufferInfoStorage, node->id(), clientStateMask, node->user_metadata_size(), node->metadata().ashmem_fd(), node->eventFd().get()); BufferTraits bufferTraits = {/*bufferDesc=*/bufferDesc, /*bufferHandle=*/hidl_handle(node->buffer_handle()), /*bufferInfo=*/bufferInfo}; /*bufferInfo=*/std::move(bufferInfo)}; _hidl_cb(/*status=*/BufferHubStatus::NO_ERROR, /*bufferClient=*/client, /*bufferTraits=*/bufferTraits); /*bufferTraits=*/std::move(bufferTraits)); return Void(); } Loading Loading @@ -344,14 +353,15 @@ void BufferHubService::onClientClosed(const BufferClient* client) { // Implementation of this function should be consistent with the definition of bufferInfo handle in // ui/BufferHubDefs.h. hidl_handle BufferHubService::buildBufferInfo(int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, const int eventFd, const int metadataFd) { native_handle_t* infoHandle = native_handle_create(BufferHubDefs::kBufferInfoNumFds, hidl_handle BufferHubService::buildBufferInfo(char* bufferInfoStorage, int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, int metadataFd, int eventFd) { native_handle_t* infoHandle = native_handle_init(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds, BufferHubDefs::kBufferInfoNumInts); infoHandle->data[0] = dup(metadataFd); infoHandle->data[1] = dup(eventFd); infoHandle->data[0] = metadataFd; infoHandle->data[1] = eventFd; infoHandle->data[2] = bufferId; // Use memcpy to convert to int without missing digit. // TOOD(b/121345852): use bit_cast to unpack bufferInfo when C++20 becomes available. Loading @@ -359,7 +369,7 @@ hidl_handle BufferHubService::buildBufferInfo(int bufferId, uint32_t clientBitMa memcpy(&infoHandle->data[4], &userMetadataSize, sizeof(userMetadataSize)); hidl_handle bufferInfo; bufferInfo.setTo(infoHandle, /*shouldOwn=*/true); bufferInfo.setTo(infoHandle, /*shouldOwn=*/false); return bufferInfo; } Loading services/bufferhub/include/bufferhub/BufferHubService.h +2 −2 Original line number Diff line number Diff line Loading @@ -58,8 +58,8 @@ public: private: // Helper function to build BufferTraits.bufferInfo handle hidl_handle buildBufferInfo(int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, const int eventFd, const int metadataFd); hidl_handle buildBufferInfo(char* bufferInfoStorage, int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, int metadataFd, int eventFd); // Helper function to remove all the token belongs to a specific client. void removeTokenByClient(const BufferClient* client); Loading Loading
services/bufferhub/BufferHubService.cpp +29 −19 Original line number Diff line number Diff line Loading @@ -65,15 +65,20 @@ Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& d std::lock_guard<std::mutex> lock(mClientSetMutex); mClientSet.emplace(client); hidl_handle bufferInfo = buildBufferInfo(node->id(), node->AddNewActiveClientsBitToMask(), node->user_metadata_size(), node->eventFd().get(), node->metadata().ashmem_fd()); // Allocate memory for bufferInfo of type hidl_handle on the stack. See // http://aosp/286282 for the usage of NATIVE_HANDLE_DECLARE_STORAGE. NATIVE_HANDLE_DECLARE_STORAGE(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds, BufferHubDefs::kBufferInfoNumInts); hidl_handle bufferInfo = buildBufferInfo(bufferInfoStorage, node->id(), node->AddNewActiveClientsBitToMask(), node->user_metadata_size(), node->metadata().ashmem_fd(), node->eventFd().get()); BufferTraits bufferTraits = {/*bufferDesc=*/description, /*bufferHandle=*/hidl_handle(node->buffer_handle()), /*bufferInfo=*/bufferInfo}; /*bufferInfo=*/std::move(bufferInfo)}; _hidl_cb(/*status=*/BufferHubStatus::NO_ERROR, /*bufferClient=*/client, /*bufferTraits=*/bufferTraits); /*bufferTraits=*/std::move(bufferTraits)); return Void(); } Loading Loading @@ -154,15 +159,19 @@ Return<void> BufferHubService::importBuffer(const hidl_handle& tokenHandle, HardwareBufferDescription bufferDesc; memcpy(&bufferDesc, &node->buffer_desc(), sizeof(HardwareBufferDescription)); hidl_handle bufferInfo = buildBufferInfo(node->id(), clientStateMask, node->user_metadata_size(), node->eventFd().get(), node->metadata().ashmem_fd()); // Allocate memory for bufferInfo of type hidl_handle on the stack. See // http://aosp/286282 for the usage of NATIVE_HANDLE_DECLARE_STORAGE. NATIVE_HANDLE_DECLARE_STORAGE(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds, BufferHubDefs::kBufferInfoNumInts); hidl_handle bufferInfo = buildBufferInfo(bufferInfoStorage, node->id(), clientStateMask, node->user_metadata_size(), node->metadata().ashmem_fd(), node->eventFd().get()); BufferTraits bufferTraits = {/*bufferDesc=*/bufferDesc, /*bufferHandle=*/hidl_handle(node->buffer_handle()), /*bufferInfo=*/bufferInfo}; /*bufferInfo=*/std::move(bufferInfo)}; _hidl_cb(/*status=*/BufferHubStatus::NO_ERROR, /*bufferClient=*/client, /*bufferTraits=*/bufferTraits); /*bufferTraits=*/std::move(bufferTraits)); return Void(); } Loading Loading @@ -344,14 +353,15 @@ void BufferHubService::onClientClosed(const BufferClient* client) { // Implementation of this function should be consistent with the definition of bufferInfo handle in // ui/BufferHubDefs.h. hidl_handle BufferHubService::buildBufferInfo(int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, const int eventFd, const int metadataFd) { native_handle_t* infoHandle = native_handle_create(BufferHubDefs::kBufferInfoNumFds, hidl_handle BufferHubService::buildBufferInfo(char* bufferInfoStorage, int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, int metadataFd, int eventFd) { native_handle_t* infoHandle = native_handle_init(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds, BufferHubDefs::kBufferInfoNumInts); infoHandle->data[0] = dup(metadataFd); infoHandle->data[1] = dup(eventFd); infoHandle->data[0] = metadataFd; infoHandle->data[1] = eventFd; infoHandle->data[2] = bufferId; // Use memcpy to convert to int without missing digit. // TOOD(b/121345852): use bit_cast to unpack bufferInfo when C++20 becomes available. Loading @@ -359,7 +369,7 @@ hidl_handle BufferHubService::buildBufferInfo(int bufferId, uint32_t clientBitMa memcpy(&infoHandle->data[4], &userMetadataSize, sizeof(userMetadataSize)); hidl_handle bufferInfo; bufferInfo.setTo(infoHandle, /*shouldOwn=*/true); bufferInfo.setTo(infoHandle, /*shouldOwn=*/false); return bufferInfo; } Loading
services/bufferhub/include/bufferhub/BufferHubService.h +2 −2 Original line number Diff line number Diff line Loading @@ -58,8 +58,8 @@ public: private: // Helper function to build BufferTraits.bufferInfo handle hidl_handle buildBufferInfo(int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, const int eventFd, const int metadataFd); hidl_handle buildBufferInfo(char* bufferInfoStorage, int bufferId, uint32_t clientBitMask, uint32_t userMetadataSize, int metadataFd, int eventFd); // Helper function to remove all the token belongs to a specific client. void removeTokenByClient(const BufferClient* client); Loading