blob: 9d04903ba767bc183013e87371befef726018af0 [file] [log] [blame]
Tharaga Balachandrana069a7e2020-01-08 17:22:12 -05001/*
2 * Copyright (c) 2020 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 __QTIGRALLOCPRIV_H__
31#define __QTIGRALLOCPRIV_H__
32
33#include <color_metadata.h>
34#include <cutils/native_handle.h>
35#include <log/log.h>
36
37#include <cinttypes>
38#include <string>
39
40#include "QtiGrallocMetadata.h"
41
42#ifndef __QTI_DISPLAY_GRALLOC__
43#pragma message "QtiGrallocPriv.h should not be included"
44#endif
45
46/*
47 *
48 * DISCLAIMER:
49 * INTERNAL GRALLOC USE ONLY - THIS FILE SHOULD NOT BE INCLUDED BY GRALLOC CLIENTS
50 * The location will be changed and this file will not be exposed
51 * once qdMetaData copy functions are deprecated
52 *
53 */
54
Tharaga Balachandran39810462020-06-16 09:34:34 -040055#define METADATA_V2
56
Tharaga Balachandrana069a7e2020-01-08 17:22:12 -050057// TODO: MetaData_t should be in qtigralloc namespace
58struct MetaData_t {
59 int32_t operation;
60 int32_t interlaced;
61 float refreshrate;
62 int32_t mapSecureBuffer;
63 /* Deprecated */
64 uint32_t s3dFormat;
65 /* VENUS output buffer is linear for UBWC Interlaced video */
66 uint32_t linearFormat;
67 /* Set by graphics to indicate that this buffer will be written to but not
68 * swapped out */
69 uint32_t isSingleBufferMode;
70
71 /* Set by camera to program the VT Timestamp */
72 uint64_t vtTimeStamp;
73 /* Color Aspects + HDR info */
74 ColorMetaData color;
75 /* Consumer should read this data as follows based on
76 * Gralloc flag "interlaced" listed above.
77 * [0] : If it is progressive.
78 * [0] : Top field, if it is interlaced.
79 * [1] : Do not read, if it is progressive.
80 * [1] : Bottom field, if it is interlaced.
81 */
82 struct UBWCStats ubwcCRStats[UBWC_STATS_ARRAY_SIZE];
83 /* Set by camera to indicate that this buffer will be used for a High
84 * Performance Video Usecase */
85 uint32_t isVideoPerfMode;
86 /* Populated and used by adreno during buffer size calculation.
87 * Set only for RGB formats. */
88 GraphicsMetadata graphics_metadata;
89 /* Video hisogram stats populated by video decoder */
90 struct VideoHistogramMetadata video_histogram_stats;
91 /*
92 * Producer (camera) will set cvp metadata and consumer (video) will
93 * use it. The format of metadata is known to producer and consumer.
94 */
95 CVPMetadata cvpMetadata;
96 CropRectangle_t crop;
97 int32_t blendMode;
98 char name[MAX_NAME_LEN];
99 ReservedRegion reservedRegion;
Tharaga Balachandran39810462020-06-16 09:34:34 -0400100 bool isStandardMetadataSet[METADATA_SET_SIZE];
101 bool isVendorMetadataSet[METADATA_SET_SIZE];
102 uint64_t reservedSize;
Shrikara B21c0d722020-08-27 18:23:10 +0530103 VideoTimestampInfo videoTsInfo;
Tharaga Balachandrana069a7e2020-01-08 17:22:12 -0500104};
105
106namespace qtigralloc {
107#define QTI_HANDLE_CONST(exp) static_cast<const private_handle_t *>(exp)
108
109#pragma pack(push, 4)
110struct private_handle_t : public native_handle_t {
111 // file-descriptors dup'd over IPC
112 int fd;
113 int fd_metadata;
114
115 // values sent over IPC
116 int magic;
117 int flags;
118 int width; // holds width of the actual buffer allocated
119 int height; // holds height of the actual buffer allocated
120 int unaligned_width; // holds width client asked to allocate
121 int unaligned_height; // holds height client asked to allocate
122 int format;
123 int buffer_type;
124 unsigned int layer_count;
125 uint64_t id;
126 uint64_t usage;
127
128 unsigned int size;
129 unsigned int offset;
130 unsigned int offset_metadata;
131 uint64_t base;
132 uint64_t base_metadata;
133 uint64_t gpuaddr;
134 static const int kNumFds = 2;
135 static const int kMagic = 'gmsm';
136
137 static inline int NumInts() {
138 return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds;
139 }
140
141 private_handle_t(int fd, int meta_fd, int flags, int width, int height, int uw, int uh,
142 int format, int buf_type, unsigned int size, uint64_t usage = 0)
143 : fd(fd),
144 fd_metadata(meta_fd),
145 magic(kMagic),
146 flags(flags),
147 width(width),
148 height(height),
149 unaligned_width(uw),
150 unaligned_height(uh),
151 format(format),
152 buffer_type(buf_type),
153 layer_count(1),
154 id(0),
155 usage(usage),
156 size(size),
157 offset(0),
158 offset_metadata(0),
159 base(0),
160 base_metadata(0),
161 gpuaddr(0) {
162 version = static_cast<int>(sizeof(native_handle));
163 numInts = NumInts();
164 numFds = kNumFds;
165 }
166
167 ~private_handle_t() { magic = 0; }
168
169 static int validate(const native_handle *h) {
170 auto *hnd = static_cast<const private_handle_t *>(h);
171 if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() ||
172 h->numFds != kNumFds) {
173 ALOGE("Invalid gralloc handle (at %p): ver(%d/%zu) ints(%d/%d) fds(%d/%d)", h,
174 h ? h->version : -1, sizeof(native_handle), h ? h->numInts : -1, NumInts(),
175 h ? h->numFds : -1, kNumFds);
176 return -1;
177 }
178 if (hnd->magic != kMagic) {
179 ALOGE("handle = %p invalid magic(%c%c%c%c/%c%c%c%c)", hnd,
180 hnd ? (((hnd->magic >> 24) & 0xFF) ? ((hnd->magic >> 24) & 0xFF) : '-') : '?',
181 hnd ? (((hnd->magic >> 16) & 0xFF) ? ((hnd->magic >> 16) & 0xFF) : '-') : '?',
182 hnd ? (((hnd->magic >> 8) & 0xFF) ? ((hnd->magic >> 8) & 0xFF) : '-') : '?',
183 hnd ? (((hnd->magic >> 0) & 0xFF) ? ((hnd->magic >> 0) & 0xFF) : '-') : '?',
184 (kMagic >> 24) & 0xFF, (kMagic >> 16) & 0xFF, (kMagic >> 8) & 0xFF,
185 (kMagic >> 0) & 0xFF);
186 return -1;
187 }
188
189 return 0;
190 }
191
192 static void Dump(const private_handle_t *hnd) {
193 ALOGD("handle id:%" PRIu64
194 " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x "
195 "usage:0x%" PRIx64 " format:0x%x layer_count: %d",
196 hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
197 hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count);
198 }
199};
200#pragma pack(pop)
201
202} // namespace qtigralloc
203
204#endif //__QTIGRALLOCPRIV_H__