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

Commit a6a4ed3a authored by Joseph Murphy's avatar Joseph Murphy Committed by Android (Google) Code Review
Browse files

Merge "Revert submission"

parents dd18a7a7 048552ff
Loading
Loading
Loading
Loading
+2 −191
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ using android::hardware::hidl_vec;
using aidl::android::hardware::graphics::common::BlendMode;
using aidl::android::hardware::graphics::common::ChromaSiting;
using aidl::android::hardware::graphics::common::Compression;
using aidl::android::hardware::graphics::common::Cta861_3;
using aidl::android::hardware::graphics::common::Dataspace;
using aidl::android::hardware::graphics::common::ExtendableType;
using aidl::android::hardware::graphics::common::Interlaced;
@@ -36,9 +35,7 @@ using aidl::android::hardware::graphics::common::PlaneLayout;
using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
using aidl::android::hardware::graphics::common::Rect;
using aidl::android::hardware::graphics::common::Smpte2086;
using aidl::android::hardware::graphics::common::StandardMetadataType;
using aidl::android::hardware::graphics::common::XyColor;

using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;

@@ -157,13 +154,6 @@ public:
        return mVec->size() > mOffset;
    }

    size_t getRemainingSize() {
        if (!mVec) {
            return 0;
        }
        return mVec->size() - mOffset;
    }

private:
    const hidl_vec<uint8_t>* mVec;
    size_t mOffset = 0;
@@ -228,15 +218,6 @@ status_t encode(const MetadataType& metadataType, const T& input, hidl_vec<uint8
    return encodeHelper(input, &outputHidlVec);
}

template <class T>
status_t encodeOptional(const MetadataType& metadataType, const std::optional<T>& input,
                        hidl_vec<uint8_t>* output, EncodeHelper<T> encodeHelper) {
    if (!input) {
        return NO_ERROR;
    }
    return encode(metadataType, *input, output, encodeHelper);
}

/**
 * decode is the main decode function. It takes in a hidl_vec and uses the decodeHelper function to
 * turn the hidl_vec byte stream into T. If an error occurs, the errorHandler function cleans up
@@ -268,32 +249,13 @@ status_t decode(const MetadataType& metadataType, const hidl_vec<uint8_t>& input
    return NO_ERROR;
}

template <class T>
status_t decodeOptional(const MetadataType& metadataType, const hidl_vec<uint8_t>& input,
                        std::optional<T>* output, DecodeHelper<T> decodeHelper) {
    if (!output) {
        return BAD_VALUE;
    }
    if (input.size() <= 0) {
        output->reset();
        return NO_ERROR;
    }
    T tmp;
    status_t err = decode(metadataType, input, &tmp, decodeHelper);
    if (!err) {
        *output = tmp;
    }
    return err;
}

/**
 * Private helper functions
 */
template <class T>
status_t encodeInteger(const T& input, OutputHidlVec* output) {
    static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value ||
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value ||
                  std::is_same<T, float>::value || std::is_same<T, double>::value);
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value);
    if (!output) {
        return BAD_VALUE;
    }
@@ -305,8 +267,7 @@ status_t encodeInteger(const T& input, OutputHidlVec* output) {
template <class T>
status_t decodeInteger(InputHidlVec* input, T* output) {
    static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value ||
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value ||
                  std::is_same<T, float>::value || std::is_same<T, double>::value);
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value);
    if (!output) {
        return BAD_VALUE;
    }
@@ -345,38 +306,6 @@ status_t decodeString(InputHidlVec* input, std::string* output) {
    return input->decode(output, size);
}

status_t encodeByteVector(const std::vector<uint8_t>& input, OutputHidlVec* output) {
    if (!output) {
        return BAD_VALUE;
    }

    status_t err = encodeInteger<int64_t>(input.size(), output);
    if (err) {
        return err;
    }

    return output->encode(input.data(), input.size());
}

status_t decodeByteVector(InputHidlVec* input, std::vector<uint8_t>* output) {
    if (!output) {
        return BAD_VALUE;
    }

    int64_t size = 0;
    status_t err = decodeInteger<int64_t>(input, &size);
    if (err || size < 0) {
        return err;
    }

    if (size > input->getRemainingSize()) {
        return BAD_VALUE;
    }
    output->resize(size);

    return input->decode(output->data(), size);
}

