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

Commit 1d9bcec5 authored by Tianyu Jiang's avatar Tianyu Jiang Committed by Android (Google) Code Review
Browse files

Merge "Create GraphicBuffer backed by BufferHubBuffer"

parents 88f1c422 2daf5189
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ cc_library_shared {
    // bufferhub is not used when building libgui for vendors
    target: {
        vendor: {
            cflags: ["-DLIBUI_IN_VNDK"],
            exclude_srcs: [
                "BufferHubBuffer.cpp",
                "BufferHubMetadata.cpp",
@@ -116,6 +117,7 @@ cc_library_shared {
            exclude_header_libs: [
                "libbufferhub_headers",
                "libdvr_headers",
                "libnativewindow_headers",
            ],
            exclude_shared_libs: [
                "libpdx_default_transport",
@@ -128,6 +130,7 @@ cc_library_shared {
        "libbufferhub_headers",
        "libdvr_headers",
        "libnativebase_headers",
        "libnativewindow_headers",
        "libhardware_headers",
        "libui_headers",
        "libpdx_headers",
@@ -155,6 +158,7 @@ cc_library_headers {
    vendor_available: true,
    target: {
        vendor: {
            cflags: ["-DLIBUI_IN_VNDK"],
            override_export_include_dirs: ["include_vndk"],
        },
    },
+10 −0
Original line number Diff line number Diff line
@@ -160,6 +160,16 @@ int BufferHubBuffer::ImportGraphicBuffer() {
    // GraphicBuffer instance can be created in future.
    mBufferHandle = bufferTraits.take_buffer_handle();

    // Populate buffer desc based on buffer traits.
    mBufferDesc.width = bufferTraits.width();
    mBufferDesc.height = bufferTraits.height();
    mBufferDesc.layers = bufferTraits.layer_count();
    mBufferDesc.format = bufferTraits.format();
    mBufferDesc.usage = bufferTraits.usage();
    mBufferDesc.stride = bufferTraits.stride();
    mBufferDesc.rfu0 = 0U;
    mBufferDesc.rfu1 = 0U;

    // If all imports succeed, replace the previous buffer and id.
    mId = bufferId;
    mClientStateMask = bufferTraits.client_state_mask();
+25 −0
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@

#include <grallocusage/GrallocUsageConversion.h>

#ifndef LIBUI_IN_VNDK
#include <ui/BufferHubBuffer.h>
#endif // LIBUI_IN_VNDK

#include <ui/Gralloc2.h>
#include <ui/GraphicBufferAllocator.h>
#include <ui/GraphicBufferMapper.h>
@@ -89,6 +93,21 @@ GraphicBuffer::GraphicBuffer(const native_handle_t* inHandle, HandleWrapMethod m
                                inUsage, inStride);
}

#ifndef LIBUI_IN_VNDK
GraphicBuffer::GraphicBuffer(std::unique_ptr<BufferHubBuffer> buffer) : GraphicBuffer() {
    if (buffer == nullptr) {
        mInitCheck = BAD_VALUE;
        return;
    }

    mInitCheck = initWithHandle(buffer->DuplicateHandle(), /*method=*/TAKE_UNREGISTERED_HANDLE,
                                buffer->desc().width, buffer->desc().height,
                                static_cast<PixelFormat>(buffer->desc().format),
                                buffer->desc().layers, buffer->desc().usage, buffer->desc().stride);
    mBufferHubBuffer = std::move(buffer);
}
#endif // LIBUI_IN_VNDK

GraphicBuffer::~GraphicBuffer()
{
    if (handle) {
@@ -483,6 +502,12 @@ status_t GraphicBuffer::unflatten(
    return NO_ERROR;
}

#ifndef LIBUI_IN_VNDK
bool GraphicBuffer::isBufferHubBuffer() const {
    return mBufferHubBuffer != nullptr;
}
#endif // LIBUI_IN_VNDK

// ---------------------------------------------------------------------------

}; // namespace android
+10 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <private/dvr/native_handle_wrapper.h>
#pragma clang diagnostic pop

#include <android/hardware_buffer.h>
#include <ui/BufferHubMetadata.h>

namespace android {
@@ -62,9 +63,9 @@ public:
    // Allocates a standalone BufferHubBuffer not associated with any producer consumer set.
    static std::unique_ptr<BufferHubBuffer> Create(uint32_t width, uint32_t height,
                                                   uint32_t layerCount, uint32_t format,
                                                   uint64_t usage, size_t mUserMetadataSize) {
                                                   uint64_t usage, size_t userMetadataSize) {
        return std::unique_ptr<BufferHubBuffer>(
                new BufferHubBuffer(width, height, layerCount, format, usage, mUserMetadataSize));
                new BufferHubBuffer(width, height, layerCount, format, usage, userMetadataSize));
    }

    // Imports the given channel handle to a BufferHubBuffer, taking ownership.
@@ -79,6 +80,9 @@ public:
    // bufferhubd share the same buffer id.
    int id() const { return mId; }

    // Returns the buffer description, which is guaranteed to be faithful values from bufferhubd.
    const AHardwareBuffer_Desc& desc() const { return mBufferDesc; }

    const native_handle_t* DuplicateHandle() { return mBufferHandle.DuplicateHandle(); }

    // Returns the current value of MetadataHeader::buffer_state.
@@ -118,7 +122,7 @@ public:

private:
    BufferHubBuffer(uint32_t width, uint32_t height, uint32_t layerCount, uint32_t format,
                    uint64_t usage, size_t mUserMetadataSize);
                    uint64_t usage, size_t userMetadataSize);

    BufferHubBuffer(pdx::LocalChannelHandle mChannelHandle);

@@ -128,6 +132,9 @@ private:
    int mId = -1;
    uint64_t mClientStateMask = 0;

    // Stores ground truth of the buffer.
    AHardwareBuffer_Desc mBufferDesc;

    // Wrapps the gralloc buffer handle of this buffer.
    dvr::NativeHandleWrapper<pdx::LocalHandle> mBufferHandle;

+19 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@

namespace android {

#ifndef LIBUI_IN_VNDK
class BufferHubBuffer;
#endif // LIBUI_IN_VNDK

class GraphicBufferMapper;

// ===========================================================================
@@ -133,6 +137,11 @@ public:
    GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
            uint32_t inUsage, std::string requestorName = "<Unknown>");

#ifndef LIBUI_IN_VNDK
    // Create a GraphicBuffer from an existing BufferHubBuffer.
    GraphicBuffer(std::unique_ptr<BufferHubBuffer> buffer);
#endif // LIBUI_IN_VNDK

    // return status
    status_t initCheck() const;

@@ -188,6 +197,11 @@ public:
    status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);

#ifndef LIBUI_IN_VNDK
    // Returns whether this GraphicBuffer is backed by BufferHubBuffer.
    bool isBufferHubBuffer() const;
#endif // LIBUI_IN_VNDK

private:
    ~GraphicBuffer();

@@ -237,6 +251,11 @@ private:
    // match the BufferQueue's internal generation number (set through
    // IGBP::setGenerationNumber), attempts to attach the buffer will fail.
    uint32_t mGenerationNumber;

#ifndef LIBUI_IN_VNDK
    // Stores a BufferHubBuffer that handles buffer signaling, identification.
    std::unique_ptr<BufferHubBuffer> mBufferHubBuffer;
#endif // LIBUI_IN_VNDK
};

}; // namespace android
Loading