Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Naseer Ahmed | a163b73 | 2013-02-12 14:53:33 -0500 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 4 | * |
| 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> |
| 29 | #include <linux/ashmem.h> |
| 30 | |
| 31 | #include <cutils/log.h> |
| 32 | #include <cutils/atomic.h> |
| 33 | #include <cutils/ashmem.h> |
| 34 | |
| 35 | #include <hardware/hardware.h> |
| 36 | #include <hardware/gralloc.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 37 | #include <linux/android_pmem.h> |
| 38 | |
| 39 | #include "gralloc_priv.h" |
| 40 | #include "gr.h" |
| 41 | #include "alloc_controller.h" |
| 42 | #include "memalloc.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 43 | #include <qdMetaData.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 44 | |
| 45 | using namespace gralloc; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 46 | /*****************************************************************************/ |
| 47 | |
| 48 | // Return the type of allocator - |
| 49 | // these are used for mapping/unmapping |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 50 | static IMemAlloc* getAllocator(int flags) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 51 | { |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 52 | IMemAlloc* memalloc; |
| 53 | IAllocController* alloc_ctrl = IAllocController::getInstance(); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 54 | memalloc = alloc_ctrl->getAllocator(flags); |
| 55 | return memalloc; |
| 56 | } |
| 57 | |
Steve Kondik | 5164dda | 2015-11-01 02:51:41 -0800 | [diff] [blame] | 58 | static int gralloc_map(gralloc_module_t const* /*module*/, |
Naseer Ahmed | cc785bf | 2013-05-08 12:28:37 -0400 | [diff] [blame] | 59 | buffer_handle_t handle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 60 | { |
| 61 | private_handle_t* hnd = (private_handle_t*)handle; |
| 62 | void *mappedAddress; |
| 63 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) && |
| 64 | !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) { |
| 65 | size_t size = hnd->size; |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 66 | IMemAlloc* memalloc = getAllocator(hnd->flags) ; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 67 | int err = memalloc->map_buffer(&mappedAddress, size, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 68 | hnd->offset, hnd->fd); |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 69 | if(err || mappedAddress == MAP_FAILED) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 70 | ALOGE("Could not mmap handle %p, fd=%d (%s)", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 71 | handle, hnd->fd, strerror(errno)); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 72 | hnd->base = 0; |
| 73 | return -errno; |
| 74 | } |
| 75 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 76 | hnd->base = intptr_t(mappedAddress) + hnd->offset; |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 77 | mappedAddress = MAP_FAILED; |
| 78 | size = ROUND_UP_PAGESIZE(sizeof(MetaData_t)); |
| 79 | err = memalloc->map_buffer(&mappedAddress, size, |
| 80 | hnd->offset_metadata, hnd->fd_metadata); |
| 81 | if(err || mappedAddress == MAP_FAILED) { |
| 82 | ALOGE("Could not mmap handle %p, fd=%d (%s)", |
| 83 | handle, hnd->fd_metadata, strerror(errno)); |
| 84 | hnd->base_metadata = 0; |
| 85 | return -errno; |
| 86 | } |
| 87 | hnd->base_metadata = intptr_t(mappedAddress) + hnd->offset_metadata; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 88 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Steve Kondik | 5164dda | 2015-11-01 02:51:41 -0800 | [diff] [blame] | 92 | static int gralloc_unmap(gralloc_module_t const* /*module*/, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 93 | buffer_handle_t handle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 94 | { |
| 95 | private_handle_t* hnd = (private_handle_t*)handle; |
| 96 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { |
| 97 | int err = -EINVAL; |
| 98 | void* base = (void*)hnd->base; |
| 99 | size_t size = hnd->size; |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 100 | IMemAlloc* memalloc = getAllocator(hnd->flags) ; |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 101 | if(memalloc != NULL) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 102 | err = memalloc->unmap_buffer(base, size, hnd->offset); |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 103 | if (err) { |
| 104 | ALOGE("Could not unmap memory at address %p", base); |
| 105 | } |
| 106 | base = (void*)hnd->base_metadata; |
| 107 | size = ROUND_UP_PAGESIZE(sizeof(MetaData_t)); |
| 108 | err = memalloc->unmap_buffer(base, size, hnd->offset_metadata); |
| 109 | if (err) { |
| 110 | ALOGE("Could not unmap memory at address %p", base); |
| 111 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
Ramkumar Radhakrishnan | 7bf31c3 | 2013-01-28 22:51:51 -0800 | [diff] [blame] | 114 | /* need to initialize the pointer to NULL otherwise unmapping for that |
| 115 | * buffer happens twice which leads to crash */ |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 116 | hnd->base = 0; |
Ramkumar Radhakrishnan | 7bf31c3 | 2013-01-28 22:51:51 -0800 | [diff] [blame] | 117 | hnd->base_metadata = 0; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /*****************************************************************************/ |
| 122 | |
| 123 | static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER; |
| 124 | |
| 125 | /*****************************************************************************/ |
| 126 | |
| 127 | int gralloc_register_buffer(gralloc_module_t const* module, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 128 | buffer_handle_t handle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 129 | { |
| 130 | if (private_handle_t::validate(handle) < 0) |
| 131 | return -EINVAL; |
| 132 | |
| 133 | // In this implementation, we don't need to do anything here |
| 134 | |
| 135 | /* NOTE: we need to initialize the buffer as not mapped/not locked |
| 136 | * because it shouldn't when this function is called the first time |
| 137 | * in a new process. Ideally these flags shouldn't be part of the |
| 138 | * handle, but instead maintained in the kernel or at least |
| 139 | * out-of-line |
| 140 | */ |
| 141 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 142 | private_handle_t* hnd = (private_handle_t*)handle; |
Kinjal Bhavsar | 139e162 | 2012-09-10 12:35:11 -0700 | [diff] [blame] | 143 | hnd->base = 0; |
Ramkumar Radhakrishnan | 7bf31c3 | 2013-01-28 22:51:51 -0800 | [diff] [blame] | 144 | hnd->base_metadata = 0; |
Naseer Ahmed | cc785bf | 2013-05-08 12:28:37 -0400 | [diff] [blame] | 145 | int err = gralloc_map(module, handle); |
Kinjal Bhavsar | 139e162 | 2012-09-10 12:35:11 -0700 | [diff] [blame] | 146 | if (err) { |
| 147 | ALOGE("%s: gralloc_map failed", __FUNCTION__); |
| 148 | return err; |
| 149 | } |
| 150 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int gralloc_unregister_buffer(gralloc_module_t const* module, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 155 | buffer_handle_t handle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 156 | { |
| 157 | if (private_handle_t::validate(handle) < 0) |
| 158 | return -EINVAL; |
| 159 | |
| 160 | /* |
| 161 | * If the buffer has been mapped during a lock operation, it's time |
| 162 | * to un-map it. It's an error to be here with a locked buffer. |
| 163 | * NOTE: the framebuffer is handled differently and is never unmapped. |
| 164 | */ |
| 165 | |
| 166 | private_handle_t* hnd = (private_handle_t*)handle; |
| 167 | |
Kinjal Bhavsar | 139e162 | 2012-09-10 12:35:11 -0700 | [diff] [blame] | 168 | if (hnd->base != 0) { |
| 169 | gralloc_unmap(module, handle); |
| 170 | } |
| 171 | hnd->base = 0; |
Ramkumar Radhakrishnan | 7bf31c3 | 2013-01-28 22:51:51 -0800 | [diff] [blame] | 172 | hnd->base_metadata = 0; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int terminateBuffer(gralloc_module_t const* module, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 177 | private_handle_t* hnd) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 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 | */ |
| 183 | |
| 184 | if (hnd->base != 0) { |
| 185 | // this buffer was mapped, unmap it now |
| 186 | if (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_PMEM | |
| 187 | private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP | |
| 188 | private_handle_t::PRIV_FLAGS_USES_ASHMEM | |
| 189 | private_handle_t::PRIV_FLAGS_USES_ION)) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 190 | gralloc_unmap(module, hnd); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 191 | } else { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 192 | ALOGE("terminateBuffer: unmapping a non pmem/ashmem buffer flags = 0x%x", |
| 193 | hnd->flags); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 194 | gralloc_unmap(module, hnd); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Naseer Ahmed | cc785bf | 2013-05-08 12:28:37 -0400 | [diff] [blame] | 201 | static int gralloc_map_and_invalidate (gralloc_module_t const* module, |
| 202 | buffer_handle_t handle, int usage) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 203 | { |
| 204 | if (private_handle_t::validate(handle) < 0) |
| 205 | return -EINVAL; |
| 206 | |
| 207 | int err = 0; |
| 208 | private_handle_t* hnd = (private_handle_t*)handle; |
| 209 | if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) { |
| 210 | if (hnd->base == 0) { |
| 211 | // we need to map for real |
| 212 | pthread_mutex_t* const lock = &sMapLock; |
| 213 | pthread_mutex_lock(lock); |
Naseer Ahmed | cc785bf | 2013-05-08 12:28:37 -0400 | [diff] [blame] | 214 | err = gralloc_map(module, handle); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 215 | pthread_mutex_unlock(lock); |
| 216 | } |
Saurabh Shah | c282508 | 2014-09-17 16:40:44 -0700 | [diff] [blame] | 217 | if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and |
Saurabh Shah | 74f3cb9 | 2014-12-19 10:05:41 -0800 | [diff] [blame] | 218 | hnd->flags & private_handle_t::PRIV_FLAGS_CACHED) { |
Saurabh Shah | c282508 | 2014-09-17 16:40:44 -0700 | [diff] [blame] | 219 | //Invalidate if CPU reads in software and there are non-CPU |
| 220 | //writers. No need to do this for the metadata buffer as it is |
| 221 | //only read/written in software. |
Saurabh Shah | 74f3cb9 | 2014-12-19 10:05:41 -0800 | [diff] [blame] | 222 | if ((usage & GRALLOC_USAGE_SW_READ_MASK) and |
| 223 | (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER)) |
| 224 | { |
Saurabh Shah | c282508 | 2014-09-17 16:40:44 -0700 | [diff] [blame] | 225 | IMemAlloc* memalloc = getAllocator(hnd->flags) ; |
| 226 | err = memalloc->clean_buffer((void*)hnd->base, |
| 227 | hnd->size, hnd->offset, hnd->fd, |
| 228 | CACHE_INVALIDATE); |
| 229 | } |
| 230 | //Mark the buffer to be flushed after CPU write. |
Naseer Ahmed | ec14798 | 2013-06-14 17:06:46 -0400 | [diff] [blame] | 231 | if (usage & GRALLOC_USAGE_SW_WRITE_MASK) { |
Naseer Ahmed | ec14798 | 2013-06-14 17:06:46 -0400 | [diff] [blame] | 232 | hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; |
| 233 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
Saurabh Shah | c282508 | 2014-09-17 16:40:44 -0700 | [diff] [blame] | 236 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 237 | return err; |
| 238 | } |
| 239 | |
Naseer Ahmed | cc785bf | 2013-05-08 12:28:37 -0400 | [diff] [blame] | 240 | int gralloc_lock(gralloc_module_t const* module, |
| 241 | buffer_handle_t handle, int usage, |
| 242 | int /*l*/, int /*t*/, int /*w*/, int /*h*/, |
| 243 | void** vaddr) |
| 244 | { |
| 245 | private_handle_t* hnd = (private_handle_t*)handle; |
| 246 | int err = gralloc_map_and_invalidate(module, handle, usage); |
| 247 | if(!err) |
| 248 | *vaddr = (void*)hnd->base; |
| 249 | return err; |
| 250 | } |
| 251 | |
| 252 | int gralloc_lock_ycbcr(gralloc_module_t const* module, |
| 253 | buffer_handle_t handle, int usage, |
| 254 | int /*l*/, int /*t*/, int /*w*/, int /*h*/, |
| 255 | struct android_ycbcr *ycbcr) |
| 256 | { |
| 257 | private_handle_t* hnd = (private_handle_t*)handle; |
| 258 | int err = gralloc_map_and_invalidate(module, handle, usage); |
Naseer Ahmed | 57b5245 | 2014-04-08 20:23:47 -0400 | [diff] [blame] | 259 | if(!err) |
| 260 | err = getYUVPlaneInfo(hnd, ycbcr); |
Naseer Ahmed | cc785bf | 2013-05-08 12:28:37 -0400 | [diff] [blame] | 261 | return err; |
| 262 | } |
| 263 | |
Steve Kondik | 5164dda | 2015-11-01 02:51:41 -0800 | [diff] [blame] | 264 | int gralloc_unlock(gralloc_module_t const* /*module*/, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 265 | buffer_handle_t handle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 266 | { |
| 267 | if (private_handle_t::validate(handle) < 0) |
| 268 | return -EINVAL; |
Naseer Ahmed | aeab91f | 2013-03-20 21:01:19 -0400 | [diff] [blame] | 269 | int err = 0; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 270 | private_handle_t* hnd = (private_handle_t*)handle; |
| 271 | |
Saurabh Shah | c282508 | 2014-09-17 16:40:44 -0700 | [diff] [blame] | 272 | IMemAlloc* memalloc = getAllocator(hnd->flags); |
| 273 | if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) { |
| 274 | err = memalloc->clean_buffer((void*)hnd->base, |
| 275 | hnd->size, hnd->offset, hnd->fd, |
| 276 | CACHE_CLEAN); |
| 277 | hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Naseer Ahmed | aeab91f | 2013-03-20 21:01:19 -0400 | [diff] [blame] | 280 | return err; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /*****************************************************************************/ |
| 284 | |
Steve Kondik | 5164dda | 2015-11-01 02:51:41 -0800 | [diff] [blame] | 285 | int gralloc_perform(struct gralloc_module_t const* /*module*/, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 286 | int operation, ... ) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 287 | { |
| 288 | int res = -EINVAL; |
| 289 | va_list args; |
| 290 | va_start(args, operation); |
| 291 | switch (operation) { |
| 292 | case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER: |
| 293 | { |
| 294 | int fd = va_arg(args, int); |
| 295 | size_t size = va_arg(args, size_t); |
| 296 | size_t offset = va_arg(args, size_t); |
| 297 | void* base = va_arg(args, void*); |
| 298 | int width = va_arg(args, int); |
| 299 | int height = va_arg(args, int); |
| 300 | int format = va_arg(args, int); |
| 301 | |
| 302 | native_handle_t** handle = va_arg(args, native_handle_t**); |
| 303 | int memoryFlags = va_arg(args, int); |
| 304 | private_handle_t* hnd = (private_handle_t*)native_handle_create( |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 305 | private_handle_t::sNumFds, private_handle_t::sNumInts); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 306 | hnd->magic = private_handle_t::sMagic; |
| 307 | hnd->fd = fd; |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 308 | hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 309 | hnd->size = size; |
| 310 | hnd->offset = offset; |
| 311 | hnd->base = intptr_t(base) + offset; |
| 312 | hnd->gpuaddr = 0; |
| 313 | hnd->width = width; |
| 314 | hnd->height = height; |
| 315 | hnd->format = format; |
| 316 | *handle = (native_handle_t *)hnd; |
| 317 | res = 0; |
| 318 | break; |
| 319 | |
| 320 | } |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 321 | case GRALLOC_MODULE_PERFORM_GET_STRIDE: |
| 322 | { |
| 323 | int width = va_arg(args, int); |
| 324 | int format = va_arg(args, int); |
| 325 | int *stride = va_arg(args, int *); |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 326 | int alignedw = 0, alignedh = 0; |
| 327 | AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width, |
| 328 | 0, format, alignedw, alignedh); |
| 329 | *stride = alignedw; |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 330 | res = 0; |
| 331 | } break; |
Raj Kamal | 9c1cb9e | 2014-03-04 05:25:33 +0530 | [diff] [blame] | 332 | case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: |
Naseer Ahmed | a978f95 | 2013-09-26 14:36:28 -0400 | [diff] [blame] | 333 | { |
| 334 | private_handle_t* hnd = va_arg(args, private_handle_t*); |
| 335 | int *stride = va_arg(args, int *); |
Steve Kondik | 86c2b7f | 2015-11-04 14:49:02 -0800 | [diff] [blame] | 336 | #ifndef GRALLOC_PERFORM_COMPAT |
Raj Kamal | 9c1cb9e | 2014-03-04 05:25:33 +0530 | [diff] [blame] | 337 | int *height = va_arg(args, int *); |
Steve Kondik | 86c2b7f | 2015-11-04 14:49:02 -0800 | [diff] [blame] | 338 | #endif |
Naseer Ahmed | a978f95 | 2013-09-26 14:36:28 -0400 | [diff] [blame] | 339 | if (private_handle_t::validate(hnd)) { |
| 340 | return res; |
| 341 | } |
| 342 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 343 | if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) { |
| 344 | *stride = metadata->bufferDim.sliceWidth; |
Steve Kondik | 86c2b7f | 2015-11-04 14:49:02 -0800 | [diff] [blame] | 345 | #ifndef GRALLOC_PERFORM_COMPAT |
Raj Kamal | 9c1cb9e | 2014-03-04 05:25:33 +0530 | [diff] [blame] | 346 | *height = metadata->bufferDim.sliceHeight; |
Steve Kondik | 86c2b7f | 2015-11-04 14:49:02 -0800 | [diff] [blame] | 347 | #endif |
Naseer Ahmed | a978f95 | 2013-09-26 14:36:28 -0400 | [diff] [blame] | 348 | } else { |
| 349 | *stride = hnd->width; |
Steve Kondik | 86c2b7f | 2015-11-04 14:49:02 -0800 | [diff] [blame] | 350 | #ifndef GRALLOC_PERFORM_COMPAT |
Raj Kamal | 9c1cb9e | 2014-03-04 05:25:33 +0530 | [diff] [blame] | 351 | *height = hnd->height; |
Steve Kondik | 86c2b7f | 2015-11-04 14:49:02 -0800 | [diff] [blame] | 352 | #endif |
Naseer Ahmed | a978f95 | 2013-09-26 14:36:28 -0400 | [diff] [blame] | 353 | } |
| 354 | res = 0; |
| 355 | } break; |
Naseer Ahmed | 57b5245 | 2014-04-08 20:23:47 -0400 | [diff] [blame] | 356 | case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: |
| 357 | { |
| 358 | private_handle_t* hnd = va_arg(args, private_handle_t*); |
| 359 | android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *); |
| 360 | if (private_handle_t::validate(hnd)) { |
| 361 | res = getYUVPlaneInfo(hnd, ycbcr); |
| 362 | } |
| 363 | } break; |
| 364 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 365 | default: |
| 366 | break; |
| 367 | } |
| 368 | va_end(args); |
| 369 | return res; |
| 370 | } |