blob: a5d3bb2975c81b1c37a421bb01b384782fbe82db [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>
Joseph Murphy048552f2019-12-17 19:58:45 +000024#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>
Marissa Wall317482c2019-12-12 14:26:59 -080027#include <aidl/android/hardware/graphics/common/StandardMetadataType.h>
Joseph Murphy048552f2019-12-17 19:58:45 +000028#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
29
Marissa Wall48586522019-11-19 14:01:36 -080030#include <android/hardware/graphics/mapper/4.0/IMapper.h>
31
32namespace android {
33
34namespace gralloc4 {
35
Marissa Wall48586522019-11-19 14:01:36 -080036#define GRALLOC4_STANDARD_METADATA_TYPE "android.hardware.graphics.common.StandardMetadataType"
Marissa Wall22b2de12019-12-02 18:11:43 -080037#define GRALLOC4_STANDARD_CHROMA_SITING "android.hardware.graphics.common.ChromaSiting"
38#define GRALLOC4_STANDARD_COMPRESSION "android.hardware.graphics.common.Compression"
39#define GRALLOC4_STANDARD_INTERLACED "android.hardware.graphics.common.Interlaced"
40#define GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE \
41 "android.hardware.graphics.common.PlaneLayoutComponentType"
Marissa Wall48586522019-11-19 14:01:36 -080042
43/*---------------------------------------------------------------------------------------------*/
44/**
45 * Definitions of the standard buffer metadata types. It is recommended that everyone uses
46 * these definitions directly for standard buffer metadata types.
47 */
48static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_BufferId = {
49 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::BUFFER_ID)
50};
51
52static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Name = {
53 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::NAME)
54};
55
56static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Width = {
57 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::WIDTH)
58};
59
60static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Height = {
61 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::HEIGHT)
62};
63
64static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_LayerCount = {
65 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::LAYER_COUNT)
66};
67
68static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PixelFormatRequested = {
69 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PIXEL_FORMAT_REQUESTED)
70};
71
72static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PixelFormatFourCC = {
73 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PIXEL_FORMAT_FOURCC)
74};
75
76static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PixelFormatModifier = {
77 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PIXEL_FORMAT_MODIFIER)
78};
79
80static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Usage = {
81 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::USAGE)
82};
83
84static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_AllocationSize = {
85 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::ALLOCATION_SIZE)
86};
87
88static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_ProtectedContent = {
89 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PROTECTED_CONTENT)
90};
91
92static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Compression = {
93 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::COMPRESSION)
94};
95
96static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Interlaced = {
97 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::INTERLACED)
98};
99
100static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_ChromaSiting = {
101 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::CHROMA_SITING)
102};
103
104static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_PlaneLayouts = {
105 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::PLANE_LAYOUTS)
106};
107
108static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_Dataspace = {
109 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::DATASPACE)
110};
111
112static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType MetadataType_BlendMode = {
113 GRALLOC4_STANDARD_METADATA_TYPE, static_cast<int64_t>(aidl::android::hardware::graphics::common::StandardMetadataType::BLEND_MODE)
114};
115
116/*---------------------------------------------------------------------------------------------*/
117
118/**
119 * Definitions of the standard compression strategies. It is recommended that everyone uses
120 * these definitions directly for standard compression strategies.
121 */
Marissa Wall22b2de12019-12-02 18:11:43 -0800122static const aidl::android::hardware::graphics::common::ExtendableType Compression_None =
123 {GRALLOC4_STANDARD_COMPRESSION,
124 static_cast<int64_t>(aidl::android::hardware::graphics::common::Compression::NONE)};
Marissa Wall48586522019-11-19 14:01:36 -0800125
Marissa Wall22b2de12019-12-02 18:11:43 -0800126static const aidl::android::hardware::graphics::common::ExtendableType
127 Compression_DisplayStreamCompression =
128 {GRALLOC4_STANDARD_COMPRESSION,
129 static_cast<int64_t>(aidl::android::hardware::graphics::common::Compression::
130 DISPLAY_STREAM_COMPRESSION)};
Marissa Wall48586522019-11-19 14:01:36 -0800131
132/*---------------------------------------------------------------------------------------------*/
133
134/**
135 * Definitions of the standard interlaced strategies. It is recommended that everyone uses
136 * these definitions directly for standard interlaced strategies.
137 */
Marissa Wall22b2de12019-12-02 18:11:43 -0800138static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_None =
139 {GRALLOC4_STANDARD_INTERLACED,
140 static_cast<int64_t>(aidl::android::hardware::graphics::common::Interlaced::NONE)};
Marissa Wall48586522019-11-19 14:01:36 -0800141
Marissa Wall22b2de12019-12-02 18:11:43 -0800142static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_TopBottom =
143 {GRALLOC4_STANDARD_INTERLACED,
144 static_cast<int64_t>(aidl::android::hardware::graphics::common::Interlaced::TOP_BOTTOM)};
Marissa Wall48586522019-11-19 14:01:36 -0800145
Marissa Wall22b2de12019-12-02 18:11:43 -0800146static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_RightLeft =
147 {GRALLOC4_STANDARD_INTERLACED,
148 static_cast<int64_t>(aidl::android::hardware::graphics::common::Interlaced::RIGHT_LEFT)};
Marissa Wall48586522019-11-19 14:01:36 -0800149
150/*---------------------------------------------------------------------------------------------*/
151
152/**
153 * Definitions of the standard chroma siting. It is recommended that everyone uses
154 * these definitions directly for standard chroma siting.
155 */
Marissa Wall22b2de12019-12-02 18:11:43 -0800156static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_None =
157 {GRALLOC4_STANDARD_CHROMA_SITING,
158 static_cast<int64_t>(aidl::android::hardware::graphics::common::ChromaSiting::NONE)};
Marissa Wall48586522019-11-19 14:01:36 -0800159
Marissa Wall22b2de12019-12-02 18:11:43 -0800160static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_Unknown =
161 {GRALLOC4_STANDARD_CHROMA_SITING,
162 static_cast<int64_t>(aidl::android::hardware::graphics::common::ChromaSiting::UNKNOWN)};
Marissa Wall48586522019-11-19 14:01:36 -0800163
Marissa Wall22b2de12019-12-02 18:11:43 -0800164static const aidl::android::hardware::graphics::common::ExtendableType
165 ChromaSiting_SitedInterstitial = {GRALLOC4_STANDARD_CHROMA_SITING,
166 static_cast<int64_t>(
167 aidl::android::hardware::graphics::common::
168 ChromaSiting::SITED_INTERSTITIAL)};
Marissa Wall48586522019-11-19 14:01:36 -0800169
Marissa Wall22b2de12019-12-02 18:11:43 -0800170static const aidl::android::hardware::graphics::common::ExtendableType
171 ChromaSiting_CositedHorizontal = {GRALLOC4_STANDARD_CHROMA_SITING,
172 static_cast<int64_t>(
173 aidl::android::hardware::graphics::common::
174 ChromaSiting::COSITED_HORIZONTAL)};
Marissa Wall48586522019-11-19 14:01:36 -0800175
176/*---------------------------------------------------------------------------------------------*/
177
178/**
179 * Definitions of the standard plane layout component types. It is recommended that everyone uses
180 * these definitions directly for standard plane layout component types
181 */
Marissa Wall22b2de12019-12-02 18:11:43 -0800182static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_Y =
183 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
184 static_cast<int64_t>(
185 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::Y)};
Marissa Wall48586522019-11-19 14:01:36 -0800186
Marissa Wall22b2de12019-12-02 18:11:43 -0800187static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CB =
188 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
189 static_cast<int64_t>(
190 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CB)};
Marissa Wall48586522019-11-19 14:01:36 -0800191
Marissa Wall22b2de12019-12-02 18:11:43 -0800192static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CR =
193 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
194 static_cast<int64_t>(
195 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CR)};
Marissa Wall48586522019-11-19 14:01:36 -0800196
Marissa Wall22b2de12019-12-02 18:11:43 -0800197static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_R =
198 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
199 static_cast<int64_t>(
200 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::R)};
Marissa Wall48586522019-11-19 14:01:36 -0800201
Marissa Wall22b2de12019-12-02 18:11:43 -0800202static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_G =
203 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
204 static_cast<int64_t>(
205 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::G)};
Marissa Wall48586522019-11-19 14:01:36 -0800206
Marissa Wall22b2de12019-12-02 18:11:43 -0800207static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_B =
208 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
209 static_cast<int64_t>(
210 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::B)};
Marissa Wall48586522019-11-19 14:01:36 -0800211
Marissa Wall22b2de12019-12-02 18:11:43 -0800212static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_A =
213 {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE,
214 static_cast<int64_t>(
215 aidl::android::hardware::graphics::common::PlaneLayoutComponentType::A)};
Marissa Wall48586522019-11-19 14:01:36 -0800216
217/*---------------------------------------------------------------------------------------------*/
218
219/**
Marissa Wall48586522019-11-19 14:01:36 -0800220 * The functions below encode and decode standard metadata into a byte stream. It is STRONGLY
221 * recommended that both the vendor and system partitions use these functions when getting
222 * and setting metadata through gralloc 4 (IMapper 4.0).
223 */
224status_t encodeBufferId(uint64_t bufferId, android::hardware::hidl_vec<uint8_t>* outBufferId);
225status_t decodeBufferId(const android::hardware::hidl_vec<uint8_t>& bufferId, uint64_t* outBufferId);
226
227status_t encodeName(const std::string& name, android::hardware::hidl_vec<uint8_t>* outName);
228status_t decodeName(const android::hardware::hidl_vec<uint8_t>& name, std::string* outName);
229
230status_t encodeWidth(uint64_t width, android::hardware::hidl_vec<uint8_t>* outWidth);
231status_t decodeWidth(const android::hardware::hidl_vec<uint8_t>& width, uint64_t* outWidth);
232
233status_t encodeHeight(uint64_t height, android::hardware::hidl_vec<uint8_t>* outHeight);
234status_t decodeHeight(const android::hardware::hidl_vec<uint8_t>& height, uint64_t* outHeight);
235
236status_t encodeLayerCount(uint64_t layerCount, android::hardware::hidl_vec<uint8_t>* outLayerCount);
237status_t decodeLayerCount(const android::hardware::hidl_vec<uint8_t>& layerCount, uint64_t* outLayerCount);
238
239status_t encodePixelFormatRequested(const hardware::graphics::common::V1_2::PixelFormat& pixelFormatRequested, android::hardware::hidl_vec<uint8_t>* outPixelFormatRequested);
240status_t decodePixelFormatRequested(const android::hardware::hidl_vec<uint8_t>& pixelFormatRequested, hardware::graphics::common::V1_2::PixelFormat* outPixelFormatRequested);
241
242status_t encodePixelFormatFourCC(uint32_t pixelFormatFourCC, android::hardware::hidl_vec<uint8_t>* outPixelFormatFourCC);
243status_t decodePixelFormatFourCC(const android::hardware::hidl_vec<uint8_t>& pixelFormatFourCC, uint32_t* outPixelFormatFourCC);
244
245status_t encodePixelFormatModifier(uint64_t pixelFormatModifier, android::hardware::hidl_vec<uint8_t>* outPixelFormatModifier);
246status_t decodePixelFormatModifier(const android::hardware::hidl_vec<uint8_t>& pixelFormatModifier, uint64_t* outPixelFormatModifier);
247
248status_t encodeUsage(uint64_t usage, android::hardware::hidl_vec<uint8_t>* outUsage);
249status_t decodeUsage(const android::hardware::hidl_vec<uint8_t>& usage, uint64_t* outUsage);
250
251status_t encodeAllocationSize(uint64_t allocationSize, android::hardware::hidl_vec<uint8_t>* outAllocationSize);
252status_t decodeAllocationSize(const android::hardware::hidl_vec<uint8_t>& allocationSize, uint64_t* outAllocationSize);
253
254status_t encodeProtectedContent(uint64_t protectedContent, android::hardware::hidl_vec<uint8_t>* outProtectedContent);
255status_t decodeProtectedContent(const android::hardware::hidl_vec<uint8_t>& protectedContent, uint64_t* outProtectedContent);
256
257status_t encodeCompression(const aidl::android::hardware::graphics::common::ExtendableType& compression, android::hardware::hidl_vec<uint8_t>* outCompression);
258status_t decodeCompression(const android::hardware::hidl_vec<uint8_t>& compression, aidl::android::hardware::graphics::common::ExtendableType* outCompression);
259
260status_t encodeInterlaced(const aidl::android::hardware::graphics::common::ExtendableType& interlaced, android::hardware::hidl_vec<uint8_t>* outInterlaced);
261status_t decodeInterlaced(const android::hardware::hidl_vec<uint8_t>& interlaced, aidl::android::hardware::graphics::common::ExtendableType* outInterlaced);
262
263status_t encodeChromaSiting(const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting, android::hardware::hidl_vec<uint8_t>* outChromaSiting);
264status_t decodeChromaSiting(const android::hardware::hidl_vec<uint8_t>& chromaSiting, aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting);
265
266status_t encodePlaneLayouts(const std::vector<aidl::android::hardware::graphics::common::PlaneLayout>& planeLayouts, android::hardware::hidl_vec<uint8_t>* outPlaneLayouts);
267status_t decodePlaneLayouts(const android::hardware::hidl_vec<uint8_t>& planeLayouts, std::vector<aidl::android::hardware::graphics::common::PlaneLayout>* outPlaneLayouts);
268
269status_t encodeDataspace(const aidl::android::hardware::graphics::common::Dataspace& dataspace, android::hardware::hidl_vec<uint8_t>* outDataspace);
270status_t decodeDataspace(const android::hardware::hidl_vec<uint8_t>& dataspace, aidl::android::hardware::graphics::common::Dataspace* outDataspace);
271
272status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec<uint8_t>* outBlendMode);
273status_t decodeBlendMode(const android::hardware::hidl_vec<uint8_t>& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode);
274
Marissa Wall22b2de12019-12-02 18:11:43 -0800275/**
276 * The functions below can be used to parse extendable types.
277 */
278bool isStandardMetadataType(
279 const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType);
280bool isStandardCompression(
281 const aidl::android::hardware::graphics::common::ExtendableType& compression);
282bool isStandardInterlaced(
283 const aidl::android::hardware::graphics::common::ExtendableType& interlaced);
284bool isStandardChromaSiting(
285 const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting);
286bool isStandardPlaneLayoutComponentType(
287 const aidl::android::hardware::graphics::common::ExtendableType& planeLayoutComponentType);
288
289aidl::android::hardware::graphics::common::StandardMetadataType getStandardMetadataTypeValue(
290 const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType);
291aidl::android::hardware::graphics::common::Compression getStandardCompressionValue(
292 const aidl::android::hardware::graphics::common::ExtendableType& compression);
293aidl::android::hardware::graphics::common::Interlaced getStandardInterlacedValue(
294 const aidl::android::hardware::graphics::common::ExtendableType& interlaced);
295aidl::android::hardware::graphics::common::ChromaSiting getStandardChromaSitingValue(
296 const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting);
297aidl::android::hardware::graphics::common::PlaneLayoutComponentType
298getStandardPlaneLayoutComponentTypeValue(
299 const aidl::android::hardware::graphics::common::ExtendableType& planeLayoutComponentType);
300
301/**
302 * The functions below return string representations of ExtendableTypes
303 */
304std::string getCompressionName(
305 const aidl::android::hardware::graphics::common::ExtendableType& compression);
306std::string getInterlacedName(
307 const aidl::android::hardware::graphics::common::ExtendableType& interlaced);
308std::string getChromaSitingName(
309 const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting);
310std::string getPlaneLayoutComponentTypeName(
311 const aidl::android::hardware::graphics::common::ExtendableType& planeLayoutComponentType);
312
Marissa Wall48586522019-11-19 14:01:36 -0800313} // namespace gralloc4
314
315} // namespace android