blob: 5ba737aadd0c3526034a6a2b25b7d32dbf23f09e [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Shuzhen Wangc502c872014-01-28 16:10:42 -08003 * Copyright (c) 2011-2014, 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;
66 void *mappedAddress;
67 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
68 !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070069 unsigned int size = hnd->size;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070070 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070071 int err = memalloc->map_buffer(&mappedAddress, size,
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 hnd->offset, hnd->fd);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080073 if(err || mappedAddress == MAP_FAILED) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070074 ALOGE("Could not mmap handle %p, fd=%d (%s)",
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 handle, hnd->fd, strerror(errno));
Iliyan Malchev202a77d2012-06-11 14:41:12 -070076 hnd->base = 0;
77 return -errno;
78 }
79
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070080 hnd->base = uint64_t(mappedAddress) + hnd->offset;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080081 mappedAddress = MAP_FAILED;
82 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
83 err = memalloc->map_buffer(&mappedAddress, size,
84 hnd->offset_metadata, hnd->fd_metadata);
85 if(err || mappedAddress == MAP_FAILED) {
86 ALOGE("Could not mmap handle %p, fd=%d (%s)",
87 handle, hnd->fd_metadata, strerror(errno));
88 hnd->base_metadata = 0;
89 return -errno;
90 }
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070091 hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070092 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070093 return 0;
94}
95
96static int gralloc_unmap(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070097 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070098{
Saurabh Shahd4749de2014-09-10 18:04:31 -070099 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800100 if(!module)
101 return -EINVAL;
102
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700103 private_handle_t* hnd = (private_handle_t*)handle;
104 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
105 int err = -EINVAL;
106 void* base = (void*)hnd->base;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700107 unsigned int size = hnd->size;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700108 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800109 if(memalloc != NULL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700110 err = memalloc->unmap_buffer(base, size, hnd->offset);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800111 if (err) {
112 ALOGE("Could not unmap memory at address %p", base);
113 }
114 base = (void*)hnd->base_metadata;
115 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
116 err = memalloc->unmap_buffer(base, size, hnd->offset_metadata);
117 if (err) {
118 ALOGE("Could not unmap memory at address %p", base);
119 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700120 }
121 }
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800122 /* need to initialize the pointer to NULL otherwise unmapping for that
123 * buffer happens twice which leads to crash */
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700124 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800125 hnd->base_metadata = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700126 return 0;
127}
128
129/*****************************************************************************/
130
131static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
132
133/*****************************************************************************/
134
135int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700137{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700138 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800139 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700140 return -EINVAL;
141
142 // In this implementation, we don't need to do anything here
143
144 /* NOTE: we need to initialize the buffer as not mapped/not locked
145 * because it shouldn't when this function is called the first time
146 * in a new process. Ideally these flags shouldn't be part of the
147 * handle, but instead maintained in the kernel or at least
148 * out-of-line
149 */
150
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700151 private_handle_t* hnd = (private_handle_t*)handle;
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700152 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800153 hnd->base_metadata = 0;
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400154 int err = gralloc_map(module, handle);
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700155 if (err) {
156 ALOGE("%s: gralloc_map failed", __FUNCTION__);
157 return err;
158 }
159
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700160 return 0;
161}
162
163int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700165{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700166 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800167 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700168 return -EINVAL;
169
170 /*
171 * If the buffer has been mapped during a lock operation, it's time
172 * to un-map it. It's an error to be here with a locked buffer.
173 * NOTE: the framebuffer is handled differently and is never unmapped.
174 */
175
176 private_handle_t* hnd = (private_handle_t*)handle;
177
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700178 if (hnd->base != 0) {
179 gralloc_unmap(module, handle);
180 }
181 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800182 hnd->base_metadata = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700183 return 0;
184}
185
186int terminateBuffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 private_handle_t* hnd)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700188{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700189 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800190 if(!module)
191 return -EINVAL;
192
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700193 /*
194 * If the buffer has been mapped during a lock operation, it's time
195 * to un-map it. It's an error to be here with a locked buffer.
196 */
197
198 if (hnd->base != 0) {
199 // this buffer was mapped, unmap it now
200 if (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_PMEM |
201 private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP |
202 private_handle_t::PRIV_FLAGS_USES_ASHMEM |
203 private_handle_t::PRIV_FLAGS_USES_ION)) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700204 gralloc_unmap(module, hnd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700205 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 ALOGE("terminateBuffer: unmapping a non pmem/ashmem buffer flags = 0x%x",
207 hnd->flags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700208 gralloc_unmap(module, hnd);
209 }
210 }
211
212 return 0;
213}
214
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400215static int gralloc_map_and_invalidate (gralloc_module_t const* module,
216 buffer_handle_t handle, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700217{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700218 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800219 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700220 return -EINVAL;
221
222 int err = 0;
223 private_handle_t* hnd = (private_handle_t*)handle;
224 if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
225 if (hnd->base == 0) {
226 // we need to map for real
227 pthread_mutex_t* const lock = &sMapLock;
228 pthread_mutex_lock(lock);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400229 err = gralloc_map(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700230 pthread_mutex_unlock(lock);
231 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700232 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and
233 not useUncached(usage)) {
234 bool nonCPUWriters = usage & (
235 GRALLOC_USAGE_HW_RENDER |
236 GRALLOC_USAGE_HW_FB |
237 GRALLOC_USAGE_HW_VIDEO_ENCODER |
238 GRALLOC_USAGE_HW_CAMERA_WRITE);
239
240 //Invalidate if CPU reads in software and there are non-CPU
241 //writers. No need to do this for the metadata buffer as it is
242 //only read/written in software.
243 //Corner case: If we reach here with a READ_RARELY, then there must
244 //be a WRITE_OFTEN that caused caching to be used.
245 if ((usage & GRALLOC_USAGE_SW_READ_MASK) and nonCPUWriters) {
246 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
247 err = memalloc->clean_buffer((void*)hnd->base,
248 hnd->size, hnd->offset, hnd->fd,
249 CACHE_INVALIDATE);
250 }
251 //Mark the buffer to be flushed after CPU write.
252 //Corner case: If we reach here with a WRITE_RARELY, then there
253 //must be a READ_OFTEN that caused caching to be used.
Naseer Ahmedec147982013-06-14 17:06:46 -0400254 if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
Naseer Ahmedec147982013-06-14 17:06:46 -0400255 hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
256 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700257 }
258 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700259
260 if(useUncached(usage))
261 hnd->flags |= private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
262
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700263 return err;
264}
265
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400266int gralloc_lock(gralloc_module_t const* module,
267 buffer_handle_t handle, int usage,
268 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
269 void** vaddr)
270{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700271 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400272 private_handle_t* hnd = (private_handle_t*)handle;
273 int err = gralloc_map_and_invalidate(module, handle, usage);
274 if(!err)
275 *vaddr = (void*)hnd->base;
276 return err;
277}
278
279int gralloc_lock_ycbcr(gralloc_module_t const* module,
280 buffer_handle_t handle, int usage,
281 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
282 struct android_ycbcr *ycbcr)
283{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700284 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400285 private_handle_t* hnd = (private_handle_t*)handle;
286 int err = gralloc_map_and_invalidate(module, handle, usage);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400287 if(!err)
288 err = getYUVPlaneInfo(hnd, ycbcr);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400289 return err;
290}
291
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700292int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700293 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700294{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700295 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800296 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700297 return -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800298
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400299 int err = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700300 private_handle_t* hnd = (private_handle_t*)handle;
301
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700302 IMemAlloc* memalloc = getAllocator(hnd->flags);
303 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
304 err = memalloc->clean_buffer((void*)hnd->base,
305 hnd->size, hnd->offset, hnd->fd,
306 CACHE_CLEAN);
307 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700308 }
309
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700310 if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH)
311 hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
312
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400313 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700314}
315
316/*****************************************************************************/
317
318int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700319 int operation, ... )
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700320{
321 int res = -EINVAL;
322 va_list args;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800323 if(!module)
324 return res;
325
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700326 va_start(args, operation);
327 switch (operation) {
328 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
329 {
330 int fd = va_arg(args, int);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700331 unsigned int size = va_arg(args, unsigned int);
332 unsigned int offset = va_arg(args, unsigned int);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700333 void* base = va_arg(args, void*);
334 int width = va_arg(args, int);
335 int height = va_arg(args, int);
336 int format = va_arg(args, int);
337
338 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700339 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700340 private_handle_t::sNumFds, private_handle_t::sNumInts());
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700341 hnd->magic = private_handle_t::sMagic;
342 hnd->fd = fd;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700343 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700344 hnd->size = size;
345 hnd->offset = offset;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700346 hnd->base = uint64_t(base) + offset;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700347 hnd->gpuaddr = 0;
348 hnd->width = width;
349 hnd->height = height;
350 hnd->format = format;
351 *handle = (native_handle_t *)hnd;
352 res = 0;
353 break;
354
355 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800356 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
357 {
358 int width = va_arg(args, int);
359 int format = va_arg(args, int);
360 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800361 int alignedw = 0, alignedh = 0;
362 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700363 0, format, false, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800364 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800365 res = 0;
366 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700367
Naseer Ahmeda978f952013-09-26 14:36:28 -0400368 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
369 {
370 private_handle_t* hnd = va_arg(args, private_handle_t*);
371 int *stride = va_arg(args, int *);
372 if (private_handle_t::validate(hnd)) {
373 return res;
374 }
375 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
376 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
377 *stride = metadata->bufferDim.sliceWidth;
378 } else {
379 *stride = hnd->width;
380 }
381 res = 0;
382 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700383
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530384 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
385 {
386 private_handle_t* hnd = va_arg(args, private_handle_t*);
387 int *stride = va_arg(args, int *);
388 int *height = va_arg(args, int *);
389 if (private_handle_t::validate(hnd)) {
390 return res;
391 }
392 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
393 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
394 *stride = metadata->bufferDim.sliceWidth;
395 *height = metadata->bufferDim.sliceHeight;
396 } else {
397 *stride = hnd->width;
398 *height = hnd->height;
399 }
400 res = 0;
401 } break;
402
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700403 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
404 {
405 int width = va_arg(args, int);
406 int height = va_arg(args, int);
407 int format = va_arg(args, int);
408 int usage = va_arg(args, int);
409 int *alignedWidth = va_arg(args, int *);
410 int *alignedHeight = va_arg(args, int *);
411 int *tileEnabled = va_arg(args,int *);
412 *tileEnabled = isMacroTileEnabled(format, usage);
413 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
414 height, format, *tileEnabled, *alignedWidth,
415 *alignedHeight);
416 res = 0;
417 } break;
418
Shuzhen Wangc502c872014-01-28 16:10:42 -0800419 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
420 {
421 private_handle_t* hnd = va_arg(args, private_handle_t*);
422 int *color_space = va_arg(args, int *);
423 if (private_handle_t::validate(hnd)) {
424 return res;
425 }
426 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
427 if(metadata && metadata->operation & UPDATE_COLOR_SPACE) {
428 *color_space = metadata->colorSpace;
429 res = 0;
430 }
431 } break;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400432 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
433 {
434 private_handle_t* hnd = va_arg(args, private_handle_t*);
435 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400436 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400437 res = getYUVPlaneInfo(hnd, ycbcr);
438 }
439 } break;
440
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700441 default:
442 break;
443 }
444 va_end(args);
445 return res;
446}