diff options
author | Jiwen 'Steve' Cai <jwcai@google.com> | 2017-11-03 17:33:33 -0700 |
---|---|---|
committer | Jiwen 'Steve' Cai <jwcai@google.com> | 2017-11-13 19:12:09 -0800 |
commit | a88e3ee3a33a60e72bd976cfb5b9fc0bd15a1078 (patch) | |
tree | 6f4371623a393ff8d79ffe9d55d34c43ddd7b757 /libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp | |
parent | de1eb9c03becf0207aea85983692d7e7e43ff3bc (diff) |
Make BufferHubQueue binder parcelable
The goal of this CL is to enable sending BufferHubQueue clients over
binder, so that ANativeWindow/Surface backed by BufferHub can be send
over binder just like the current binder BufferQueue based
implementation.
To enable PDX clients to be binder parcelable, this CL introduced new
DPX interface: pdx::ChannelParcelable with UDS-backed
implementation. Note that the ChannelParcelable interface is only
exposed to each implementation of PDX client (BufferHubQueue clients in
this CL) through protected pdx::Client interface. The reason for doing
that is each client implementation may require different custom clean up
logic between the client can be safely exported to another
process. Thus, we don't want to expose this export-to-binder becomes a
pdx-Client level feature, but let each client implement their own. In
addition, there is no immediate need for all types of pdx::Client
implementation being binder parcelable, thus we only implemented the
logic for BufferHubQueue.
This is the first of a seriers of CLs to eventually enable binder
parcelable ANativeSurface backed by BufferHub.
Bug: 37517761
Bug: 63909629
Test: buffer_hub_queue-test
Change-Id: I41c8a710af3095312db823ff01bc5aa526775edd
Diffstat (limited to 'libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp')
-rw-r--r-- | libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp index 8bea0cde7a..a5cefd9852 100644 --- a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp +++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp @@ -137,6 +137,28 @@ Status<LocalChannelHandle> BufferHubQueue::CreateConsumerQueueHandle( return status; } +pdx::Status<ConsumerQueueParcelable> +BufferHubQueue::CreateConsumerQueueParcelable(bool silent) { + auto status = CreateConsumerQueueHandle(silent); + if (!status) + return status.error_status(); + + // A temporary consumer queue client to pull its channel parcelable. + auto consumer_queue = + std::unique_ptr<ConsumerQueue>(new ConsumerQueue(status.take())); + ConsumerQueueParcelable queue_parcelable( + consumer_queue->GetChannel()->TakeChannelParcelable()); + + if (!queue_parcelable.IsValid()) { + ALOGE( + "BufferHubQueue::CreateConsumerQueueParcelable: Failed to create " + "consumer queue parcelable."); + return ErrorStatus(EINVAL); + } + + return {std::move(queue_parcelable)}; +} + bool BufferHubQueue::WaitForBuffers(int timeout) { ATRACE_NAME("BufferHubQueue::WaitForBuffers"); std::array<epoll_event, kMaxEvents> events; @@ -555,6 +577,25 @@ pdx::Status<std::shared_ptr<BufferProducer>> ProducerQueue::Dequeue( return {std::move(buffer)}; } +pdx::Status<ProducerQueueParcelable> ProducerQueue::TakeAsParcelable() { + if (capacity() != 0) { + ALOGE( + "ProducerQueue::TakeAsParcelable: producer queue can only be taken out" + " as a parcelable when empty. Current queue capacity: %zu", + capacity()); + return ErrorStatus(EINVAL); + } + + std::unique_ptr<pdx::ClientChannel> channel = TakeChannel(); + ProducerQueueParcelable queue_parcelable(channel->TakeChannelParcelable()); + + // Here the queue parcelable is returned and holds the underlying system + // resources backing the queue; while the original client channel of this + // producer queue is destroyed in place so that this client can no longer + // provide producer operations. + return {std::move(queue_parcelable)}; +} + ConsumerQueue::ConsumerQueue(LocalChannelHandle handle) : BufferHubQueue(std::move(handle)) { auto status = ImportQueue(); |