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

Commit aa04f5be authored by Chia-I Wu's avatar Chia-I Wu Committed by android-build-merger
Browse files

graphics: clang-format allocator default impl am: 864c9f82 am: 06515116

am: c11b3505

Change-Id: Iffa1203ba058201539f0bb34c910c5fddb93a66f
parents 986c62c8 c11b3505
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@

#include <hidl/LegacySupport.h>

using android::hardware::graphics::allocator::V2_0::IAllocator;
using android::hardware::defaultPassthroughServiceImplementation;
using android::hardware::graphics::allocator::V2_0::IAllocator;

int main() {
    return defaultPassthroughServiceImplementation<IAllocator>(4);
+7 −11
Original line number Diff line number Diff line
@@ -32,14 +32,12 @@ namespace allocator {
namespace V2_0 {
namespace implementation {

using android::hardware::graphics::mapper::V2_0::implementation::
    grallocDecodeBufferDescriptor;
using android::hardware::graphics::mapper::V2_0::implementation::grallocDecodeBufferDescriptor;

Gralloc0Allocator::Gralloc0Allocator(const hw_module_t* module) {
    int result = gralloc_open(module, &mDevice);
    if (result) {
        LOG_ALWAYS_FATAL("failed to open gralloc0 device: %s",
                         strerror(-result));
        LOG_ALWAYS_FATAL("failed to open gralloc0 device: %s", strerror(-result));
    }
}

@@ -59,8 +57,8 @@ Return<void> Gralloc0Allocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
    return Void();
}

Return<void> Gralloc0Allocator::allocate(const BufferDescriptor& descriptor,
                                         uint32_t count, allocate_cb hidl_cb) {
Return<void> Gralloc0Allocator::allocate(const BufferDescriptor& descriptor, uint32_t count,
                                         allocate_cb hidl_cb) {
    IMapper::BufferDescriptorInfo descriptorInfo;
    if (!grallocDecodeBufferDescriptor(descriptor, &descriptorInfo)) {
        hidl_cb(Error::BAD_DESCRIPTOR, 0, hidl_vec<hidl_handle>());
@@ -110,17 +108,15 @@ Return<void> Gralloc0Allocator::allocate(const BufferDescriptor& descriptor,
}

Error Gralloc0Allocator::allocateOne(const IMapper::BufferDescriptorInfo& info,
                                     buffer_handle_t* outBuffer,
                                     uint32_t* outStride) {
                                     buffer_handle_t* outBuffer, uint32_t* outStride) {
    if (info.layerCount > 1 || (info.usage >> 32) != 0) {
        return Error::BAD_VALUE;
    }

    buffer_handle_t buffer = nullptr;
    int stride = 0;
    int result = mDevice->alloc(mDevice, info.width, info.height,
                                static_cast<int>(info.format), info.usage,
                                &buffer, &stride);
    int result = mDevice->alloc(mDevice, info.width, info.height, static_cast<int>(info.format),
                                info.usage, &buffer, &stride);
    if (result) {
        switch (result) {
            case -EINVAL:
+3 −3
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ namespace allocator {
namespace V2_0 {
namespace implementation {

using android::hardware::graphics::mapper::V2_0::IMapper;
using android::hardware::graphics::mapper::V2_0::BufferDescriptor;
using android::hardware::graphics::mapper::V2_0::Error;
using android::hardware::graphics::mapper::V2_0::IMapper;

class Gralloc0Allocator : public IAllocator {
   public:
@@ -43,8 +43,8 @@ class Gralloc0Allocator : public IAllocator {
                          allocate_cb hidl_cb) override;

   private:
    Error allocateOne(const IMapper::BufferDescriptorInfo& info,
                      buffer_handle_t* outBuffer, uint32_t* outStride);
    Error allocateOne(const IMapper::BufferDescriptorInfo& info, buffer_handle_t* outBuffer,
                      uint32_t* outStride);

    alloc_device_t* mDevice;
};
+20 −36
Original line number Diff line number Diff line
@@ -33,15 +33,13 @@ namespace V2_0 {
namespace implementation {

using android::hardware::graphics::common::V1_0::BufferUsage;
using android::hardware::graphics::mapper::V2_0::implementation::
    grallocDecodeBufferDescriptor;
using android::hardware::graphics::mapper::V2_0::implementation::grallocDecodeBufferDescriptor;

Gralloc1Allocator::Gralloc1Allocator(const hw_module_t* module)
    : mDevice(nullptr), mCapabilities(), mDispatch() {
    int result = gralloc1_open(module, &mDevice);
    if (result) {
        LOG_ALWAYS_FATAL("failed to open gralloc1 device: %s",
                         strerror(-result));
        LOG_ALWAYS_FATAL("failed to open gralloc1 device: %s", strerror(-result));
    }

    initCapabilities();
@@ -69,8 +67,7 @@ void Gralloc1Allocator::initCapabilities() {
}

template <typename T>
void Gralloc1Allocator::initDispatch(gralloc1_function_descriptor_t desc,
                                     T* outPfn) {
void Gralloc1Allocator::initDispatch(gralloc1_function_descriptor_t desc, T* outPfn) {
    auto pfn = mDevice->getFunction(mDevice, desc);
    if (!pfn) {
        LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc);
@@ -81,20 +78,15 @@ void Gralloc1Allocator::initDispatch(gralloc1_function_descriptor_t desc,

void Gralloc1Allocator::initDispatch() {
    initDispatch(GRALLOC1_FUNCTION_DUMP, &mDispatch.dump);
    initDispatch(GRALLOC1_FUNCTION_CREATE_DESCRIPTOR,
                 &mDispatch.createDescriptor);
    initDispatch(GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR,
                 &mDispatch.destroyDescriptor);
    initDispatch(GRALLOC1_FUNCTION_CREATE_DESCRIPTOR, &mDispatch.createDescriptor);
    initDispatch(GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR, &mDispatch.destroyDescriptor);
    initDispatch(GRALLOC1_FUNCTION_SET_DIMENSIONS, &mDispatch.setDimensions);
    initDispatch(GRALLOC1_FUNCTION_SET_FORMAT, &mDispatch.setFormat);
    if (mCapabilities.layeredBuffers) {
        initDispatch(GRALLOC1_FUNCTION_SET_LAYER_COUNT,
                     &mDispatch.setLayerCount);
        initDispatch(GRALLOC1_FUNCTION_SET_LAYER_COUNT, &mDispatch.setLayerCount);
    }
    initDispatch(GRALLOC1_FUNCTION_SET_CONSUMER_USAGE,
                 &mDispatch.setConsumerUsage);
    initDispatch(GRALLOC1_FUNCTION_SET_PRODUCER_USAGE,
                 &mDispatch.setProducerUsage);
    initDispatch(GRALLOC1_FUNCTION_SET_CONSUMER_USAGE, &mDispatch.setConsumerUsage);
    initDispatch(GRALLOC1_FUNCTION_SET_PRODUCER_USAGE, &mDispatch.setProducerUsage);
    initDispatch(GRALLOC1_FUNCTION_GET_STRIDE, &mDispatch.getStride);
    initDispatch(GRALLOC1_FUNCTION_ALLOCATE, &mDispatch.allocate);
    initDispatch(GRALLOC1_FUNCTION_RELEASE, &mDispatch.release);
@@ -116,8 +108,8 @@ Return<void> Gralloc1Allocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
    return Void();
}

Return<void> Gralloc1Allocator::allocate(const BufferDescriptor& descriptor,
                                         uint32_t count, allocate_cb hidl_cb) {
Return<void> Gralloc1Allocator::allocate(const BufferDescriptor& descriptor, uint32_t count,
                                         allocate_cb hidl_cb) {
    IMapper::BufferDescriptorInfo descriptorInfo;
    if (!grallocDecodeBufferDescriptor(descriptor, &descriptorInfo)) {
        hidl_cb(Error::BAD_DESCRIPTOR, 0, hidl_vec<hidl_handle>());
@@ -199,8 +191,7 @@ uint64_t Gralloc1Allocator::toProducerUsage(uint64_t usage) {
    // this is potentially broken as we have no idea which private flags
    // should be filtered out
    uint64_t producerUsage =
        usage &
        ~static_cast<uint64_t>(BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK |
        usage & ~static_cast<uint64_t>(BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK |
                                       BufferUsage::GPU_DATA_BUFFER);

    switch (usage & BufferUsage::CPU_WRITE_MASK) {
@@ -258,36 +249,30 @@ uint64_t Gralloc1Allocator::toConsumerUsage(uint64_t usage) {
    return consumerUsage;
}

Error Gralloc1Allocator::createDescriptor(
    const IMapper::BufferDescriptorInfo& info,
Error Gralloc1Allocator::createDescriptor(const IMapper::BufferDescriptorInfo& info,
                                          gralloc1_buffer_descriptor_t* outDescriptor) {
    gralloc1_buffer_descriptor_t descriptor;

    int32_t error = mDispatch.createDescriptor(mDevice, &descriptor);

    if (error == GRALLOC1_ERROR_NONE) {
        error = mDispatch.setDimensions(mDevice, descriptor, info.width,
                                        info.height);
        error = mDispatch.setDimensions(mDevice, descriptor, info.width, info.height);
    }
    if (error == GRALLOC1_ERROR_NONE) {
        error = mDispatch.setFormat(mDevice, descriptor,
                                    static_cast<int32_t>(info.format));
        error = mDispatch.setFormat(mDevice, descriptor, static_cast<int32_t>(info.format));
    }
    if (error == GRALLOC1_ERROR_NONE) {
        if (mCapabilities.layeredBuffers) {
            error =
                mDispatch.setLayerCount(mDevice, descriptor, info.layerCount);
            error = mDispatch.setLayerCount(mDevice, descriptor, info.layerCount);
        } else if (info.layerCount > 1) {
            error = GRALLOC1_ERROR_UNSUPPORTED;
        }
    }
    if (error == GRALLOC1_ERROR_NONE) {
        error = mDispatch.setProducerUsage(mDevice, descriptor,
                                           toProducerUsage(info.usage));
        error = mDispatch.setProducerUsage(mDevice, descriptor, toProducerUsage(info.usage));
    }
    if (error == GRALLOC1_ERROR_NONE) {
        error = mDispatch.setConsumerUsage(mDevice, descriptor,
                                           toConsumerUsage(info.usage));
        error = mDispatch.setConsumerUsage(mDevice, descriptor, toConsumerUsage(info.usage));
    }

    if (error == GRALLOC1_ERROR_NONE) {
@@ -300,8 +285,7 @@ Error Gralloc1Allocator::createDescriptor(
}

Error Gralloc1Allocator::allocateOne(gralloc1_buffer_descriptor_t descriptor,
                                     buffer_handle_t* outBuffer,
                                     uint32_t* outStride) {
                                     buffer_handle_t* outBuffer, uint32_t* outStride) {
    buffer_handle_t buffer = nullptr;
    int32_t error = mDispatch.allocate(mDevice, 1, &descriptor, &buffer);
    if (error != GRALLOC1_ERROR_NONE && error != GRALLOC1_ERROR_NOT_SHARED) {
+3 −3
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ namespace allocator {
namespace V2_0 {
namespace implementation {

using android::hardware::graphics::mapper::V2_0::IMapper;
using android::hardware::graphics::mapper::V2_0::BufferDescriptor;
using android::hardware::graphics::mapper::V2_0::Error;
using android::hardware::graphics::mapper::V2_0::IMapper;

class Gralloc1Allocator : public IAllocator {
   public:
@@ -55,8 +55,8 @@ class Gralloc1Allocator : public IAllocator {

    Error createDescriptor(const IMapper::BufferDescriptorInfo& info,
                           gralloc1_buffer_descriptor_t* outDescriptor);
    Error allocateOne(gralloc1_buffer_descriptor_t descriptor,
                      buffer_handle_t* outBuffer, uint32_t* outStride);
    Error allocateOne(gralloc1_buffer_descriptor_t descriptor, buffer_handle_t* outBuffer,
                      uint32_t* outStride);

    gralloc1_device_t* mDevice;

+6 −6

File changed.

Contains only whitespace changes.

+7 −7

File changed.

Contains only whitespace changes.

Loading