status_t encodeExtendableType(const ExtendableType& input, OutputHidlVec* output) {
    status_t err = encodeString(input.name, output);
    if (err) {
@@ -462,30 +391,6 @@ status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedM
    return NO_ERROR;
}

status_t encodeXyColor(const XyColor& input, OutputHidlVec* output) {
    status_t err = encodeInteger<float>(input.x, output);
    if (err) {
        return err;
    }
    return encodeInteger<float>(input.y, output);
}

status_t decodeXyColor(InputHidlVec* input, XyColor* output) {
    status_t err = decodeInteger<float>(input, &output->x);
    if (err) {
        return err;
    }
    return decodeInteger<float>(input, &output->y);
}

void clearXyColor(XyColor* output) {
    if (!output) {
        return;
    }
    output->x = 0;
    output->y = 0;
}

status_t encodeRect(const Rect& input, OutputHidlVec* output) {
    status_t err = encodeInteger<int32_t>(static_cast<int32_t>(input.left), output);
    if (err) {
@@ -730,70 +635,6 @@ void clearPlaneLayouts(std::vector<PlaneLayout>* output) {
    output->clear();
}

status_t encodeSmpte2086Helper(const Smpte2086& smpte2086, OutputHidlVec* outOutputHidlVec) {
    status_t err = encodeXyColor(smpte2086.primaryRed, outOutputHidlVec);
    if (err) {
        return err;
    }
    err = encodeXyColor(smpte2086.primaryGreen, outOutputHidlVec);
    if (err) {
        return err;
    }
    err = encodeXyColor(smpte2086.primaryBlue, outOutputHidlVec);
    if (err) {
        return err;
    }
    err = encodeXyColor(smpte2086.whitePoint, outOutputHidlVec);
    if (err) {
        return err;
    }
    err = encodeInteger<float>(smpte2086.maxLuminance, outOutputHidlVec);
    if (err) {
        return err;
    }
    return encodeInteger<float>(smpte2086.minLuminance, outOutputHidlVec);
}

status_t decodeSmpte2086Helper(InputHidlVec* inputHidlVec, Smpte2086* outSmpte2086) {
    status_t err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryRed);
    if (err) {
        return err;
    }
    err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryGreen);
    if (err) {
        return err;
    }
    err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryBlue);
    if (err) {
        return err;
    }
    err = decodeXyColor(inputHidlVec, &outSmpte2086->whitePoint);
    if (err) {
        return err;
    }
    err = decodeInteger<float>(inputHidlVec, &outSmpte2086->maxLuminance);
    if (err) {
        return err;
    }
    return decodeInteger<float>(inputHidlVec, &outSmpte2086->minLuminance);
}

status_t encodeCta861_3Helper(const Cta861_3& cta861_3, OutputHidlVec* outOutputHidlVec) {
    status_t err = encodeInteger<float>(cta861_3.maxContentLightLevel, outOutputHidlVec);
    if (err) {
        return err;
    }
    return encodeInteger<float>(cta861_3.maxFrameAverageLightLevel, outOutputHidlVec);
}

status_t decodeCta861_3Helper(InputHidlVec* inputHidlVec, Cta861_3* outCta861_3) {
    status_t err = decodeInteger<float>(inputHidlVec, &outCta861_3->maxContentLightLevel);
    if (err) {
        return err;
    }
    return decodeInteger<float>(inputHidlVec, &outCta861_3->maxFrameAverageLightLevel);
}

/**
 * Public API functions
 */
@@ -957,36 +798,6 @@ status_t decodeBlendMode(const hidl_vec<uint8_t>& blendMode, BlendMode* outBlend
                  decodeInteger);
}

status_t encodeSmpte2086(const std::optional<Smpte2086>& smpte2086,
                         hidl_vec<uint8_t>* outSmpte2086) {
    return encodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, encodeSmpte2086Helper);
}

status_t decodeSmpte2086(const hidl_vec<uint8_t>& smpte2086,
                         std::optional<Smpte2086>* outSmpte2086) {
    return decodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, decodeSmpte2086Helper);
}

status_t encodeCta861_3(const std::optional<Cta861_3>& cta861_3, hidl_vec<uint8_t>* outCta861_3) {
    return encodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, encodeCta861_3Helper);
}

status_t decodeCta861_3(const hidl_vec<uint8_t>& cta861_3, std::optional<Cta861_3>* outCta861_3) {
    return decodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, decodeCta861_3Helper);
}

status_t encodeSmpte2094_40(const std::optional<std::vector<uint8_t>>& smpte2094_40,
                            hidl_vec<uint8_t>* outSmpte2094_40) {
    return encodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40,
                          encodeByteVector);
}

status_t decodeSmpte2094_40(const hidl_vec<uint8_t>& smpte2094_40,
                            std::optional<std::vector<uint8_t>>* outSmpte2094_40) {
    return decodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40,
                          decodeByteVector);
}

bool isStandardMetadataType(const MetadataType& metadataType) {
    return !std::strncmp(metadataType.name.c_str(), GRALLOC4_STANDARD_METADATA_TYPE,
                         metadataType.name.size());
+0 −3
Original line number Diff line number Diff line
@@ -60,8 +60,5 @@ std::vector<GrallocTypesDecode> GRALLOCTYPES_DECODE_FUNCTIONS {
    GRALLOCTYPES_DECODE(std::vector<aidl::android::hardware::graphics::common::PlaneLayout>, ::android::gralloc4::decodePlaneLayouts),
    GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::Dataspace, ::android::gralloc4::decodeDataspace),
    GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::BlendMode, ::android::gralloc4::decodeBlendMode),
    GRALLOCTYPES_DECODE(std::optional<aidl::android::hardware::graphics::common::Smpte2086>, ::android::gralloc4::decodeSmpte2086),
    GRALLOCTYPES_DECODE(std::optional<aidl::android::hardware::graphics::common::Cta861_3>, ::android::gralloc4::decodeCta861_3),
    GRALLOCTYPES_DECODE(std::optional<std::vector<uint8_t>>, ::android::gralloc4::decodeSmpte2094_40),
};
// clang-format on
+5 −41
Original line number Diff line number Diff line
@@ -17,17 +17,16 @@
#pragma once

