blob: e06234551912688529b39c66c2fd55ea0d0d403e [file] [log] [blame]
Marissa Wall48586522019-11-19 14:01:36 -08001/*
2 * Copyright 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
17#pragma once
18
19#include <aidl/android/hardware/graphics/common/BlendMode.h>
20#include <aidl/android/hardware/graphics/common/Dataspace.h>
21#include <aidl/android/hardware/graphics/common/ExtendableType.h>
22#include <aidl/android/hardware/graphics/common/Interlaced.h>
23#include <aidl/android/hardware/graphics/common/PlaneLayout.h>
24#include <aidl/android/hardware/graphics/common/ChromaSiting.h>
25#include <aidl/android/hardware/graphics/common/Compression.h>
26#include <aidl/android/hardware/graphics/common/Interlaced.h>
27#include <aidl/android/hardware/graphics/common/StandardMetadataType.h>
28#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
29
30#include <android/hardware/graphics/mapper/4.0/IMapper.h>
31
32namespace android {
33
34namespace gralloc4 {
35
36/**
37 * This library is compiled into VNDK-SP and FWK_ONLY copies. When a device is upgraded, the vendor
38 * partition may choose to use an older copy of the VNDK-SP.
39 *
40 * Prepend the version to every encode and decode so the system partition can fallback to an older
41 * version if necessary.
42 */
43#define GRALLOC4_METADATA_VERSION 1
44
45#define GRALLOC4_STANDARD_METADATA_TYPE "android.hardware.graphics.common.StandardMetadataType"
46#define GRALLOC4_CHROMA_SITING "android.hardware.graphics.common.ChromaSiting"
47#define GRALLOC4_COMPRESSION "android.hardware.graphics.common.Compression"
48#define GRALLOC4_INTERLACED "android.hardware.graphics.common.Interlaced"
49#define GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE "android.hardware.graphics.common.PlaneLayoutComponentType"
50
51/*---------------------------------------------------------------------------------------------*/
52/**
53 * Definitions of the standard buffer metadata types. It is recommended that everyone uses
54 * these definitions directly for standard buffer metadata types.
55 */
56static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_BufferId = {
57 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::BUFFER_ID)
58};
59
60static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Name = {
61 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::NAME)
62};
63
64static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Width = {
65 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::WIDTH)
66};
67
68static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Height = {
69 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::HEIGHT)
70};
71
72static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_LayerCount = {
73 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::LAYER_COUNT)
74};
75
76static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PixelFormatRequested = {
77 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PIXEL_FORMAT_REQUESTED)
78};
79
80static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PixelFormatFourCC = {
81 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PIXEL_FORMAT_FOURCC)
82};
83
84static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PixelFormatModifier = {
85 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PIXEL_FORMAT_MODIFIER)
86};
87
88static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Usage = {
89 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::USAGE)
90};
91
92static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_AllocationSize = {
93 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::ALLOCATION_SIZE)
94};
95
96static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_ProtectedContent = {
97 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PROTECTED_CONTENT)
98};
99
100static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Compression = {
101 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::COMPRESSION)
102};
103
104static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Interlaced = {
105 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::INTERLACED)
106};
107
108static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_ChromaSiting = {
109 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::CHROMA_SITING)
110};
111
112static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PlaneLayouts = {
113 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PLANE_LAYOUTS)
114};
115
116static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Dataspace = {
117 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::DATASPACE)
118};
119
120static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_BlendMode = {
121 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::BLEND_MODE)
122};
123
124/*---------------------------------------------------------------------------------------------*/
125
126/**
127 * Definitions of the standard compression strategies. It is recommended that everyone uses
128 * these definitions directly for standard compression strategies.
129 */
130static const aidl::android::hardware::graphics::common::ExtendableType Compression_None = {
131 GRALLOC4_COMPRESSION, static_cast<int64_t>(aidl::android::hardware::graphics::common::Compression::NONE)
132};
133
134static const aidl::android::hardware::graphics::common::ExtendableType Compression_DisplayStreamCompression = {
135 GRALLOC4_COMPRESSION, static_cast<int64_t>(aidl::android::hardware::graphics::common::Compression::DISPLAY_STREAM_COMPRESSION)
136};
137
138/*---------------------------------------------------------------------------------------------*/
139
140/**
141 * Definitions of the standard interlaced strategies. It is recommended that everyone uses
142 * these definitions directly for standard interlaced strategies.
143 */
144static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_None = {
145 GRALLOC4_INTERLACED, static_cast<int64_t>(aidl::android::hardware::graphics::common::Interlaced::NONE)
146};
147
148static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_TopBottom = {
149 GRALLOC4_INTERLACED, static_cast<int64_t>(aidl::android::hardware::graphics::common::Interlaced::TOP_BOTTOM)
150};
151
152static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_RightLeft = {
153 GRALLOC4_INTERLACED, static_cast<int64_t>(aidl::android::hardware::graphics::common::Interlaced::RIGHT_LEFT)
154};
155
156/*---------------------------------------------------------------------------------------------*/
157
158/**
159 * Definitions of the standard chroma siting. It is recommended that everyone uses
160 * these definitions directly for standard chroma siting.
161 */
162static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_None = {
163 GRALLOC4_CHROMA_SITING, static_cast<int64_t>(aidl::android::hardware::graphics::common::ChromaSiting::NONE)
164};
165
166static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_Unknown = {
167 GRALLOC4_CHROMA_SITING, static_cast<int64_t>(aidl::android::hardware::graphics::common::ChromaSiting::UNKNOWN)
168};
169
170static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_SitedInterstitial = {
171 GRALLOC4_CHROMA_SITING, static_cast<int64_t>(aidl::android::hardware::graphics::common::ChromaSiting::SITED_INTERSTITIAL)
172};
173
174static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_CositedHorizontal = {
175 GRALLOC4_CHROMA_SITING, static_cast<int64_t>(aidl::android::hardware::graphics::common::ChromaSiting::COSITED_HORIZONTAL)
176};
177
178/*---------------------------------------------------------------------------------------------*/
179
180/**
181 * Definitions of the standard plane layout component types. It is recommended that everyone uses
182 * these definitions directly for standard plane layout component types
183 */
184static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_Y = {
185 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::Y)
186};
187
188static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CB = {
189 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CB)
190};
191
192static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CR = {
193 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CR)
194};
195
196static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_R = {
197 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::R)
198};
199
200static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_G = {
201 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::G)
202};
203
204static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_B = {
205 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::B)
206};
207
208static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_A = {
209 GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::A)
210};
211
212/*---------------------------------------------------------------------------------------------*/
213
214/**
215 * The functions below can be used to parse a StandardMetadataType.
216 */
217bool isStandardMetadataType(const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType);
218
219aidl::android::hardware::graphics::common::StandardMetadataType getStandardMetadataTypeValue(const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType);
220
221/**
222 * The functions below encode and decode standard metadata into a byte stream. It is STRONGLY
223 * recommended that both the vendor and system partitions use these functions when getting
224 * and setting metadata through gralloc 4 (IMapper 4.0).
225 */
226status_t encodeBufferId(uint64_t bufferId, android::hardware::hidl_vec<uint8_t>* outBufferId);
227status_t decodeBufferId(const android::hardware::hidl_vec<uint8_t>& bufferId, uint64_t* outBufferId);
228
229status_t encodeName(const std::string& name, android::hardware::hidl_vec<uint8_t>* outName);
230status_t decodeName(const android::hardware::hidl_vec<uint8_t>& name, std::string* outName);
231
232status_t encodeWidth(uint64_t width, android::hardware::hidl_vec<uint8_t>* outWidth);
233status_t decodeWidth(const android::hardware::hidl_vec<uint8_t>& width, uint64_t* outWidth);
234
235status_t encodeHeight(uint64_t height, android::hardware::hidl_vec<uint8_t>* outHeight);
236status_t decodeHeight(const android::hardware::hidl_vec<uint8_t>& height, uint64_t* outHeight);
237
238status_t encodeLayerCount(uint64_t layerCount, android::hardware::hidl_vec<uint8_t>* outLayerCount);
239status_t decodeLayerCount(const android::hardware::hidl_vec<uint8_t>& layerCount, uint64_t* outLayerCount);
240
241status_t encodePixelFormatRequested(const hardware::graphics::common::V1_2::PixelFormat& pixelFormatRequested, android::hardware::hidl_vec<uint8_t>* outPixelFormatRequested);
242status_t decodePixelFormatRequested(const android::hardware::hidl_vec<uint8_t>& pixelFormatRequested, hardware::graphics::common::V1_2::PixelFormat* outPixelFormatRequested);
243
244status_t encodePixelFormatFourCC(uint32_t pixelFormatFourCC, android::hardware::hidl_vec<uint8_t>* outPixelFormatFourCC);
245status_t decodePixelFormatFourCC(const android::hardware::hidl_vec<uint8_t>& pixelFormatFourCC, uint32_t* outPixelFormatFourCC);
246
247status_t encodePixelFormatModifier(uint64_t pixelFormatModifier, android::hardware::hidl_vec<uint8_t>* outPixelFormatModifier);
248status_t decodePixelFormatModifier(const android::hardware::hidl_vec<uint8_t>& pixelFormatModifier, uint64_t* outPixelFormatModifier);
249
250status_t encodeUsage(uint64_t usage, android::hardware::hidl_vec<uint8_t>* outUsage);
251status_t decodeUsage(const android::hardware::hidl_vec<uint8_t>& usage, uint64_t* outUsage);
252
253status_t encodeAllocationSize(uint64_t allocationSize, android::hardware::hidl_vec<uint8_t>* outAllocationSize);
254status_t decodeAllocationSize(const android::hardware::hidl_vec<uint8_t>& allocationSize, uint64_t* outAllocationSize);
255
256status_t encodeProtectedContent(uint64_t protectedContent, android::hardware::hidl_vec<uint8_t>* outProtectedContent);
257status_t decodeProtectedContent(const android::hardware::hidl_vec<uint8_t>& protectedContent, uint64_t* outProtectedContent);
258
259status_t encodeCompression(const aidl::android::hardware::graphics::common::ExtendableType& compression, android::hardware::hidl_vec<uint8_t>* outCompression);
260status_t decodeCompression(const android::hardware::hidl_vec<uint8_t>& compression, aidl::android::hardware::graphics::common::ExtendableType* outCompression);
261
262status_t encodeInterlaced(const aidl::android::hardware::graphics::common::ExtendableType& interlaced, android::hardware::hidl_vec<uint8_t>* outInterlaced);
263status_t decodeInterlaced(const android::hardware::hidl_vec<uint8_t>& interlaced, aidl::android::hardware::graphics::common::ExtendableType* outInterlaced);
264
265status_t encodeChromaSiting(const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting, android::hardware::hidl_vec<uint8_t>* outChromaSiting);
266status_t decodeChromaSiting(const android::hardware::hidl_vec<uint8_t>& chromaSiting, aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting);
267
268status_t encodePlaneLayouts(const std::vector<aidl::android::hardware::graphics::common::PlaneLayout>& planeLayouts, android::hardware::hidl_vec<uint8_t>* outPlaneLayouts);
269status_t decodePlaneLayouts(const android::hardware::hidl_vec<uint8_t>& planeLayouts, std::vector<aidl::android::hardware::graphics::common::PlaneLayout>* outPlaneLayouts);
270
271status_t encodeDataspace(const aidl::android::hardware::graphics::common::Dataspace& dataspace, android::hardware::hidl_vec<uint8_t>* outDataspace);
272status_t decodeDataspace(const android::hardware::hidl_vec<uint8_t>& dataspace, aidl::android::hardware::graphics::common::Dataspace* outDataspace);
273
274status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec<uint8_t>* outBlendMode);
275status_t decodeBlendMode(const android::hardware::hidl_vec<uint8_t>& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode);
276
277} // namespace gralloc4
278
279} // namespace android