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

Commit 332765e8 authored by Alec Mouri's avatar Alec Mouri
Browse files

Update gralloc wrappers to support querying SMPTE 2094-10 metadata

Bug: 200309502
Test: builds
Test: GrallocTypes_test
Change-Id: Ia5b17d414d1ed83612e402e2615814f23d18830c
parent f76d573a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1134,6 +1134,18 @@ status_t decodeSmpte2094_40(const hidl_vec<uint8_t>& smpte2094_40,
                          decodeByteVector);
}

status_t encodeSmpte2094_10(const std::optional<std::vector<uint8_t>>& smpte2094_10,
                            hidl_vec<uint8_t>* outSmpte2094_10) {
    return encodeOptionalMetadata(MetadataType_Smpte2094_10, smpte2094_10, outSmpte2094_10,
                                  encodeByteVector);
}

status_t decodeSmpte2094_10(const hidl_vec<uint8_t>& smpte2094_10,
                            std::optional<std::vector<uint8_t>>* outSmpte2094_10) {
    return decodeOptionalMetadata(MetadataType_Smpte2094_10, smpte2094_10, outSmpte2094_10,
                                  decodeByteVector);
}

status_t encodeUint32(const MetadataType& metadataType, uint32_t input,
                      hidl_vec<uint8_t>* output) {
    return encodeMetadata(metadataType, input, output, encodeInteger);
+11 −0
Original line number Diff line number Diff line
@@ -134,6 +134,12 @@ static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType
                                             aidl::android::hardware::graphics::common::
                                                     StandardMetadataType::SMPTE2094_40)};

static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType
        MetadataType_Smpte2094_10 = {GRALLOC4_STANDARD_METADATA_TYPE,
                                     static_cast<int64_t>(
                                             aidl::android::hardware::graphics::common::
                                                     StandardMetadataType::SMPTE2094_10)};

/*---------------------------------------------------------------------------------------------*/

/**
@@ -327,6 +333,11 @@ status_t encodeSmpte2094_40(const std::optional<std::vector<uint8_t>>& smpte2094
status_t decodeSmpte2094_40(const android::hardware::hidl_vec<uint8_t>& smpte2094_40,
                            std::optional<std::vector<uint8_t>>* outSmpte2094_40);

status_t encodeSmpte2094_10(const std::optional<std::vector<uint8_t>>& smpte2094_10,
                            android::hardware::hidl_vec<uint8_t>* outSmpte2094_10);
status_t decodeSmpte2094_10(const android::hardware::hidl_vec<uint8_t>& smpte2094_10,
                            std::optional<std::vector<uint8_t>>* outSmpte2094_10);

/**
 * The functions below can be used to encode and decode vendor metadata types.
 */
+28 −0
Original line number Diff line number Diff line
@@ -455,6 +455,32 @@ TEST_P(Gralloc4TestSmpte2094_40, Smpte2094_40) {
    ASSERT_NO_FATAL_FAILURE(testHelperStableAidlTypeOptional(GetParam(), gralloc4::encodeSmpte2094_40, gralloc4::decodeSmpte2094_40));
}

class Gralloc4TestSmpte2094_10
      : public testing::TestWithParam<std::optional<std::vector<uint8_t>>> {};

INSTANTIATE_TEST_CASE_P(
        Gralloc4TestSmpte2094_10Params, Gralloc4TestSmpte2094_10,
        ::testing::Values(
                std::optional<std::vector<uint8_t>>({}),
                std::optional<std::vector<uint8_t>>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}),
                std::optional<std::vector<uint8_t>>({std::numeric_limits<uint8_t>::min(),
                                                     std::numeric_limits<uint8_t>::min() + 1,
                                                     std::numeric_limits<uint8_t>::min() + 2,
                                                     std::numeric_limits<uint8_t>::min() + 3,
                                                     std::numeric_limits<uint8_t>::min() + 4}),
                std::optional<std::vector<uint8_t>>({std::numeric_limits<uint8_t>::max(),
                                                     std::numeric_limits<uint8_t>::max() - 1,
                                                     std::numeric_limits<uint8_t>::max() - 2,
                                                     std::numeric_limits<uint8_t>::max() - 3,
                                                     std::numeric_limits<uint8_t>::max() - 4}),
                std::nullopt));

TEST_P(Gralloc4TestSmpte2094_10, Smpte2094_10) {
    ASSERT_NO_FATAL_FAILURE(testHelperStableAidlTypeOptional(GetParam(),
                                                             gralloc4::encodeSmpte2094_10,
                                                             gralloc4::decodeSmpte2094_10));
}

class Gralloc4TestBufferDescriptorInfo : public testing::TestWithParam<BufferDescriptorInfo> { };

INSTANTIATE_TEST_CASE_P(
@@ -491,6 +517,7 @@ TEST_F(Gralloc4TestErrors, Gralloc4TestEncodeNull) {
    ASSERT_NE(NO_ERROR, gralloc4::encodeSmpte2086({{}}, nullptr));
    ASSERT_NE(NO_ERROR, gralloc4::encodeCta861_3({{}}, nullptr));
    ASSERT_NE(NO_ERROR, gralloc4::encodeSmpte2094_40({{}}, nullptr));
    ASSERT_NE(NO_ERROR, gralloc4::encodeSmpte2094_10({{}}, nullptr));
}

TEST_F(Gralloc4TestErrors, Gralloc4TestDecodeNull) {
@@ -516,6 +543,7 @@ TEST_F(Gralloc4TestErrors, Gralloc4TestDecodeNull) {
    ASSERT_NE(NO_ERROR, gralloc4::decodeSmpte2086(vec, nullptr));
    ASSERT_NE(NO_ERROR, gralloc4::decodeCta861_3(vec, nullptr));
    ASSERT_NE(NO_ERROR, gralloc4::decodeSmpte2094_40(vec, nullptr));
    ASSERT_NE(NO_ERROR, gralloc4::decodeSmpte2094_10(vec, nullptr));
}

TEST_F(Gralloc4TestErrors, Gralloc4TestDecodeBadVec) {
+6 −0
Original line number Diff line number Diff line
@@ -634,6 +634,12 @@ status_t Gralloc4Mapper::getSmpte2094_40(
               outSmpte2094_40);
}

status_t Gralloc4Mapper::getSmpte2094_10(
        buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>>* outSmpte2094_10) const {
    return get(bufferHandle, gralloc4::MetadataType_Smpte2094_10, gralloc4::decodeSmpte2094_10,
               outSmpte2094_10);
}

template <class T>
status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format,
                                    uint32_t layerCount, uint64_t usage,
+5 −0
Original line number Diff line number Diff line
@@ -301,6 +301,11 @@ status_t GraphicBufferMapper::getSmpte2094_40(
    return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40);
}

status_t GraphicBufferMapper::getSmpte2094_10(
        buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>>* outSmpte2094_10) {
    return mMapper->getSmpte2094_10(bufferHandle, outSmpte2094_10);
}

status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height,
                                                          PixelFormat format, uint32_t layerCount,
                                                          uint64_t usage,
Loading