blob: 4a1b2cd78b20a547d33db38fca78c69cdb2ec9e9 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Arun Kumar K.R563fbde2014-11-24 08:51:17 -08003 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Naseer Ahmed9eb5e092014-09-25 13:24:44 -040018#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070019#include <limits.h>
20#include <errno.h>
21#include <pthread.h>
22#include <unistd.h>
23#include <string.h>
24#include <stdarg.h>
25
26#include <sys/mman.h>
27#include <sys/stat.h>
28#include <sys/types.h>
29#include <sys/ioctl.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070030
31#include <cutils/log.h>
32#include <cutils/atomic.h>
Saurabh Shahd4749de2014-09-10 18:04:31 -070033#include <utils/Trace.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070034
35#include <hardware/hardware.h>
36#include <hardware/gralloc.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070037
38#include "gralloc_priv.h"
39#include "gr.h"
40#include "alloc_controller.h"
41#include "memalloc.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080042#include <qdMetaData.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070043
Saurabh Shahd4749de2014-09-10 18:04:31 -070044
Iliyan Malchev202a77d2012-06-11 14:41:12 -070045using namespace gralloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070046/*****************************************************************************/
47
48// Return the type of allocator -
49// these are used for mapping/unmapping
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070050static IMemAlloc* getAllocator(int flags)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070051{
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070052 IMemAlloc* memalloc;
53 IAllocController* alloc_ctrl = IAllocController::getInstance();
Iliyan Malchev202a77d2012-06-11 14:41:12 -070054 memalloc = alloc_ctrl->getAllocator(flags);
55 return memalloc;
56}
57
58static int gralloc_map(gralloc_module_t const* module,
Naseer Ahmed34d33bc2013-05-08 12:28:37 -040059 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070060{
Saurabh Shahd4749de2014-09-10 18:04:31 -070061 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080062 if(!module)
63 return -EINVAL;
64
Iliyan Malchev202a77d2012-06-11 14:41:12 -070065 private_handle_t* hnd = (private_handle_t*)handle;
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070066 unsigned int size = 0;
67 int err = 0;
68 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070069 void *mappedAddress;
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070070 // Dont map FRAMEBUFFER and SECURE_BUFFERS
Iliyan Malchev202a77d2012-06-11 14:41:12 -070071 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
72 !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070073 size = hnd->size;
74 err = memalloc->map_buffer(&mappedAddress, size,
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 hnd->offset, hnd->fd);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080076 if(err || mappedAddress == MAP_FAILED) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070077 ALOGE("Could not mmap handle %p, fd=%d (%s)",
Naseer Ahmed29a26812012-06-14 00:56:20 -070078 handle, hnd->fd, strerror(errno));
Iliyan Malchev202a77d2012-06-11 14:41:12 -070079 hnd->base = 0;
80 return -errno;
81 }
82
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070083 hnd->base = uint64_t(mappedAddress) + hnd->offset;
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070084 }
85
86 //Allow mapping of metadata for all buffers and SECURE_BUFFER
87 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080088 mappedAddress = MAP_FAILED;
89 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
90 err = memalloc->map_buffer(&mappedAddress, size,
91 hnd->offset_metadata, hnd->fd_metadata);
92 if(err || mappedAddress == MAP_FAILED) {
93 ALOGE("Could not mmap handle %p, fd=%d (%s)",
94 handle, hnd->fd_metadata, strerror(errno));
95 hnd->base_metadata = 0;
96 return -errno;
97 }
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070098 hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070099 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700100 return 0;
101}
102
103static int gralloc_unmap(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700105{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700106 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800107 if(!module)
108 return -EINVAL;
109
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700110 private_handle_t* hnd = (private_handle_t*)handle;
111 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
112 int err = -EINVAL;
113 void* base = (void*)hnd->base;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700114 unsigned int size = hnd->size;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700115 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800116 if(memalloc != NULL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700117 err = memalloc->unmap_buffer(base, size, hnd->offset);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800118 if (err) {
119 ALOGE("Could not unmap memory at address %p", base);
120 }
121 base = (void*)hnd->base_metadata;
122 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
123 err = memalloc->unmap_buffer(base, size, hnd->offset_metadata);
124 if (err) {
125 ALOGE("Could not unmap memory at address %p", base);
126 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700127 }
128 }
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800129 /* need to initialize the pointer to NULL otherwise unmapping for that
130 * buffer happens twice which leads to crash */
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700131 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800132 hnd->base_metadata = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700133 return 0;
134}
135
136/*****************************************************************************/
137
138static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
139
140/*****************************************************************************/
141
142int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700144{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700145 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800146 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700147 return -EINVAL;
148
149 // In this implementation, we don't need to do anything here
150
151 /* NOTE: we need to initialize the buffer as not mapped/not locked
152 * because it shouldn't when this function is called the first time
153 * in a new process. Ideally these flags shouldn't be part of the
154 * handle, but instead maintained in the kernel or at least
155 * out-of-line
156 */
157
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700158 private_handle_t* hnd = (private_handle_t*)handle;
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700159 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800160 hnd->base_metadata = 0;
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400161 int err = gralloc_map(module, handle);
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700162 if (err) {
163 ALOGE("%s: gralloc_map failed", __FUNCTION__);
164 return err;
165 }
166
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700167 return 0;
168}
169
170int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700172{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700173 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800174 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700175 return -EINVAL;
176
177 /*
178 * If the buffer has been mapped during a lock operation, it's time
179 * to un-map it. It's an error to be here with a locked buffer.
180 * NOTE: the framebuffer is handled differently and is never unmapped.
181 */
182
183 private_handle_t* hnd = (private_handle_t*)handle;
184
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700185 if (hnd->base != 0) {
186 gralloc_unmap(module, handle);
187 }
188 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800189 hnd->base_metadata = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700190 return 0;
191}
192
193int terminateBuffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194 private_handle_t* hnd)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700195{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700196 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800197 if(!module)
198 return -EINVAL;
199
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700200 /*
201 * If the buffer has been mapped during a lock operation, it's time
202 * to un-map it. It's an error to be here with a locked buffer.
203 */
204
205 if (hnd->base != 0) {
206 // this buffer was mapped, unmap it now
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500207 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700208 gralloc_unmap(module, hnd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700209 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210 ALOGE("terminateBuffer: unmapping a non pmem/ashmem buffer flags = 0x%x",
211 hnd->flags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700212 gralloc_unmap(module, hnd);
213 }
214 }
215
216 return 0;
217}
218
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400219static int gralloc_map_and_invalidate (gralloc_module_t const* module,
220 buffer_handle_t handle, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700221{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700222 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800223 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700224 return -EINVAL;
225
226 int err = 0;
227 private_handle_t* hnd = (private_handle_t*)handle;
228 if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
229 if (hnd->base == 0) {
230 // we need to map for real
231 pthread_mutex_t* const lock = &sMapLock;
232 pthread_mutex_lock(lock);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400233 err = gralloc_map(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700234 pthread_mutex_unlock(lock);
235 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700236 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800237 hnd->flags & private_handle_t::PRIV_FLAGS_CACHED) {
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700238 //Invalidate if CPU reads in software and there are non-CPU
239 //writers. No need to do this for the metadata buffer as it is
240 //only read/written in software.
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800241 if ((usage & GRALLOC_USAGE_SW_READ_MASK) and
242 (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER))
243 {
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700244 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
245 err = memalloc->clean_buffer((void*)hnd->base,
246 hnd->size, hnd->offset, hnd->fd,
247 CACHE_INVALIDATE);
248 }
249 //Mark the buffer to be flushed after CPU write.
Naseer Ahmedec147982013-06-14 17:06:46 -0400250 if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
Naseer Ahmedec147982013-06-14 17:06:46 -0400251 hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
252 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700253 }
254 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700255
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700256 return err;
257}
258
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400259int gralloc_lock(gralloc_module_t const* module,
260 buffer_handle_t handle, int usage,
261 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
262 void** vaddr)
263{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700264 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400265 private_handle_t* hnd = (private_handle_t*)handle;
266 int err = gralloc_map_and_invalidate(module, handle, usage);
267 if(!err)
268 *vaddr = (void*)hnd->base;
269 return err;
270}
271
272int gralloc_lock_ycbcr(gralloc_module_t const* module,
273 buffer_handle_t handle, int usage,
274 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
275 struct android_ycbcr *ycbcr)
276{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700277 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400278 private_handle_t* hnd = (private_handle_t*)handle;
279 int err = gralloc_map_and_invalidate(module, handle, usage);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400280 if(!err)
281 err = getYUVPlaneInfo(hnd, ycbcr);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400282 return err;
283}
284
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700285int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700286 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700287{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700288 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800289 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700290 return -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800291
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400292 int err = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700293 private_handle_t* hnd = (private_handle_t*)handle;
294
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700295 IMemAlloc* memalloc = getAllocator(hnd->flags);
296 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
297 err = memalloc->clean_buffer((void*)hnd->base,
298 hnd->size, hnd->offset, hnd->fd,
299 CACHE_CLEAN);
300 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700301 }
302
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400303 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700304}
305
306/*****************************************************************************/
307
308int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309 int operation, ... )
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700310{
311 int res = -EINVAL;
312 va_list args;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800313 if(!module)
314 return res;
315
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700316 va_start(args, operation);
317 switch (operation) {
318 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
319 {
320 int fd = va_arg(args, int);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700321 unsigned int size = va_arg(args, unsigned int);
322 unsigned int offset = va_arg(args, unsigned int);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700323 void* base = va_arg(args, void*);
324 int width = va_arg(args, int);
325 int height = va_arg(args, int);
326 int format = va_arg(args, int);
327
328 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700329 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700330 private_handle_t::sNumFds, private_handle_t::sNumInts());
Ramakant Singh04b6b242015-03-23 15:01:12 +0530331 if (hnd) {
332 hnd->magic = private_handle_t::sMagic;
333 hnd->fd = fd;
334 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
335 hnd->size = size;
336 hnd->offset = offset;
337 hnd->base = uint64_t(base) + offset;
338 hnd->gpuaddr = 0;
339 hnd->width = width;
340 hnd->height = height;
341 hnd->format = format;
342 *handle = (native_handle_t *)hnd;
343 res = 0;
344 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700345 break;
346
347 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800348 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
349 {
350 int width = va_arg(args, int);
351 int format = va_arg(args, int);
352 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800353 int alignedw = 0, alignedh = 0;
354 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800355 0, format, 0, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800356 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800357 res = 0;
358 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700359
Naseer Ahmeda978f952013-09-26 14:36:28 -0400360 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
361 {
362 private_handle_t* hnd = va_arg(args, private_handle_t*);
363 int *stride = va_arg(args, int *);
364 if (private_handle_t::validate(hnd)) {
365 return res;
366 }
367 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
368 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
369 *stride = metadata->bufferDim.sliceWidth;
370 } else {
371 *stride = hnd->width;
372 }
373 res = 0;
374 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700375
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530376 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
377 {
378 private_handle_t* hnd = va_arg(args, private_handle_t*);
379 int *stride = va_arg(args, int *);
380 int *height = va_arg(args, int *);
381 if (private_handle_t::validate(hnd)) {
382 return res;
383 }
384 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
385 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
386 *stride = metadata->bufferDim.sliceWidth;
387 *height = metadata->bufferDim.sliceHeight;
388 } else {
389 *stride = hnd->width;
390 *height = hnd->height;
391 }
392 res = 0;
393 } break;
394
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700395 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
396 {
397 int width = va_arg(args, int);
398 int height = va_arg(args, int);
399 int format = va_arg(args, int);
400 int usage = va_arg(args, int);
401 int *alignedWidth = va_arg(args, int *);
402 int *alignedHeight = va_arg(args, int *);
403 int *tileEnabled = va_arg(args,int *);
404 *tileEnabled = isMacroTileEnabled(format, usage);
405 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800406 height, format, usage, *alignedWidth, *alignedHeight);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700407 res = 0;
408 } break;
409
Shuzhen Wangc502c872014-01-28 16:10:42 -0800410 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
411 {
412 private_handle_t* hnd = va_arg(args, private_handle_t*);
413 int *color_space = va_arg(args, int *);
414 if (private_handle_t::validate(hnd)) {
415 return res;
416 }
417 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
418 if(metadata && metadata->operation & UPDATE_COLOR_SPACE) {
419 *color_space = metadata->colorSpace;
420 res = 0;
421 }
422 } break;
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800423
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400424 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
425 {
426 private_handle_t* hnd = va_arg(args, private_handle_t*);
427 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400428 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400429 res = getYUVPlaneInfo(hnd, ycbcr);
430 }
431 } break;
432
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800433 case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO:
434 {
435 private_handle_t* hnd = va_arg(args, private_handle_t*);
436 int *map_secure_buffer = va_arg(args, int *);
437 if (private_handle_t::validate(hnd)) {
438 return res;
439 }
440 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
441 if(metadata && metadata->operation & MAP_SECURE_BUFFER) {
442 *map_secure_buffer = metadata->mapSecureBuffer;
443 res = 0;
444 } else {
445 *map_secure_buffer = 0;
446 }
447 } break;
448
Sushil Chauhana9d47002015-02-18 14:55:03 -0800449 case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG:
450 {
451 private_handle_t* hnd = va_arg(args, private_handle_t*);
452 int *flag = va_arg(args, int *);
453 if (private_handle_t::validate(hnd)) {
454 return res;
455 }
456 *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
457 res = 0;
458 } break;
459
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700460 case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS:
461 {
462 private_handle_t* hnd = va_arg(args, private_handle_t*);
463 void* rgb_data = va_arg(args, void*);
464 if (!private_handle_t::validate(hnd)) {
465 res = getRgbDataAddress(hnd, rgb_data);
466 }
467 } break;
468
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700469 default:
470 break;
471 }
472 va_end(args);
473 return res;
474}