diff options
author | 2018-02-07 17:29:56 -0800 | |
---|---|---|
committer | 2018-02-13 15:16:16 -0800 | |
commit | a2a27b2679bcfd204090a89234e9751eafe23231 (patch) | |
tree | 33e03d3f01817cd4453f0c2ddef81c7241a7ff08 | |
parent | dc82be74c578c982d1ca8dcbbdbf2fe24f00f94d (diff) |
Add BufferHub-based IGBC implementation
This is mostly a placeholder to create an IGBC/IGBP pair based on
BufferHub for testing purpose. A fully functional implementation will be
filled in later.
Bug: 72972441
Bug: 70046255
Test: libgui_test
Change-Id: I2215bd78da1d0104f2cbb9599f874c810898be56
-rw-r--r-- | libs/gui/Android.bp | 1 | ||||
-rw-r--r-- | libs/gui/BufferHubConsumer.cpp | 161 | ||||
-rw-r--r-- | libs/gui/include/gui/BufferHubConsumer.h | 112 | ||||
-rw-r--r-- | libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp | 6 | ||||
-rw-r--r-- | libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h | 5 |
5 files changed, 281 insertions, 4 deletions
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index 6655eb6a89..a1a0928154 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -85,6 +85,7 @@ cc_library_shared { srcs: [ "BitTube.cpp", + "BufferHubConsumer.cpp", "BufferHubProducer.cpp", "BufferItem.cpp", "BufferItemConsumer.cpp", diff --git a/libs/gui/BufferHubConsumer.cpp b/libs/gui/BufferHubConsumer.cpp new file mode 100644 index 0000000000..b5cdeb280a --- /dev/null +++ b/libs/gui/BufferHubConsumer.cpp @@ -0,0 +1,161 @@ +/* + * Copyright 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 <gui/BufferHubConsumer.h> + +namespace android { + +using namespace dvr; + +/* static */ +sp<BufferHubConsumer> BufferHubConsumer::Create(const std::shared_ptr<ConsumerQueue>& queue) { + sp<BufferHubConsumer> consumer = new BufferHubConsumer; + consumer->mQueue = queue; + return consumer; +} + +/* static */ sp<BufferHubConsumer> BufferHubConsumer::Create(ConsumerQueueParcelable parcelable) { + if (!parcelable.IsValid()) { + ALOGE("BufferHubConsumer::Create: Invalid consumer parcelable."); + return nullptr; + } + + sp<BufferHubConsumer> consumer = new BufferHubConsumer; + consumer->mQueue = ConsumerQueue::Import(parcelable.TakeChannelHandle()); + return consumer; +} + +status_t BufferHubConsumer::acquireBuffer(BufferItem* /*buffer*/, nsecs_t /*presentWhen*/, + uint64_t /*maxFrameNumber*/) { + ALOGE("BufferHubConsumer::acquireBuffer: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::detachBuffer(int /*slot*/) { + ALOGE("BufferHubConsumer::detachBuffer: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::attachBuffer(int* /*outSlot*/, const sp<GraphicBuffer>& /*buffer*/) { + ALOGE("BufferHubConsumer::attachBuffer: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::releaseBuffer(int /*buf*/, uint64_t /*frameNumber*/, + EGLDisplay /*display*/, EGLSyncKHR /*fence*/, + const sp<Fence>& /*releaseFence*/) { + ALOGE("BufferHubConsumer::releaseBuffer: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::consumerConnect(const sp<IConsumerListener>& /*consumer*/, + bool /*controlledByApp*/) { + ALOGE("BufferHubConsumer::consumerConnect: not implemented."); + + // TODO(b/73267953): Make BufferHub honor producer and consumer connection. Returns NO_ERROR to + // make IGraphicBufferConsumer_test happy. + return NO_ERROR; +} + +status_t BufferHubConsumer::consumerDisconnect() { + ALOGE("BufferHubConsumer::consumerDisconnect: not implemented."); + + // TODO(b/73267953): Make BufferHub honor producer and consumer connection. Returns NO_ERROR to + // make IGraphicBufferConsumer_test happy. + return NO_ERROR; +} + +status_t BufferHubConsumer::getReleasedBuffers(uint64_t* /*slotMask*/) { + ALOGE("BufferHubConsumer::getReleasedBuffers: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) { + ALOGE("BufferHubConsumer::setDefaultBufferSize: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setMaxBufferCount(int /*bufferCount*/) { + ALOGE("BufferHubConsumer::setMaxBufferCount: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setMaxAcquiredBufferCount(int /*maxAcquiredBuffers*/) { + ALOGE("BufferHubConsumer::setMaxAcquiredBufferCount: not implemented."); + + // TODO(b/73267953): Make BufferHub honor producer and consumer connection. Returns NO_ERROR to + // make IGraphicBufferConsumer_test happy. + return NO_ERROR; +} + +status_t BufferHubConsumer::setConsumerName(const String8& /*name*/) { + ALOGE("BufferHubConsumer::setConsumerName: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setDefaultBufferFormat(PixelFormat /*defaultFormat*/) { + ALOGE("BufferHubConsumer::setDefaultBufferFormat: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setDefaultBufferDataSpace(android_dataspace /*defaultDataSpace*/) { + ALOGE("BufferHubConsumer::setDefaultBufferDataSpace: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setConsumerUsageBits(uint64_t /*usage*/) { + ALOGE("BufferHubConsumer::setConsumerUsageBits: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setConsumerIsProtected(bool /*isProtected*/) { + ALOGE("BufferHubConsumer::setConsumerIsProtected: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::setTransformHint(uint32_t /*hint*/) { + ALOGE("BufferHubConsumer::setTransformHint: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::getSidebandStream(sp<NativeHandle>* /*outStream*/) const { + ALOGE("BufferHubConsumer::getSidebandStream: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::getOccupancyHistory( + bool /*forceFlush*/, std::vector<OccupancyTracker::Segment>* /*outHistory*/) { + ALOGE("BufferHubConsumer::getOccupancyHistory: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::discardFreeBuffers() { + ALOGE("BufferHubConsumer::discardFreeBuffers: not implemented."); + return INVALID_OPERATION; +} + +status_t BufferHubConsumer::dumpState(const String8& /*prefix*/, String8* /*outResult*/) const { + ALOGE("BufferHubConsumer::dumpState: not implemented."); + return INVALID_OPERATION; +} + +IBinder* BufferHubConsumer::onAsBinder() { + ALOGE("BufferHubConsumer::onAsBinder: BufferHubConsumer should never be used as an Binder " + "object."); + return nullptr; +} + +} // namespace android diff --git a/libs/gui/include/gui/BufferHubConsumer.h b/libs/gui/include/gui/BufferHubConsumer.h new file mode 100644 index 0000000000..d38077014b --- /dev/null +++ b/libs/gui/include/gui/BufferHubConsumer.h @@ -0,0 +1,112 @@ +/* + * Copyright 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_GUI_BUFFERHUBCONSUMER_H_ +#define ANDROID_GUI_BUFFERHUBCONSUMER_H_ + +#include <gui/IGraphicBufferConsumer.h> +#include <private/dvr/buffer_hub_queue_client.h> +#include <private/dvr/buffer_hub_queue_parcelable.h> + +namespace android { + +class BufferHubConsumer : public IGraphicBufferConsumer { +public: + // Creates a BufferHubConsumer instance by importing an existing producer queue. + static sp<BufferHubConsumer> Create(const std::shared_ptr<dvr::ConsumerQueue>& queue); + + // Creates a BufferHubConsumer instance by importing an existing producer + // parcelable. Note that this call takes the ownership of the parcelable + // object and is guaranteed to succeed if parcelable object is valid. + static sp<BufferHubConsumer> Create(dvr::ConsumerQueueParcelable parcelable); + + // See |IGraphicBufferConsumer::acquireBuffer| + status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, + uint64_t maxFrameNumber = 0) override; + + // See |IGraphicBufferConsumer::detachBuffer| + status_t detachBuffer(int slot) override; + + // See |IGraphicBufferConsumer::attachBuffer| + status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer) override; + + // See |IGraphicBufferConsumer::releaseBuffer| + status_t releaseBuffer(int buf, uint64_t frameNumber, EGLDisplay display, EGLSyncKHR fence, + const sp<Fence>& releaseFence) override; + + // See |IGraphicBufferConsumer::consumerConnect| + status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) override; + + // See |IGraphicBufferConsumer::consumerDisconnect| + status_t consumerDisconnect() override; + + // See |IGraphicBufferConsumer::getReleasedBuffers| + status_t getReleasedBuffers(uint64_t* slotMask) override; + + // See |IGraphicBufferConsumer::setDefaultBufferSize| + status_t setDefaultBufferSize(uint32_t w, uint32_t h) override; + + // See |IGraphicBufferConsumer::setMaxBufferCount| + status_t setMaxBufferCount(int bufferCount) override; + + // See |IGraphicBufferConsumer::setMaxAcquiredBufferCount| + status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) override; + + // See |IGraphicBufferConsumer::setConsumerName| + status_t setConsumerName(const String8& name) override; + + // See |IGraphicBufferConsumer::setDefaultBufferFormat| + status_t setDefaultBufferFormat(PixelFormat defaultFormat) override; + + // See |IGraphicBufferConsumer::setDefaultBufferDataSpace| + status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) override; + + // See |IGraphicBufferConsumer::setConsumerUsageBits| + status_t setConsumerUsageBits(uint64_t usage) override; + + // See |IGraphicBufferConsumer::setConsumerIsProtected| + status_t setConsumerIsProtected(bool isProtected) override; + + // See |IGraphicBufferConsumer::setTransformHint| + status_t setTransformHint(uint32_t hint) override; + + // See |IGraphicBufferConsumer::getSidebandStream| + status_t getSidebandStream(sp<NativeHandle>* outStream) const override; + + // See |IGraphicBufferConsumer::getOccupancyHistory| + status_t getOccupancyHistory(bool forceFlush, + std::vector<OccupancyTracker::Segment>* outHistory) override; + + // See |IGraphicBufferConsumer::discardFreeBuffers| + status_t discardFreeBuffers() override; + + // See |IGraphicBufferConsumer::dumpState| + status_t dumpState(const String8& prefix, String8* outResult) const override; + + // BufferHubConsumer provides its own logic to cast to a binder object. + IBinder* onAsBinder() override; + +private: + // Private constructor to force use of |Create|. + BufferHubConsumer() = default; + + // Concrete implementation backed by BufferHubBuffer. + std::shared_ptr<dvr::ConsumerQueue> mQueue; +}; + +} // namespace android + +#endif // ANDROID_GUI_BUFFERHUBCONSUMER_H_ diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp index c75c67f6d8..8feb1cd803 100644 --- a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp +++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp @@ -582,6 +582,12 @@ pdx::Status<ProducerQueueParcelable> ProducerQueue::TakeAsParcelable() { return {std::move(queue_parcelable)}; } +/*static */ +std::unique_ptr<ConsumerQueue> ConsumerQueue::Import( + LocalChannelHandle handle) { + return std::unique_ptr<ConsumerQueue>(new ConsumerQueue(std::move(handle))); +} + ConsumerQueue::ConsumerQueue(LocalChannelHandle handle) : BufferHubQueue(std::move(handle)) { auto status = ImportQueue(); diff --git a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h b/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h index 9eaebcbfbd..60e1c4b8a9 100644 --- a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h +++ b/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h @@ -385,10 +385,7 @@ class ConsumerQueue : public BufferHubQueue { // used to avoid participation in the buffer lifecycle by a consumer queue // that is only used to spawn other consumer queues, such as in an // intermediate service. - static std::unique_ptr<ConsumerQueue> Import(pdx::LocalChannelHandle handle) { - return std::unique_ptr<ConsumerQueue>( - new ConsumerQueue(std::move(handle))); - } + static std::unique_ptr<ConsumerQueue> Import(pdx::LocalChannelHandle handle); // Import newly created buffers from the service side. // Returns number of buffers successfully imported or an error. |