1 #pragma once
2 
3 #include <aidl/android/hardware/graphics/common/StandardMetadataType.h>
4 #include <gralloctypes/Gralloc4.h>
5 
6 #include <cstdint>
7 #include <limits>
8 
9 #include "format.h"
10 #include "format_type.h"
11 
12 namespace pixel::graphics {
13 
14 constexpr const char* kGralloc4StandardMetadataTypeName = GRALLOC4_STANDARD_METADATA_TYPE;
15 constexpr const char* kPixelMetadataTypeName = "android.hardware.graphics.common.PixelMetadataType";
16 
17 using StandardMetadataType = aidl::android::hardware::graphics::common::StandardMetadataType;
18 
19 #define MapMetadataType(f) f = static_cast<uint64_t>(StandardMetadataType::f)
20 
21 // This seemingly clashes with MetadataType in Mapper, but this enum represents just the "value"
22 // member of that struct. MetadataType comprises of a metadata name and value. Name is just there to
23 // identify what kind of metadata it is. So, for all StandardMetadataType, clients need to use
24 // kGralloc4StandardMetadataType and for pixel specific metadata, clients should use
25 // kPixelMetadataType.
26 enum class MetadataType : int64_t {
27     MapMetadataType(INVALID),
28     MapMetadataType(BUFFER_ID),
29     MapMetadataType(NAME),
30     MapMetadataType(WIDTH),
31     MapMetadataType(HEIGHT),
32     MapMetadataType(LAYER_COUNT),
33     MapMetadataType(PIXEL_FORMAT_REQUESTED),
34     MapMetadataType(PIXEL_FORMAT_FOURCC),
35     MapMetadataType(PIXEL_FORMAT_MODIFIER),
36     MapMetadataType(USAGE),
37     MapMetadataType(ALLOCATION_SIZE),
38     MapMetadataType(PROTECTED_CONTENT),
39     MapMetadataType(COMPRESSION),
40     MapMetadataType(INTERLACED),
41     MapMetadataType(CHROMA_SITING),
42     MapMetadataType(PLANE_LAYOUTS),
43     MapMetadataType(CROP),
44     MapMetadataType(DATASPACE),
45     MapMetadataType(BLEND_MODE),
46     MapMetadataType(SMPTE2086),
47     MapMetadataType(CTA861_3),
48     MapMetadataType(SMPTE2094_40),
49     MapMetadataType(SMPTE2094_10),
50     MapMetadataType(STRIDE),
51 
52     // Pixel specific metadata
53     // Make sure to use kPixelMetadataType as the name when using these metadata.
54 
55     // TODO: These metadata queries returns a pointer inside metadata for now. Need to change that
56     // so we are returning proper data only.
57     // Returns: void*
58     VIDEO_HDR = std::numeric_limits<int64_t>::max() - (1 << 16),
59 
60     // TODO(b/289448426#comment2): ROIINFO is probably not being used. Remove this after
61     // confirmation.
62     // Returns: void*
63     VIDEO_ROI,
64 
65     // This metadata just refers to the same fd contained in buffer handle and not a clone.
66     // So the client should not attempt to close these fds.
67     // Returns: std::vector<int>
68     PLANE_DMA_BUFS,
69 
70     // PLANE_LAYOUTS from gralloc reply with the actual offset of the plane from the start of the
71     // header if any. But some IPs require the offset starting from the body of a plane.
72     // Returns: std::vector<CompressedPlaneLayout>
73     COMPRESSED_PLANE_LAYOUTS,
74 
75     // Ideally drivers should be using fourcc to identify an allocation, but some of the drivers
76     // depend upon the format too much that updating them will require longer time.
77     // Returns: ::pixel::graphics::Format
78     PIXEL_FORMAT_ALLOCATED,
79 
80     // Returns: ::pixel::graphics::FormatType
81     FORMAT_TYPE,
82 
83     // This is a experimental feature
84     VIDEO_GMV,
85 };
86 
87 struct VideoGMV {
88     int x;
89     int y;
90 };
91 
92 #undef MapMetadataType
93 
94 // There is no backward compatibility guarantees, all dependencies must be built together.
95 struct CompressedPlaneLayout {
96     uint64_t header_offset_in_bytes;
97     uint64_t header_size_in_bytes;
98     uint64_t body_offset_in_bytes;
99     uint64_t body_size_in_bytes;
100 
101     bool operator==(const CompressedPlaneLayout& other) const {
102         return header_offset_in_bytes == other.header_offset_in_bytes &&
103                 header_size_in_bytes == other.header_size_in_bytes &&
104                 body_offset_in_bytes == other.body_offset_in_bytes &&
105                 body_size_in_bytes == other.body_size_in_bytes;
106     }
107 
108     bool operator!=(const CompressedPlaneLayout& other) const { return !(*this == other); }
109 };
110 
111 template <MetadataType T>
112 struct always_false : std::false_type {};
113 
114 namespace metadata {
115 
116 template <MetadataType T>
117 struct ReturnType {
118     static_assert(always_false<T>::value, "Unspecialized ReturnType is not supported");
119     using type = void;
120 };
121 
122 #define DEFINE_TYPE(meta_name, return_type)      \
123     template <>                                  \
124     struct ReturnType<MetadataType::meta_name> { \
125         using type = return_type;                \
126     };
127 
128 DEFINE_TYPE(PLANE_DMA_BUFS, std::vector<int>);
129 DEFINE_TYPE(VIDEO_HDR, void*);
130 DEFINE_TYPE(VIDEO_ROI, void*);
131 DEFINE_TYPE(VIDEO_GMV, VideoGMV);
132 
133 DEFINE_TYPE(COMPRESSED_PLANE_LAYOUTS, std::vector<CompressedPlaneLayout>);
134 DEFINE_TYPE(PIXEL_FORMAT_ALLOCATED, Format);
135 DEFINE_TYPE(FORMAT_TYPE, FormatType);
136 
137 #undef DEFINE_TYPE
138 
139 } // namespace metadata
140 
141 } // namespace pixel::graphics
142