blob: 05a636280d082dc5fa60f94b01709c7f29cacad8 [file] [log] [blame]
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05301/*
Ramakant Singh13596ae2020-01-06 20:12:34 +05302 * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05303
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
Saurabh Shah14c8e5b2017-04-07 10:37:23 -070030#include <media/msm_media_info.h>
31#include <algorithm>
32
Saurabh Shah14c8e5b2017-04-07 10:37:23 -070033#include "gr_adreno_info.h"
Naseer Ahmede36f2242017-12-01 15:33:56 -050034#include "gr_utils.h"
Saurabh Shah14c8e5b2017-04-07 10:37:23 -070035
36#define ASTC_BLOCK_SIZE 16
37
38#ifndef COLOR_FMT_P010_UBWC
39#define COLOR_FMT_P010_UBWC 9
40#endif
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053041
Naseer Ahmede36f2242017-12-01 15:33:56 -050042namespace gralloc {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053043
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +053044bool IsYuvFormat(int format) {
45 switch (format) {
Saurabh Shahdbb572e2018-01-04 15:38:01 -080046 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
47 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
48 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Naseer Ahmede36f2242017-12-01 15:33:56 -050049 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: // Same as YCbCr_420_SP_VENUS
Ramakant Singh13596ae2020-01-06 20:12:34 +053050 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
Saurabh Shahdbb572e2018-01-04 15:38:01 -080051 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
52 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
53 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
54 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
55 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
56 case HAL_PIXEL_FORMAT_NV21_ZSL:
57 case HAL_PIXEL_FORMAT_RAW16:
58 case HAL_PIXEL_FORMAT_Y16:
59 case HAL_PIXEL_FORMAT_RAW12:
60 case HAL_PIXEL_FORMAT_RAW10:
61 case HAL_PIXEL_FORMAT_YV12:
62 case HAL_PIXEL_FORMAT_Y8:
63 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
64 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
65 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
66 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +053067 // Below formats used by camera and VR
68 case HAL_PIXEL_FORMAT_BLOB:
69 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
Rajavenu Kyatham6e8c1822018-07-31 10:27:19 +053070 case HAL_PIXEL_FORMAT_NV12_HEIF:
Camus Wonga300db62018-09-27 16:38:50 -040071 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
Saurabh Shahdbb572e2018-01-04 15:38:01 -080072 return true;
73 default:
74 return false;
75 }
76}
77
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053078bool IsUncompressedRGBFormat(int format) {
79 switch (format) {
80 case HAL_PIXEL_FORMAT_RGBA_8888:
81 case HAL_PIXEL_FORMAT_RGBX_8888:
82 case HAL_PIXEL_FORMAT_RGB_888:
83 case HAL_PIXEL_FORMAT_RGB_565:
84 case HAL_PIXEL_FORMAT_BGR_565:
85 case HAL_PIXEL_FORMAT_BGRA_8888:
86 case HAL_PIXEL_FORMAT_RGBA_5551:
87 case HAL_PIXEL_FORMAT_RGBA_4444:
88 case HAL_PIXEL_FORMAT_R_8:
89 case HAL_PIXEL_FORMAT_RG_88:
90 case HAL_PIXEL_FORMAT_BGRX_8888:
91 case HAL_PIXEL_FORMAT_RGBA_1010102:
92 case HAL_PIXEL_FORMAT_ARGB_2101010:
93 case HAL_PIXEL_FORMAT_RGBX_1010102:
94 case HAL_PIXEL_FORMAT_XRGB_2101010:
95 case HAL_PIXEL_FORMAT_BGRA_1010102:
96 case HAL_PIXEL_FORMAT_ABGR_2101010:
97 case HAL_PIXEL_FORMAT_BGRX_1010102:
98 case HAL_PIXEL_FORMAT_XBGR_2101010:
Naseer Ahmed1c473d82017-02-27 13:39:37 -050099 case HAL_PIXEL_FORMAT_RGBA_FP16:
Camus Wong5c5e6fb2017-03-21 17:02:48 -0400100 case HAL_PIXEL_FORMAT_BGR_888:
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530101 return true;
102 default:
103 break;
104 }
105
106 return false;
107}
108
109bool IsCompressedRGBFormat(int format) {
110 switch (format) {
111 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
112 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
113 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR:
114 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
115 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR:
116 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
117 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR:
118 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
119 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR:
120 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
121 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR:
122 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
123 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR:
124 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
125 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR:
126 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
127 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR:
128 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
129 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR:
130 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
131 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR:
132 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
133 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR:
134 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
135 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR:
136 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
137 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR:
138 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
139 return true;
140 default:
141 break;
142 }
143
144 return false;
145}
146
147uint32_t GetBppForUncompressedRGB(int format) {
148 uint32_t bpp = 0;
149 switch (format) {
Naseer Ahmed1c473d82017-02-27 13:39:37 -0500150 case HAL_PIXEL_FORMAT_RGBA_FP16:
151 bpp = 8;
152 break;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530153 case HAL_PIXEL_FORMAT_RGBA_8888:
154 case HAL_PIXEL_FORMAT_RGBX_8888:
155 case HAL_PIXEL_FORMAT_BGRA_8888:
156 case HAL_PIXEL_FORMAT_BGRX_8888:
Arun Kumar K.Rb97ca302017-04-06 15:59:33 -0700157 case HAL_PIXEL_FORMAT_RGBA_1010102:
158 case HAL_PIXEL_FORMAT_ARGB_2101010:
159 case HAL_PIXEL_FORMAT_RGBX_1010102:
160 case HAL_PIXEL_FORMAT_XRGB_2101010:
161 case HAL_PIXEL_FORMAT_BGRA_1010102:
162 case HAL_PIXEL_FORMAT_ABGR_2101010:
163 case HAL_PIXEL_FORMAT_BGRX_1010102:
164 case HAL_PIXEL_FORMAT_XBGR_2101010:
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530165 bpp = 4;
166 break;
167 case HAL_PIXEL_FORMAT_RGB_888:
Camus Wong5c5e6fb2017-03-21 17:02:48 -0400168 case HAL_PIXEL_FORMAT_BGR_888:
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530169 bpp = 3;
170 break;
171 case HAL_PIXEL_FORMAT_RGB_565:
172 case HAL_PIXEL_FORMAT_BGR_565:
173 case HAL_PIXEL_FORMAT_RGBA_5551:
174 case HAL_PIXEL_FORMAT_RGBA_4444:
175 bpp = 2;
176 break;
177 default:
Arun Kumar K.Rb97ca302017-04-06 15:59:33 -0700178 ALOGE("Error : %s New format request = 0x%x", __FUNCTION__, format);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530179 break;
180 }
181
182 return bpp;
183}
184
Naseer Ahmede36f2242017-12-01 15:33:56 -0500185bool CpuCanAccess(uint64_t usage) {
186 return CpuCanRead(usage) || CpuCanWrite(usage);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530187}
188
Naseer Ahmede36f2242017-12-01 15:33:56 -0500189bool CpuCanRead(uint64_t usage) {
190 if (usage & BufferUsage::CPU_READ_MASK) {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530191 return true;
192 }
193
194 return false;
195}
196
Naseer Ahmede36f2242017-12-01 15:33:56 -0500197bool CpuCanWrite(uint64_t usage) {
198 if (usage & BufferUsage::CPU_WRITE_MASK) {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530199 // Application intends to use CPU for rendering
200 return true;
201 }
202
203 return false;
204}
205
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400206uint32_t GetDataAlignment(int format, uint64_t usage) {
207 uint32_t align = UINT(getpagesize());
208 if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) {
209 align = SIZE_8K;
210 }
211
212 if (usage & BufferUsage::PROTECTED) {
213 if ((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY)) {
214 // The alignment here reflects qsee mmu V7L/V8L requirement
215 align = SZ_2M;
216 } else {
217 align = SECURE_ALIGN;
218 }
219 }
220
221 return align;
222}
223
Saurabh Dubey937c4e52018-06-26 11:31:18 +0530224bool IsGPUFlagSupported(uint64_t usage) {
225 bool ret = true;
226 if ((usage & BufferUsage::GPU_MIPMAP_COMPLETE)) {
227 ALOGE("GPU_MIPMAP_COMPLETE not supported");
228 ret = false;
229 }
230
231 if ((usage & BufferUsage::GPU_CUBE_MAP)) {
232 ALOGE("GPU_CUBE_MAP not supported");
233 ret = false;
234 }
235
236 return ret;
237}
238
Tharaga Balachandranab150ab2019-09-26 19:17:58 -0400239int GetBpp(int format) {
240 if (IsUncompressedRGBFormat(format)) {
241 return GetBppForUncompressedRGB(format);
242 }
243 switch (format) {
244 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
245 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
246 case HAL_PIXEL_FORMAT_RAW8:
247 case HAL_PIXEL_FORMAT_Y8:
248 return 1;
249 case HAL_PIXEL_FORMAT_RAW16:
250 case HAL_PIXEL_FORMAT_Y16:
251 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
252 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
253 case HAL_PIXEL_FORMAT_YCbCr_422_I:
254 case HAL_PIXEL_FORMAT_YCrCb_422_I:
255 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
256 return 2;
257 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
258 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
259 return 3;
260 default:
261 return -1;
262 }
263}
264
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400265// Returns the final buffer size meant to be allocated with ion
Naseer Ahmede36f2242017-12-01 15:33:56 -0500266unsigned int GetSize(const BufferInfo &info, unsigned int alignedw, unsigned int alignedh) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700267 unsigned int size = 0;
268 int format = info.format;
269 int width = info.width;
270 int height = info.height;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500271 uint64_t usage = info.usage;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700272
Saurabh Dubey937c4e52018-06-26 11:31:18 +0530273 if (!IsGPUFlagSupported(usage)) {
274 ALOGE("Unsupported GPU usage flags present 0x%" PRIx64, usage);
275 return 0;
276 }
277
Naseer Ahmede36f2242017-12-01 15:33:56 -0500278 if (IsUBwcEnabled(format, usage)) {
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400279 size = GetUBwcSize(width, height, format, alignedw, alignedh);
280 } else if (IsUncompressedRGBFormat(format)) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700281 uint32_t bpp = GetBppForUncompressedRGB(format);
282 size = alignedw * alignedh * bpp;
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400283 } else if (IsCompressedRGBFormat(format)) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700284 size = alignedw * alignedh * ASTC_BLOCK_SIZE;
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400285 } else {
286 // Below switch should be for only YUV/custom formats
287 switch (format) {
288 case HAL_PIXEL_FORMAT_RAW16:
289 case HAL_PIXEL_FORMAT_Y16:size = alignedw * alignedh * 2;
290 break;
291 case HAL_PIXEL_FORMAT_RAW10:
292 case HAL_PIXEL_FORMAT_RAW12:size = ALIGN(alignedw * alignedh, SIZE_4K);
293 break;
294 case HAL_PIXEL_FORMAT_RAW8:
295 case HAL_PIXEL_FORMAT_Y8:size = alignedw * alignedh * 1;
296 break;
297 // adreno formats
298 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21
299 size = ALIGN(alignedw * alignedh, SIZE_4K);
300 size += (unsigned int) ALIGN(2 * ALIGN(width / 2, 32) * ALIGN(height / 2, 32), SIZE_4K);
301 break;
302 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12
303 // The chroma plane is subsampled,
304 // but the pitch in bytes is unchanged
305 // The GPU needs 4K alignment, but the video decoder needs 8K
306 size = ALIGN(alignedw * alignedh, SIZE_8K);
307 size += ALIGN(alignedw * (unsigned int) ALIGN(height / 2, 32), SIZE_8K);
308 break;
309 case HAL_PIXEL_FORMAT_YV12:
310 if ((format == HAL_PIXEL_FORMAT_YV12) && ((width & 1) || (height & 1))) {
311 ALOGE("w or h is odd for the YV12 format");
312 return 0;
313 }
314 size = alignedw * alignedh + (ALIGN(alignedw / 2, 16) * (alignedh / 2)) * 2;
315 size = ALIGN(size, (unsigned int) SIZE_4K);
316 break;
317 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
318 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
319 size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2 + 1, SIZE_4K);
320 break;
321 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
322 size = ALIGN((alignedw * alignedh * 2) + (alignedw * alignedh) + 1, SIZE_4K);
323 break;
324 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
325 size = VENUS_BUFFER_SIZE(COLOR_FMT_P010,
326 width,
327 height);
328 break;
329 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
330 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
331 case HAL_PIXEL_FORMAT_YCbCr_422_I:
332 case HAL_PIXEL_FORMAT_YCrCb_422_I:
333 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
334 if (width & 1) {
335 ALOGE("width is odd for the YUV422_SP format");
336 return 0;
337 }
338 size = ALIGN(alignedw * alignedh * 2, SIZE_4K);
339 break;
340 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
341 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
342 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height);
343 break;
344 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
345 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
346 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV21, width, height);
347 break;
348 case HAL_PIXEL_FORMAT_BLOB:
349 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
350 if (height != 1) {
351 ALOGE("%s: Buffers with HAL_PIXEL_FORMAT_BLOB must have height 1 ", __FUNCTION__);
352 return 0;
353 }
354 size = (unsigned int) width;
355 break;
356 case HAL_PIXEL_FORMAT_NV21_ZSL:
357 size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2,
358 SIZE_4K);
359 break;
Rajavenu Kyatham6e8c1822018-07-31 10:27:19 +0530360 case HAL_PIXEL_FORMAT_NV12_HEIF:
361 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_512, width, height);
362 break;
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400363 default:ALOGE("%s: Unrecognized pixel format: 0x%x", __FUNCTION__, format);
364 return 0;
365 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700366 }
Naseer Ahmedda214ec2018-03-12 20:15:07 -0400367 auto align = GetDataAlignment(format, usage);
368 size = ALIGN(size, align) * info.layer_count;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700369 return size;
370}
371
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -0700372int GetBufferSizeAndDimensions(const BufferInfo &info, unsigned int *size, unsigned int *alignedw,
373 unsigned int *alignedh) {
Saurabh Dubeyefd7f9e2018-06-15 18:00:02 +0530374 GraphicsMetadata graphics_metadata = {};
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -0700375 return GetBufferSizeAndDimensions(info, size, alignedw, alignedh, &graphics_metadata);
Saurabh Dubeyefd7f9e2018-06-15 18:00:02 +0530376}
377
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -0700378int GetBufferSizeAndDimensions(const BufferInfo &info, unsigned int *size, unsigned int *alignedw,
379 unsigned int *alignedh, GraphicsMetadata *graphics_metadata) {
Saurabh Dubeyefd7f9e2018-06-15 18:00:02 +0530380 int buffer_type = GetBufferType(info.format);
381 if (CanUseAdrenoForSize(buffer_type, info.usage)) {
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -0700382 return GetGpuResourceSizeAndDimensions(info, size, alignedw, alignedh, graphics_metadata);
Saurabh Dubeyefd7f9e2018-06-15 18:00:02 +0530383 } else {
384 GetAlignedWidthAndHeight(info, alignedw, alignedh);
385 *size = GetSize(info, *alignedw, *alignedh);
386 }
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -0700387 return 0;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700388}
389
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530390void GetYuvUbwcSPPlaneInfo(uint32_t width, uint32_t height, int color_format,
391 PlaneLayoutInfo *plane_info) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700392 // UBWC buffer has these 4 planes in the following sequence:
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530393 // Y_Plane, UV_Plane, Y_Meta_Plane, UV_Meta_Plane
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700394 unsigned int y_meta_stride, y_meta_height, y_meta_size;
395 unsigned int y_stride, y_height, y_size;
396 unsigned int c_meta_stride, c_meta_height, c_meta_size;
397 unsigned int alignment = 4096;
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530398 unsigned int c_stride, c_height, c_size;
399 uint64_t yOffset, cOffset, yMetaOffset, cMetaOffset;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700400
401 y_meta_stride = VENUS_Y_META_STRIDE(color_format, INT(width));
402 y_meta_height = VENUS_Y_META_SCANLINES(color_format, INT(height));
403 y_meta_size = ALIGN((y_meta_stride * y_meta_height), alignment);
404
405 y_stride = VENUS_Y_STRIDE(color_format, INT(width));
406 y_height = VENUS_Y_SCANLINES(color_format, INT(height));
407 y_size = ALIGN((y_stride * y_height), alignment);
408
409 c_meta_stride = VENUS_UV_META_STRIDE(color_format, INT(width));
410 c_meta_height = VENUS_UV_META_SCANLINES(color_format, INT(height));
411 c_meta_size = ALIGN((c_meta_stride * c_meta_height), alignment);
412
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530413 c_stride = VENUS_UV_STRIDE(color_format, INT(width));
414 c_height = VENUS_UV_SCANLINES(color_format, INT(height));
415 c_size = ALIGN((c_stride * c_height), alignment);
416
417 yMetaOffset = 0;
418 yOffset = y_meta_size;
419 cMetaOffset = y_meta_size + y_size;
420 cOffset = y_meta_size + y_size + c_meta_size;
421
422 plane_info[0].component = (PlaneComponent)PLANE_COMPONENT_Y;
423 plane_info[0].offset = (uint32_t)yOffset;
424 plane_info[0].stride = static_cast<int32_t>(UINT(width));
425 plane_info[0].stride_bytes = static_cast<int32_t>(y_stride);
426 plane_info[0].scanlines = static_cast<int32_t>(y_height);
427 plane_info[0].size = static_cast<uint32_t>(y_size);
428
429 plane_info[1].component = (PlaneComponent)(PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr);
430 plane_info[1].offset = (uint32_t)cOffset;
431 plane_info[1].stride = static_cast<int32_t>(UINT(width));
432 plane_info[1].stride_bytes = static_cast<int32_t>(c_stride);
433 plane_info[1].scanlines = static_cast<int32_t>(c_height);
434 plane_info[1].size = static_cast<uint32_t>(c_size);
435
436 plane_info[2].component = (PlaneComponent)(PLANE_COMPONENT_META | PLANE_COMPONENT_Y);
437 plane_info[2].offset = (uint32_t)yMetaOffset;
438 plane_info[2].stride = static_cast<int32_t>(UINT(width));
439 plane_info[2].stride_bytes = static_cast<int32_t>(y_meta_stride);
440 plane_info[2].scanlines = static_cast<int32_t>(y_meta_height);
441 plane_info[2].size = static_cast<uint32_t>(y_meta_size);
442
443 plane_info[3].component =
444 (PlaneComponent)(PLANE_COMPONENT_META | PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr);
445 plane_info[3].offset = (uint32_t)cMetaOffset;
446 plane_info[3].stride = static_cast<int32_t>(UINT(width));
447 plane_info[3].stride_bytes = static_cast<int32_t>(c_meta_stride);
448 plane_info[3].scanlines = static_cast<int32_t>(c_meta_height);
449 plane_info[3].size = static_cast<uint32_t>(c_meta_size);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700450}
451
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530452// This API gets information about 8 planes (Y_Plane, UV_Plane, Y_Meta_Plane, UV_Meta_Plane,
453// Y_Plane, UV_Plane, Y_Meta_Plane, UV_Meta_Plane) and it stores the
454// information in PlaneLayoutInfo array.
455void GetYuvUbwcInterlacedSPPlaneInfo(uint32_t width, uint32_t height,
456 PlaneLayoutInfo plane_info[8]) {
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700457 // UBWC interlaced has top-bottom field layout with each field as
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530458 // 8-plane (including meta plane also) NV12_UBWC with width = image_width
459 // & height = image_height / 2.
460 // Client passed plane_info argument is ptr to struct PlaneLayoutInfo[8].
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700461 // Plane info to be filled for each field separately.
462 height = (height + 1) >> 1;
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700463
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530464 GetYuvUbwcSPPlaneInfo(width, height, COLOR_FMT_NV12_UBWC, &plane_info[0]);
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700465
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530466 GetYuvUbwcSPPlaneInfo(width, height, COLOR_FMT_NV12_UBWC, &plane_info[4]);
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700467}
468
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530469// This API gets information about 2 planes (Y_Plane & UV_Plane)
470void GetYuvSPPlaneInfo(const BufferInfo &info, int format, uint32_t width, uint32_t height,
471 uint32_t bpp, PlaneLayoutInfo *plane_info) {
472 int unaligned_width = info.width;
473 int unaligned_height = info.height;
474 unsigned int y_stride = 0, y_height = 0, y_size = 0;
475 unsigned int c_stride = 0, c_height = 0, c_size = 0;
476 uint64_t yOffset, cOffset;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700477
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530478 y_stride = c_stride = UINT(width) * bpp;
479 y_height = INT(height);
480 y_size = y_stride * y_height;
481 switch (format) {
482 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
483 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
484 c_size = (width * height) / 2 + 1;
485 c_height = height >> 1;
486 break;
487 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
488 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
489 if (unaligned_width & 1) {
490 ALOGE("width is odd for the YUV422_SP format");
491 return;
492 }
493 c_size = width * height;
494 c_height = height;
495 break;
496 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
497 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
498 c_height = VENUS_UV_SCANLINES(COLOR_FMT_NV12, height);
499 c_size = c_stride * c_height;
500 break;
501 case HAL_PIXEL_FORMAT_NV12_HEIF:
502 c_height = VENUS_UV_SCANLINES(COLOR_FMT_NV12_512, height);
503 c_size = c_stride * c_height;
504 break;
505 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
506 y_size = ALIGN(width * height, 4096);
507 c_size = ALIGN(2 * ALIGN(unaligned_width / 2, 32) * ALIGN(unaligned_height / 2, 32), 4096);
508 break;
509 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
Ramakant Singh13596ae2020-01-06 20:12:34 +0530510 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530511 c_height = VENUS_UV_SCANLINES(COLOR_FMT_NV21, height);
512 c_size = c_stride * c_height;
513 break;
514 case HAL_PIXEL_FORMAT_NV21_ZSL:
515 c_size = (width * height) / 2;
516 c_height = height >> 1;
517 break;
518 case HAL_PIXEL_FORMAT_RAW16:
519 case HAL_PIXEL_FORMAT_Y16:
520 c_size = width * height;
521 c_height = height;
522 break;
523 case HAL_PIXEL_FORMAT_RAW10:
524 c_size = 0;
525 break;
526 case HAL_PIXEL_FORMAT_RAW8:
527 case HAL_PIXEL_FORMAT_Y8:
528 c_size = 0;
529 break;
530 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
531 c_size = (width * height) + 1;
532 c_height = height;
533 break;
534 default:
535 break;
536 }
537
538 yOffset = 0;
539 cOffset = y_size;
540
541 plane_info[0].component = (PlaneComponent)PLANE_COMPONENT_Y;
542 plane_info[0].offset = (uint32_t)yOffset;
543 plane_info[0].step = 1;
544 plane_info[0].stride = static_cast<int32_t>(UINT(width));
545 plane_info[0].stride_bytes = static_cast<int32_t>(y_stride);
546 plane_info[0].scanlines = static_cast<int32_t>(y_height);
547 plane_info[0].size = static_cast<uint32_t>(y_size);
548
549 plane_info[1].component = (PlaneComponent)(PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr);
550 plane_info[1].offset = (uint32_t)cOffset;
551 plane_info[1].step = 2 * bpp;
552 plane_info[1].stride = static_cast<int32_t>(UINT(width));
553 plane_info[1].stride_bytes = static_cast<int32_t>(c_stride);
554 plane_info[1].scanlines = static_cast<int32_t>(c_height);
555 plane_info[1].size = static_cast<uint32_t>(c_size);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700556}
557
Naseer Ahmed7aff2612017-10-05 20:39:05 -0400558int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700559 int err = 0;
560 uint32_t width = UINT(hnd->width);
561 uint32_t height = UINT(hnd->height);
562 int format = hnd->format;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500563 uint64_t usage = hnd->usage;
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530564 int32_t interlaced = 0;
565 int plane_count = 0;
566 int unaligned_width = INT(hnd->unaligned_width);
567 int unaligned_height = INT(hnd->unaligned_height);
568 BufferInfo info(unaligned_width, unaligned_height, format, usage);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700569
570 memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700571
572 // Check if UBWC buffer has been rendered in linear format.
Ramakant Singhc7d07792017-07-26 15:36:33 +0530573 int linear_format = 0;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500574 if (getMetaData(const_cast<private_handle_t *>(hnd), GET_LINEAR_FORMAT, &linear_format) == 0) {
575 format = INT(linear_format);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700576 }
577
578 // Check metadata if the geometry has been updated.
Ramakant Singhc7d07792017-07-26 15:36:33 +0530579 BufferDim_t buffer_dim;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500580 if (getMetaData(const_cast<private_handle_t *>(hnd), GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
581 BufferInfo info(buffer_dim.sliceWidth, buffer_dim.sliceHeight, format, usage);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700582 GetAlignedWidthAndHeight(info, &width, &height);
583 }
584
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700585 // Check metadata for interlaced content.
Ramakant Singhc7d07792017-07-26 15:36:33 +0530586 int interlace_flag = 0;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500587 if (getMetaData(const_cast<private_handle_t *>(hnd), GET_PP_PARAM_INTERLACED, &interlace_flag) ==
588 0) {
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530589 if (interlace_flag) {
590 interlaced = LAYOUT_INTERLACED_FLAG;
591 }
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700592 }
593
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530594 PlaneLayoutInfo plane_info[8] = {};
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700595 // Get the chroma offsets from the handle width/height. We take advantage
596 // of the fact the width _is_ the stride
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530597 err = GetYUVPlaneInfo(info, format, width, height, interlaced, &plane_count, plane_info);
598 if (err == 0) {
599 if (interlaced && format == HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC) {
600 CopyPlaneLayoutInfotoAndroidYcbcr(hnd->base, plane_count, &plane_info[0], &ycbcr[0]);
601 unsigned int uv_stride, uv_height, uv_size;
602 unsigned int alignment = 4096;
603 uint64_t field_base;
604 height = (height + 1) >> 1;
605 uv_stride = VENUS_UV_STRIDE(COLOR_FMT_NV12_UBWC, INT(width));
606 uv_height = VENUS_UV_SCANLINES(COLOR_FMT_NV12_UBWC, INT(height));
607 uv_size = ALIGN((uv_stride * uv_height), alignment);
608 field_base = hnd->base + plane_info[1].offset + uv_size;
609 memset(ycbcr[1].reserved, 0, sizeof(ycbcr[1].reserved));
610 CopyPlaneLayoutInfotoAndroidYcbcr(field_base, plane_count, &plane_info[4], &ycbcr[1]);
611 } else {
612 CopyPlaneLayoutInfotoAndroidYcbcr(hnd->base, plane_count, plane_info, ycbcr);
613 switch (format) {
614 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
615 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
616 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
617 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
618 case HAL_PIXEL_FORMAT_NV21_ZSL:
619 case HAL_PIXEL_FORMAT_RAW16:
620 case HAL_PIXEL_FORMAT_Y16:
621 case HAL_PIXEL_FORMAT_RAW10:
622 case HAL_PIXEL_FORMAT_RAW8:
623 case HAL_PIXEL_FORMAT_Y8:
624 std::swap(ycbcr->cb, ycbcr->cr);
Rohit Kulkarnia152c312017-06-02 14:22:35 -0700625 }
Ashish Kumarb9392ff2019-03-27 18:30:39 +0530626 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700627 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700628 return err;
629}
630
631// Explicitly defined UBWC formats
632bool IsUBwcFormat(int format) {
633 switch (format) {
634 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
635 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
636 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
637 return true;
638 default:
639 return false;
640 }
641}
642
643bool IsUBwcSupported(int format) {
644 // Existing HAL formats with UBWC support
645 switch (format) {
646 case HAL_PIXEL_FORMAT_BGR_565:
647 case HAL_PIXEL_FORMAT_RGBA_8888:
648 case HAL_PIXEL_FORMAT_RGBX_8888:
649 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
650 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
651 case HAL_PIXEL_FORMAT_RGBA_1010102:
652 case HAL_PIXEL_FORMAT_RGBX_1010102:
Saurabh Dubey11df8e12018-07-25 19:16:25 +0530653 case HAL_PIXEL_FORMAT_DEPTH_16:
654 case HAL_PIXEL_FORMAT_DEPTH_24:
655 case HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8:
656 case HAL_PIXEL_FORMAT_DEPTH_32F:
657 case HAL_PIXEL_FORMAT_STENCIL_8:
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700658 return true;
659 default:
660 break;
661 }
662
663 return false;
664}
665
Saurabh Dubey48b757d2018-05-24 19:13:53 +0530666bool IsUBwcPISupported(int format, uint64_t usage) {
667 if (usage & BufferUsage::COMPOSER_OVERLAY || !(usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI)) {
668 return false;
669 }
670
671 // As of now only two formats
672 switch (format) {
673 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
674 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: {
675 if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) {
676 if (AdrenoMemInfo::GetInstance()) {
677 return AdrenoMemInfo::GetInstance()->IsPISupportedByGPU(format, usage);
678 }
679 } else {
680 return true;
681 }
682 }
683 }
684
685 return false;
686}
687
Naseer Ahmede36f2242017-12-01 15:33:56 -0500688bool IsUBwcEnabled(int format, uint64_t usage) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700689 // Allow UBWC, if client is using an explicitly defined UBWC pixel format.
690 if (IsUBwcFormat(format)) {
691 return true;
692 }
693
694 // Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP
695 // support the format. OR if a non-OpenGL client like Rotator, sets UBWC
696 // usage flag and MDP supports the format.
Naseer Ahmed2023cf32019-01-28 19:02:40 -0500697 if (((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) ||
698 (usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI) ||
699 (usage & BufferUsage::COMPOSER_CLIENT_TARGET))
Saurabh Dubey48b757d2018-05-24 19:13:53 +0530700 && IsUBwcSupported(format)) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700701 bool enable = true;
702 // Query GPU for UBWC only if buffer is intended to be used by GPU.
Naseer Ahmede36f2242017-12-01 15:33:56 -0500703 if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) {
Pramodh Kumar Mukunda927729d2017-06-15 16:18:51 +0530704 if (AdrenoMemInfo::GetInstance()) {
705 enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format);
706 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700707 }
708
709 // Allow UBWC, only if CPU usage flags are not set
Naseer Ahmede36f2242017-12-01 15:33:56 -0500710 if (enable && !(CpuCanAccess(usage))) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700711 return true;
712 }
713 }
714
715 return false;
716}
717
718void GetYuvUBwcWidthAndHeight(int width, int height, int format, unsigned int *aligned_w,
719 unsigned int *aligned_h) {
720 switch (format) {
721 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
722 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
723 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
724 *aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV12_UBWC, width);
725 *aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12_UBWC, height);
726 break;
727 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
728 // The macro returns the stride which is 4/3 times the width, hence * 3/4
729 *aligned_w = (VENUS_Y_STRIDE(COLOR_FMT_NV12_BPP10_UBWC, width) * 3) / 4;
730 *aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12_BPP10_UBWC, height);
731 break;
732 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
733 // The macro returns the stride which is 2 times the width, hence / 2
734 *aligned_w = (VENUS_Y_STRIDE(COLOR_FMT_P010_UBWC, width) / 2);
735 *aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_P010_UBWC, height);
736 break;
737 default:
738 ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format);
739 *aligned_w = 0;
740 *aligned_h = 0;
741 break;
742 }
743}
744
745void GetRgbUBwcBlockSize(uint32_t bpp, int *block_width, int *block_height) {
746 *block_width = 0;
747 *block_height = 0;
748
749 switch (bpp) {
750 case 2:
751 case 4:
752 *block_width = 16;
753 *block_height = 4;
754 break;
755 case 8:
756 *block_width = 8;
757 *block_height = 4;
758 break;
759 case 16:
760 *block_width = 4;
761 *block_height = 4;
762 break;
763 default:
764 ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp);
765 break;
766 }
767}
768
769unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp) {
770 unsigned int size = 0;
771 int meta_width, meta_height;
772 int block_width, block_height;
773
774 GetRgbUBwcBlockSize(bpp, &block_width, &block_height);
775 if (!block_width || !block_height) {
776 ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp);
777 return size;
778 }
779
780 // Align meta buffer height to 16 blocks
781 meta_height = ALIGN(((height + block_height - 1) / block_height), 16);
782
783 // Align meta buffer width to 64 blocks
784 meta_width = ALIGN(((width + block_width - 1) / block_width), 64);
785
786 // Align meta buffer size to 4K
787 size = (unsigned int)ALIGN((meta_width * meta_height), 4096);
788
789 return size;
790}
791
792unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw,
793 unsigned int alignedh) {
794 unsigned int size = 0;
795 uint32_t bpp = 0;
796 switch (format) {
797 case HAL_PIXEL_FORMAT_BGR_565:
798 case HAL_PIXEL_FORMAT_RGBA_8888:
799 case HAL_PIXEL_FORMAT_RGBX_8888:
800 case HAL_PIXEL_FORMAT_RGBA_1010102:
801 case HAL_PIXEL_FORMAT_RGBX_1010102:
802 bpp = GetBppForUncompressedRGB(format);
803 size = alignedw * alignedh * bpp;
804 size += GetRgbUBwcMetaBufferSize(width, height, bpp);
805 break;
806 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
807 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
808 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
809 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_UBWC, width, height);
810 break;
811 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
812 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_BPP10_UBWC, width, height);
813 break;
814 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
815 size = VENUS_BUFFER_SIZE(COLOR_FMT_P010_UBWC, width, height);
816 break;
817 default:
818 ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format);
819 break;
820 }
821
822 return size;
823}
824
Ashish Kumar8a1b56e2019-11-15 18:15:22 +0530825unsigned int GetRgbMetaSize(int format, uint32_t width, uint32_t height, uint64_t usage) {
826 unsigned int meta_size = 0;
827 if (!IsUBwcEnabled(format, usage)) {
828 return meta_size;
829 }
830 uint32_t bpp = GetBppForUncompressedRGB(format);
831 switch (format) {
832 case HAL_PIXEL_FORMAT_BGR_565:
833 case HAL_PIXEL_FORMAT_RGBA_8888:
834 case HAL_PIXEL_FORMAT_RGBX_8888:
835 case HAL_PIXEL_FORMAT_RGBA_1010102:
836 case HAL_PIXEL_FORMAT_RGBX_1010102:
837 case HAL_PIXEL_FORMAT_RGBA_FP16:
838 meta_size = GetRgbUBwcMetaBufferSize(width, height, bpp);
839 break;
840 default:
841 ALOGE("%s:Unsupported RGB format: 0x%x", __FUNCTION__, format);
842 break;
843 }
844 return meta_size;
845}
846
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700847int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data) {
848 int err = 0;
849
850 // This api is for RGB* formats
Naseer Ahmede36f2242017-12-01 15:33:56 -0500851 if (!IsUncompressedRGBFormat(hnd->format)) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700852 return -EINVAL;
853 }
854
855 // linear buffer, nothing to do further
856 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED)) {
857 *rgb_data = reinterpret_cast<void *>(hnd->base);
858 return err;
859 }
Ashish Kumar8a1b56e2019-11-15 18:15:22 +0530860 unsigned int meta_size = GetRgbMetaSize(hnd->format, hnd->width, hnd->height, hnd->usage);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700861
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700862 *rgb_data = reinterpret_cast<void *>(hnd->base + meta_size);
863
864 return err;
865}
866
Naseer Ahmede36f2242017-12-01 15:33:56 -0500867void GetCustomDimensions(private_handle_t *hnd, int *stride, int *height) {
868 BufferDim_t buffer_dim;
869 int interlaced = 0;
870
871 *stride = hnd->width;
872 *height = hnd->height;
873 if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
874 *stride = buffer_dim.sliceWidth;
875 *height = buffer_dim.sliceHeight;
876 } else if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, &interlaced) == 0) {
877 if (interlaced && IsUBwcFormat(hnd->format)) {
878 unsigned int alignedw = 0, alignedh = 0;
879 // Get re-aligned height for single ubwc interlaced field and
880 // multiply by 2 to get frame height.
881 BufferInfo info(hnd->width, ((hnd->height + 1) >> 1), hnd->format);
882 GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
883 *stride = static_cast<int>(alignedw);
884 *height = static_cast<int>(alignedh * 2);
885 }
886 }
887}
888
889void GetColorSpaceFromMetadata(private_handle_t *hnd, int *color_space) {
890 ColorMetaData color_metadata;
891 if (getMetaData(hnd, GET_COLOR_METADATA, &color_metadata) == 0) {
892 switch (color_metadata.colorPrimaries) {
893 case ColorPrimaries_BT709_5:
894 *color_space = HAL_CSC_ITU_R_709;
895 break;
896 case ColorPrimaries_BT601_6_525:
897 case ColorPrimaries_BT601_6_625:
898 *color_space = ((color_metadata.range) ? HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601);
899 break;
900 case ColorPrimaries_BT2020:
901 *color_space = (color_metadata.range) ? HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020;
902 break;
903 default:
904 ALOGE("Unknown Color Space = %d", color_metadata.colorPrimaries);
905 break;
906 }
907 } else if (getMetaData(hnd, GET_COLOR_SPACE, color_space) != 0) {
908 *color_space = 0;
909 }
910}
911
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700912void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw,
913 unsigned int *alignedh) {
914 int width = info.width;
915 int height = info.height;
916 int format = info.format;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500917 uint64_t usage = info.usage;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700918
919 // Currently surface padding is only computed for RGB* surfaces.
Naseer Ahmede36f2242017-12-01 15:33:56 -0500920 bool ubwc_enabled = IsUBwcEnabled(format, usage);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700921 int tile = ubwc_enabled;
922
923 if (IsUncompressedRGBFormat(format)) {
Pramodh Kumar Mukunda927729d2017-06-15 16:18:51 +0530924 if (AdrenoMemInfo::GetInstance()) {
925 AdrenoMemInfo::GetInstance()->AlignUnCompressedRGB(width, height, format, tile, alignedw,
926 alignedh);
927 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700928 return;
929 }
930
931 if (ubwc_enabled) {
932 GetYuvUBwcWidthAndHeight(width, height, format, alignedw, alignedh);
933 return;
934 }
935
936 if (IsCompressedRGBFormat(format)) {
Pramodh Kumar Mukunda927729d2017-06-15 16:18:51 +0530937 if (AdrenoMemInfo::GetInstance()) {
938 AdrenoMemInfo::GetInstance()->AlignCompressedRGB(width, height, format, alignedw, alignedh);
939 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700940 return;
941 }
942
943 int aligned_w = width;
944 int aligned_h = height;
945 unsigned int alignment = 32;
946
947 // Below should be only YUV family
948 switch (format) {
949 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
950 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
Pramodh Kumar Mukunda927729d2017-06-15 16:18:51 +0530951 if (AdrenoMemInfo::GetInstance() == nullptr) {
952 return;
953 }
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700954 alignment = AdrenoMemInfo::GetInstance()->GetGpuPixelAlignment();
955 aligned_w = ALIGN(width, alignment);
956 break;
957 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
958 aligned_w = ALIGN(width, alignment);
959 break;
960 case HAL_PIXEL_FORMAT_RAW16:
Anjaneya Prasad Musunurib1654142017-04-18 10:32:42 +0530961 case HAL_PIXEL_FORMAT_Y16:
962 case HAL_PIXEL_FORMAT_Y8:
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700963 aligned_w = ALIGN(width, 16);
964 break;
965 case HAL_PIXEL_FORMAT_RAW12:
Naseer Ahmed1187a572017-08-14 13:16:55 -0400966 aligned_w = ALIGN(width * 12 / 8, 16);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700967 break;
968 case HAL_PIXEL_FORMAT_RAW10:
Naseer Ahmed1187a572017-08-14 13:16:55 -0400969 aligned_w = ALIGN(width * 10 / 8, 16);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700970 break;
971 case HAL_PIXEL_FORMAT_RAW8:
Naseer Ahmed1187a572017-08-14 13:16:55 -0400972 aligned_w = ALIGN(width, 16);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700973 break;
974 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
975 aligned_w = ALIGN(width, 128);
976 break;
977 case HAL_PIXEL_FORMAT_YV12:
978 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
979 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
980 case HAL_PIXEL_FORMAT_YCbCr_422_I:
981 case HAL_PIXEL_FORMAT_YCrCb_422_I:
982 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
983 aligned_w = ALIGN(width, 16);
984 break;
Mathew Joseph Karimpanala73082e2017-10-16 18:01:21 +0530985 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
986 aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_P010, width) / 2);
987 aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_P010, height));
988 break;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700989 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
990 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
991 aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_NV12, width));
992 aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_NV12, height));
993 break;
994 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
Ramakant Singh13596ae2020-01-06 20:12:34 +0530995 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
Saurabh Shah14c8e5b2017-04-07 10:37:23 -0700996 aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_NV21, width));
997 aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_NV21, height));
998 break;
999 case HAL_PIXEL_FORMAT_BLOB:
1000 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
1001 break;
1002 case HAL_PIXEL_FORMAT_NV21_ZSL:
1003 aligned_w = ALIGN(width, 64);
1004 aligned_h = ALIGN(height, 64);
1005 break;
Rajavenu Kyatham6e8c1822018-07-31 10:27:19 +05301006 case HAL_PIXEL_FORMAT_NV12_HEIF:
1007 aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_NV12_512, width));
1008 aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_NV12_512, height));
1009 break;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001010 default:
1011 break;
1012 }
1013
1014 *alignedw = (unsigned int)aligned_w;
1015 *alignedh = (unsigned int)aligned_h;
1016}
1017
Naseer Ahmede36f2242017-12-01 15:33:56 -05001018int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4], uint32_t offset[4],
1019 uint32_t *num_planes) {
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001020 if (!hnd || !stride || !offset || !num_planes) {
1021 return -EINVAL;
1022 }
1023
Naseer Ahmed7aff2612017-10-05 20:39:05 -04001024 struct android_ycbcr yuvPlaneInfo[2] = {};
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001025 *num_planes = 1;
1026 stride[0] = 0;
1027
1028 switch (hnd->format) {
1029 case HAL_PIXEL_FORMAT_RGB_565:
1030 case HAL_PIXEL_FORMAT_BGR_565:
1031 case HAL_PIXEL_FORMAT_RGBA_5551:
1032 case HAL_PIXEL_FORMAT_RGBA_4444:
1033 stride[0] = static_cast<uint32_t>(hnd->width * 2);
1034 break;
1035 case HAL_PIXEL_FORMAT_RGB_888:
1036 stride[0] = static_cast<uint32_t>(hnd->width * 3);
1037 break;
1038 case HAL_PIXEL_FORMAT_RGBA_8888:
1039 case HAL_PIXEL_FORMAT_BGRA_8888:
1040 case HAL_PIXEL_FORMAT_RGBX_8888:
1041 case HAL_PIXEL_FORMAT_BGRX_8888:
1042 case HAL_PIXEL_FORMAT_RGBA_1010102:
1043 case HAL_PIXEL_FORMAT_ARGB_2101010:
1044 case HAL_PIXEL_FORMAT_RGBX_1010102:
1045 case HAL_PIXEL_FORMAT_XRGB_2101010:
1046 case HAL_PIXEL_FORMAT_BGRA_1010102:
1047 case HAL_PIXEL_FORMAT_ABGR_2101010:
1048 case HAL_PIXEL_FORMAT_BGRX_1010102:
1049 case HAL_PIXEL_FORMAT_XBGR_2101010:
1050 stride[0] = static_cast<uint32_t>(hnd->width * 4);
1051 break;
1052 }
1053
1054 // Format is RGB
1055 if (stride[0]) {
1056 return 0;
1057 }
1058
1059 (*num_planes)++;
Naseer Ahmed7aff2612017-10-05 20:39:05 -04001060 int ret = GetYUVPlaneInfo(hnd, yuvPlaneInfo);
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001061 if (ret < 0) {
1062 ALOGE("%s failed", __FUNCTION__);
1063 return ret;
1064 }
1065
Naseer Ahmed7aff2612017-10-05 20:39:05 -04001066 // We are only returning buffer layout for progressive or single field formats.
1067 struct android_ycbcr yuvInfo = yuvPlaneInfo[0];
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001068 stride[0] = static_cast<uint32_t>(yuvInfo.ystride);
1069 offset[0] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.y) - hnd->base);
1070 stride[1] = static_cast<uint32_t>(yuvInfo.cstride);
1071 switch (hnd->format) {
1072 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
1073 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
1074 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
1075 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
1076 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
1077 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
1078 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
1079 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
Mathew Joseph Karimpanala73082e2017-10-16 18:01:21 +05301080 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
Rajavenu Kyatham6e8c1822018-07-31 10:27:19 +05301081 case HAL_PIXEL_FORMAT_NV12_HEIF:
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001082 offset[1] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
1083 break;
1084 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
1085 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
1086 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
Ramakant Singh13596ae2020-01-06 20:12:34 +05301087 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001088 offset[1] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
1089 break;
1090 case HAL_PIXEL_FORMAT_YV12:
1091 offset[1] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
1092 stride[2] = static_cast<uint32_t>(yuvInfo.cstride);
1093 offset[2] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
1094 (*num_planes)++;
1095 break;
Camus Wonga300db62018-09-27 16:38:50 -04001096 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
1097 *num_planes = 1;
1098 break;
Saurabh Shah14c8e5b2017-04-07 10:37:23 -07001099 default:
1100 ALOGW("%s: Unsupported format", __FUNCTION__);
1101 ret = -EINVAL;
1102 }
1103
1104 if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
1105 std::fill(offset, offset + 4, 0);
1106 }
1107
1108 return 0;
1109}
1110
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -07001111int GetGpuResourceSizeAndDimensions(const BufferInfo &info, unsigned int *size,
1112 unsigned int *alignedw, unsigned int *alignedh,
1113 GraphicsMetadata *graphics_metadata) {
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301114 GetAlignedWidthAndHeight(info, alignedw, alignedh);
1115 AdrenoMemInfo* adreno_mem_info = AdrenoMemInfo::GetInstance();
1116 graphics_metadata->size = adreno_mem_info->AdrenoGetMetadataBlobSize();
1117 uint64_t adreno_usage = info.usage;
1118 // If gralloc disables UBWC based on any of the checks,
1119 // we pass modified usage flag to adreno to convey this.
1120 int is_ubwc_enabled = IsUBwcEnabled(info.format, info.usage);
1121 if (!is_ubwc_enabled) {
1122 adreno_usage &= ~(GRALLOC_USAGE_PRIVATE_ALLOC_UBWC);
Naseer Ahmed2023cf32019-01-28 19:02:40 -05001123 } else {
1124 adreno_usage |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301125 }
1126
1127 // Call adreno api for populating metadata blob
Saurabh Dubeyb637bb32018-05-15 16:20:10 +05301128 // Layer count is for 2D/Cubemap arrays and depth is used for 3D slice
1129 // Using depth to pass layer_count here
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301130 int ret = adreno_mem_info->AdrenoInitMemoryLayout(graphics_metadata->data, info.width,
Saurabh Dubeyb637bb32018-05-15 16:20:10 +05301131 info.height, info.layer_count, /* depth */
1132 info.format, 1, is_ubwc_enabled,
1133 adreno_usage, 1);
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301134 if (ret != 0) {
1135 ALOGE("%s Graphics metadata init failed", __FUNCTION__);
1136 *size = 0;
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -07001137 return -EINVAL;
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301138 }
1139 // Call adreno api with the metadata blob to get buffer size
1140 *size = adreno_mem_info->AdrenoGetAlignedGpuBufferSize(graphics_metadata->data);
Ramkumar Radhakrishnan30ea0f02018-10-11 19:25:10 -07001141 return 0;
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301142}
1143
Saurabh Dubey52eb7a62018-06-15 16:31:23 +05301144bool CanUseAdrenoForSize(int buffer_type, uint64_t usage) {
1145 if (buffer_type == BUFFER_TYPE_VIDEO || !GetAdrenoSizeAPIStatus()) {
1146 return false;
1147 }
1148
1149 if ((usage & BufferUsage::PROTECTED) && ((usage & BufferUsage::CAMERA_OUTPUT) ||
1150 (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY))) {
1151 return false;
1152 }
1153
1154 return true;
1155}
1156
Saurabh Dubeyb28b82b2018-05-29 09:46:41 +05301157bool GetAdrenoSizeAPIStatus() {
1158 AdrenoMemInfo* adreno_mem_info = AdrenoMemInfo::GetInstance();
1159 if (adreno_mem_info) {
1160 return adreno_mem_info->AdrenoSizeAPIAvaliable();
1161 }
1162 return false;
1163}
1164
Saurabh Dubey48b757d2018-05-24 19:13:53 +05301165bool UseUncached(int format, uint64_t usage) {
1166 if ((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) || (usage & BufferUsage::PROTECTED)) {
1167 return true;
1168 }
1169
1170 // CPU read rarely
1171 if ((usage & BufferUsage::CPU_READ_MASK) == static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY)) {
1172 return true;
1173 }
1174
1175 // CPU write rarely
1176 if ((usage & BufferUsage::CPU_WRITE_MASK) ==
1177 static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY)) {
1178 return true;
1179 }
1180
1181 if ((usage & BufferUsage::SENSOR_DIRECT_DATA) || (usage & BufferUsage::GPU_DATA_BUFFER)) {
1182 return true;
1183 }
1184
1185 if (format && IsUBwcEnabled(format, usage)) {
1186 return true;
1187 }
1188
1189 return false;
1190}
1191
1192uint64_t GetHandleFlags(int format, uint64_t usage) {
1193 uint64_t priv_flags = 0;
1194
1195 if (usage & BufferUsage::VIDEO_ENCODER) {
1196 priv_flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
1197 }
1198
1199 if (usage & BufferUsage::CAMERA_OUTPUT) {
1200 priv_flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
1201 }
1202
1203 if (usage & BufferUsage::CAMERA_INPUT) {
1204 priv_flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
1205 }
1206
1207 if (usage & BufferUsage::COMPOSER_OVERLAY) {
1208 priv_flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER;
1209 }
1210
1211 if (usage & BufferUsage::GPU_TEXTURE) {
1212 priv_flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
1213 }
1214
1215 if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
1216 priv_flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
1217 }
1218
1219 if (IsUBwcEnabled(format, usage)) {
1220 if (IsUBwcPISupported(format, usage)) {
1221 priv_flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED_PI;
1222 } else {
1223 priv_flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
1224 }
1225 }
1226
1227 if (usage & (BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK)) {
1228 priv_flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
1229 }
1230
1231 if ((usage & (BufferUsage::VIDEO_ENCODER | BufferUsage::VIDEO_DECODER |
1232 BufferUsage::CAMERA_OUTPUT | BufferUsage::GPU_RENDER_TARGET))) {
1233 priv_flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
1234 }
1235
1236 if (!UseUncached(format, usage)) {
1237 priv_flags |= private_handle_t::PRIV_FLAGS_CACHED;
1238 }
1239
1240 return priv_flags;
1241}
1242
1243int GetImplDefinedFormat(uint64_t usage, int format) {
1244 int gr_format = format;
1245
1246 // If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
1247 // the usage bits, gralloc assigns a format.
1248 if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
1249 format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
Mathew Joseph Karimpanal71517182018-08-14 16:40:34 +05301250 if ((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC || usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI)
1251 && format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
Saurabh Dubey81aef932018-06-27 09:41:31 +05301252 gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
Saurabh Dubey48b757d2018-05-24 19:13:53 +05301253 } else if (usage & BufferUsage::VIDEO_ENCODER) {
1254 if (usage & GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER) {
1255 gr_format = HAL_PIXEL_FORMAT_NV21_ENCODEABLE; // NV21
Manikanta Kanamarlapudidfa32e82019-03-26 14:06:47 +05301256 } else if (usage & GRALLOC_USAGE_PRIVATE_HEIF) {
1257 gr_format = HAL_PIXEL_FORMAT_NV12_HEIF;
Mathew Joseph Karimpanal71517182018-08-14 16:40:34 +05301258 } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
1259 gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS;
Saurabh Dubey48b757d2018-05-24 19:13:53 +05301260 } else {
1261 gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12
1262 }
1263 } else if (usage & BufferUsage::CAMERA_INPUT) {
1264 if (usage & BufferUsage::CAMERA_OUTPUT) {
1265 // Assumed ZSL if both producer and consumer camera flags set
1266 gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
1267 } else {
1268 gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21
1269 }
1270 } else if (usage & BufferUsage::CAMERA_OUTPUT) {
1271 if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
1272 gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
1273 } else {
1274 gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview
1275 }
1276 } else if (usage & BufferUsage::COMPOSER_OVERLAY) {
1277 // XXX: If we still haven't set a format, default to RGBA8888
1278 gr_format = HAL_PIXEL_FORMAT_RGBA_8888;
1279 } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
1280 // If no other usage flags are detected, default the
1281 // flexible YUV format to NV21_ZSL
1282 gr_format = HAL_PIXEL_FORMAT_NV21_ZSL;
1283 }
1284 }
1285
1286 return gr_format;
1287}
1288
1289int GetCustomFormatFlags(int format, uint64_t usage,
1290 int *custom_format, uint64_t *priv_flags) {
1291 *custom_format = GetImplDefinedFormat(usage, format);
1292 *priv_flags = GetHandleFlags(*custom_format, usage);
1293
Saurabh Dubey81aef932018-06-27 09:41:31 +05301294 if (usage & GRALLOC_USAGE_PROTECTED) {
1295 *priv_flags |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
1296 }
1297
1298 *priv_flags |= private_handle_t::PRIV_FLAGS_USES_ION;
1299
Saurabh Dubey48b757d2018-05-24 19:13:53 +05301300 return 0;
1301}
1302
Saurabh Dubeyefd7f9e2018-06-15 18:00:02 +05301303int GetBufferType(int inputFormat) {
1304 return IsYuvFormat(inputFormat) ? BUFFER_TYPE_VIDEO : BUFFER_TYPE_UI;
1305}
1306
Ashish Kumarb9392ff2019-03-27 18:30:39 +05301307int GetYUVPlaneInfo(const BufferInfo &info, int32_t format, int32_t width, int32_t height,
1308 int32_t flags, int *plane_count, PlaneLayoutInfo *plane_info) {
1309 int err = 0;
1310 unsigned int y_stride, c_stride, y_height, c_height, y_size, c_size;
1311 uint64_t yOffset, cOffset, crOffset, cbOffset;
1312 int h_subsampling = 0, v_subsampling = 0;
1313 switch (format) {
1314 // Semiplanar
1315 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
1316 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
1317 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
1318 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Ramakant Singh13596ae2020-01-06 20:12:34 +05301319 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
Ashish Kumarb9392ff2019-03-27 18:30:39 +05301320 case HAL_PIXEL_FORMAT_NV12_HEIF: // Same as YCbCr_420_SP_VENUS
1321 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
1322 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
1323 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
1324 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
1325 case HAL_PIXEL_FORMAT_NV21_ZSL:
1326 case HAL_PIXEL_FORMAT_RAW16:
1327 case HAL_PIXEL_FORMAT_Y16:
1328 case HAL_PIXEL_FORMAT_RAW10:
1329 case HAL_PIXEL_FORMAT_RAW8:
1330 case HAL_PIXEL_FORMAT_Y8:
1331 *plane_count = 2;
1332 GetYuvSPPlaneInfo(info, format, width, height, 1, plane_info);
1333 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1334 plane_info[0].h_subsampling = 0;
1335 plane_info[0].v_subsampling = 0;
1336 plane_info[1].h_subsampling = h_subsampling;
1337 plane_info[1].v_subsampling = v_subsampling;
1338 break;
1339
1340 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
1341 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1342 if (flags & LAYOUT_INTERLACED_FLAG) {
1343 *plane_count = 8;
1344 GetYuvUbwcInterlacedSPPlaneInfo(width, height, plane_info);
1345 plane_info[0].step = plane_info[4].step = 1;
1346 plane_info[1].step = plane_info[5].step = 2;
1347 plane_info[0].h_subsampling = plane_info[4].h_subsampling = 0;
1348 plane_info[0].v_subsampling = plane_info[4].v_subsampling = 0;
1349 plane_info[1].h_subsampling = plane_info[5].h_subsampling = h_subsampling;
1350 plane_info[1].v_subsampling = plane_info[5].v_subsampling = v_subsampling;
1351 plane_info[2].h_subsampling = plane_info[3].h_subsampling = 0;
1352 plane_info[2].v_subsampling = plane_info[3].v_subsampling = 0;
1353 plane_info[2].step = plane_info[3].step = 0;
1354 plane_info[6].h_subsampling = plane_info[7].h_subsampling = 0;
1355 plane_info[6].v_subsampling = plane_info[7].v_subsampling = 0;
1356 plane_info[6].step = plane_info[7].step = 0;
1357 } else {
1358 *plane_count = 4;
1359 GetYuvUbwcSPPlaneInfo(width, height, COLOR_FMT_NV12_UBWC, plane_info);
1360 plane_info[0].h_subsampling = 0;
1361 plane_info[0].v_subsampling = 0;
1362 plane_info[0].step = 1;
1363 plane_info[1].h_subsampling = h_subsampling;
1364 plane_info[1].v_subsampling = v_subsampling;
1365 plane_info[1].step = 2;
1366 plane_info[2].h_subsampling = plane_info[3].h_subsampling = 0;
1367 plane_info[2].v_subsampling = plane_info[3].v_subsampling = 0;
1368 plane_info[2].step = plane_info[3].step = 0;
1369 }
1370 break;
1371
1372 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
1373 *plane_count = 2;
1374 GetYuvSPPlaneInfo(info, format, width, height, 2, plane_info);
1375 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1376 plane_info[0].h_subsampling = 0;
1377 plane_info[0].v_subsampling = 0;
1378 plane_info[1].h_subsampling = h_subsampling;
1379 plane_info[1].v_subsampling = v_subsampling;
1380 break;
1381
1382 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
1383 *plane_count = 4;
1384 GetYuvUbwcSPPlaneInfo(width, height, COLOR_FMT_NV12_BPP10_UBWC, plane_info);
1385 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1386 plane_info[0].h_subsampling = 0;
1387 plane_info[0].v_subsampling = 0;
1388 plane_info[1].step = 1;
1389 plane_info[1].h_subsampling = h_subsampling;
1390 plane_info[1].v_subsampling = v_subsampling;
1391 plane_info[1].step = 3;
1392 plane_info[2].h_subsampling = plane_info[3].h_subsampling = 0;
1393 plane_info[2].v_subsampling = plane_info[3].v_subsampling = 0;
1394 plane_info[2].step = plane_info[3].step = 0;
1395 break;
1396
1397 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
1398 *plane_count = 4;
1399 GetYuvUbwcSPPlaneInfo(width, height, COLOR_FMT_P010_UBWC, plane_info);
1400 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1401 plane_info[0].h_subsampling = 0;
1402 plane_info[0].v_subsampling = 0;
1403 plane_info[1].step = 1;
1404 plane_info[1].h_subsampling = h_subsampling;
1405 plane_info[1].v_subsampling = v_subsampling;
1406 plane_info[1].step = 4;
1407 plane_info[2].h_subsampling = plane_info[3].h_subsampling = 0;
1408 plane_info[2].v_subsampling = plane_info[3].v_subsampling = 0;
1409 plane_info[2].step = plane_info[3].step = 0;
1410 break;
1411
1412 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
1413 *plane_count = 2;
1414 y_stride = VENUS_Y_STRIDE(COLOR_FMT_P010, width);
1415 c_stride = VENUS_UV_STRIDE(COLOR_FMT_P010, width);
1416 y_height = VENUS_Y_SCANLINES(COLOR_FMT_P010, height);
1417 y_size = y_stride * y_height;
1418 yOffset = 0;
1419 cOffset = y_size;
1420 c_height = VENUS_UV_SCANLINES(COLOR_FMT_P010, INT(height));
1421 c_size = c_stride * c_height;
1422 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1423
1424 plane_info[0].component = (PlaneComponent)PLANE_COMPONENT_Y;
1425 plane_info[0].offset = (uint32_t)yOffset;
1426 plane_info[0].stride = static_cast<int32_t>(UINT(width));
1427 plane_info[0].stride_bytes = static_cast<int32_t>(y_stride);
1428 plane_info[0].scanlines = static_cast<int32_t>(y_height);
1429 plane_info[0].size = static_cast<uint32_t>(y_size);
1430 plane_info[0].step = 1;
1431 plane_info[0].h_subsampling = 0;
1432 plane_info[0].v_subsampling = 0;
1433
1434 plane_info[1].component = (PlaneComponent)(PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr);
1435 plane_info[1].offset = (uint32_t)cOffset;
1436 plane_info[1].stride = static_cast<int32_t>(UINT(width));
1437 plane_info[1].stride_bytes = static_cast<int32_t>(c_stride);
1438 plane_info[1].scanlines = static_cast<int32_t>(c_height);
1439 plane_info[1].size = static_cast<uint32_t>(c_size);
1440 plane_info[1].step = 4;
1441 plane_info[1].h_subsampling = h_subsampling;
1442 plane_info[1].v_subsampling = v_subsampling;
1443 break;
1444
1445 // Planar
1446 case HAL_PIXEL_FORMAT_YV12:
1447 if ((info.width & 1) || (info.height & 1)) {
1448 ALOGE("w or h is odd for the YV12 format");
1449 err = -EINVAL;
1450 return err;
1451 }
1452 *plane_count = 3;
1453 y_stride = width;
1454 c_stride = ALIGN(width / 2, 16);
1455 y_height = UINT(height);
1456 y_size = (y_stride * y_height);
1457 height = height >> 1;
1458 c_height = UINT(height);
1459 c_size = (c_stride * c_height);
1460 yOffset = 0;
1461 crOffset = y_size;
1462 cbOffset = (y_size + c_size);
1463 GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
1464
1465 plane_info[0].component = (PlaneComponent)PLANE_COMPONENT_Y;
1466 plane_info[0].offset = (uint32_t)yOffset;
1467 plane_info[0].stride = static_cast<int32_t>(UINT(width));
1468 plane_info[0].stride_bytes = static_cast<int32_t>(y_stride);
1469 plane_info[0].scanlines = static_cast<int32_t>(y_height);
1470 plane_info[0].size = static_cast<uint32_t>(y_size);
1471 plane_info[0].step = 1;
1472 plane_info[0].h_subsampling = 0;
1473 plane_info[0].v_subsampling = 0;
1474
1475 plane_info[1].component = (PlaneComponent)PLANE_COMPONENT_Cb;
1476 plane_info[1].offset = (uint32_t)cbOffset;
1477 plane_info[2].component = (PlaneComponent)PLANE_COMPONENT_Cr;
1478 plane_info[2].offset = (uint32_t)crOffset;
1479 for (int i = 1; i < 3; i++) {
1480 plane_info[i].stride = static_cast<int32_t>(UINT(width));
1481 plane_info[i].stride_bytes = static_cast<int32_t>(c_stride);
1482 plane_info[i].scanlines = static_cast<int32_t>(c_height);
1483 plane_info[i].size = static_cast<uint32_t>(c_size);
1484 plane_info[i].step = 1;
1485 plane_info[i].h_subsampling = h_subsampling;
1486 plane_info[i].v_subsampling = v_subsampling;
1487 }
1488 break;
1489 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
1490 if (info.width & 1) {
1491 ALOGE("width is odd for the YUV422_SP format");
1492 err = -EINVAL;
1493 return err;
1494 }
1495 *plane_count = 1;
1496 y_stride = width * 2;
1497 y_height = UINT(height);
1498 y_size = y_stride * y_height;
1499 yOffset = 0;
1500 plane_info[0].component = (PlaneComponent)PLANE_COMPONENT_Y;
1501 plane_info[0].offset = (uint32_t)yOffset;
1502 plane_info[0].stride = static_cast<int32_t>(UINT(width));
1503 plane_info[0].stride_bytes = static_cast<int32_t>(y_stride);
1504 plane_info[0].scanlines = static_cast<int32_t>(y_height);
1505 plane_info[0].size = static_cast<uint32_t>(y_size);
1506 plane_info[0].step = 1;
1507 plane_info[0].h_subsampling = 0;
1508 plane_info[0].v_subsampling = 0;
1509 break;
1510
1511 // Unsupported formats
1512 case HAL_PIXEL_FORMAT_YCbCr_422_I:
1513 case HAL_PIXEL_FORMAT_YCrCb_422_I:
1514 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
1515 default:
1516 *plane_count = 0;
1517 ALOGD("%s: Invalid format passed: 0x%x", __FUNCTION__, format);
1518 err = -EINVAL;
1519 }
1520 return err;
1521}
1522
1523void GetYuvSubSamplingFactor(int32_t format, int *h_subsampling, int *v_subsampling) {
1524 switch (format) {
1525 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
1526 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
1527 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
1528 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
1529 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
1530 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
1531 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
1532 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
1533 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
1534 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
1535 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: // Same as YCbCr_420_SP_VENUS
Ramakant Singh13596ae2020-01-06 20:12:34 +05301536 case HAL_PIXEL_FORMAT_NV21_ENCODEABLE:
Ashish Kumarb9392ff2019-03-27 18:30:39 +05301537 case HAL_PIXEL_FORMAT_NV21_ZSL:
1538 case HAL_PIXEL_FORMAT_YV12:
1539 *h_subsampling = 1;
1540 *v_subsampling = 1;
1541 break;
1542 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
1543 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
1544 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
1545 *h_subsampling = 1;
1546 *v_subsampling = 0;
1547 break;
1548 case HAL_PIXEL_FORMAT_RAW16:
1549 case HAL_PIXEL_FORMAT_Y16:
1550 case HAL_PIXEL_FORMAT_RAW12:
1551 case HAL_PIXEL_FORMAT_RAW10:
1552 case HAL_PIXEL_FORMAT_Y8:
1553 case HAL_PIXEL_FORMAT_BLOB:
1554 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
1555 case HAL_PIXEL_FORMAT_NV12_HEIF:
1556 default:
1557 *h_subsampling = 0;
1558 *v_subsampling = 0;
1559 break;
1560 }
1561}
1562
1563void CopyPlaneLayoutInfotoAndroidYcbcr(uint64_t base, int plane_count, PlaneLayoutInfo *plane_info,
1564 struct android_ycbcr *ycbcr) {
1565 ycbcr->y = reinterpret_cast<void *>(base + plane_info[0].offset);
1566 ycbcr->ystride = plane_info[0].stride_bytes;
1567 if (plane_count == 1) {
1568 ycbcr->cb = NULL;
1569 ycbcr->cr = NULL;
1570 ycbcr->cstride = 0;
1571 ycbcr->chroma_step = 0;
1572 } else if (plane_count == 2 || plane_count == 4 || plane_count == 8) {
1573 /* For YUV semiplanar :-
1574 * - In progressive & linear case plane count is 2 and plane_info[0] will
1575 * contain info about Y plane and plane_info[1] will contain info about UV plane.
1576 * - In progressive & compressed case plane count is 4 then plane_info[0] will
1577 * contain info about Y plane and plane_info[1] will contain info about UV plane.
1578 * Remaining two plane (plane_info[2] & plane_info[3]) contain info about the
1579 * Y_Meta_Plane and UV_Meta_Plane.
1580 * - In interlaced & compressed case plane count is 8 then plane_info[0], plane_info[1],
1581 * plane_info[4] & plane_info[5] will contain info about Y_plane, UV_plane, Y_plane
1582 * & UV_plane. Remaining plane will contain info about the meta planes. As in this case
1583 * this API is called twice through GetYUVPlaneInfo() with address of plane_info[0] &
1584 * plane_info[4], so this will calculate the information accordingly and will fill the
1585 * ycbcr structure with interlaced plane info only.
1586 */
1587 ycbcr->cb = reinterpret_cast<void *>(base + plane_info[1].offset);
1588 ycbcr->cr = reinterpret_cast<void *>(base + plane_info[1].offset + 1);
1589 ycbcr->cstride = plane_info[1].stride_bytes;
1590 ycbcr->chroma_step = plane_info[1].step;
1591 } else if (plane_count == 3) {
1592 /* For YUV planar :-
1593 * Plane size is 3 and plane_info[0], plane_info[1], plane_info[2] will
1594 * contain info about y_plane, cb_plane and cr_plane accordingly.
1595 */
1596 ycbcr->cb = reinterpret_cast<void *>(base + plane_info[1].offset);
1597 ycbcr->cr = reinterpret_cast<void *>(base + plane_info[2].offset);
1598 ycbcr->cstride = plane_info[1].stride_bytes;
1599 ycbcr->chroma_step = plane_info[1].step;
1600 }
1601}
1602
Ashish Kumar8a1b56e2019-11-15 18:15:22 +05301603bool HasAlphaComponent(int32_t format) {
1604 switch (format) {
1605 case HAL_PIXEL_FORMAT_RGBA_8888:
1606 case HAL_PIXEL_FORMAT_BGRA_8888:
1607 case HAL_PIXEL_FORMAT_RGBA_5551:
1608 case HAL_PIXEL_FORMAT_RGBA_4444:
1609 case HAL_PIXEL_FORMAT_RGBA_1010102:
1610 case HAL_PIXEL_FORMAT_ARGB_2101010:
1611 case HAL_PIXEL_FORMAT_BGRA_1010102:
1612 case HAL_PIXEL_FORMAT_ABGR_2101010:
1613 case HAL_PIXEL_FORMAT_RGBA_FP16:
1614 return true;
1615 default:
1616 return false;
1617 }
1618}
1619
1620void GetRGBPlaneInfo(const BufferInfo &info, int32_t format, int32_t width, int32_t height,
1621 int32_t /* flags */, int *plane_count, PlaneLayoutInfo *plane_info) {
1622 uint64_t usage = info.usage;
1623 *plane_count = 1;
1624 uint32_t bpp = 0;
1625 if (IsUncompressedRGBFormat(format)) {
1626 bpp = GetBppForUncompressedRGB(format);
1627 }
1628 plane_info->component =
1629 (PlaneComponent)(PLANE_COMPONENT_R | PLANE_COMPONENT_G | PLANE_COMPONENT_B);
1630 if (HasAlphaComponent(format)) {
1631 plane_info->component = (PlaneComponent)(plane_info->component | PLANE_COMPONENT_A);
1632 }
1633 plane_info->size = GetSize(info, width, height);
1634 plane_info->step = bpp;
1635 plane_info->offset = GetRgbMetaSize(format, width, height, usage);
1636 plane_info->h_subsampling = 0;
1637 plane_info->v_subsampling = 0;
1638 plane_info->stride = width;
1639 plane_info->stride_bytes = width * plane_info->step;
1640 plane_info->scanlines = height;
1641}
1642
Naseer Ahmede36f2242017-12-01 15:33:56 -05001643} // namespace gralloc