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

Commit c6394fff authored by Yichi Chen's avatar Yichi Chen
Browse files

gralloc4-vts: Allow YCRCB_420_SP to be unsupported in Lock_YCRCB_420_SP

Some devices may not support the legacy YCRCB_420_SP format. To allow
the test can pass through such devices, the patch adds the flexibility
when UNSUPPORTED is returned from buffer allocation.

Bug: 150461327
Bug: 152510209
Test: VtsHalGraphicsMapperV4_0Target

Change-Id: I393fc3c4a7d2421f07eeff88915041c92e8cdf05
parent f207cca0
Loading
Loading
Loading
Loading
+40 −40
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ sp<IAllocator> Gralloc::getAllocator() const {
    return mAllocator;
}

const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle) {
const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle,
                                            enum Tolerance /*tolerance*/) {
    const native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle());
    EXPECT_NE(nullptr, bufferHandle);

@@ -84,32 +85,27 @@ const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle) {

std::vector<const native_handle_t*> Gralloc::allocate(const BufferDescriptor& descriptor,
                                                      uint32_t count, bool import,
                                                      bool allowFailure, uint32_t* outStride) {
                                                      enum Tolerance tolerance,
                                                      uint32_t* outStride) {
    std::vector<const native_handle_t*> bufferHandles;
    bufferHandles.reserve(count);
    mAllocator->allocate(
            descriptor, count,
    mAllocator->allocate(descriptor, count,
                         [&](const auto& tmpError, const auto& tmpStride, const auto& tmpBuffers) {
                if (allowFailure && tmpError == Error::UNSUPPORTED) {
                             if (canTolerate(tolerance, tmpError)) {
                                 return;
                             }

                             ASSERT_EQ(Error::NONE, tmpError) << "failed to allocate buffers";
                             ASSERT_EQ(count, tmpBuffers.size()) << "invalid buffer array";

                             for (uint32_t i = 0; i < count; i++) {
                                 const native_handle_t* bufferHandle = nullptr;
                                 if (import) {
                        if (allowFailure) {
                            bufferHandle = importBuffer(tmpBuffers[i]);
                        } else {
                            ASSERT_NO_FATAL_FAILURE(bufferHandle = importBuffer(tmpBuffers[i]));
                        }
                                     ASSERT_NO_FATAL_FAILURE(
                                             bufferHandle = importBuffer(tmpBuffers[i], tolerance));
                                 } else {
                        if (allowFailure) {
                            bufferHandle = cloneBuffer(tmpBuffers[i]);
                        } else {
                            ASSERT_NO_FATAL_FAILURE(bufferHandle = cloneBuffer(tmpBuffers[i]));
                        }
                                     ASSERT_NO_FATAL_FAILURE(
                                             bufferHandle = cloneBuffer(tmpBuffers[i], tolerance));
                                 }
                                 if (bufferHandle) {
                                     bufferHandles.push_back(bufferHandle);
@@ -129,13 +125,14 @@ std::vector<const native_handle_t*> Gralloc::allocate(const BufferDescriptor& de
}

const native_handle_t* Gralloc::allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
                                         bool import, bool allowFailure, uint32_t* outStride) {
                                         bool import, enum Tolerance tolerance,
                                         uint32_t* outStride) {
    BufferDescriptor descriptor = createDescriptor(descriptorInfo);
    if (::testing::Test::HasFatalFailure()) {
        return nullptr;
    }

    auto buffers = allocate(descriptor, 1, import, allowFailure, outStride);
    auto buffers = allocate(descriptor, 1, import, tolerance, outStride);
    if (::testing::Test::HasFatalFailure()) {
        return nullptr;
    }
@@ -160,11 +157,14 @@ BufferDescriptor Gralloc::createDescriptor(const IMapper::BufferDescriptorInfo&
    return descriptor;
}

const native_handle_t* Gralloc::importBuffer(const hidl_handle& rawHandle) {
const native_handle_t* Gralloc::importBuffer(const hidl_handle& rawHandle,
                                             enum Tolerance tolerance) {
    const native_handle_t* bufferHandle = nullptr;
    mMapper->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBuffer) {
        if (!canTolerate(tolerance, tmpError)) {
            ASSERT_EQ(Error::NONE, tmpError)
                    << "failed to import buffer %p" << rawHandle.getNativeHandle();
        }
        bufferHandle = static_cast<const native_handle_t*>(tmpBuffer);
    });

+44 −7
Original line number Diff line number Diff line
@@ -37,6 +37,16 @@ using android::hardware::graphics::allocator::V4_0::IAllocator;
// A wrapper to IAllocator and IMapper.
class Gralloc {
  public:
    enum class Tolerance : uint32_t {
        kToleranceStrict = 0x0U,
        kToleranceBadDescriptor = 0x1U << std::underlying_type_t<Error>(Error::BAD_DESCRIPTOR),
        kToleranceBadBuffer = 0x1U << std::underlying_type_t<Error>(Error::BAD_BUFFER),
        kToleranceBadValue = 0x1U << std::underlying_type_t<Error>(Error::BAD_VALUE),
        kToleranceNoResource = 0x1U << std::underlying_type_t<Error>(Error::NO_RESOURCES),
        kToleranceUnSupported = 0x1U << std::underlying_type_t<Error>(Error::UNSUPPORTED),
        kToleranceAllErrors = ~0x0U,
    };

    Gralloc(const std::string& allocatorServiceName = "default",
            const std::string& mapperServiceName = "default", bool errOnFailure = true);
    ~Gralloc();
@@ -49,12 +59,27 @@ class Gralloc {
    // is true, the returned buffers are also imported into the mapper.
    //
    // Either case, the returned buffers must be freed with freeBuffer.
    std::vector<const native_handle_t*> allocate(const BufferDescriptor& descriptor, uint32_t count,
                                                 bool import = true, bool allowFailure = false,
                                                 uint32_t* outStride = nullptr);
    std::vector<const native_handle_t*> allocate(
            const BufferDescriptor& descriptor, uint32_t count, bool import = true,
            enum Tolerance tolerance = Tolerance::kToleranceStrict, uint32_t* outStride = nullptr);

    const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
                                    bool import = true, bool allowFailure = false,
                                    uint32_t* outStride = nullptr);
                                    bool import, enum Tolerance tolerance, uint32_t* outStride);

    const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
                                    bool import) {
        return allocate(descriptorInfo, import, Tolerance::kToleranceStrict);
    }

    const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
                                    bool import, enum Tolerance tolerance) {
        return allocate(descriptorInfo, import, tolerance, nullptr);
    }

    const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
                                    bool import, uint32_t* outStride) {
        return allocate(descriptorInfo, import, Tolerance::kToleranceStrict, outStride);
    }

    // IMapper methods

@@ -62,7 +87,11 @@ class Gralloc {

    BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo);

    const native_handle_t* importBuffer(const hidl_handle& rawHandle);
    const native_handle_t* importBuffer(const hidl_handle& rawHandle, enum Tolerance tolerance);
    const native_handle_t* importBuffer(const hidl_handle& rawHandle) {
        return importBuffer(rawHandle, Tolerance::kToleranceStrict);
    }

    void freeBuffer(const native_handle_t* bufferHandle);

    // We use fd instead of hidl_handle in these functions to pass fences
@@ -96,11 +125,19 @@ class Gralloc {
                            uint64_t* outReservedSize);

  private:
    bool canTolerate(Tolerance tolerance, Error error) {
        return (std::underlying_type_t<Tolerance>(tolerance) &
                0x1U << std::underlying_type_t<Error>(error)) != 0;
    }

    void init(const std::string& allocatorServiceName, const std::string& mapperServiceName);

    // initialize without checking for failure to get service
    void initNoErr(const std::string& allocatorServiceName, const std::string& mapperServiceName);
    const native_handle_t* cloneBuffer(const hidl_handle& rawHandle);
    const native_handle_t* cloneBuffer(const hidl_handle& rawHandle, enum Tolerance tolerance);
    const native_handle_t* cloneBuffer(const hidl_handle& rawHandle) {
        return cloneBuffer(rawHandle, Tolerance::kToleranceStrict);
    }

    sp<IAllocator> mAllocator;
    sp<IMapper> mMapper;
+16 −8
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ namespace {

using android::hardware::graphics::common::V1_2::BufferUsage;
using android::hardware::graphics::common::V1_2::PixelFormat;
using Tolerance = ::android::hardware::graphics::mapper::V4_0::vts::Gralloc::Tolerance;
using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;
using aidl::android::hardware::graphics::common::BlendMode;
using aidl::android::hardware::graphics::common::Cta861_3;
@@ -331,8 +332,9 @@ TEST_P(GraphicsMapperHidlTest, AllocatorAllocate) {
    for (uint32_t count = 0; count < 5; count++) {
        std::vector<const native_handle_t*> bufferHandles;
        uint32_t stride;
        ASSERT_NO_FATAL_FAILURE(
                bufferHandles = mGralloc->allocate(descriptor, count, false, false, &stride));
        ASSERT_NO_FATAL_FAILURE(bufferHandles =
                                        mGralloc->allocate(descriptor, count, false,
                                                           Tolerance::kToleranceStrict, &stride));

        if (count >= 1) {
            EXPECT_LE(mDummyDescriptorInfo.width, stride) << "invalid buffer stride";
@@ -532,7 +534,8 @@ TEST_P(GraphicsMapperHidlTest, LockUnlockBasic) {

    const native_handle_t* bufferHandle;
    uint32_t stride;
    ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(info, true, false, &stride));
    ASSERT_NO_FATAL_FAILURE(
            bufferHandle = mGralloc->allocate(info, true, Tolerance::kToleranceStrict, &stride));

    // lock buffer for writing
    const IMapper::Rect region{0, 0, static_cast<int32_t>(info.width),
@@ -566,7 +569,12 @@ TEST_P(GraphicsMapperHidlTest, Lock_YCRCB_420_SP) {

    const native_handle_t* bufferHandle;
    uint32_t stride;
    ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(info, true, false, &stride));
    ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(
                                    info, true, Tolerance::kToleranceUnSupported, &stride));
    if (bufferHandle == nullptr) {
        GTEST_SUCCEED() << "YCRCB_420_SP format is unsupported";
        return;
    }

    // lock buffer for writing
    const IMapper::Rect region{0, 0, static_cast<int32_t>(info.width),
@@ -741,8 +749,8 @@ TEST_P(GraphicsMapperHidlTest, FlushRereadBasic) {

    const native_handle_t* rawHandle;
    uint32_t stride;
    ASSERT_NO_FATAL_FAILURE(
            rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false, false, &stride));
    ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false,
                                                           Tolerance::kToleranceStrict, &stride));

    const native_handle_t* writeBufferHandle;
    const native_handle_t* readBufferHandle;
@@ -964,7 +972,7 @@ TEST_P(GraphicsMapperHidlTest, GetProtectedContent) {
    info.usage = BufferUsage::PROTECTED | BufferUsage::COMPOSER_OVERLAY;

    const native_handle_t* bufferHandle = nullptr;
    bufferHandle = mGralloc->allocate(info, true, true);
    bufferHandle = mGralloc->allocate(info, true, Tolerance::kToleranceAllErrors);
    if (!bufferHandle) {
        GTEST_SUCCEED() << "unable to allocate protected content";
        return;
@@ -1267,7 +1275,7 @@ TEST_P(GraphicsMapperHidlTest, SetProtectedContent) {
    auto info = mDummyDescriptorInfo;
    info.usage = BufferUsage::PROTECTED | BufferUsage::COMPOSER_OVERLAY;

    bufferHandle = mGralloc->allocate(info, true, true);
    bufferHandle = mGralloc->allocate(info, true, Tolerance::kToleranceAllErrors);
    if (!bufferHandle) {
        GTEST_SUCCEED() << "unable to allocate protected content";
        return;