blob: ee0c6a404ad38771f7e9411913ffb1ad9694545c [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
55// TODO: MetaData_t should be in qtigralloc namespace
56struct MetaData_t {
57 int32_t operation;
58 int32_t interlaced;
59 float refreshrate;
60 int32_t mapSecureBuffer;
61 /* Deprecated */
62 uint32_t s3dFormat;
63 /* VENUS output buffer is linear for UBWC Interlaced video */
64 uint32_t linearFormat;
65 /* Set by graphics to indicate that this buffer will be written to but not
66 * swapped out */
67 uint32_t isSingleBufferMode;
68
69 /* Set by camera to program the VT Timestamp */
70 uint64_t vtTimeStamp;
71 /* Color Aspects + HDR info */
72 ColorMetaData color;
73 /* Consumer should read this data as follows based on
74 * Gralloc flag "interlaced" listed above.
75 * [0] : If it is progressive.
76 * [0] : Top field, if it is interlaced.
77 * [1] : Do not read, if it is progressive.
78 * [1] : Bottom field, if it is interlaced.
79 */
80 struct UBWCStats ubwcCRStats[UBWC_STATS_ARRAY_SIZE];
81 /* Set by camera to indicate that this buffer will be used for a High
82 * Performance Video Usecase */
83 uint32_t isVideoPerfMode;
84 /* Populated and used by adreno during buffer size calculation.
85 * Set only for RGB formats. */
86 GraphicsMetadata graphics_metadata;
87 /* Video hisogram stats populated by video decoder */
88 struct VideoHistogramMetadata video_histogram_stats;
89 /*
90 * Producer (camera) will set cvp metadata and consumer (video) will
91 * use it. The format of metadata is known to producer and consumer.
92 */
93 CVPMetadata cvpMetadata;
94 CropRectangle_t crop;
95 int32_t blendMode;
96 char name[MAX_NAME_LEN];
97 ReservedRegion reservedRegion;
98};
99
100namespace qtigralloc {
101#define QTI_HANDLE_CONST(exp) static_cast<const private_handle_t *>(exp)
102
103#pragma pack(push, 4)
104struct private_handle_t : public native_handle_t {
105 // file-descriptors dup'd over IPC
106 int fd;
107 int fd_metadata;
108
109 // values sent over IPC
110 int magic;
111 int flags;
112 int width; // holds width of the actual buffer allocated
113 int height; // holds height of the actual buffer allocated
114 int unaligned_width; // holds width client asked to allocate
115 int unaligned_height; // holds height client asked to allocate
116 int format;
117 int buffer_type;
118 unsigned int layer_count;
119 uint64_t id;
120 uint64_t usage;
121
122 unsigned int size;
123 unsigned int offset;
124 unsigned int offset_metadata;
125 uint64_t base;
126 uint64_t base_metadata;
127 uint64_t gpuaddr;
128 static const int kNumFds = 2;
129 static const int kMagic = 'gmsm';
130
131 static inline int NumInts() {
132 return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds;
133 }
134
135 private_handle_t(int fd, int meta_fd, int flags, int width, int height, int uw, int uh,
136 int format, int buf_type, unsigned int size, uint64_t usage = 0)
137 : fd(fd),
138 fd_metadata(meta_fd),
139 magic(kMagic),
140 flags(flags),
141 width(width),
142 height(height),
143 unaligned_width(uw),
144 unaligned_height(uh),
145 format(format),
146 buffer_type(buf_type),
147 layer_count(1),
148 id(0),
149 usage(usage),
150 size(size),
151 offset(0),
152 offset_metadata(0),
153 base(0),
154 base_metadata(0),
155 gpuaddr(0) {
156 version = static_cast<int>(sizeof(native_handle));
157 numInts = NumInts();
158 numFds = kNumFds;
159 }
160
161 ~private_handle_t() { magic = 0; }
162
163 static int validate(const native_handle *h) {
164 auto *hnd = static_cast<const private_handle_t *>(h);
165 if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() ||
166 h->numFds != kNumFds) {
167 ALOGE("Invalid gralloc handle (at %p): ver(%d/%zu) ints(%d/%d) fds(%d/%d)", h,
168 h ? h->version : -1, sizeof(native_handle), h ? h->numInts : -1, NumInts(),
169 h ? h->numFds : -1, kNumFds);
170 return -1;
171 }
172 if (hnd->magic != kMagic) {
173 ALOGE("handle = %p invalid magic(%c%c%c%c/%c%c%c%c)", hnd,
174 hnd ? (((hnd->magic >> 24) & 0xFF) ? ((hnd->magic >> 24) & 0xFF) : '-') : '?',
175 hnd ? (((hnd->magic >> 16) & 0xFF) ? ((hnd->magic >> 16) & 0xFF) : '-') : '?',
176 hnd ? (((hnd->magic >> 8) & 0xFF) ? ((hnd->magic >> 8) & 0xFF) : '-') : '?',
177 hnd ? (((hnd->magic >> 0) & 0xFF) ? ((hnd->magic >> 0) & 0xFF) : '-') : '?',
178 (kMagic >> 24) & 0xFF, (kMagic >> 16) & 0xFF, (kMagic >> 8) & 0xFF,
179 (kMagic >> 0) & 0xFF);
180 return -1;
181 }
182
183 return 0;
184 }
185
186 static void Dump(const private_handle_t *hnd) {
187 ALOGD("handle id:%" PRIu64
188 " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x "
189 "usage:0x%" PRIx64 " format:0x%x layer_count: %d",
190 hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
191 hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count);
192 }
193};
194#pragma pack(pop)
195
196} // namespace qtigralloc
197
198#endif //__QTIGRALLOCPRIV_H__