blob: 48da09ebc00368fef5273e8477e9ecbeeee34d3c [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R6c85f052014-01-21 21:47:41 -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 <unistd.h>
20#include <fcntl.h>
21#include <cutils/properties.h>
22#include <sys/mman.h>
23
Iliyan Malchev202a77d2012-06-11 14:41:12 -070024#include "gr.h"
25#include "gpu.h"
26#include "memalloc.h"
27#include "alloc_controller.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080028#include <qdMetaData.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070029
30using namespace gralloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070031
Praveen Chavan4e931c12012-11-28 19:43:17 -080032#define SZ_1M 0x100000
33
Iliyan Malchev202a77d2012-06-11 14:41:12 -070034gpu_context_t::gpu_context_t(const private_module_t* module,
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070035 IAllocController* alloc_ctrl ) :
Iliyan Malchev202a77d2012-06-11 14:41:12 -070036 mAllocCtrl(alloc_ctrl)
37{
38 // Zero out the alloc_device_t
39 memset(static_cast<alloc_device_t*>(this), 0, sizeof(alloc_device_t));
40
Iliyan Malchev202a77d2012-06-11 14:41:12 -070041 // Initialize the procs
42 common.tag = HARDWARE_DEVICE_TAG;
43 common.version = 0;
44 common.module = const_cast<hw_module_t*>(&module->base.common);
45 common.close = gralloc_close;
46 alloc = gralloc_alloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070047 free = gralloc_free;
48
49}
50
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070051int gpu_context_t::gralloc_alloc_buffer(unsigned int size, int usage,
Iliyan Malchev202a77d2012-06-11 14:41:12 -070052 buffer_handle_t* pHandle, int bufferType,
53 int format, int width, int height)
54{
55 int err = 0;
56 int flags = 0;
57 size = roundUpToPageSize(size);
58 alloc_data data;
59 data.offset = 0;
60 data.fd = -1;
61 data.base = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070062 if(format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED)
63 data.align = 8192;
64 else
65 data.align = getpagesize();
Praveen Chavan4e931c12012-11-28 19:43:17 -080066
67 /* force 1MB alignment selectively for secure buffers, MDP5 onwards */
Naseer Ahmed84786722013-06-14 16:29:59 -040068#ifdef MDSS_TARGET
Praveena Pachipulusu95e16d42014-06-03 18:23:16 +053069 if ((usage & GRALLOC_USAGE_PROTECTED) &&
70 (usage & GRALLOC_USAGE_PRIVATE_MM_HEAP)) {
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080071 data.align = ALIGN((int) data.align, SZ_1M);
Praveen Chavan4e931c12012-11-28 19:43:17 -080072 size = ALIGN(size, data.align);
73 }
Naseer Ahmed84786722013-06-14 16:29:59 -040074#endif
75
Praveen Chavan4e931c12012-11-28 19:43:17 -080076 data.size = size;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080077 data.pHandle = (uintptr_t) pHandle;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070078 err = mAllocCtrl->allocate(data, usage);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070079
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080080 if (!err) {
81 /* allocate memory for enhancement data */
82 alloc_data eData;
83 eData.fd = -1;
84 eData.base = 0;
85 eData.offset = 0;
86 eData.size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
87 eData.pHandle = data.pHandle;
88 eData.align = getpagesize();
89 int eDataUsage = GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP;
90 int eDataErr = mAllocCtrl->allocate(eData, eDataUsage);
91 ALOGE_IF(eDataErr, "gralloc failed for eDataErr=%s",
92 strerror(-eDataErr));
Iliyan Malchev202a77d2012-06-11 14:41:12 -070093
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080094 if (usage & GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY) {
95 flags |= private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080096 }
Naseer Ahmed59802502012-08-21 17:03:27 -040097
Naseer Ahmed42e5dde2014-03-28 19:32:01 -040098 ColorSpace_t colorSpace = ITU_R_601;
99 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601;
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400100 if (bufferType == BUFFER_TYPE_VIDEO) {
101 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
Naseer Ahmed84786722013-06-14 16:29:59 -0400102#ifndef MDSS_TARGET
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400103 colorSpace = ITU_R_601_FR;
Naseer Ahmed84786722013-06-14 16:29:59 -0400104 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
105#else
Naseer Ahmed22fa2d32013-08-14 12:59:24 -0400106 // Per the camera spec ITU 709 format should be set only for
107 // video encoding.
108 // It should be set to ITU 601 full range format for any other
109 // camera buffer
110 //
111 if (usage & GRALLOC_USAGE_HW_CAMERA_MASK) {
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400112 if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) {
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400113 flags |= private_handle_t::PRIV_FLAGS_ITU_R_709;
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400114 colorSpace = ITU_R_709;
115 } else {
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400116 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400117 colorSpace = ITU_R_601_FR;
118 }
Naseer Ahmed22fa2d32013-08-14 12:59:24 -0400119 }
Naseer Ahmed84786722013-06-14 16:29:59 -0400120#endif
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400121 }
122 }
123
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800124 if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) {
125 flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
126 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400127
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800128 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
129 flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
130 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400131
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800132 if (usage & GRALLOC_USAGE_HW_CAMERA_READ) {
133 flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
134 }
135
Naseer Ahmede41ad9c2013-04-05 17:59:28 -0400136 if (usage & GRALLOC_USAGE_HW_COMPOSER) {
137 flags |= private_handle_t::PRIV_FLAGS_HW_COMPOSER;
138 }
139
Shuzhen Wang46ca2262013-04-10 23:02:22 -0700140 if (usage & GRALLOC_USAGE_HW_TEXTURE) {
141 flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
142 }
143
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700144 if(usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
145 flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
146 }
147
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700148 if(isMacroTileEnabled(format, usage)) {
149 flags |= private_handle_t::PRIV_FLAGS_TILE_RENDERED;
150 }
151
Sushil Chauhan81594f62015-01-26 16:00:51 -0800152 if (AdrenoMemInfo::getInstance().isUBWCSupportedByGPU(format) &&
153 isUBwcEnabled(format, usage)) {
Sushil Chauhan65e26302015-01-14 10:48:57 -0800154 flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
155 }
156
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800157 if(usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
158 flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
159 }
160
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800161 if (usage & (GRALLOC_USAGE_HW_VIDEO_ENCODER |
162 GRALLOC_USAGE_HW_CAMERA_WRITE |
163 GRALLOC_USAGE_HW_RENDER |
164 GRALLOC_USAGE_HW_FB)) {
165 flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
166 }
167
168 if(false == data.uncached) {
169 flags |= private_handle_t::PRIV_FLAGS_CACHED;
170 }
171
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700172 flags |= data.allocType;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700173 uint64_t eBaseAddr = (uint64_t)(eData.base) + eData.offset;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800174 private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
175 bufferType, format, width, height, eData.fd, eData.offset,
176 eBaseAddr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700177
178 hnd->offset = data.offset;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700179 hnd->base = (uint64_t)(data.base) + data.offset;
Naseer Ahmeda163b732013-02-12 14:53:33 -0500180 hnd->gpuaddr = 0;
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400181 setMetaData(hnd, UPDATE_COLOR_SPACE, (void*) &colorSpace);
Naseer Ahmeda163b732013-02-12 14:53:33 -0500182
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700183 *pHandle = hnd;
184 }
185
186 ALOGE_IF(err, "gralloc failed err=%s", strerror(-err));
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800187
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700188 return err;
189}
190
191void gpu_context_t::getGrallocInformationFromFormat(int inputFormat,
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700192 int *bufferType)
193{
194 *bufferType = BUFFER_TYPE_VIDEO;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700195
Jesse Hallfbe96d22013-09-20 01:39:43 -0700196 if (inputFormat <= HAL_PIXEL_FORMAT_sRGB_X_8888) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700197 // RGB formats
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700198 *bufferType = BUFFER_TYPE_UI;
199 } else if ((inputFormat == HAL_PIXEL_FORMAT_R_8) ||
200 (inputFormat == HAL_PIXEL_FORMAT_RG_88)) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700201 *bufferType = BUFFER_TYPE_UI;
202 }
203}
204
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800205int gpu_context_t::gralloc_alloc_framebuffer_locked(int usage,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400206 buffer_handle_t* pHandle)
207{
208 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
209
210 // we don't support framebuffer allocations with graphics heap flags
211 if (usage & GRALLOC_HEAP_MASK) {
212 return -EINVAL;
213 }
214
215 if (m->framebuffer == NULL) {
216 ALOGE("%s: Invalid framebuffer", __FUNCTION__);
217 return -EINVAL;
218 }
219
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700220 const unsigned int bufferMask = m->bufferMask;
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400221 const uint32_t numBuffers = m->numBuffers;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700222 unsigned int bufferSize = m->finfo.line_length * m->info.yres;
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400223
224 //adreno needs FB size to be page aligned
225 bufferSize = roundUpToPageSize(bufferSize);
226
227 if (numBuffers == 1) {
228 // If we have only one buffer, we never use page-flipping. Instead,
229 // we return a regular buffer which will be memcpy'ed to the main
230 // screen when post is called.
231 int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D;
232 return gralloc_alloc_buffer(bufferSize, newUsage, pHandle, BUFFER_TYPE_UI,
233 m->fbFormat, m->info.xres, m->info.yres);
234 }
235
236 if (bufferMask >= ((1LU<<numBuffers)-1)) {
237 // We ran out of buffers.
238 return -ENOMEM;
239 }
240
241 // create a "fake" handle for it
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700242 uint64_t vaddr = uint64_t(m->framebuffer->base);
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700243 // As GPU needs ION FD, the private handle is created
244 // using ION fd and ION flags are set
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400245 private_handle_t* hnd = new private_handle_t(
246 dup(m->framebuffer->fd), bufferSize,
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700247 private_handle_t::PRIV_FLAGS_USES_ION |
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400248 private_handle_t::PRIV_FLAGS_FRAMEBUFFER,
249 BUFFER_TYPE_UI, m->fbFormat, m->info.xres,
250 m->info.yres);
251
252 // find a free slot
253 for (uint32_t i=0 ; i<numBuffers ; i++) {
254 if ((bufferMask & (1LU<<i)) == 0) {
Shalaj Jaina70b4352014-06-15 13:47:47 -0700255 m->bufferMask |= (uint32_t)(1LU<<i);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400256 break;
257 }
258 vaddr += bufferSize;
259 }
260 hnd->base = vaddr;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700261 hnd->offset = (unsigned int)(vaddr - m->framebuffer->base);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400262 *pHandle = hnd;
263 return 0;
264}
265
266
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800267int gpu_context_t::gralloc_alloc_framebuffer(int usage,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400268 buffer_handle_t* pHandle)
269{
270 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
271 pthread_mutex_lock(&m->lock);
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800272 int err = gralloc_alloc_framebuffer_locked(usage, pHandle);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400273 pthread_mutex_unlock(&m->lock);
274 return err;
275}
276
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700277int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278 buffer_handle_t* pHandle, int* pStride,
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700279 unsigned int bufferSize) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700280 if (!pHandle || !pStride)
281 return -EINVAL;
282
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700283 unsigned int size;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700284 int alignedw, alignedh;
Naseer Ahmed59802502012-08-21 17:03:27 -0400285 int grallocFormat = format;
286 int bufferType;
Naseer Ahmed59802502012-08-21 17:03:27 -0400287
Saurabh Shahaedf2362012-09-05 11:30:59 -0700288 //If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
289 //the usage bits, gralloc assigns a format.
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400290 if(format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
291 format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
Saurabh Shahaedf2362012-09-05 11:30:59 -0700292 if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
Naseer Ahmedf2feca92013-08-16 14:48:59 -0400293 grallocFormat = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; //NV12
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700294 else if((usage & GRALLOC_USAGE_HW_CAMERA_MASK)
295 == GRALLOC_USAGE_HW_CAMERA_ZSL)
296 grallocFormat = HAL_PIXEL_FORMAT_NV21_ZSL; //NV21 ZSL
Saurabh Shahaedf2362012-09-05 11:30:59 -0700297 else if(usage & GRALLOC_USAGE_HW_CAMERA_READ)
298 grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
299 else if(usage & GRALLOC_USAGE_HW_CAMERA_WRITE)
300 grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
Manoj Kumar AVMcdb4fd52013-10-25 19:40:45 -0700301 else if(usage & GRALLOC_USAGE_HW_COMPOSER)
302 //XXX: If we still haven't set a format, default to RGBA8888
303 grallocFormat = HAL_PIXEL_FORMAT_RGBA_8888;
Baldev Sahu5f673b42013-12-05 09:49:09 +0530304 }
305
Saurabh Shahaedf2362012-09-05 11:30:59 -0700306 getGrallocInformationFromFormat(grallocFormat, &bufferType);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700307 size = getBufferSizeAndDimensions(w, h, grallocFormat, usage, alignedw,
308 alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700309
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700310 if ((unsigned int)size <= 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700311 return -EINVAL;
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800312 size = (bufferSize >= size)? bufferSize : size;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700313
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400314 bool useFbMem = false;
315 char property[PROPERTY_VALUE_MAX];
316 if((usage & GRALLOC_USAGE_HW_FB) &&
317 (property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
318 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
319 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
320 useFbMem = true;
321 }
322
323 int err = 0;
324 if(useFbMem) {
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800325 err = gralloc_alloc_framebuffer(usage, pHandle);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400326 } else {
327 err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
328 grallocFormat, alignedw, alignedh);
329 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700330
331 if (err < 0) {
332 return err;
333 }
334
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700335 *pStride = alignedw;
336 return 0;
337}
338
339int gpu_context_t::free_impl(private_handle_t const* hnd) {
340 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400341 if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700342 const unsigned int bufferSize = m->finfo.line_length * m->info.yres;
343 unsigned int index = (unsigned int) ((hnd->base - m->framebuffer->base)
344 / bufferSize);
Shalaj Jaina70b4352014-06-15 13:47:47 -0700345 m->bufferMask &= (uint32_t)~(1LU<<index);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400346 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800347
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400348 terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
349 IMemAlloc* memalloc = mAllocCtrl->getAllocator(hnd->flags);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700350 int err = memalloc->free_buffer((void*)hnd->base, hnd->size,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400351 hnd->offset, hnd->fd);
352 if(err)
353 return err;
354 // free the metadata space
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700355 unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400356 err = memalloc->free_buffer((void*)hnd->base_metadata,
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800357 size, hnd->offset_metadata,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400358 hnd->fd_metadata);
359 if (err)
360 return err;
361 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700362 delete hnd;
363 return 0;
364}
365
366int gpu_context_t::gralloc_alloc(alloc_device_t* dev, int w, int h, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367 int usage, buffer_handle_t* pHandle,
368 int* pStride)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700369{
370 if (!dev) {
371 return -EINVAL;
372 }
373 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
374 return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, 0);
375}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376int gpu_context_t::gralloc_alloc_size(alloc_device_t* dev, int w, int h,
377 int format, int usage,
378 buffer_handle_t* pHandle, int* pStride,
379 int bufferSize)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700380{
381 if (!dev) {
382 return -EINVAL;
383 }
384 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
385 return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, bufferSize);
386}
387
388
389int gpu_context_t::gralloc_free(alloc_device_t* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700390 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700391{
392 if (private_handle_t::validate(handle) < 0)
393 return -EINVAL;
394
395 private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle);
396 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
397 return gpu->free_impl(hnd);
398}
399
400/*****************************************************************************/
401
402int gpu_context_t::gralloc_close(struct hw_device_t *dev)
403{
404 gpu_context_t* ctx = reinterpret_cast<gpu_context_t*>(dev);
405 if (ctx) {
406 /* TODO: keep a list of all buffer_handle_t created, and free them
407 * all here.
408 */
409 delete ctx;
410 }
411 return 0;
412}
413