1 /*
2  * Copyright (C) 2020 Arm Limited. All rights reserved.
3  *
4  * Copyright 2016 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef GRALLOC_COMMON_MAPPER_METADATA_H
20 #define GRALLOC_COMMON_MAPPER_METADATA_H
21 
22 #include <inttypes.h>
23 #include "mali_gralloc_log.h"
24 #include "core/mali_gralloc_bufferdescriptor.h"
25 #include "mali_gralloc_buffer.h"
26 
27 #include "4.x/gralloc_mapper_hidl_header.h"
28 
29 #include <aidl/arm/graphics/Compression.h>
30 #include <aidl/arm/graphics/ArmMetadataType.h>
31 
32 
33 namespace arm
34 {
35 namespace mapper
36 {
37 namespace common
38 {
39 using android::hardware::hidl_vec;
40 using aidl::android::hardware::graphics::common::ExtendableType;
41 
42 #define GRALLOC_ARM_COMPRESSION_TYPE_NAME "arm.graphics.Compression"
43 const static ExtendableType Compression_AFBC{ GRALLOC_ARM_COMPRESSION_TYPE_NAME,
44                                                   static_cast<int64_t>(aidl::arm::graphics::Compression::AFBC) };
45 
46 #define GRALLOC_ARM_METADATA_TYPE_NAME "arm.graphics.ArmMetadataType"
47 const static IMapper::MetadataType ArmMetadataType_PLANE_FDS{ GRALLOC_ARM_METADATA_TYPE_NAME,
48                                                   static_cast<int64_t>(aidl::arm::graphics::ArmMetadataType::PLANE_FDS) };
49 
50 /**
51  * Retrieves a Buffer's metadata value.
52  *
53  * @param handle       [in] The private handle of the buffer to query for metadata.
54  * @param metadataType [in] The type of metadata queried.
55  * @param hidl_cb      [in] HIDL callback function generating -
56  *                          error: NONE on success.
57  *                                 UNSUPPORTED on error when reading or unsupported metadata type.
58  *                          metadata: Vector of bytes representing the metadata value.
59  */
60 void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &metadataType, IMapper::get_cb hidl_cb);
61 
62 /**
63  * Sets a Buffer's metadata value.
64  *
65  * @param handle       [in] The private handle of the buffer for which to modify metadata.
66  * @param metadataType [in] The type of metadata to modify.
67  * @param metadata     [in] Vector of bytes representing the new value for the metadata associated with the buffer.
68  *
69  * @return Error::NONE on success.
70  *         Error::UNSUPPORTED on error when writing or unsupported metadata type.
71  */
72 Error set_metadata(const private_handle_t *handle, const IMapper::MetadataType &metadataType,
73                    const hidl_vec<uint8_t> &metadata);
74 
75 /**
76  * Query basic metadata information about a buffer form its descriptor before allocation.
77  *
78  * @param description  [in] The buffer descriptor.
79  * @param metadataType [in] The type of metadata to query
80  * @param hidl_cb      [in] HIDL callback function generating -
81  *                          error: NONE on success.
82  *                                 UNSUPPORTED on unsupported metadata type.
83  *                          metadata: Vector of bytes representing the metadata value.
84  */
85 void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &description,
86                                  IMapper::MetadataType const &metadataType,
87                                  IMapper::getFromBufferDescriptorInfo_cb hidl_cb);
88 
89 } // namespace common
90 } // namespace mapper
91 } // namespace arm
92 
93 #endif
94