blob: d8880ef3cb60411a5792325903bdc4abbc42f919 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Naseer Ahmedf8d5f822016-08-02 11:28:13 -04003 * 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) ;
Saurabh Shahdbe41c52015-04-23 11:50:50 -070069 void *mappedAddress = MAP_FAILED;
70 hnd->base = 0;
Naseer Ahmedf8d5f822016-08-02 11:28:13 -040071 hnd->base_metadata = 0;
Saurabh Shahdbe41c52015-04-23 11:50:50 -070072
73 // Dont map framebuffer and secure buffers
Iliyan Malchev202a77d2012-06-11 14:41:12 -070074 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
75 !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070076 size = hnd->size;
77 err = memalloc->map_buffer(&mappedAddress, size,
Naseer Ahmed29a26812012-06-14 00:56:20 -070078 hnd->offset, hnd->fd);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080079 if(err || mappedAddress == MAP_FAILED) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070080 ALOGE("Could not mmap handle %p, fd=%d (%s)",
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 handle, hnd->fd, strerror(errno));
Iliyan Malchev202a77d2012-06-11 14:41:12 -070082 return -errno;
83 }
84
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070085 hnd->base = uint64_t(mappedAddress) + hnd->offset;
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070086 }
87
Saurabh Shahdbe41c52015-04-23 11:50:50 -070088 //Allow mapping of metadata for all buffers including secure ones, but not
89 //of framebuffer
Naseer Ahmedf8d5f822016-08-02 11:28:13 -040090 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
91 mappedAddress = MAP_FAILED;
92 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
93 err = memalloc->map_buffer(&mappedAddress, size,
94 hnd->offset_metadata, hnd->fd_metadata);
95 if(err || mappedAddress == MAP_FAILED) {
96 ALOGE("Could not mmap handle %p, fd=%d (%s)",
97 handle, hnd->fd_metadata, strerror(errno));
98 return -errno;
99 }
100 hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700101 }
Naseer Ahmedf8d5f822016-08-02 11:28:13 -0400102 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700103}
104
105static int gralloc_unmap(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700107{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700108 ATRACE_CALL();
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700109 int err = -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800110 if(!module)
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700111 return err;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800112
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700113 private_handle_t* hnd = (private_handle_t*)handle;
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700114 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
115 if(!memalloc)
116 return err;
117
118 if(hnd->base) {
119 err = memalloc->unmap_buffer((void*)hnd->base, hnd->size, hnd->offset);
120 if (err) {
Naseer Ahmedb8ecfbf2015-11-02 20:34:29 -0500121 ALOGE("Could not unmap memory at address %p, %s", (void*) hnd->base,
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700122 strerror(errno));
123 return -errno;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700124 }
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700125 hnd->base = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700126 }
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700127
128 if(hnd->base_metadata) {
129 unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
130 err = memalloc->unmap_buffer((void*)hnd->base_metadata,
131 size, hnd->offset_metadata);
132 if (err) {
133 ALOGE("Could not unmap memory at address %p, %s",
Naseer Ahmedb8ecfbf2015-11-02 20:34:29 -0500134 (void*) hnd->base_metadata, strerror(errno));
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700135 return -errno;
136 }
137 hnd->base_metadata = 0;
138 }
139
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700140 return 0;
141}
142
143/*****************************************************************************/
144
145static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
146
147/*****************************************************************************/
148
149int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700150 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700151{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700152 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800153 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700154 return -EINVAL;
Naseer Ahmedf8d5f822016-08-02 11:28:13 -0400155
156 /* NOTE: we need to initialize the buffer as not mapped/not locked
157 * because it shouldn't when this function is called the first time
158 * in a new process. Ideally these flags shouldn't be part of the
159 * handle, but instead maintained in the kernel or at least
160 * out-of-line
161 */
162
163 int err = gralloc_map(module, handle);
164 if (err) {
165 ALOGE("%s: gralloc_map failed", __FUNCTION__);
166 return err;
167 }
168
169 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700170}
171
172int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700174{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700175 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800176 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700177 return -EINVAL;
178
179 /*
180 * If the buffer has been mapped during a lock operation, it's time
181 * to un-map it. It's an error to be here with a locked buffer.
182 * NOTE: the framebuffer is handled differently and is never unmapped.
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700183 * Also base and base_metadata are reset.
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700184 */
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700185 return gralloc_unmap(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700186}
187
188int terminateBuffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189 private_handle_t* hnd)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700190{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700191 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800192 if(!module)
193 return -EINVAL;
194
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700195 /*
196 * If the buffer has been mapped during a lock operation, it's time
197 * to un-map it. It's an error to be here with a locked buffer.
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700198 * NOTE: the framebuffer is handled differently and is never unmapped.
199 * Also base and base_metadata are reset.
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700200 */
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700201 return gralloc_unmap(module, hnd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700202}
203
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400204static int gralloc_map_and_invalidate (gralloc_module_t const* module,
205 buffer_handle_t handle, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700206{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700207 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800208 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700209 return -EINVAL;
210
211 int err = 0;
212 private_handle_t* hnd = (private_handle_t*)handle;
213 if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
214 if (hnd->base == 0) {
215 // we need to map for real
216 pthread_mutex_t* const lock = &sMapLock;
217 pthread_mutex_lock(lock);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400218 err = gralloc_map(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700219 pthread_mutex_unlock(lock);
220 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700221 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800222 hnd->flags & private_handle_t::PRIV_FLAGS_CACHED) {
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700223 //Invalidate if CPU reads in software and there are non-CPU
224 //writers. No need to do this for the metadata buffer as it is
225 //only read/written in software.
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800226 if ((usage & GRALLOC_USAGE_SW_READ_MASK) and
227 (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER))
228 {
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700229 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
230 err = memalloc->clean_buffer((void*)hnd->base,
231 hnd->size, hnd->offset, hnd->fd,
232 CACHE_INVALIDATE);
233 }
234 //Mark the buffer to be flushed after CPU write.
Naseer Ahmedec147982013-06-14 17:06:46 -0400235 if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
Naseer Ahmedec147982013-06-14 17:06:46 -0400236 hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
237 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700238 }
239 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700240
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700241 return err;
242}
243
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400244int gralloc_lock(gralloc_module_t const* module,
245 buffer_handle_t handle, int usage,
246 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
247 void** vaddr)
248{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700249 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400250 private_handle_t* hnd = (private_handle_t*)handle;
251 int err = gralloc_map_and_invalidate(module, handle, usage);
252 if(!err)
253 *vaddr = (void*)hnd->base;
254 return err;
255}
256
257int gralloc_lock_ycbcr(gralloc_module_t const* module,
258 buffer_handle_t handle, int usage,
259 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
260 struct android_ycbcr *ycbcr)
261{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700262 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400263 private_handle_t* hnd = (private_handle_t*)handle;
264 int err = gralloc_map_and_invalidate(module, handle, usage);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400265 if(!err)
266 err = getYUVPlaneInfo(hnd, ycbcr);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400267 return err;
268}
269
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700270int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700272{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700273 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800274 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700275 return -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800276
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400277 int err = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700278 private_handle_t* hnd = (private_handle_t*)handle;
279
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700280 IMemAlloc* memalloc = getAllocator(hnd->flags);
281 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
282 err = memalloc->clean_buffer((void*)hnd->base,
283 hnd->size, hnd->offset, hnd->fd,
284 CACHE_CLEAN);
285 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700286 }
287
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400288 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700289}
290
291/*****************************************************************************/
292
293int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700294 int operation, ... )
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700295{
296 int res = -EINVAL;
297 va_list args;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800298 if(!module)
299 return res;
300
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700301 va_start(args, operation);
302 switch (operation) {
303 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
304 {
305 int fd = va_arg(args, int);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700306 unsigned int size = va_arg(args, unsigned int);
307 unsigned int offset = va_arg(args, unsigned int);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700308 void* base = va_arg(args, void*);
309 int width = va_arg(args, int);
310 int height = va_arg(args, int);
311 int format = va_arg(args, int);
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700312 int alignedw = 0, alignedh = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700313
314 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700315 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700316 private_handle_t::sNumFds, private_handle_t::sNumInts());
Ramakant Singh04b6b242015-03-23 15:01:12 +0530317 if (hnd) {
318 hnd->magic = private_handle_t::sMagic;
319 hnd->fd = fd;
320 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
321 hnd->size = size;
322 hnd->offset = offset;
323 hnd->base = uint64_t(base) + offset;
324 hnd->gpuaddr = 0;
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700325 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
326 height, format, 0, alignedw, alignedh);
327 hnd->width = alignedw;
328 hnd->height = alignedh;
329 hnd->unaligned_width = width;
330 hnd->unaligned_height = height;
Ramakant Singh04b6b242015-03-23 15:01:12 +0530331 hnd->format = format;
332 *handle = (native_handle_t *)hnd;
333 res = 0;
334 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700335 break;
336
337 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800338 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
339 {
340 int width = va_arg(args, int);
341 int format = va_arg(args, int);
342 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800343 int alignedw = 0, alignedh = 0;
344 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800345 0, format, 0, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800346 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800347 res = 0;
348 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700349
Naseer Ahmeda978f952013-09-26 14:36:28 -0400350 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
351 {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700352 const private_handle_t* hnd = va_arg(args, private_handle_t*);
Naseer Ahmeda978f952013-09-26 14:36:28 -0400353 int *stride = va_arg(args, int *);
354 if (private_handle_t::validate(hnd)) {
355 return res;
356 }
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700357
358 int alignedw = 0, alignedh = 0;
359 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
360 *stride = alignedw;
361
Naseer Ahmeda978f952013-09-26 14:36:28 -0400362 res = 0;
363 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700364
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530365 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
366 {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700367 const private_handle_t* hnd = va_arg(args, private_handle_t*);
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530368 int *stride = va_arg(args, int *);
369 int *height = va_arg(args, int *);
370 if (private_handle_t::validate(hnd)) {
371 return res;
372 }
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700373
374 int alignedw = 0, alignedh = 0;
375 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
376 *stride = alignedw;
377 *height = alignedh;
378
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530379 res = 0;
380 } break;
381
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700382 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
383 {
384 int width = va_arg(args, int);
385 int height = va_arg(args, int);
386 int format = va_arg(args, int);
387 int usage = va_arg(args, int);
388 int *alignedWidth = va_arg(args, int *);
389 int *alignedHeight = va_arg(args, int *);
390 int *tileEnabled = va_arg(args,int *);
Sushil Chauhane61fac52015-04-30 17:14:37 -0700391 *tileEnabled = isUBwcEnabled(format, usage) ||
392 isMacroTileEnabled(format, usage);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700393 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800394 height, format, usage, *alignedWidth, *alignedHeight);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700395 res = 0;
396 } break;
397
Shuzhen Wangc502c872014-01-28 16:10:42 -0800398 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
399 {
400 private_handle_t* hnd = va_arg(args, private_handle_t*);
401 int *color_space = va_arg(args, int *);
402 if (private_handle_t::validate(hnd)) {
403 return res;
404 }
405 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
406 if(metadata && metadata->operation & UPDATE_COLOR_SPACE) {
407 *color_space = metadata->colorSpace;
408 res = 0;
409 }
410 } break;
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800411
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400412 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
413 {
414 private_handle_t* hnd = va_arg(args, private_handle_t*);
415 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400416 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400417 res = getYUVPlaneInfo(hnd, ycbcr);
418 }
419 } break;
420
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800421 case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO:
422 {
423 private_handle_t* hnd = va_arg(args, private_handle_t*);
424 int *map_secure_buffer = va_arg(args, int *);
425 if (private_handle_t::validate(hnd)) {
426 return res;
427 }
428 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
429 if(metadata && metadata->operation & MAP_SECURE_BUFFER) {
430 *map_secure_buffer = metadata->mapSecureBuffer;
431 res = 0;
432 } else {
433 *map_secure_buffer = 0;
434 }
435 } break;
436
Sushil Chauhana9d47002015-02-18 14:55:03 -0800437 case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG:
438 {
439 private_handle_t* hnd = va_arg(args, private_handle_t*);
440 int *flag = va_arg(args, int *);
441 if (private_handle_t::validate(hnd)) {
442 return res;
443 }
444 *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700445 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
446 if (metadata && (metadata->operation & LINEAR_FORMAT)) {
447 *flag = 0;
448 }
Sushil Chauhana9d47002015-02-18 14:55:03 -0800449 res = 0;
450 } break;
451
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700452 case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS:
453 {
454 private_handle_t* hnd = va_arg(args, private_handle_t*);
Sushil Chauhanc85b65b2015-04-30 11:05:36 -0700455 void** rgb_data = va_arg(args, void**);
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700456 if (!private_handle_t::validate(hnd)) {
457 res = getRgbDataAddress(hnd, rgb_data);
458 }
459 } break;
460
Dileep Marchya1a7e1f12015-09-25 19:11:57 -0700461 case GRALLOC_MODULE_PERFORM_GET_IGC:
462 {
463 private_handle_t* hnd = va_arg(args, private_handle_t*);
464 uint32_t *igc = va_arg(args, uint32_t *);
465 if (!private_handle_t::validate(hnd) && igc) {
466 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
467 if (metadata && (metadata->operation & SET_IGC)) {
468 *igc = metadata->igc;
469 res = 0;
470 }
471 }
472 } break;
473
474 case GRALLOC_MODULE_PERFORM_SET_IGC:
Dileep Marchyaa2129342016-01-05 18:15:57 -0800475 res = 0;
476 break;
Dileep Marchya1a7e1f12015-09-25 19:11:57 -0700477
Saurabh Shah95f83682015-10-16 10:30:04 -0700478 case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE:
479 {
480 private_handle_t* hnd = va_arg(args, private_handle_t*);
Saurabh Shahb8067a42015-11-06 16:52:02 -0800481 uint32_t *enable = va_arg(args, uint32_t*);
Sushil Chauhan76466212016-01-05 18:09:22 -0800482 if (!private_handle_t::validate(hnd)) {
483 setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable);
484 res = 0;
Saurabh Shah95f83682015-10-16 10:30:04 -0700485 }
Saurabh Shah95f83682015-10-16 10:30:04 -0700486 } break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700487 default:
488 break;
489 }
490 va_end(args);
491 return res;
492}