Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Duy Truong | 73d36df | 2013-02-09 20:33:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012 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 <unistd.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <cutils/properties.h> |
| 22 | #include <sys/mman.h> |
| 23 | |
| 24 | #include <genlock.h> |
| 25 | |
| 26 | #include "gr.h" |
| 27 | #include "gpu.h" |
| 28 | #include "memalloc.h" |
| 29 | #include "alloc_controller.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 30 | #include <qdMetaData.h> |
Praveen Chavan | 4e931c1 | 2012-11-28 19:43:17 -0800 | [diff] [blame] | 31 | #include "mdp_version.h" |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 32 | |
| 33 | using namespace gralloc; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 34 | |
Praveen Chavan | 4e931c1 | 2012-11-28 19:43:17 -0800 | [diff] [blame] | 35 | #define SZ_1M 0x100000 |
| 36 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 37 | gpu_context_t::gpu_context_t(const private_module_t* module, |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 38 | IAllocController* alloc_ctrl ) : |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 39 | mAllocCtrl(alloc_ctrl) |
| 40 | { |
| 41 | // Zero out the alloc_device_t |
| 42 | memset(static_cast<alloc_device_t*>(this), 0, sizeof(alloc_device_t)); |
| 43 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 44 | // Initialize the procs |
| 45 | common.tag = HARDWARE_DEVICE_TAG; |
| 46 | common.version = 0; |
| 47 | common.module = const_cast<hw_module_t*>(&module->base.common); |
| 48 | common.close = gralloc_close; |
| 49 | alloc = gralloc_alloc; |
Naseer Ahmed | 7421472 | 2013-02-09 08:11:36 -0500 | [diff] [blame] | 50 | #ifdef QCOM_BSP |
Ramkumar Radhakrishnan | 3d4c0ac | 2012-12-10 15:42:54 -0800 | [diff] [blame] | 51 | allocSize = gralloc_alloc_size; |
Naseer Ahmed | 7421472 | 2013-02-09 08:11:36 -0500 | [diff] [blame] | 52 | #endif |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 53 | free = gralloc_free; |
| 54 | |
| 55 | } |
| 56 | |
| 57 | int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | buffer_handle_t* pHandle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 59 | { |
| 60 | private_module_t* m = reinterpret_cast<private_module_t*>(common.module); |
| 61 | |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 62 | // we don't support framebuffer allocations with graphics heap flags |
| 63 | if (usage & GRALLOC_HEAP_MASK) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 64 | return -EINVAL; |
| 65 | } |
| 66 | |
| 67 | if (m->framebuffer == NULL) { |
| 68 | ALOGE("%s: Invalid framebuffer", __FUNCTION__); |
| 69 | return -EINVAL; |
| 70 | } |
| 71 | |
| 72 | const uint32_t bufferMask = m->bufferMask; |
| 73 | const uint32_t numBuffers = m->numBuffers; |
| 74 | size_t bufferSize = m->finfo.line_length * m->info.yres; |
| 75 | |
| 76 | //adreno needs FB size to be page aligned |
| 77 | bufferSize = roundUpToPageSize(bufferSize); |
| 78 | |
| 79 | if (numBuffers == 1) { |
| 80 | // If we have only one buffer, we never use page-flipping. Instead, |
| 81 | // we return a regular buffer which will be memcpy'ed to the main |
| 82 | // screen when post is called. |
| 83 | int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D; |
| 84 | return gralloc_alloc_buffer(bufferSize, newUsage, pHandle, BUFFER_TYPE_UI, |
| 85 | m->fbFormat, m->info.xres, m->info.yres); |
| 86 | } |
| 87 | |
| 88 | if (bufferMask >= ((1LU<<numBuffers)-1)) { |
| 89 | // We ran out of buffers. |
| 90 | return -ENOMEM; |
| 91 | } |
| 92 | |
Naseer Ahmed | d7f8427 | 2012-12-13 13:09:53 -0500 | [diff] [blame] | 93 | // create a "fake" handle for it |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 94 | intptr_t vaddr = intptr_t(m->framebuffer->base); |
Naseer Ahmed | d7f8427 | 2012-12-13 13:09:53 -0500 | [diff] [blame] | 95 | private_handle_t* hnd = new private_handle_t( |
| 96 | dup(m->framebuffer->fd), bufferSize, |
| 97 | private_handle_t::PRIV_FLAGS_USES_ION | |
| 98 | private_handle_t::PRIV_FLAGS_FRAMEBUFFER, |
| 99 | BUFFER_TYPE_UI, m->fbFormat, m->info.xres, |
| 100 | m->info.yres); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 101 | |
| 102 | // find a free slot |
| 103 | for (uint32_t i=0 ; i<numBuffers ; i++) { |
| 104 | if ((bufferMask & (1LU<<i)) == 0) { |
| 105 | m->bufferMask |= (1LU<<i); |
| 106 | break; |
| 107 | } |
| 108 | vaddr += bufferSize; |
| 109 | } |
| 110 | |
| 111 | hnd->base = vaddr; |
| 112 | hnd->offset = vaddr - intptr_t(m->framebuffer->base); |
| 113 | *pHandle = hnd; |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | int gpu_context_t::gralloc_alloc_framebuffer(size_t size, int usage, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 119 | buffer_handle_t* pHandle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 120 | { |
| 121 | private_module_t* m = reinterpret_cast<private_module_t*>(common.module); |
| 122 | pthread_mutex_lock(&m->lock); |
| 123 | int err = gralloc_alloc_framebuffer_locked(size, usage, pHandle); |
| 124 | pthread_mutex_unlock(&m->lock); |
| 125 | return err; |
| 126 | } |
| 127 | |
| 128 | int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage, |
| 129 | buffer_handle_t* pHandle, int bufferType, |
| 130 | int format, int width, int height) |
| 131 | { |
| 132 | int err = 0; |
| 133 | int flags = 0; |
| 134 | size = roundUpToPageSize(size); |
| 135 | alloc_data data; |
| 136 | data.offset = 0; |
| 137 | data.fd = -1; |
| 138 | data.base = 0; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 139 | if(format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) |
| 140 | data.align = 8192; |
| 141 | else |
| 142 | data.align = getpagesize(); |
Praveen Chavan | 4e931c1 | 2012-11-28 19:43:17 -0800 | [diff] [blame] | 143 | |
| 144 | /* force 1MB alignment selectively for secure buffers, MDP5 onwards */ |
| 145 | if ((qdutils::MDPVersion::getInstance().getMDPVersion() >= \ |
| 146 | qdutils::MDSS_V5) && (usage & GRALLOC_USAGE_PROTECTED)) { |
| 147 | data.align = ALIGN(data.align, SZ_1M); |
| 148 | size = ALIGN(size, data.align); |
| 149 | } |
| 150 | data.size = size; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 151 | data.pHandle = (unsigned int) pHandle; |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 152 | err = mAllocCtrl->allocate(data, usage); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 153 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 154 | if (!err) { |
| 155 | /* allocate memory for enhancement data */ |
| 156 | alloc_data eData; |
| 157 | eData.fd = -1; |
| 158 | eData.base = 0; |
| 159 | eData.offset = 0; |
| 160 | eData.size = ROUND_UP_PAGESIZE(sizeof(MetaData_t)); |
| 161 | eData.pHandle = data.pHandle; |
| 162 | eData.align = getpagesize(); |
| 163 | int eDataUsage = GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP; |
| 164 | int eDataErr = mAllocCtrl->allocate(eData, eDataUsage); |
| 165 | ALOGE_IF(eDataErr, "gralloc failed for eDataErr=%s", |
| 166 | strerror(-eDataErr)); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 167 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 168 | if (usage & GRALLOC_USAGE_PRIVATE_UNSYNCHRONIZED) { |
| 169 | flags |= private_handle_t::PRIV_FLAGS_UNSYNCHRONIZED; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 170 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 171 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 172 | if (usage & GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY) { |
| 173 | flags |= private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY; |
| 174 | //The EXTERNAL_BLOCK flag is always an add-on |
| 175 | if (usage & GRALLOC_USAGE_PRIVATE_EXTERNAL_BLOCK) { |
| 176 | flags |= private_handle_t::PRIV_FLAGS_EXTERNAL_BLOCK; |
| 177 | } |
| 178 | if (usage & GRALLOC_USAGE_PRIVATE_EXTERNAL_CC) { |
| 179 | flags |= private_handle_t::PRIV_FLAGS_EXTERNAL_CC; |
| 180 | } |
| 181 | } |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 182 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 183 | if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) { |
| 184 | flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER; |
| 185 | } |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 186 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 187 | if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) { |
| 188 | flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE; |
| 189 | } |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 190 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 191 | if (usage & GRALLOC_USAGE_HW_CAMERA_READ) { |
| 192 | flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ; |
| 193 | } |
| 194 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 195 | flags |= data.allocType; |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 196 | int eBaseAddr = int(eData.base) + eData.offset; |
| 197 | private_handle_t *hnd = new private_handle_t(data.fd, size, flags, |
| 198 | bufferType, format, width, height, eData.fd, eData.offset, |
| 199 | eBaseAddr); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 200 | |
| 201 | hnd->offset = data.offset; |
| 202 | hnd->base = int(data.base) + data.offset; |
| 203 | *pHandle = hnd; |
| 204 | } |
| 205 | |
| 206 | ALOGE_IF(err, "gralloc failed err=%s", strerror(-err)); |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 207 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 208 | return err; |
| 209 | } |
| 210 | |
| 211 | void gpu_context_t::getGrallocInformationFromFormat(int inputFormat, |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 212 | int *bufferType) |
| 213 | { |
| 214 | *bufferType = BUFFER_TYPE_VIDEO; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 215 | |
Naseer Ahmed | 65f1656 | 2012-06-15 20:53:42 -0700 | [diff] [blame] | 216 | if (inputFormat < 0x7) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 217 | // RGB formats |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 218 | *bufferType = BUFFER_TYPE_UI; |
| 219 | } else if ((inputFormat == HAL_PIXEL_FORMAT_R_8) || |
| 220 | (inputFormat == HAL_PIXEL_FORMAT_RG_88)) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 221 | *bufferType = BUFFER_TYPE_UI; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | int gpu_context_t::alloc_impl(int w, int h, int format, int usage, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 226 | buffer_handle_t* pHandle, int* pStride, |
| 227 | size_t bufferSize) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 228 | if (!pHandle || !pStride) |
| 229 | return -EINVAL; |
| 230 | |
| 231 | size_t size; |
| 232 | int alignedw, alignedh; |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 233 | int grallocFormat = format; |
| 234 | int bufferType; |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 235 | |
Saurabh Shah | aedf236 | 2012-09-05 11:30:59 -0700 | [diff] [blame] | 236 | //If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on |
| 237 | //the usage bits, gralloc assigns a format. |
| 238 | if(format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) { |
| 239 | if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) |
| 240 | grallocFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP; //NV12 |
| 241 | else if(usage & GRALLOC_USAGE_HW_CAMERA_READ) |
| 242 | grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21 |
| 243 | else if(usage & GRALLOC_USAGE_HW_CAMERA_WRITE) |
| 244 | grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21 |
| 245 | } |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 246 | |
Saurabh Shah | aedf236 | 2012-09-05 11:30:59 -0700 | [diff] [blame] | 247 | getGrallocInformationFromFormat(grallocFormat, &bufferType); |
Naseer Ahmed | 5980250 | 2012-08-21 17:03:27 -0400 | [diff] [blame] | 248 | size = getBufferSizeAndDimensions(w, h, grallocFormat, alignedw, alignedh); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 249 | |
| 250 | if ((ssize_t)size <= 0) |
| 251 | return -EINVAL; |
Ramkumar Radhakrishnan | 3d4c0ac | 2012-12-10 15:42:54 -0800 | [diff] [blame] | 252 | size = (bufferSize != 0)? bufferSize : size; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 253 | |
| 254 | // All buffers marked as protected or for external |
| 255 | // display need to go to overlay |
| 256 | if ((usage & GRALLOC_USAGE_EXTERNAL_DISP) || |
Sushil Chauhan | 7651a80 | 2013-01-08 16:08:09 -0800 | [diff] [blame] | 257 | (usage & GRALLOC_USAGE_PROTECTED)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 258 | bufferType = BUFFER_TYPE_VIDEO; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 259 | } |
Naseer Ahmed | 768619e | 2012-11-28 17:02:52 -0500 | [diff] [blame] | 260 | |
| 261 | int err = gralloc_alloc_buffer(size, usage, pHandle, bufferType, |
| 262 | grallocFormat, alignedw, alignedh); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 263 | |
| 264 | if (err < 0) { |
| 265 | return err; |
| 266 | } |
| 267 | |
| 268 | // Create a genlock lock for this buffer handle. |
| 269 | err = genlock_create_lock((native_handle_t*)(*pHandle)); |
| 270 | if (err) { |
| 271 | ALOGE("%s: genlock_create_lock failed", __FUNCTION__); |
| 272 | free_impl(reinterpret_cast<private_handle_t*>(pHandle)); |
| 273 | return err; |
| 274 | } |
| 275 | *pStride = alignedw; |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | int gpu_context_t::free_impl(private_handle_t const* hnd) { |
| 280 | private_module_t* m = reinterpret_cast<private_module_t*>(common.module); |
| 281 | if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) { |
| 282 | // free this buffer |
| 283 | const size_t bufferSize = m->finfo.line_length * m->info.yres; |
| 284 | int index = (hnd->base - m->framebuffer->base) / bufferSize; |
| 285 | m->bufferMask &= ~(1<<index); |
| 286 | } else { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 287 | terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd)); |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 288 | IMemAlloc* memalloc = mAllocCtrl->getAllocator(hnd->flags); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 289 | int err = memalloc->free_buffer((void*)hnd->base, (size_t) hnd->size, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 290 | hnd->offset, hnd->fd); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 291 | if(err) |
| 292 | return err; |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 293 | // free the metadata space |
| 294 | unsigned long size = ROUND_UP_PAGESIZE(sizeof(MetaData_t)); |
| 295 | err = memalloc->free_buffer((void*)hnd->base_metadata, |
| 296 | (size_t) size, hnd->offset_metadata, |
| 297 | hnd->fd_metadata); |
| 298 | if (err) |
| 299 | return err; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // Release the genlock |
| 303 | int err = genlock_release_lock((native_handle_t*)hnd); |
| 304 | if (err) { |
| 305 | ALOGE("%s: genlock_release_lock failed", __FUNCTION__); |
| 306 | } |
| 307 | |
| 308 | delete hnd; |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | int gpu_context_t::gralloc_alloc(alloc_device_t* dev, int w, int h, int format, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 313 | int usage, buffer_handle_t* pHandle, |
| 314 | int* pStride) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 315 | { |
| 316 | if (!dev) { |
| 317 | return -EINVAL; |
| 318 | } |
| 319 | gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev); |
| 320 | return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, 0); |
| 321 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 322 | int gpu_context_t::gralloc_alloc_size(alloc_device_t* dev, int w, int h, |
| 323 | int format, int usage, |
| 324 | buffer_handle_t* pHandle, int* pStride, |
| 325 | int bufferSize) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 326 | { |
| 327 | if (!dev) { |
| 328 | return -EINVAL; |
| 329 | } |
| 330 | gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev); |
| 331 | return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, bufferSize); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | int gpu_context_t::gralloc_free(alloc_device_t* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 336 | buffer_handle_t handle) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 337 | { |
| 338 | if (private_handle_t::validate(handle) < 0) |
| 339 | return -EINVAL; |
| 340 | |
| 341 | private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle); |
| 342 | gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev); |
| 343 | return gpu->free_impl(hnd); |
| 344 | } |
| 345 | |
| 346 | /*****************************************************************************/ |
| 347 | |
| 348 | int gpu_context_t::gralloc_close(struct hw_device_t *dev) |
| 349 | { |
| 350 | gpu_context_t* ctx = reinterpret_cast<gpu_context_t*>(dev); |
| 351 | if (ctx) { |
| 352 | /* TODO: keep a list of all buffer_handle_t created, and free them |
| 353 | * all here. |
| 354 | */ |
| 355 | delete ctx; |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |