blob: 24a0aa1cda4a8ddd50f5b08fdaa526619d915697 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Naseer Ahmed7a86b842016-05-03 15:25:02 -04003 * Copyright (c) 2011-2016, 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
Naseer Ahmed7a86b842016-05-03 15:25:02 -040058static int gralloc_map_metadata(buffer_handle_t handle) {
59 private_handle_t* hnd = (private_handle_t*)handle;
60 hnd->base_metadata = 0;
61 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
62 void *mappedAddress = MAP_FAILED;
63 unsigned int size = 0;
64 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
65 mappedAddress = MAP_FAILED;
66 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
67 int ret = memalloc->map_buffer(&mappedAddress, size,
68 hnd->offset_metadata, hnd->fd_metadata);
69 if(ret || mappedAddress == MAP_FAILED) {
70 ALOGE("Could not mmap metadata for handle %p, fd=%d (%s)",
71 hnd, hnd->fd_metadata, strerror(errno));
72 return -errno;
73 }
74 hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
75 }
76 return 0;
77}
78
Iliyan Malchev202a77d2012-06-11 14:41:12 -070079static int gralloc_map(gralloc_module_t const* module,
Naseer Ahmed34d33bc2013-05-08 12:28:37 -040080 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070081{
Saurabh Shahd4749de2014-09-10 18:04:31 -070082 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080083 if(!module)
84 return -EINVAL;
85
Iliyan Malchev202a77d2012-06-11 14:41:12 -070086 private_handle_t* hnd = (private_handle_t*)handle;
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070087 unsigned int size = 0;
88 int err = 0;
89 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Saurabh Shahdbe41c52015-04-23 11:50:50 -070090 void *mappedAddress = MAP_FAILED;
91 hnd->base = 0;
Saurabh Shahdbe41c52015-04-23 11:50:50 -070092
93 // Dont map framebuffer and secure buffers
Iliyan Malchev202a77d2012-06-11 14:41:12 -070094 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
95 !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -070096 size = hnd->size;
97 err = memalloc->map_buffer(&mappedAddress, size,
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 hnd->offset, hnd->fd);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080099 if(err || mappedAddress == MAP_FAILED) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700100 ALOGE("Could not mmap handle %p, fd=%d (%s)",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 handle, hnd->fd, strerror(errno));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700102 return -errno;
103 }
104
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700105 hnd->base = uint64_t(mappedAddress) + hnd->offset;
Naseer Ahmed7a86b842016-05-03 15:25:02 -0400106 } else {
107 // Cannot map secure buffers or framebuffers, but still need to map
108 // metadata for secure buffers.
109 // If mapping a secure buffers fails, the framework needs to get
110 // an error code.
111 err = -EINVAL;
Arun Kumar K.Rda2f69b2014-09-30 15:45:37 -0700112 }
113
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700114 //Allow mapping of metadata for all buffers including secure ones, but not
115 //of framebuffer
Naseer Ahmed7a86b842016-05-03 15:25:02 -0400116 int metadata_err = gralloc_map_metadata(handle);
117 if (!err) {
118 err = metadata_err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700119 }
Naseer Ahmed7a86b842016-05-03 15:25:02 -0400120 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700121}
122
123static int gralloc_unmap(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700125{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700126 ATRACE_CALL();
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700127 int err = -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800128 if(!module)
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700129 return err;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800130
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700131 private_handle_t* hnd = (private_handle_t*)handle;
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700132 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
133 if(!memalloc)
134 return err;
135
136 if(hnd->base) {
137 err = memalloc->unmap_buffer((void*)hnd->base, hnd->size, hnd->offset);
138 if (err) {
Naseer Ahmedb8ecfbf2015-11-02 20:34:29 -0500139 ALOGE("Could not unmap memory at address %p, %s", (void*) hnd->base,
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700140 strerror(errno));
141 return -errno;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700142 }
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700143 hnd->base = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700144 }
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700145
146 if(hnd->base_metadata) {
147 unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
148 err = memalloc->unmap_buffer((void*)hnd->base_metadata,
149 size, hnd->offset_metadata);
150 if (err) {
151 ALOGE("Could not unmap memory at address %p, %s",
Naseer Ahmedb8ecfbf2015-11-02 20:34:29 -0500152 (void*) hnd->base_metadata, strerror(errno));
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700153 return -errno;
154 }
155 hnd->base_metadata = 0;
156 }
157
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700158 return 0;
159}
160
161/*****************************************************************************/
162
163static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
164
165/*****************************************************************************/
166
167int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700169{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700170 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800171 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700172 return -EINVAL;
Naseer Ahmed7a86b842016-05-03 15:25:02 -0400173 // The base address received via IPC is invalid in this process
174 // Reset it to 0 here since it will be mapped in lock()
175 private_handle_t* hnd = (private_handle_t*)handle;
176 hnd->base = 0;
177 return gralloc_map_metadata(handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700178}
179
180int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700182{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700183 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800184 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700185 return -EINVAL;
186
187 /*
188 * If the buffer has been mapped during a lock operation, it's time
189 * to un-map it. It's an error to be here with a locked buffer.
190 * NOTE: the framebuffer is handled differently and is never unmapped.
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700191 * Also base and base_metadata are reset.
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700192 */
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700193 return gralloc_unmap(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700194}
195
196int terminateBuffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197 private_handle_t* hnd)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700198{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700199 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800200 if(!module)
201 return -EINVAL;
202
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700203 /*
204 * If the buffer has been mapped during a lock operation, it's time
205 * to un-map it. It's an error to be here with a locked buffer.
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700206 * NOTE: the framebuffer is handled differently and is never unmapped.
207 * Also base and base_metadata are reset.
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700208 */
Saurabh Shahdbe41c52015-04-23 11:50:50 -0700209 return gralloc_unmap(module, hnd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700210}
211
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400212static int gralloc_map_and_invalidate (gralloc_module_t const* module,
213 buffer_handle_t handle, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700214{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700215 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800216 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700217 return -EINVAL;
218
219 int err = 0;
220 private_handle_t* hnd = (private_handle_t*)handle;
221 if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
222 if (hnd->base == 0) {
223 // we need to map for real
224 pthread_mutex_t* const lock = &sMapLock;
225 pthread_mutex_lock(lock);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400226 err = gralloc_map(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700227 pthread_mutex_unlock(lock);
228 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700229 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800230 hnd->flags & private_handle_t::PRIV_FLAGS_CACHED) {
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700231 //Invalidate if CPU reads in software and there are non-CPU
232 //writers. No need to do this for the metadata buffer as it is
233 //only read/written in software.
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800234 if ((usage & GRALLOC_USAGE_SW_READ_MASK) and
235 (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER))
236 {
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700237 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
238 err = memalloc->clean_buffer((void*)hnd->base,
239 hnd->size, hnd->offset, hnd->fd,
240 CACHE_INVALIDATE);
241 }
242 //Mark the buffer to be flushed after CPU write.
Naseer Ahmedec147982013-06-14 17:06:46 -0400243 if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
Naseer Ahmedec147982013-06-14 17:06:46 -0400244 hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
245 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700246 }
247 }
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700248
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700249 return err;
250}
251
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400252int gralloc_lock(gralloc_module_t const* module,
253 buffer_handle_t handle, int usage,
254 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
255 void** vaddr)
256{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700257 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400258 private_handle_t* hnd = (private_handle_t*)handle;
259 int err = gralloc_map_and_invalidate(module, handle, usage);
260 if(!err)
261 *vaddr = (void*)hnd->base;
262 return err;
263}
264
265int gralloc_lock_ycbcr(gralloc_module_t const* module,
266 buffer_handle_t handle, int usage,
267 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
268 struct android_ycbcr *ycbcr)
269{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700270 ATRACE_CALL();
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400271 private_handle_t* hnd = (private_handle_t*)handle;
272 int err = gralloc_map_and_invalidate(module, handle, usage);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400273 if(!err)
274 err = getYUVPlaneInfo(hnd, ycbcr);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400275 return err;
276}
277
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700278int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700279 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700280{
Saurabh Shahd4749de2014-09-10 18:04:31 -0700281 ATRACE_CALL();
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800282 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700283 return -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800284
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400285 int err = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700286 private_handle_t* hnd = (private_handle_t*)handle;
287
Saurabh Shah9ff53a92014-09-17 16:40:44 -0700288 IMemAlloc* memalloc = getAllocator(hnd->flags);
289 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
290 err = memalloc->clean_buffer((void*)hnd->base,
291 hnd->size, hnd->offset, hnd->fd,
292 CACHE_CLEAN);
293 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700294 }
295
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400296 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700297}
298
299/*****************************************************************************/
300
301int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302 int operation, ... )
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700303{
304 int res = -EINVAL;
305 va_list args;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800306 if(!module)
307 return res;
308
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700309 va_start(args, operation);
310 switch (operation) {
311 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
312 {
313 int fd = va_arg(args, int);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700314 unsigned int size = va_arg(args, unsigned int);
315 unsigned int offset = va_arg(args, unsigned int);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700316 void* base = va_arg(args, void*);
317 int width = va_arg(args, int);
318 int height = va_arg(args, int);
319 int format = va_arg(args, int);
320
321 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700322 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700323 private_handle_t::sNumFds, private_handle_t::sNumInts());
Ramakant Singh04b6b242015-03-23 15:01:12 +0530324 if (hnd) {
325 hnd->magic = private_handle_t::sMagic;
326 hnd->fd = fd;
327 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
328 hnd->size = size;
329 hnd->offset = offset;
330 hnd->base = uint64_t(base) + offset;
331 hnd->gpuaddr = 0;
332 hnd->width = width;
333 hnd->height = height;
334 hnd->format = format;
335 *handle = (native_handle_t *)hnd;
336 res = 0;
337 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700338 break;
339
340 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800341 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
342 {
343 int width = va_arg(args, int);
344 int format = va_arg(args, int);
345 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800346 int alignedw = 0, alignedh = 0;
347 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800348 0, format, 0, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800349 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800350 res = 0;
351 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700352
Naseer Ahmeda978f952013-09-26 14:36:28 -0400353 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
354 {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700355 const private_handle_t* hnd = va_arg(args, private_handle_t*);
Naseer Ahmeda978f952013-09-26 14:36:28 -0400356 int *stride = va_arg(args, int *);
357 if (private_handle_t::validate(hnd)) {
358 return res;
359 }
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700360
361 int alignedw = 0, alignedh = 0;
362 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
363 *stride = alignedw;
364
Naseer Ahmeda978f952013-09-26 14:36:28 -0400365 res = 0;
366 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700367
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530368 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
369 {
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700370 const private_handle_t* hnd = va_arg(args, private_handle_t*);
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530371 int *stride = va_arg(args, int *);
372 int *height = va_arg(args, int *);
373 if (private_handle_t::validate(hnd)) {
374 return res;
375 }
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700376
377 int alignedw = 0, alignedh = 0;
378 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
379 *stride = alignedw;
380 *height = alignedh;
381
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530382 res = 0;
383 } break;
384
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700385 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
386 {
387 int width = va_arg(args, int);
388 int height = va_arg(args, int);
389 int format = va_arg(args, int);
390 int usage = va_arg(args, int);
391 int *alignedWidth = va_arg(args, int *);
392 int *alignedHeight = va_arg(args, int *);
393 int *tileEnabled = va_arg(args,int *);
Sushil Chauhane61fac52015-04-30 17:14:37 -0700394 *tileEnabled = isUBwcEnabled(format, usage) ||
395 isMacroTileEnabled(format, usage);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700396 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800397 height, format, usage, *alignedWidth, *alignedHeight);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700398 res = 0;
399 } break;
400
Shuzhen Wangc502c872014-01-28 16:10:42 -0800401 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
402 {
403 private_handle_t* hnd = va_arg(args, private_handle_t*);
404 int *color_space = va_arg(args, int *);
405 if (private_handle_t::validate(hnd)) {
406 return res;
407 }
408 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
409 if(metadata && metadata->operation & UPDATE_COLOR_SPACE) {
410 *color_space = metadata->colorSpace;
411 res = 0;
412 }
413 } break;
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800414
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400415 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
416 {
417 private_handle_t* hnd = va_arg(args, private_handle_t*);
418 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400419 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400420 res = getYUVPlaneInfo(hnd, ycbcr);
421 }
422 } break;
423
Arun Kumar K.R563fbde2014-11-24 08:51:17 -0800424 case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO:
425 {
426 private_handle_t* hnd = va_arg(args, private_handle_t*);
427 int *map_secure_buffer = va_arg(args, int *);
428 if (private_handle_t::validate(hnd)) {
429 return res;
430 }
431 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
432 if(metadata && metadata->operation & MAP_SECURE_BUFFER) {
433 *map_secure_buffer = metadata->mapSecureBuffer;
434 res = 0;
435 } else {
436 *map_secure_buffer = 0;
437 }
438 } break;
439
Sushil Chauhana9d47002015-02-18 14:55:03 -0800440 case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG:
441 {
442 private_handle_t* hnd = va_arg(args, private_handle_t*);
443 int *flag = va_arg(args, int *);
444 if (private_handle_t::validate(hnd)) {
445 return res;
446 }
447 *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
Sushil Chauhane7acc3c2015-06-23 16:22:30 -0700448 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
449 if (metadata && (metadata->operation & LINEAR_FORMAT)) {
450 *flag = 0;
451 }
Sushil Chauhana9d47002015-02-18 14:55:03 -0800452 res = 0;
453 } break;
454
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700455 case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS:
456 {
457 private_handle_t* hnd = va_arg(args, private_handle_t*);
Sushil Chauhanc85b65b2015-04-30 11:05:36 -0700458 void** rgb_data = va_arg(args, void**);
Sushil Chauhan7dd3a432015-04-08 15:54:42 -0700459 if (!private_handle_t::validate(hnd)) {
460 res = getRgbDataAddress(hnd, rgb_data);
461 }
462 } break;
463
Dileep Marchya1a7e1f12015-09-25 19:11:57 -0700464 case GRALLOC_MODULE_PERFORM_GET_IGC:
465 {
466 private_handle_t* hnd = va_arg(args, private_handle_t*);
467 uint32_t *igc = va_arg(args, uint32_t *);
468 if (!private_handle_t::validate(hnd) && igc) {
469 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
470 if (metadata && (metadata->operation & SET_IGC)) {
471 *igc = metadata->igc;
472 res = 0;
473 }
474 }
475 } break;
476
477 case GRALLOC_MODULE_PERFORM_SET_IGC:
Dileep Marchyaa2129342016-01-05 18:15:57 -0800478 res = 0;
479 break;
Dileep Marchya1a7e1f12015-09-25 19:11:57 -0700480
Saurabh Shah95f83682015-10-16 10:30:04 -0700481 case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE:
482 {
483 private_handle_t* hnd = va_arg(args, private_handle_t*);
Saurabh Shahb8067a42015-11-06 16:52:02 -0800484 uint32_t *enable = va_arg(args, uint32_t*);
Sushil Chauhan76466212016-01-05 18:09:22 -0800485 if (!private_handle_t::validate(hnd)) {
486 setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable);
487 res = 0;
Saurabh Shah95f83682015-10-16 10:30:04 -0700488 }
Saurabh Shah95f83682015-10-16 10:30:04 -0700489 } break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700490 default:
491 break;
492 }
493 va_end(args);
494 return res;
495}