blob: 13e662ad2851bb0636cb1457ba769007f258f176 [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
18#include <limits.h>
19#include <errno.h>
20#include <pthread.h>
21#include <unistd.h>
22#include <string.h>
23#include <stdarg.h>
24
25#include <sys/mman.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <sys/ioctl.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070029
30#include <cutils/log.h>
31#include <cutils/atomic.h>
Saurabh Shahd4749de2014-09-10 18:04:31 -070032#include <utils/Trace.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070033
34#include <hardware/hardware.h>
35#include <hardware/gralloc.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070036
37#include "gralloc_priv.h"
38#include "gr.h"
39#include "alloc_controller.h"
40#include "memalloc.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080041#include <qdMetaData.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070042
Saurabh Shahd4749de2014-09-10 18:04:31 -070043#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
44
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 }
Naseer Ahmedec147982013-06-14 17:06:46 -0400232 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
233 //Invalidate if reading in software. No need to do this for the
234 //metadata buffer as it is only read/written in software.
235 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
236 err = memalloc->clean_buffer((void*)hnd->base,
237 hnd->size, hnd->offset, hnd->fd,
238 CACHE_INVALIDATE);
239 if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
240 // Mark the buffer to be flushed after cpu read/write
241 hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
242 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700243 }
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400244 } else {
245 hnd->flags |= private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700246 }
247 return err;
248}
249
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400250int gralloc_lock(gralloc_module_t const* module,
251 buffer_handle_t handle, int usage,
252 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
253 void** vaddr)
254{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700255 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400256 private_handle_t* hnd = (private_handle_t*)handle;
257 int err = gralloc_map_and_invalidate(module, handle, usage);
258 if(!err)
259 *vaddr = (void*)hnd->base;
260 return err;
261}
262
263int gralloc_lock_ycbcr(gralloc_module_t const* module,
264 buffer_handle_t handle, int usage,
265 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
266 struct android_ycbcr *ycbcr)
267{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700268 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400269 private_handle_t* hnd = (private_handle_t*)handle;
270 int err = gralloc_map_and_invalidate(module, handle, usage);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400271 if(!err)
272 err = getYUVPlaneInfo(hnd, ycbcr);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400273 return err;
274}
275
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700276int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700278{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700279 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800280 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700281 return -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800282
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400283 int err = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700284 private_handle_t* hnd = (private_handle_t*)handle;
285
Naseer Ahmedec147982013-06-14 17:06:46 -0400286 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
Naseer Ahmed69662ac2013-08-28 13:16:48 -0400287 IMemAlloc* memalloc = getAllocator(hnd->flags);
Naseer Ahmedec147982013-06-14 17:06:46 -0400288 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
289 err = memalloc->clean_buffer((void*)hnd->base,
290 hnd->size, hnd->offset, hnd->fd,
291 CACHE_CLEAN_AND_INVALIDATE);
292 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
293 } else if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
294 hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
295 } else {
296 //Probably a round about way to do this, but this avoids adding new
297 //flags
298 err = memalloc->clean_buffer((void*)hnd->base,
299 hnd->size, hnd->offset, hnd->fd,
300 CACHE_INVALIDATE);
301 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700302 }
303
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400304 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700305}
306
307/*****************************************************************************/
308
309int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700310 int operation, ... )
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700311{
312 int res = -EINVAL;
313 va_list args;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800314 if(!module)
315 return res;
316
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700317 va_start(args, operation);
318 switch (operation) {
319 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
320 {
321 int fd = va_arg(args, int);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700322 unsigned int size = va_arg(args, unsigned int);
323 unsigned int offset = va_arg(args, unsigned int);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700324 void* base = va_arg(args, void*);
325 int width = va_arg(args, int);
326 int height = va_arg(args, int);
327 int format = va_arg(args, int);
328
329 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700330 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700331 private_handle_t::sNumFds, private_handle_t::sNumInts());
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700332 hnd->magic = private_handle_t::sMagic;
333 hnd->fd = fd;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700334 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700335 hnd->size = size;
336 hnd->offset = offset;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700337 hnd->base = uint64_t(base) + offset;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700338 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 break;
345
346 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800347 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
348 {
349 int width = va_arg(args, int);
350 int format = va_arg(args, int);
351 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800352 int alignedw = 0, alignedh = 0;
353 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700354 0, format, false, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800355 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800356 res = 0;
357 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700358
Naseer Ahmeda978f952013-09-26 14:36:28 -0400359 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
360 {
361 private_handle_t* hnd = va_arg(args, private_handle_t*);
362 int *stride = va_arg(args, int *);
363 if (private_handle_t::validate(hnd)) {
364 return res;
365 }
366 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
367 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
368 *stride = metadata->bufferDim.sliceWidth;
369 } else {
370 *stride = hnd->width;
371 }
372 res = 0;
373 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700374
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530375 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
376 {
377 private_handle_t* hnd = va_arg(args, private_handle_t*);
378 int *stride = va_arg(args, int *);
379 int *height = va_arg(args, int *);
380 if (private_handle_t::validate(hnd)) {
381 return res;
382 }
383 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
384 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
385 *stride = metadata->bufferDim.sliceWidth;
386 *height = metadata->bufferDim.sliceHeight;
387 } else {
388 *stride = hnd->width;
389 *height = hnd->height;
390 }
391 res = 0;
392 } break;
393
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700394 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
395 {
396 int width = va_arg(args, int);
397 int height = va_arg(args, int);
398 int format = va_arg(args, int);
399 int usage = va_arg(args, int);
400 int *alignedWidth = va_arg(args, int *);
401 int *alignedHeight = va_arg(args, int *);
402 int *tileEnabled = va_arg(args,int *);
403 *tileEnabled = isMacroTileEnabled(format, usage);
404 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
405 height, format, *tileEnabled, *alignedWidth,
406 *alignedHeight);
407 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;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400423 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
424 {
425 private_handle_t* hnd = va_arg(args, private_handle_t*);
426 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400427 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400428 res = getYUVPlaneInfo(hnd, ycbcr);
429 }
430 } break;
431
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700432 default:
433 break;
434 }
435 va_end(args);
436 return res;
437}