1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #define FUZZ_LOG_TAG "gralloctypes" 17 18 #include <cstdint> 19 20 #include <aidl/android/hardware/graphics/common/BlendMode.h> 21 #include <aidl/android/hardware/graphics/common/Dataspace.h> 22 #include <aidl/android/hardware/graphics/common/ExtendableType.h> 23 #include <aidl/android/hardware/graphics/common/PlaneLayout.h> 24 #include <android/hardware/graphics/common/1.2/types.h> 25 #include <gralloctypes/Gralloc4.h> 26 #include <hidl/HidlSupport.h> 27 #include <utils/Errors.h> 28 29 #include "gralloctypes.h" 30 #include "util.h" 31 32 using ::android::status_t; 33 using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; 34 using BufferDescriptorInfo = android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo; 35 36 #define GRALLOCTYPES_DECODE(T, FUNC) \ 37 [] (const ::android::hardware::hidl_vec<uint8_t>& vec) {\ 38 FUZZ_LOG() << "about to read " #T " using " #FUNC;\ 39 T t;\ 40 status_t err = FUNC(vec, &t);\ 41 (void) err;\ 42 FUZZ_LOG() << #T " done " /* << "err: " << err*/;\ 43 } 44 45 #define GRALLOCTYPES_DECODE_VENDOR_HELPER(T, FUNC) \ 46 [] (const MetadataType& metadataType, const ::android::hardware::hidl_vec<uint8_t>& vec) {\ 47 FUZZ_LOG() << "about to read " #T " using " #FUNC;\ 48 T t;\ 49 status_t err = FUNC(metadataType, vec, &t);\ 50 (void) err;\ 51 FUZZ_LOG() << #T " done " /* << "err: " << err*/;\ 52 } 53 54 55 // clang-format off 56 std::vector<GrallocTypesDecode> GRALLOCTYPES_DECODE_FUNCTIONS { 57 GRALLOCTYPES_DECODE(BufferDescriptorInfo, ::android::gralloc4::decodeBufferDescriptorInfo), 58 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeBufferId), 59 GRALLOCTYPES_DECODE(std::string, ::android::gralloc4::decodeName), 60 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeWidth), 61 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeHeight), 62 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeLayerCount), 63 GRALLOCTYPES_DECODE(::android::hardware::graphics::common::V1_2::PixelFormat, ::android::gralloc4::decodePixelFormatRequested), 64 GRALLOCTYPES_DECODE(uint32_t, ::android::gralloc4::decodePixelFormatFourCC), 65 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodePixelFormatModifier), 66 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeUsage), 67 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeAllocationSize), 68 GRALLOCTYPES_DECODE(uint64_t, ::android::gralloc4::decodeProtectedContent), 69 GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::ExtendableType, ::android::gralloc4::decodeCompression), 70 GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::ExtendableType, ::android::gralloc4::decodeInterlaced), 71 GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::ExtendableType, ::android::gralloc4::decodeChromaSiting), 72 GRALLOCTYPES_DECODE(std::vector<aidl::android::hardware::graphics::common::PlaneLayout>, ::android::gralloc4::decodePlaneLayouts), 73 GRALLOCTYPES_DECODE(std::vector<aidl::android::hardware::graphics::common::Rect>, ::android::gralloc4::decodeCrop), 74 GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::Dataspace, ::android::gralloc4::decodeDataspace), 75 GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::BlendMode, ::android::gralloc4::decodeBlendMode), 76 GRALLOCTYPES_DECODE(std::optional<aidl::android::hardware::graphics::common::Smpte2086>, ::android::gralloc4::decodeSmpte2086), 77 GRALLOCTYPES_DECODE(std::optional<aidl::android::hardware::graphics::common::Cta861_3>, ::android::gralloc4::decodeCta861_3), 78 GRALLOCTYPES_DECODE(std::optional<std::vector<uint8_t>>, ::android::gralloc4::decodeSmpte2094_40), 79 }; 80 81 std::vector<GrallocTypesVendorHelperDecode> GRALLOCTYPES_DECODE_VENDOR_HELPER_FUNCTIONS { 82 GRALLOCTYPES_DECODE_VENDOR_HELPER(uint32_t, ::android::gralloc4::decodeUint32), 83 GRALLOCTYPES_DECODE_VENDOR_HELPER(int32_t, ::android::gralloc4::decodeInt32), 84 GRALLOCTYPES_DECODE_VENDOR_HELPER(uint64_t, ::android::gralloc4::decodeUint64), 85 GRALLOCTYPES_DECODE_VENDOR_HELPER(int64_t, ::android::gralloc4::decodeInt64), 86 GRALLOCTYPES_DECODE_VENDOR_HELPER(float, ::android::gralloc4::decodeFloat), 87 GRALLOCTYPES_DECODE_VENDOR_HELPER(double, ::android::gralloc4::decodeDouble), 88 GRALLOCTYPES_DECODE_VENDOR_HELPER(std::string, ::android::gralloc4::decodeString), 89 }; 90 // clang-format on 91