blob: cb1adecc8c16abb63a156f9ab257df823eca2e72 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08002 * Copyright (c) 2011 - 2016, The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07003
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.
Duy Truong73d36df2013-02-09 20:33:23 -080013 * * Neither the name of The Linux Foundation nor the names of its
Iliyan Malchev202a77d2012-06-11 14:41:12 -070014 * 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#include <cutils/log.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070031#include <fcntl.h>
Naomi Luis01f5c8e2013-02-11 12:46:24 -080032#include <dlfcn.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070033#include "gralloc_priv.h"
34#include "alloc_controller.h"
35#include "memalloc.h"
36#include "ionalloc.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070037#include "gr.h"
Ramkumar Radhakrishnan29a36a52015-06-16 20:22:42 -070038#include "qd_utils.h"
Kaushik Kanetkar071aca62015-01-22 23:16:26 -070039#include <qdMetaData.h>
Ramkumar Radhakrishnan29a36a52015-06-16 20:22:42 -070040#include <utils/Singleton.h>
41#include <utils/Mutex.h>
42
Iliyan Malchev202a77d2012-06-11 14:41:12 -070043
Sushil Chauhanc6bd6d92012-12-12 12:33:01 -080044#ifdef VENUS_COLOR_FORMAT
45#include <media/msm_media_info.h>
46#else
47#define VENUS_Y_STRIDE(args...) 0
48#define VENUS_Y_SCANLINES(args...) 0
49#define VENUS_BUFFER_SIZE(args...) 0
50#endif
51
Naseer Ahmed63326f42013-12-18 02:45:48 -050052#define ASTC_BLOCK_SIZE 16
Naseer Ahmed63326f42013-12-18 02:45:48 -050053
Shalaj Jain3c490412015-04-22 16:52:03 -070054#ifndef ION_FLAG_CP_PIXEL
Shalaj Jain1f9725a2015-03-04 17:53:49 -080055#define ION_FLAG_CP_PIXEL 0
Shalaj Jain1f9725a2015-03-04 17:53:49 -080056#endif
57
58#ifndef ION_FLAG_ALLOW_NON_CONTIG
59#define ION_FLAG_ALLOW_NON_CONTIG 0
60#endif
61
Shalaj Jain3c490412015-04-22 16:52:03 -070062#ifdef MASTER_SIDE_CP
63#define CP_HEAP_ID ION_SECURE_HEAP_ID
Arun Kumar K.R7f0b24b2015-07-05 21:20:57 -070064#define SD_HEAP_ID ION_SECURE_DISPLAY_HEAP_ID
Shalaj Jain3c490412015-04-22 16:52:03 -070065#define ION_CP_FLAGS (ION_SECURE | ION_FLAG_CP_PIXEL)
Arun Kumar K.R7f0b24b2015-07-05 21:20:57 -070066#define ION_SD_FLAGS (ION_SECURE | ION_FLAG_CP_SEC_DISPLAY)
Shalaj Jain3c490412015-04-22 16:52:03 -070067#else // SLAVE_SIDE_CP
68#define CP_HEAP_ID ION_CP_MM_HEAP_ID
69#define SD_HEAP_ID CP_HEAP_ID
70#define ION_CP_FLAGS (ION_SECURE | ION_FLAG_ALLOW_NON_CONTIG)
71#define ION_SD_FLAGS ION_SECURE
72#endif
73
Iliyan Malchev202a77d2012-06-11 14:41:12 -070074using namespace gralloc;
Naseer Ahmeda87da602012-07-01 23:54:19 -070075using namespace qdutils;
Ramkumar Radhakrishnan29a36a52015-06-16 20:22:42 -070076using namespace android;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070077
Naomi Luisa44100c2013-02-08 12:42:03 -080078ANDROID_SINGLETON_STATIC_INSTANCE(AdrenoMemInfo);
Ramakant Singhc85ccee2016-04-01 15:25:17 +053079ANDROID_SINGLETON_STATIC_INSTANCE(MDPCapabilityInfo);
Naomi Luisa44100c2013-02-08 12:42:03 -080080
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -080081static void getYuvUBwcWidthHeight(int, int, int, int&, int&);
Sushil Chauhan65e26302015-01-14 10:48:57 -080082static unsigned int getUBwcSize(int, int, int, const int, const int);
83
Iliyan Malchev202a77d2012-06-11 14:41:12 -070084//Common functions
Iliyan Malchev202a77d2012-06-11 14:41:12 -070085
Saurabh Shah1adcafe2014-12-19 10:05:41 -080086/* The default policy is to return cached buffers unless the client explicity
87 * sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely
88 * read or written in software. Any combination with a _RARELY_ flag will be
89 * treated as uncached. */
90static bool useUncached(const int& usage) {
Naseer Ahmedde758fd2016-05-03 15:10:23 -040091 if ((usage & GRALLOC_USAGE_PROTECTED) or
92 (usage & GRALLOC_USAGE_PRIVATE_UNCACHED) or
93 ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_RARELY) or
94 ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_RARELY))
Saurabh Shah1adcafe2014-12-19 10:05:41 -080095 return true;
96
97 return false;
98}
99
Ramakant Singhc85ccee2016-04-01 15:25:17 +0530100//------------- MDPCapabilityInfo-----------------------//
101MDPCapabilityInfo :: MDPCapabilityInfo() {
102 isMacroTileSupported = false;
103 qdutils::querySDEInfo(HAS_MACRO_TILE, &isMacroTileSupported);
104}
105
106int MDPCapabilityInfo :: isMacroTilingSupportedByMDP(){
107 return isMacroTileSupported;
108 }
109
110//------------- AdrenoMemInfo-----------------------//
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800111AdrenoMemInfo::AdrenoMemInfo()
112{
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800113 LINK_adreno_compute_aligned_width_and_height = NULL;
114 LINK_adreno_compute_padding = NULL;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700115 LINK_adreno_isMacroTilingSupportedByGpu = NULL;
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800116 LINK_adreno_compute_compressedfmt_aligned_width_and_height = NULL;
Sushil Chauhan082acd62015-01-14 16:49:29 -0800117 LINK_adreno_isUBWCSupportedByGpu = NULL;
Sushil Chauhan521ce352015-08-28 11:33:30 -0700118 LINK_adreno_get_gpu_pixel_alignment = NULL;
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800119
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800120 libadreno_utils = ::dlopen("libadreno_utils.so", RTLD_NOW);
121 if (libadreno_utils) {
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800122 *(void **)&LINK_adreno_compute_aligned_width_and_height =
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700123 ::dlsym(libadreno_utils, "compute_aligned_width_and_height");
124 *(void **)&LINK_adreno_compute_padding =
125 ::dlsym(libadreno_utils, "compute_surface_padding");
126 *(void **)&LINK_adreno_isMacroTilingSupportedByGpu =
127 ::dlsym(libadreno_utils, "isMacroTilingSupportedByGpu");
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800128 *(void **)&LINK_adreno_compute_compressedfmt_aligned_width_and_height =
129 ::dlsym(libadreno_utils,
130 "compute_compressedfmt_aligned_width_and_height");
Sushil Chauhan082acd62015-01-14 16:49:29 -0800131 *(void **)&LINK_adreno_isUBWCSupportedByGpu =
132 ::dlsym(libadreno_utils, "isUBWCSupportedByGpu");
Sushil Chauhan521ce352015-08-28 11:33:30 -0700133 *(void **)&LINK_adreno_get_gpu_pixel_alignment =
134 ::dlsym(libadreno_utils, "get_gpu_pixel_alignment");
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800135 }
Mohan Maiyacbeab9e2015-04-20 09:20:44 -0700136
137 // Check if the overriding property debug.gralloc.gfx_ubwc_disable
138 // that disables UBWC allocations for the graphics stack is set
139 gfx_ubwc_disable = 0;
140 char property[PROPERTY_VALUE_MAX];
141 property_get("debug.gralloc.gfx_ubwc_disable", property, "0");
142 if(!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
143 !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
144 gfx_ubwc_disable = 1;
145 }
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800146}
147
148AdrenoMemInfo::~AdrenoMemInfo()
149{
150 if (libadreno_utils) {
151 ::dlclose(libadreno_utils);
152 }
153}
154
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700155int AdrenoMemInfo::isMacroTilingSupportedByGPU()
156{
157 if ((libadreno_utils)) {
158 if(LINK_adreno_isMacroTilingSupportedByGpu) {
159 return LINK_adreno_isMacroTilingSupportedByGpu();
160 }
161 }
162 return 0;
163}
164
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700165void AdrenoMemInfo::getAlignedWidthAndHeight(const private_handle_t *hnd, int& aligned_w,
166 int& aligned_h) {
167 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
168 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
169 int w = metadata->bufferDim.sliceWidth;
170 int h = metadata->bufferDim.sliceHeight;
171 int f = hnd->format;
172 int usage = 0;
173
174 if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
175 usage = GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
176 }
177
178 getAlignedWidthAndHeight(w, h, f, usage, aligned_w, aligned_h);
179 } else {
180 aligned_w = hnd->width;
181 aligned_h = hnd->height;
182 }
183
184}
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700185
Naomi Luiscffc5bd2015-08-28 14:57:31 -0700186bool isUncompressedRgbFormat(int format)
187{
188 bool is_rgb_format = false;
189
190 switch (format)
191 {
192 case HAL_PIXEL_FORMAT_RGBA_8888:
193 case HAL_PIXEL_FORMAT_RGBX_8888:
194 case HAL_PIXEL_FORMAT_RGB_888:
195 case HAL_PIXEL_FORMAT_RGB_565:
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -0600196 case HAL_PIXEL_FORMAT_BGR_565:
Naomi Luiscffc5bd2015-08-28 14:57:31 -0700197 case HAL_PIXEL_FORMAT_BGRA_8888:
198 case HAL_PIXEL_FORMAT_RGBA_5551:
199 case HAL_PIXEL_FORMAT_RGBA_4444:
200 case HAL_PIXEL_FORMAT_R_8:
201 case HAL_PIXEL_FORMAT_RG_88:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800202 case HAL_PIXEL_FORMAT_BGRX_8888:
203 case HAL_PIXEL_FORMAT_RGBA_1010102:
204 case HAL_PIXEL_FORMAT_ARGB_2101010:
205 case HAL_PIXEL_FORMAT_RGBX_1010102:
206 case HAL_PIXEL_FORMAT_XRGB_2101010:
207 case HAL_PIXEL_FORMAT_BGRA_1010102:
208 case HAL_PIXEL_FORMAT_ABGR_2101010:
209 case HAL_PIXEL_FORMAT_BGRX_1010102:
210 case HAL_PIXEL_FORMAT_XBGR_2101010: // Intentional fallthrough
Naomi Luiscffc5bd2015-08-28 14:57:31 -0700211 is_rgb_format = true;
212 break;
213 default:
214 break;
215 }
216
217 return is_rgb_format;
218}
219
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800220void AdrenoMemInfo::getAlignedWidthAndHeight(int width, int height, int format,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800221 int usage, int& aligned_w, int& aligned_h)
Naomi Luisa44100c2013-02-08 12:42:03 -0800222{
Sushil Chauhane61fac52015-04-30 17:14:37 -0700223 bool ubwc_enabled = isUBwcEnabled(format, usage);
224
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800225 // Currently surface padding is only computed for RGB* surfaces.
Naomi Luiscffc5bd2015-08-28 14:57:31 -0700226 if (isUncompressedRgbFormat(format) == true) {
Sushil Chauhane61fac52015-04-30 17:14:37 -0700227 int tileEnabled = ubwc_enabled || isMacroTileEnabled(format, usage);
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700228 getGpuAlignedWidthHeight(width, height, format, tileEnabled, aligned_w, aligned_h);
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800229 } else if (ubwc_enabled) {
230 getYuvUBwcWidthHeight(width, height, format, aligned_w, aligned_h);
231 } else {
232 aligned_w = width;
233 aligned_h = height;
234 int alignment = 32;
235 switch (format)
236 {
237 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
238 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
239 if (LINK_adreno_get_gpu_pixel_alignment) {
240 alignment = LINK_adreno_get_gpu_pixel_alignment();
241 }
242 aligned_w = ALIGN(width, alignment);
243 break;
244 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
245 aligned_w = ALIGN(width, alignment);
246 break;
247 case HAL_PIXEL_FORMAT_RAW16:
248 aligned_w = ALIGN(width, 16);
249 break;
250 case HAL_PIXEL_FORMAT_RAW10:
251 aligned_w = ALIGN(width * 10 / 8, 8);
252 break;
253 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
254 aligned_w = ALIGN(width, 128);
255 break;
256 case HAL_PIXEL_FORMAT_YV12:
257 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
258 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
259 case HAL_PIXEL_FORMAT_YCbCr_422_I:
260 case HAL_PIXEL_FORMAT_YCrCb_422_I:
261 aligned_w = ALIGN(width, 16);
262 break;
263 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
264 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
265 aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
266 aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12, height);
267 break;
268 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
269 aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV21, width);
270 aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV21, height);
271 break;
272 case HAL_PIXEL_FORMAT_BLOB:
273 break;
274 case HAL_PIXEL_FORMAT_NV21_ZSL:
275 aligned_w = ALIGN(width, 64);
276 aligned_h = ALIGN(height, 64);
277 break;
278 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
279 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
280 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR:
281 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
282 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR:
283 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
284 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR:
285 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
286 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR:
287 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
288 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR:
289 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
290 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR:
291 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
292 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR:
293 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
294 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR:
295 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
296 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR:
297 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
298 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR:
299 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
300 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR:
301 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
302 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR:
303 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
304 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR:
305 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
306 if(LINK_adreno_compute_compressedfmt_aligned_width_and_height) {
307 int bytesPerPixel = 0;
308 int raster_mode = 0; //Adreno unknown raster mode.
309 int padding_threshold = 512; //Threshold for padding
310 //surfaces.
Sushil Chauhan65e26302015-01-14 10:48:57 -0800311
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800312 LINK_adreno_compute_compressedfmt_aligned_width_and_height(
313 width, height, format, 0,raster_mode, padding_threshold,
314 &aligned_w, &aligned_h, &bytesPerPixel);
315 } else {
316 ALOGW("%s: Warning!! Symbols" \
317 " compute_compressedfmt_aligned_width_and_height" \
318 " not found", __FUNCTION__);
319 }
320 break;
321 default: break;
322 }
Sushil Chauhan65e26302015-01-14 10:48:57 -0800323 }
324}
325
326void AdrenoMemInfo::getGpuAlignedWidthHeight(int width, int height, int format,
327 int tile_enabled, int& aligned_w, int& aligned_h)
328{
329 aligned_w = ALIGN(width, 32);
330 aligned_h = ALIGN(height, 32);
331
332 // Don't add any additional padding if debug.gralloc.map_fb_memory
333 // is enabled
334 char property[PROPERTY_VALUE_MAX];
335 if((property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
336 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
337 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
338 return;
339 }
340
341 int bpp = 4;
342 switch(format)
343 {
344 case HAL_PIXEL_FORMAT_RGB_888:
345 bpp = 3;
346 break;
347 case HAL_PIXEL_FORMAT_RGB_565:
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -0600348 case HAL_PIXEL_FORMAT_BGR_565:
Sushil Chauhan65e26302015-01-14 10:48:57 -0800349 case HAL_PIXEL_FORMAT_RGBA_5551:
350 case HAL_PIXEL_FORMAT_RGBA_4444:
351 bpp = 2;
352 break;
353 default: break;
354 }
355
356 if (libadreno_utils) {
357 int raster_mode = 0; // Adreno unknown raster mode.
358 int padding_threshold = 512; // Threshold for padding surfaces.
359 // the function below computes aligned width and aligned height
360 // based on linear or macro tile mode selected.
361 if(LINK_adreno_compute_aligned_width_and_height) {
362 LINK_adreno_compute_aligned_width_and_height(width,
363 height, bpp, tile_enabled,
364 raster_mode, padding_threshold,
365 &aligned_w, &aligned_h);
366
367 } else if(LINK_adreno_compute_padding) {
368 int surface_tile_height = 1; // Linear surface
369 aligned_w = LINK_adreno_compute_padding(width, bpp,
370 surface_tile_height, raster_mode,
371 padding_threshold);
372 ALOGW("%s: Warning!! Old GFX API is used to calculate stride",
373 __FUNCTION__);
374 } else {
375 ALOGW("%s: Warning!! Symbols compute_surface_padding and " \
376 "compute_aligned_width_and_height not found", __FUNCTION__);
377 }
378 }
379}
380
381int AdrenoMemInfo::isUBWCSupportedByGPU(int format)
382{
Mohan Maiyacbeab9e2015-04-20 09:20:44 -0700383 if (!gfx_ubwc_disable && libadreno_utils) {
Sushil Chauhan082acd62015-01-14 16:49:29 -0800384 if (LINK_adreno_isUBWCSupportedByGpu) {
385 ADRENOPIXELFORMAT gpu_format = getGpuPixelFormat(format);
386 return LINK_adreno_isUBWCSupportedByGpu(gpu_format);
387 }
388 }
Sushil Chauhan65e26302015-01-14 10:48:57 -0800389 return 0;
Naomi Luisa44100c2013-02-08 12:42:03 -0800390}
391
Sushil Chauhan082acd62015-01-14 16:49:29 -0800392ADRENOPIXELFORMAT AdrenoMemInfo::getGpuPixelFormat(int hal_format)
393{
394 switch (hal_format) {
395 case HAL_PIXEL_FORMAT_RGBA_8888:
396 return ADRENO_PIXELFORMAT_R8G8B8A8;
Sushil Chauhan6686c802015-04-15 11:30:39 -0700397 case HAL_PIXEL_FORMAT_RGBX_8888:
398 return ADRENO_PIXELFORMAT_R8G8B8X8;
Sushil Chauhan082acd62015-01-14 16:49:29 -0800399 case HAL_PIXEL_FORMAT_RGB_565:
400 return ADRENO_PIXELFORMAT_B5G6R5;
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -0600401 case HAL_PIXEL_FORMAT_BGR_565:
402 return ADRENO_PIXELFORMAT_R5G6B5;
Sushil Chauhan082acd62015-01-14 16:49:29 -0800403 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Sushil Chauhana9d47002015-02-18 14:55:03 -0800404 return ADRENO_PIXELFORMAT_NV12;
Sushil Chauhan082acd62015-01-14 16:49:29 -0800405 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
406 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
Sushil Chauhana9d47002015-02-18 14:55:03 -0800407 return ADRENO_PIXELFORMAT_NV12_EXT;
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800408 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
409 return ADRENO_PIXELFORMAT_TP10;
410 case HAL_PIXEL_FORMAT_RGBA_1010102:
411 return ADRENO_PIXELFORMAT_R10G10B10A2_UNORM;
412 case HAL_PIXEL_FORMAT_RGBX_1010102:
413 return ADRENO_PIXELFORMAT_R10G10B10X2_UNORM;
414 case HAL_PIXEL_FORMAT_ABGR_2101010:
415 return ADRENO_PIXELFORMAT_A2B10G10R10_UNORM;
Sushil Chauhan082acd62015-01-14 16:49:29 -0800416 default:
417 ALOGE("%s: No map for format: 0x%x", __FUNCTION__, hal_format);
418 break;
419 }
420 return ADRENO_PIXELFORMAT_UNKNOWN;
421}
422
Naomi Luisa44100c2013-02-08 12:42:03 -0800423//-------------- IAllocController-----------------------//
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700424IAllocController* IAllocController::sController = NULL;
425IAllocController* IAllocController::getInstance(void)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700426{
427 if(sController == NULL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700428 sController = new IonController();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700429 }
430 return sController;
431}
432
433
434//-------------- IonController-----------------------//
435IonController::IonController()
436{
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530437 allocateIonMem();
Manikanta Kanamarlapudicb44d972016-02-03 17:49:55 +0530438
439 char property[PROPERTY_VALUE_MAX];
440 property_get("video.disable.ubwc", property, "0");
441 mDisableUBWCForEncode = atoi(property);
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530442}
443
444void IonController::allocateIonMem()
445{
446 mIonAlloc = new IonAlloc();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700447}
448
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700449int IonController::allocate(alloc_data& data, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700450{
451 int ionFlags = 0;
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500452 int ionHeapId = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700453 int ret;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700454
455 data.uncached = useUncached(usage);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700456 data.allocType = 0;
457
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530458 if(usage & GRALLOC_USAGE_PROTECTED) {
Naseer Ahmed934a4c32016-04-11 17:20:02 -0400459 if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
460 ionHeapId = ION_HEAP(SD_HEAP_ID);
461 /*
462 * There is currently no flag in ION for Secure Display
463 * VM. Please add it to the define once available.
464 */
465 ionFlags |= ION_SD_FLAGS;
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530466 } else {
Naseer Ahmed934a4c32016-04-11 17:20:02 -0400467 ionHeapId = ION_HEAP(CP_HEAP_ID);
468 ionFlags |= ION_CP_FLAGS;
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500469 }
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530470 } else if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
471 //MM Heap is exclusively a secure heap.
472 //If it is used for non secure cases, fallback to IOMMU heap
473 ALOGW("GRALLOC_USAGE_PRIVATE_MM_HEAP \
474 cannot be used as an insecure heap!\
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500475 trying to use system heap instead !!");
476 ionHeapId |= ION_HEAP(ION_SYSTEM_HEAP_ID);
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500477 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700478
Arun Kumar K.Rff78b892013-05-24 12:37:51 -0700479 if(usage & GRALLOC_USAGE_PRIVATE_CAMERA_HEAP)
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500480 ionHeapId |= ION_HEAP(ION_CAMERA_HEAP_ID);
Arun Kumar K.Rff78b892013-05-24 12:37:51 -0700481
Arun Kumar K.R0daaa992013-03-12 15:08:29 -0700482 if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP)
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500483 ionHeapId |= ION_HEAP(ION_ADSP_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700484
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530485 if(ionFlags & ION_SECURE)
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500486 data.allocType |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700487
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500488 // if no ion heap flags are set, default to system heap
489 if(!ionHeapId)
490 ionHeapId = ION_HEAP(ION_SYSTEM_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700491
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500492 //At this point we should have the right heap set, there is no fallback
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700493 data.flags = ionFlags;
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500494 data.heapId = ionHeapId;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700495 ret = mIonAlloc->alloc_buffer(data);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700496
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700497 if(ret >= 0 ) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700498 data.allocType |= private_handle_t::PRIV_FLAGS_USES_ION;
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500499 } else {
500 ALOGE("%s: Failed to allocate buffer - heap: 0x%x flags: 0x%x",
501 __FUNCTION__, ionHeapId, ionFlags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700502 }
503
504 return ret;
505}
506
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700507IMemAlloc* IonController::getAllocator(int flags)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700508{
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700509 IMemAlloc* memalloc = NULL;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700510 if (flags & private_handle_t::PRIV_FLAGS_USES_ION) {
511 memalloc = mIonAlloc;
512 } else {
513 ALOGE("%s: Invalid flags passed: 0x%x", __FUNCTION__, flags);
514 }
515
516 return memalloc;
517}
518
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700519bool isMacroTileEnabled(int format, int usage)
520{
521 bool tileEnabled = false;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700522 // Check whether GPU & MDSS supports MacroTiling feature
523 if(AdrenoMemInfo::getInstance().isMacroTilingSupportedByGPU() &&
Ramakant Singhc85ccee2016-04-01 15:25:17 +0530524 MDPCapabilityInfo::getInstance().isMacroTilingSupportedByMDP())
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700525 {
526 // check the format
527 switch(format)
528 {
529 case HAL_PIXEL_FORMAT_RGBA_8888:
530 case HAL_PIXEL_FORMAT_RGBX_8888:
531 case HAL_PIXEL_FORMAT_BGRA_8888:
Manoj Kumar AVM5a5529b2014-02-24 18:16:37 -0800532 case HAL_PIXEL_FORMAT_RGB_565:
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -0600533 case HAL_PIXEL_FORMAT_BGR_565:
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700534 {
535 tileEnabled = true;
536 // check the usage flags
537 if (usage & (GRALLOC_USAGE_SW_READ_MASK |
538 GRALLOC_USAGE_SW_WRITE_MASK)) {
539 // Application intends to use CPU for rendering
540 tileEnabled = false;
541 }
542 break;
543 }
544 default:
545 break;
546 }
547 }
548 return tileEnabled;
549}
550
551// helper function
Sushil Chauhan65e26302015-01-14 10:48:57 -0800552unsigned int getSize(int format, int width, int height, int usage,
553 const int alignedw, const int alignedh) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700554
Sushil Chauhan65e26302015-01-14 10:48:57 -0800555 if (isUBwcEnabled(format, usage)) {
556 return getUBwcSize(width, height, format, alignedw, alignedh);
557 }
558
559 unsigned int size = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700560 switch (format) {
561 case HAL_PIXEL_FORMAT_RGBA_8888:
562 case HAL_PIXEL_FORMAT_RGBX_8888:
563 case HAL_PIXEL_FORMAT_BGRA_8888:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800564 case HAL_PIXEL_FORMAT_RGBA_1010102:
565 case HAL_PIXEL_FORMAT_ARGB_2101010:
566 case HAL_PIXEL_FORMAT_RGBX_1010102:
567 case HAL_PIXEL_FORMAT_XRGB_2101010:
568 case HAL_PIXEL_FORMAT_BGRA_1010102:
569 case HAL_PIXEL_FORMAT_ABGR_2101010:
570 case HAL_PIXEL_FORMAT_BGRX_1010102:
571 case HAL_PIXEL_FORMAT_XBGR_2101010:
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700572 size = alignedw * alignedh * 4;
573 break;
574 case HAL_PIXEL_FORMAT_RGB_888:
575 size = alignedw * alignedh * 3;
576 break;
577 case HAL_PIXEL_FORMAT_RGB_565:
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -0600578 case HAL_PIXEL_FORMAT_BGR_565:
Ramkumar Radhakrishnan96439522014-10-09 13:37:52 -0700579 case HAL_PIXEL_FORMAT_RGBA_5551:
580 case HAL_PIXEL_FORMAT_RGBA_4444:
Ajay Dudani4dc06492015-03-26 07:28:11 -0700581 case HAL_PIXEL_FORMAT_RAW16:
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700582 size = alignedw * alignedh * 2;
583 break;
Mansoor Aftabe9912a62014-07-15 01:40:26 -0700584 case HAL_PIXEL_FORMAT_RAW10:
585 size = ALIGN(alignedw * alignedh, 4096);
586 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700587
588 // adreno formats
589 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21
590 size = ALIGN(alignedw*alignedh, 4096);
591 size += ALIGN(2 * ALIGN(width/2, 32) * ALIGN(height/2, 32), 4096);
592 break;
593 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12
594 // The chroma plane is subsampled,
595 // but the pitch in bytes is unchanged
596 // The GPU needs 4K alignment, but the video decoder needs 8K
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700597 size = ALIGN( alignedw * alignedh, 8192);
598 size += ALIGN( alignedw * ALIGN(height/2, 32), 8192);
599 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700600 case HAL_PIXEL_FORMAT_YV12:
601 if ((format == HAL_PIXEL_FORMAT_YV12) && ((width&1) || (height&1))) {
602 ALOGE("w or h is odd for the YV12 format");
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800603 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700604 }
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400605 size = alignedw*alignedh +
Naseer Ahmed29a26812012-06-14 00:56:20 -0700606 (ALIGN(alignedw/2, 16) * (alignedh/2))*2;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700607 size = ALIGN(size, (unsigned int)4096);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700608 break;
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800609 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
610 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
Naseer Ahmed2c215292013-09-18 23:47:42 -0400611 size = ALIGN((alignedw*alignedh) + (alignedw* alignedh)/2 + 1, 4096);
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800612 break;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700613 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
614 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700615 case HAL_PIXEL_FORMAT_YCbCr_422_I:
616 case HAL_PIXEL_FORMAT_YCrCb_422_I:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700617 if(width & 1) {
618 ALOGE("width is odd for the YUV422_SP format");
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800619 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700620 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700621 size = ALIGN(alignedw * alignedh * 2, 4096);
622 break;
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700623 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400624 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Sushil Chauhane8a01792012-11-01 16:25:45 -0700625 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height);
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700626 break;
Raj Kamal8bb3b8f2015-03-24 16:22:17 +0530627 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
628 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV21, width, height);
629 break;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400630 case HAL_PIXEL_FORMAT_BLOB:
631 if(height != 1) {
632 ALOGE("%s: Buffers with format HAL_PIXEL_FORMAT_BLOB \
633 must have height==1 ", __FUNCTION__);
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800634 return 0;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400635 }
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400636 size = width;
637 break;
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700638 case HAL_PIXEL_FORMAT_NV21_ZSL:
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700639 size = ALIGN((alignedw*alignedh) + (alignedw* alignedh)/2, 4096);
640 break;
Naseer Ahmed63326f42013-12-18 02:45:48 -0500641 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
642 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR:
643 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR:
644 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR:
645 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR:
646 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR:
647 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR:
648 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR:
649 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR:
650 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR:
651 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR:
652 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR:
653 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR:
654 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR:
655 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
656 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
657 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
658 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
659 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
660 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
661 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
662 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
663 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
664 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
665 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
666 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
667 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
Jeykumar Sankaran8f4585f2014-02-05 15:23:40 -0800668 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500669 size = alignedw * alignedh * ASTC_BLOCK_SIZE;
670 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700671 default:
Naseer Ahmedb8ecfbf2015-11-02 20:34:29 -0500672 ALOGE("%s: Unrecognized pixel format: 0x%x", __FUNCTION__, format);
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800673 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700674 }
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700675 return size;
676}
677
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700678unsigned int getBufferSizeAndDimensions(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700679 int& alignedw, int &alignedh)
680{
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700681 unsigned int size;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700682
683 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
684 height,
685 format,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800686 0,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700687 alignedw,
688 alignedh);
689
Sushil Chauhan65e26302015-01-14 10:48:57 -0800690 size = getSize(format, width, height, 0 /* usage */, alignedw, alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700691
692 return size;
693}
694
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700695
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700696unsigned int getBufferSizeAndDimensions(int width, int height, int format,
697 int usage, int& alignedw, int &alignedh)
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700698{
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700699 unsigned int size;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700700
701 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
702 height,
703 format,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800704 usage,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700705 alignedw,
706 alignedh);
707
Sushil Chauhan65e26302015-01-14 10:48:57 -0800708 size = getSize(format, width, height, usage, alignedw, alignedh);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700709
710 return size;
711}
712
713
714void getBufferAttributes(int width, int height, int format, int usage,
Sushil Chauhane61fac52015-04-30 17:14:37 -0700715 int& alignedw, int &alignedh, int& tiled, unsigned int& size)
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700716{
Sushil Chauhane61fac52015-04-30 17:14:37 -0700717 tiled = isUBwcEnabled(format, usage) || isMacroTileEnabled(format, usage);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700718
719 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
720 height,
721 format,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800722 usage,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700723 alignedw,
724 alignedh);
Sushil Chauhan65e26302015-01-14 10:48:57 -0800725 size = getSize(format, width, height, usage, alignedw, alignedh);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700726}
727
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700728void getYuvUbwcSPPlaneInfo(uint64_t base, int width, int height,
729 int color_format, struct android_ycbcr* ycbcr)
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800730{
731 // UBWC buffer has these 4 planes in the following sequence:
732 // Y_Meta_Plane, Y_Plane, UV_Meta_Plane, UV_Plane
733 unsigned int y_meta_stride, y_meta_height, y_meta_size;
734 unsigned int y_stride, y_height, y_size;
735 unsigned int c_meta_stride, c_meta_height, c_meta_size;
736 unsigned int alignment = 4096;
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800737
738 y_meta_stride = VENUS_Y_META_STRIDE(color_format, width);
739 y_meta_height = VENUS_Y_META_SCANLINES(color_format, height);
740 y_meta_size = ALIGN((y_meta_stride * y_meta_height), alignment);
741
742 y_stride = VENUS_Y_STRIDE(color_format, width);
743 y_height = VENUS_Y_SCANLINES(color_format, height);
744 y_size = ALIGN((y_stride * y_height), alignment);
745
746 c_meta_stride = VENUS_UV_META_STRIDE(color_format, width);
747 c_meta_height = VENUS_UV_META_SCANLINES(color_format, height);
748 c_meta_size = ALIGN((c_meta_stride * c_meta_height), alignment);
749
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700750 ycbcr->y = (void*)(base + y_meta_size);
751 ycbcr->cb = (void*)(base + y_meta_size + y_size + c_meta_size);
752 ycbcr->cr = (void*)(base + y_meta_size + y_size +
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800753 c_meta_size + 1);
754 ycbcr->ystride = y_stride;
755 ycbcr->cstride = VENUS_UV_STRIDE(color_format, width);
756}
757
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700758void getYuvSPPlaneInfo(uint64_t base, int width, int height, int bpp,
759 struct android_ycbcr* ycbcr)
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800760{
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800761 unsigned int ystride, cstride;
762
763 ystride = cstride = width * bpp;
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700764 ycbcr->y = (void*)base;
765 ycbcr->cb = (void*)(base + ystride * height);
766 ycbcr->cr = (void*)(base + ystride * height + 1);
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800767 ycbcr->ystride = ystride;
768 ycbcr->cstride = cstride;
769 ycbcr->chroma_step = 2 * bpp;
770}
771
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400772int getYUVPlaneInfo(private_handle_t* hnd, struct android_ycbcr* ycbcr)
773{
774 int err = 0;
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700775 int width = hnd->width;
776 int height = hnd->height;
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700777 int format = hnd->format;
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700778
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700779 unsigned int ystride, cstride;
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700780
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400781 memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700782 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
783
784 // Check if UBWC buffer has been rendered in linear format.
785 if (metadata && (metadata->operation & LINEAR_FORMAT)) {
786 format = metadata->linearFormat;
787 }
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400788
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700789 // Check metadata if the geometry has been updated.
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700790 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700791 int usage = 0;
792
793 if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
794 usage = GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
795 }
796
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700797 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(metadata->bufferDim.sliceWidth,
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700798 metadata->bufferDim.sliceHeight, format, usage, width, height);
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700799 }
800
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400801 // Get the chroma offsets from the handle width/height. We take advantage
802 // of the fact the width _is_ the stride
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700803 switch (format) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400804 //Semiplanar
805 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
806 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
807 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
808 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: //Same as YCbCr_420_SP_VENUS
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700809 getYuvSPPlaneInfo(hnd->base, width, height, 1, ycbcr);
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800810 break;
811
812 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700813 getYuvSPPlaneInfo(hnd->base, width, height, 2, ycbcr);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400814 break;
815
Sushil Chauhan4686c972015-02-20 15:44:52 -0800816 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700817 getYuvUbwcSPPlaneInfo(hnd->base, width, height,
818 COLOR_FMT_NV12_UBWC, ycbcr);
Sushil Chauhan4686c972015-02-20 15:44:52 -0800819 ycbcr->chroma_step = 2;
820 break;
821
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800822 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700823 getYuvUbwcSPPlaneInfo(hnd->base, width, height,
824 COLOR_FMT_NV12_BPP10_UBWC, ycbcr);
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800825 ycbcr->chroma_step = 3;
826 break;
827
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400828 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
829 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
830 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
Raj Kamal8bb3b8f2015-03-24 16:22:17 +0530831 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400832 case HAL_PIXEL_FORMAT_NV21_ZSL:
Ajay Dudani4dc06492015-03-26 07:28:11 -0700833 case HAL_PIXEL_FORMAT_RAW16:
Mansoor Aftabe9912a62014-07-15 01:40:26 -0700834 case HAL_PIXEL_FORMAT_RAW10:
Ramkumar Radhakrishnan790357e2016-03-24 17:03:41 -0700835 getYuvSPPlaneInfo(hnd->base, width, height, 1, ycbcr);
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800836 std::swap(ycbcr->cb, ycbcr->cr);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400837 break;
838
839 //Planar
840 case HAL_PIXEL_FORMAT_YV12:
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700841 ystride = width;
842 cstride = ALIGN(width/2, 16);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400843 ycbcr->y = (void*)hnd->base;
Kaushik Kanetkar071aca62015-01-22 23:16:26 -0700844 ycbcr->cr = (void*)(hnd->base + ystride * height);
845 ycbcr->cb = (void*)(hnd->base + ystride * height +
846 cstride * height/2);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400847 ycbcr->ystride = ystride;
848 ycbcr->cstride = cstride;
849 ycbcr->chroma_step = 1;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400850 break;
851 //Unsupported formats
852 case HAL_PIXEL_FORMAT_YCbCr_422_I:
853 case HAL_PIXEL_FORMAT_YCrCb_422_I:
854 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
855 default:
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700856 ALOGD("%s: Invalid format passed: 0x%x", __FUNCTION__, format);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400857 err = -EINVAL;
858 }
859 return err;
860
861}
862
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700863
864
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700865// Allocate buffer from width, height and format into a
866// private_handle_t. It is the responsibility of the caller
867// to free the buffer using the free_buffer function
868int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
869{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700870 alloc_data data;
871 int alignedw, alignedh;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700872 gralloc::IAllocController* sAlloc =
873 gralloc::IAllocController::getInstance();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700874 data.base = 0;
875 data.fd = -1;
876 data.offset = 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700877 data.size = getBufferSizeAndDimensions(w, h, format, usage, alignedw,
878 alignedh);
879
Naseer Ahmed29a26812012-06-14 00:56:20 -0700880 data.align = getpagesize();
881 data.uncached = useUncached(usage);
882 int allocFlags = usage;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700883
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700884 int err = sAlloc->allocate(data, allocFlags);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700885 if (0 != err) {
886 ALOGE("%s: allocate failed", __FUNCTION__);
887 return -ENOMEM;
888 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700889
radhakrishnad7131e62015-10-13 12:32:30 +0530890 if(isUBwcEnabled(format, usage)) {
891 data.allocType |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
892 }
893
Naseer Ahmed29a26812012-06-14 00:56:20 -0700894 private_handle_t* hnd = new private_handle_t(data.fd, data.size,
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700895 data.allocType, 0, format,
896 alignedw, alignedh);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700897 hnd->base = (uint64_t) data.base;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700898 hnd->offset = data.offset;
899 hnd->gpuaddr = 0;
900 *pHnd = hnd;
901 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700902}
903
904void free_buffer(private_handle_t *hnd)
905{
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700906 gralloc::IAllocController* sAlloc =
907 gralloc::IAllocController::getInstance();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700908 if (hnd && hnd->fd > 0) {
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700909 IMemAlloc* memalloc = sAlloc->getAllocator(hnd->flags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700910 memalloc->free_buffer((void*)hnd->base, hnd->size, hnd->offset, hnd->fd);
911 }
912 if(hnd)
913 delete hnd;
914
915}
Sushil Chauhan65e26302015-01-14 10:48:57 -0800916
917// UBWC helper functions
918static bool isUBwcFormat(int format)
919{
920 // Explicitly defined UBWC formats
921 switch(format)
922 {
923 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800924 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
Sushil Chauhan65e26302015-01-14 10:48:57 -0800925 return true;
926 default:
927 return false;
928 }
929}
930
931static bool isUBwcSupported(int format)
932{
933 // Existing HAL formats with UBWC support
934 switch(format)
935 {
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -0600936 case HAL_PIXEL_FORMAT_BGR_565:
Sushil Chauhan65e26302015-01-14 10:48:57 -0800937 case HAL_PIXEL_FORMAT_RGBA_8888:
Sushil Chauhan6686c802015-04-15 11:30:39 -0700938 case HAL_PIXEL_FORMAT_RGBX_8888:
Sushil Chauhan65e26302015-01-14 10:48:57 -0800939 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
940 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800941 case HAL_PIXEL_FORMAT_RGBA_1010102:
942 case HAL_PIXEL_FORMAT_RGBX_1010102:
Sushil Chauhan65e26302015-01-14 10:48:57 -0800943 return true;
944 default:
945 return false;
946 }
947}
948
949bool isUBwcEnabled(int format, int usage)
950{
Sushil Chauhan81594f62015-01-26 16:00:51 -0800951 // Allow UBWC, if client is using an explicitly defined UBWC pixel format.
952 if (isUBwcFormat(format))
953 return true;
954
Manikanta Kanamarlapudicb44d972016-02-03 17:49:55 +0530955 if ((usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
956 gralloc::IAllocController::getInstance()->isDisableUBWCForEncoder()) {
957 return false;
958 }
959
Sushil Chauhan7807d192015-08-13 10:10:48 -0700960 // Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP
961 // support the format. OR if a non-OpenGL client like Rotator, sets UBWC
962 // usage flag and MDP supports the format.
963 if ((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) && isUBwcSupported(format)) {
964 bool enable = true;
965 // Query GPU for UBWC only if buffer is intended to be used by GPU.
966 if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER)) {
967 enable = AdrenoMemInfo::getInstance().isUBWCSupportedByGPU(format);
968 }
Sushil Chauhan81594f62015-01-26 16:00:51 -0800969 // Allow UBWC, only if CPU usage flags are not set
Sushil Chauhan7807d192015-08-13 10:10:48 -0700970 if (enable && !(usage & (GRALLOC_USAGE_SW_READ_MASK |
971 GRALLOC_USAGE_SW_WRITE_MASK))) {
Sushil Chauhan65e26302015-01-14 10:48:57 -0800972 return true;
973 }
974 }
975 return false;
976}
977
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800978static void getYuvUBwcWidthHeight(int width, int height, int format,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800979 int& aligned_w, int& aligned_h)
980{
981 switch (format)
982 {
983 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
984 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
985 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
986 aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV12_UBWC, width);
987 aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12_UBWC, height);
988 break;
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -0800989 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
990 aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV12_BPP10_UBWC, width);
991 aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12_BPP10_UBWC, height);
992 break;
Sushil Chauhan65e26302015-01-14 10:48:57 -0800993 default:
994 ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format);
995 aligned_w = 0;
996 aligned_h = 0;
997 break;
998 }
999}
1000
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001001static void getRgbUBwcBlockSize(int bpp, int& block_width, int& block_height)
Sushil Chauhan65e26302015-01-14 10:48:57 -08001002{
1003 block_width = 0;
1004 block_height = 0;
1005
1006 switch(bpp)
1007 {
1008 case 2:
1009 case 4:
1010 block_width = 16;
1011 block_height = 4;
1012 break;
1013 case 8:
1014 block_width = 8;
1015 block_height = 4;
1016 break;
1017 case 16:
1018 block_width = 4;
1019 block_height = 4;
1020 break;
1021 default:
1022 ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp);
1023 break;
1024 }
1025}
1026
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001027static unsigned int getRgbUBwcMetaBufferSize(int width, int height, int bpp)
Sushil Chauhan65e26302015-01-14 10:48:57 -08001028{
1029 unsigned int size = 0;
1030 int meta_width, meta_height;
1031 int block_width, block_height;
1032
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001033 getRgbUBwcBlockSize(bpp, block_width, block_height);
Sushil Chauhan65e26302015-01-14 10:48:57 -08001034
1035 if (!block_width || !block_height) {
1036 ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp);
1037 return size;
1038 }
1039
1040 // Align meta buffer height to 16 blocks
1041 meta_height = ALIGN(((height + block_height - 1) / block_height), 16);
1042
1043 // Align meta buffer width to 64 blocks
1044 meta_width = ALIGN(((width + block_width - 1) / block_width), 64);
1045
1046 // Align meta buffer size to 4K
Sushil Chauhanc85b65b2015-04-30 11:05:36 -07001047 size = ALIGN((meta_width * meta_height), 4096);
Sushil Chauhan65e26302015-01-14 10:48:57 -08001048 return size;
1049}
1050
1051static unsigned int getUBwcSize(int width, int height, int format,
1052 const int alignedw, const int alignedh) {
1053
1054 unsigned int size = 0;
1055 switch (format) {
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -06001056 case HAL_PIXEL_FORMAT_BGR_565:
Sushil Chauhan65e26302015-01-14 10:48:57 -08001057 size = alignedw * alignedh * 2;
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001058 size += getRgbUBwcMetaBufferSize(width, height, 2);
Sushil Chauhan65e26302015-01-14 10:48:57 -08001059 break;
1060 case HAL_PIXEL_FORMAT_RGBA_8888:
Sushil Chauhan6686c802015-04-15 11:30:39 -07001061 case HAL_PIXEL_FORMAT_RGBX_8888:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001062 case HAL_PIXEL_FORMAT_RGBA_1010102:
1063 case HAL_PIXEL_FORMAT_RGBX_1010102:
Sushil Chauhan65e26302015-01-14 10:48:57 -08001064 size = alignedw * alignedh * 4;
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001065 size += getRgbUBwcMetaBufferSize(width, height, 4);
Sushil Chauhan65e26302015-01-14 10:48:57 -08001066 break;
1067 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
1068 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
1069 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
1070 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_UBWC, width, height);
1071 break;
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001072 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
1073 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_BPP10_UBWC, width, height);
1074 break;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001075 default:
1076 ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format);
1077 break;
1078 }
1079 return size;
1080}
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001081
Sushil Chauhanc85b65b2015-04-30 11:05:36 -07001082int getRgbDataAddress(private_handle_t* hnd, void** rgb_data)
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001083{
1084 int err = 0;
1085
1086 // This api is for RGB* formats
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -06001087 if (!isUncompressedRgbFormat(hnd->format)) {
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001088 return -EINVAL;
1089 }
1090
1091 // linear buffer
1092 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED)) {
Sushil Chauhanc85b65b2015-04-30 11:05:36 -07001093 *rgb_data = (void*)hnd->base;
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001094 return err;
1095 }
1096
1097 unsigned int meta_size = 0;
1098 switch (hnd->format) {
Kaushik Kanetkar4cb337c2015-08-29 20:16:54 -06001099 case HAL_PIXEL_FORMAT_BGR_565:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001100 meta_size = getRgbUBwcMetaBufferSize(hnd->width, hnd->height, 2);
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001101 break;
1102 case HAL_PIXEL_FORMAT_RGBA_8888:
1103 case HAL_PIXEL_FORMAT_RGBX_8888:
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -08001104 meta_size = getRgbUBwcMetaBufferSize(hnd->width, hnd->height, 4);
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001105 break;
1106 default:
1107 ALOGE("%s:Unsupported RGB format: 0x%x", __FUNCTION__, hnd->format);
1108 err = -EINVAL;
1109 break;
1110 }
1111
Sushil Chauhanc85b65b2015-04-30 11:05:36 -07001112 *rgb_data = (void*)(hnd->base + meta_size);
Sushil Chauhan7dd3a432015-04-08 15:54:42 -07001113 return err;
1114}