blob: 37e83bc0657ec9a04427f0e8b44ee6e55cda4a9f [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) ;
Saurabh Shahdbe41c52015-04-23 11:50:50 -070069 void *mappedAddress = MAP_FAILED;
70 hnd->base = 0;
71 hnd->base_metadata = 0;
72
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
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070090 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080091 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));
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080098 return -errno;
99 }
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700100 hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700101 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700102 return 0;
103}
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;
155
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700156 /* 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
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400163 int err = gralloc_map(module, handle);
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700164 if (err) {
165 ALOGE("%s: gralloc_map failed", __FUNCTION__);
166 return err;
167 }
168
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700169 return 0;
170}
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);
312
313 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700314 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700315 private_handle_t::sNumFds, private_handle_t::sNumInts());
Ramakant Singh04b6b242015-03-23 15:01:12 +0530316 if (hnd) {
317 hnd->magic = private_handle_t::sMagic;
318 hnd->fd = fd;
319 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
320 hnd->size = size;
321 hnd->offset = offset;
322 hnd->base = uint64_t(base) + offset;
323 hnd->gpuaddr = 0;
324 hnd->width = width;
325 hnd->height = height;
326 hnd->format = format;
327 *handle = (native_handle_t *)hnd;
328 res = 0;
329 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700330 break;
331
332 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800333 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
334 {
335 int width = va_arg(args, int);
336 int format = va_arg(args, int);
337 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800338 int alignedw = 0, alignedh = 0;
339 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800340 0, format, 0, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800341 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800342 res = 0;
343 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700344
Naseer Ahmeda978f952013-09-26 14:36:28 -0400345 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
346 {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700347 const private_handle_t* hnd = va_arg(args, private_handle_t*);
Naseer Ahmeda978f952013-09-26 14:36:28 -0400348 int *stride = va_arg(args, int *);
349 if (private_handle_t::validate(hnd)) {
350 return res;
351 }
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700352
353 int alignedw = 0, alignedh = 0;
354 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
355 *stride = alignedw;
356
Naseer Ahmeda978f952013-09-26 14:36:28 -0400357 res = 0;
358 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700359
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530360 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
361 {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700362 const private_handle_t* hnd = va_arg(args, private_handle_t*);
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530363 int *stride = va_arg(args, int *);
364 int *height = va_arg(args, int *);
365 if (private_handle_t::validate(hnd)) {
366 return res;
367 }
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700368
369 int alignedw = 0, alignedh = 0;
370 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
371 *stride = alignedw;
372 *height = alignedh;
373
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530374 res = 0;
375 } break;
376
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700377 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
378 {
379 int width = va_arg(args, int);
380 int height = va_arg(args, int);
381 int format = va_arg(args, int);
382 int usage = va_arg(args, int);
383 int *alignedWidth = va_arg(args, int *);
384 int *alignedHeight = va_arg(args, int *);
385 int *tileEnabled = va_arg(args,int *);
Sushil Chauhane61fac52015-04-30 17:14:37 -0700386 *tileEnabled = isUBwcEnabled(format, usage) ||
387 isMacroTileEnabled(format, usage);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700388 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800389 height, format, usage, *alignedWidth, *alignedHeight);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700390 res = 0;
391 } break;
392
Shuzhen Wangc502c872014-01-28 16:10:42 -0800393 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
394 {
395 private_handle_t* hnd = va_arg(args, private_handle_t*);
396 int *color_space = va_arg(args, int *);
397 if (private_handle_t::validate(hnd)) {
398 return res;
399 }
400 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
401 if(metadata && metadata->operation & UPDATE_COLOR_SPACE) {
402 *color_space = metadata->colorSpace;
403 res = 0;
404 }
405 } break;
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800406
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400407 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
408 {
409 private_handle_t* hnd = va_arg(args, private_handle_t*);
410 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400411 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400412 res = getYUVPlaneInfo(hnd, ycbcr);
413 }
414 } break;
415
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800416 case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO:
417 {
418 private_handle_t* hnd = va_arg(args, private_handle_t*);
419 int *map_secure_buffer = va_arg(args, int *);
420 if (private_handle_t::validate(hnd)) {
421 return res;
422 }
423 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
424 if(metadata && metadata->operation & MAP_SECURE_BUFFER) {
425 *map_secure_buffer = metadata->mapSecureBuffer;
426 res = 0;
427 } else {
428 *map_secure_buffer = 0;
429 }
430 } break;
431
Sushil Chauhana9d47002015-02-18 14:55:03 -0800432 case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG:
433 {
434 private_handle_t* hnd = va_arg(args, private_handle_t*);
435 int *flag = va_arg(args, int *);
436 if (private_handle_t::validate(hnd)) {
437 return res;
438 }
439 *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700440 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
441 if (metadata && (metadata->operation & LINEAR_FORMAT)) {
442 *flag = 0;
443 }
Sushil Chauhana9d47002015-02-18 14:55:03 -0800444 res = 0;
445 } break;
446
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700447 case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS:
448 {
449 private_handle_t* hnd = va_arg(args, private_handle_t*);
Sushil Chauhanc85b65b2015-04-30 11:05:36 -0700450 void** rgb_data = va_arg(args, void**);
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700451 if (!private_handle_t::validate(hnd)) {
452 res = getRgbDataAddress(hnd, rgb_data);
453 }
454 } break;
455
Dileep Marchya1a7e1f12015-09-25 19:11:57 -0700456 case GRALLOC_MODULE_PERFORM_GET_IGC:
457 {
458 private_handle_t* hnd = va_arg(args, private_handle_t*);
459 uint32_t *igc = va_arg(args, uint32_t *);
460 if (!private_handle_t::validate(hnd) && igc) {
461 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
462 if (metadata && (metadata->operation & SET_IGC)) {
463 *igc = metadata->igc;
464 res = 0;
465 }
466 }
467 } break;
468
469 case GRALLOC_MODULE_PERFORM_SET_IGC:
470 {
471 private_handle_t* hnd = va_arg(args, private_handle_t*);
472 uint32_t igc = va_arg(args, uint32_t);
473 if (!private_handle_t::validate(hnd)) {
474 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
475 if (metadata) {
476 metadata->igc = (IGC_t) igc;
477 metadata->operation |= SET_IGC;
478 res = 0;
479 }
480 }
481 } break;
482
Saurabh Shah95f83682015-10-16 10:30:04 -0700483 case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE:
484 {
485 private_handle_t* hnd = va_arg(args, private_handle_t*);
486 bool *enable = va_arg(args, bool*);
487 if (private_handle_t::validate(hnd)) {
488 return res;
489 }
490 setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable);
491 } break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700492 default:
493 break;
494 }
495 va_end(args);
496 return res;
497}