#include <aidl/android/hardware/graphics/common/BlendMode.h>
#include <aidl/android/hardware/graphics/common/ChromaSiting.h>
#include <aidl/android/hardware/graphics/common/Compression.h>
#include <aidl/android/hardware/graphics/common/Cta861_3.h>
#include <aidl/android/hardware/graphics/common/Dataspace.h>
#include <aidl/android/hardware/graphics/common/ExtendableType.h>
#include <aidl/android/hardware/graphics/common/Interlaced.h>
#include <aidl/android/hardware/graphics/common/PlaneLayout.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <aidl/android/hardware/graphics/common/Smpte2086.h>
#include <aidl/android/hardware/graphics/common/ChromaSiting.h>
#include <aidl/android/hardware/graphics/common/Compression.h>
#include <aidl/android/hardware/graphics/common/Interlaced.h>
#include <aidl/android/hardware/graphics/common/StandardMetadataType.h>
#include <aidl/android/hardware/graphics/common/XyColor.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>

#include <android/hardware/graphics/mapper/4.0/IMapper.h>

namespace android {
@@ -114,22 +113,6 @@ static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType Me
        GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::BLEND_MODE)
};

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

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

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

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

/**
@@ -289,25 +272,6 @@ status_t decodeDataspace(const android::hardware::hidl_vec<uint8_t>& dataspace,
status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec<uint8_t>* outBlendMode);
status_t decodeBlendMode(const android::hardware::hidl_vec<uint8_t>& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode);

status_t encodeSmpte2086(
        const std::optional<aidl::android::hardware::graphics::common::Smpte2086>& smpte2086,
        android::hardware::hidl_vec<uint8_t>* outSmpte2086);
status_t decodeSmpte2086(
        const android::hardware::hidl_vec<uint8_t>& smpte2086,
        std::optional<aidl::android::hardware::graphics::common::Smpte2086>* outSmpte2086);

status_t encodeCta861_3(
        const std::optional<aidl::android::hardware::graphics::common::Cta861_3>& cta861_3,
        android::hardware::hidl_vec<uint8_t>* outCta861_3);
status_t decodeCta861_3(
        const android::hardware::hidl_vec<uint8_t>& cta861_3,
        std::optional<aidl::android::hardware::graphics::common::Cta861_3>* outCta861_3);

status_t encodeSmpte2094_40(const std::optional<std::vector<uint8_t>>& smpte2094_40,
                            android::hardware::hidl_vec<uint8_t>* outSmpte2094_40);
status_t decodeSmpte2094_40(const android::hardware::hidl_vec<uint8_t>& smpte2094_40,
                            std::optional<std::vector<uint8_t>>* outSmpte2094_40);

/**
 * The functions below can be used to parse extendable types.
 */
+0 −18
Original line number Diff line number Diff line
@@ -614,24 +614,6 @@ status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle,
               outBlendMode);
}

status_t Gralloc4Mapper::getSmpte2086(buffer_handle_t bufferHandle,
                                      std::optional<ui::Smpte2086>* outSmpte2086) const {
    return get(bufferHandle, gralloc4::MetadataType_Smpte2086, gralloc4::decodeSmpte2086,
               outSmpte2086);
}

status_t Gralloc4Mapper::getCta861_3(buffer_handle_t bufferHandle,
                                     std::optional<ui::Cta861_3>* outCta861_3) const {
    return get(bufferHandle, gralloc4::MetadataType_Cta861_3, gralloc4::decodeCta861_3,
               outCta861_3);
}

status_t Gralloc4Mapper::getSmpte2094_40(
        buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>>* outSmpte2094_40) const {
    return get(bufferHandle, gralloc4::MetadataType_Smpte2094_40, gralloc4::decodeSmpte2094_40,
               outSmpte2094_40);
}

template <class T>
status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format,
                                    uint32_t layerCount, uint64_t usage,
+0 −15
Original line number Diff line number Diff line
@@ -286,21 +286,6 @@ status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle,
    return mMapper->getBlendMode(bufferHandle, outBlendMode);
}

status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle,
                                           std::optional<ui::Smpte2086>* outSmpte2086) {
    return mMapper->getSmpte2086(bufferHandle, outSmpte2086);
}

status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle,
                                          std::optional<ui::Cta861_3>* outCta861_3) {
    return mMapper->getCta861_3(bufferHandle, outCta861_3);
}

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

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