Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2a27b26 authored by Jiwen 'Steve' Cai's avatar Jiwen 'Steve' Cai
Browse files

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
parent dc82be74
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ cc_library_shared {

    srcs: [
        "BitTube.cpp",
        "BufferHubConsumer.cpp",
        "BufferHubProducer.cpp",
        "BufferItem.cpp",
        "BufferItemConsumer.cpp",
+161 −0
Original line number Diff line number Diff line
/*
 * 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
+112 −0
Original line number Diff line number Diff line
/*
 * 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_
+6 −0
Original line number Diff line number Diff line
@@ -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();
+1 −4
Original line number Diff line number Diff line
@@ -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.