1 /*
2  * Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above
10  *       copyright notice, this list of conditions and the following
11  *       disclaimer in the documentation and/or other materials provided
12  *       with the distribution.
13  *     * Neither the name of The Linux Foundation nor the names of its
14  *       contributors may be used to endorse or promote products derived
15  *       from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _QDMETADATA_H
31 #define _QDMETADATA_H
32 
33 #include <color_metadata.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #define MAX_UBWC_STATS_LENGTH 32
40 #define GRAPHICS_METADATA_SIZE 4096
41 
42 enum ColorSpace_t{
43     ITU_R_601,
44     ITU_R_601_FR,
45     ITU_R_709,
46     ITU_R_2020,
47     ITU_R_2020_FR,
48 };
49 
50 enum IGC_t {
51     IGC_NotSpecified,
52     IGC_sRGB,
53 };
54 
55 struct HSICData_t {
56     int32_t hue;
57     float   saturation;
58     int32_t intensity;
59     float   contrast;
60 };
61 
62 struct BufferDim_t {
63     int32_t sliceWidth;
64     int32_t sliceHeight;
65 };
66 
67 enum UBWC_Version {
68     UBWC_UNUSED      = 0,
69     UBWC_1_0         = 0x1,
70     UBWC_2_0         = 0x2,
71     UBWC_MAX_VERSION = 0xFF,
72 };
73 
74 struct UBWC_2_0_Stats {
75     uint32_t nCRStatsTile32;  /**< UBWC Stats info for  32 Byte Tile */
76     uint32_t nCRStatsTile64;  /**< UBWC Stats info for  64 Byte Tile */
77     uint32_t nCRStatsTile96;  /**< UBWC Stats info for  96 Byte Tile */
78     uint32_t nCRStatsTile128; /**< UBWC Stats info for 128 Byte Tile */
79     uint32_t nCRStatsTile160; /**< UBWC Stats info for 160 Byte Tile */
80     uint32_t nCRStatsTile192; /**< UBWC Stats info for 192 Byte Tile */
81     uint32_t nCRStatsTile256; /**< UBWC Stats info for 256 Byte Tile */
82 };
83 
84 struct UBWCStats {
85     enum UBWC_Version version; /* Union depends on this version. */
86     uint8_t bDataValid;      /* If [non-zero], CR Stats data is valid.
87                                * Consumers may use stats data.
88                                * If [zero], CR Stats data is invalid.
89                                * Consumers *Shall* not use stats data */
90     union {
91         struct UBWC_2_0_Stats ubwc_stats;
92         uint32_t reserved[MAX_UBWC_STATS_LENGTH]; /* This is for future */
93     };
94 };
95 
96 struct S3DGpuComp_t {
97     int32_t displayId; /* on which display S3D is composed by client */
98     uint32_t s3dMode; /* the S3D format of this layer to be accessed by client */
99 };
100 
101 typedef struct GraphicsMetadata {
102     uint32_t size;
103     uint32_t data[GRAPHICS_METADATA_SIZE];
104 } GraphicsMetadata;
105 
106 struct MetaData_t {
107     int32_t operation;
108     int32_t interlaced;
109     struct BufferDim_t bufferDim;
110     float refreshrate;
111     enum ColorSpace_t colorSpace;
112     enum IGC_t igc;
113      /* Gralloc sets PRIV_SECURE_BUFFER flag to inform that the buffers are from
114       * ION_SECURE. which should not be mapped. However, for GPU post proc
115       * feature, GFX needs to map this buffer, in the client context and in SF
116       * context, it should not. Hence to differentiate, add this metadata field
117       * for clients to set, and GPU will to read and know when to map the
118       * SECURE_BUFFER(ION) */
119     int32_t mapSecureBuffer;
120     /* The supported formats are defined in gralloc_priv.h to
121      * support legacy code*/
122     uint32_t s3dFormat;
123     /* VENUS output buffer is linear for UBWC Interlaced video */
124     uint32_t linearFormat;
125     /* Set by graphics to indicate that this buffer will be written to but not
126      * swapped out */
127     uint32_t isSingleBufferMode;
128     /* Indicate GPU to draw S3D layer on dedicate display device */
129     struct S3DGpuComp_t s3dComp;
130 
131     /* Set by camera to program the VT Timestamp */
132     uint64_t vtTimeStamp;
133     /* Color Aspects + HDR info */
134     ColorMetaData color;
135     /* Consumer should read this data as follows based on
136      * Gralloc flag "interlaced" listed above.
137      * [0] : If it is progressive.
138      * [0] : Top field, if it is interlaced.
139      * [1] : Do not read, if it is progressive.
140      * [1] : Bottom field, if it is interlaced.
141      */
142     struct UBWCStats ubwcCRStats[2];
143     /* Set by camera to indicate that this buffer will be used for a High
144      * Performance Video Usecase */
145     uint32_t isVideoPerfMode;
146     /* Populated and used by adreno during buffer size calculation.
147      * Set only for RGB formats. */
148     GraphicsMetadata graphics_metadata;
149 };
150 
151 enum DispParamType {
152     SET_VT_TIMESTAMP           = 0x0001,
153     COLOR_METADATA             = 0x0002,
154     PP_PARAM_INTERLACED        = 0x0004,
155     SET_VIDEO_PERF_MODE        = 0x0008,
156     SET_GRAPHICS_METADATA      = 0x0010,
157     SET_UNUSED                 = 0x0020,
158     SET_UBWC_CR_STATS_INFO     = 0x0040,
159     UPDATE_BUFFER_GEOMETRY     = 0x0080,
160     UPDATE_REFRESH_RATE        = 0x0100,
161     UPDATE_COLOR_SPACE         = 0x0200,
162     MAP_SECURE_BUFFER          = 0x0400,
163     S3D_FORMAT                 = 0x0800,
164     LINEAR_FORMAT              = 0x1000,
165     SET_IGC                    = 0x2000,
166     SET_SINGLE_BUFFER_MODE     = 0x4000,
167     SET_S3D_COMP               = 0x8000,
168 };
169 
170 enum DispFetchParamType {
171     GET_VT_TIMESTAMP          = 0x0001,
172     GET_COLOR_METADATA        = 0x0002,
173     GET_PP_PARAM_INTERLACED   = 0x0004,
174     GET_VIDEO_PERF_MODE       = 0x0008,
175     GET_GRAPHICS_METADATA     = 0x0010,
176     GET_UNUSED                = 0X0020,
177     GET_UBWC_CR_STATS_INFO    = 0x0040,
178     GET_BUFFER_GEOMETRY       = 0x0080,
179     GET_REFRESH_RATE          = 0x0100,
180     GET_COLOR_SPACE           = 0x0200,
181     GET_MAP_SECURE_BUFFER     = 0x0400,
182     GET_S3D_FORMAT            = 0x0800,
183     GET_LINEAR_FORMAT         = 0x1000,
184     GET_IGC                   = 0x2000,
185     GET_SINGLE_BUFFER_MODE    = 0x4000,
186     GET_S3D_COMP              = 0x8000,
187 };
188 
189 struct private_handle_t;
190 int setMetaData(struct private_handle_t *handle, enum DispParamType paramType,
191                 void *param);
192 int setMetaDataVa(struct MetaData_t* data, enum DispParamType paramType,
193                   void *param);
194 
195 int getMetaData(struct private_handle_t *handle,
196                 enum DispFetchParamType paramType,
197                 void *param);
198 int getMetaDataVa(struct MetaData_t* data, enum DispFetchParamType paramType,
199                   void *param);
200 
201 int copyMetaData(struct private_handle_t *src, struct private_handle_t *dst);
202 int copyMetaDataVaToHandle(struct MetaData_t *src, struct private_handle_t *dst);
203 int copyMetaDataHandleToVa(struct private_handle_t* src, struct MetaData_t *dst);
204 int copyMetaDataVaToVa(struct MetaData_t *src, struct MetaData_t *dst);
205 
206 int clearMetaData(struct private_handle_t *handle, enum DispParamType paramType);
207 int clearMetaDataVa(struct MetaData_t *data, enum DispParamType paramType);
208 
209 unsigned long getMetaDataSize();
210 
211 // Map, access metadata and unmap. Used by clients that do not import/free but
212 //  clone and delete native_handle
213 int setMetaDataAndUnmap(struct private_handle_t *handle, enum DispParamType paramType,
214                         void *param);
215 int getMetaDataAndUnmap(struct private_handle_t *handle,
216                         enum DispFetchParamType paramType,
217                         void *param);
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #endif /* _QDMETADATA_H */
224 
225