blob: 0cba07a4dbd04c5d7cb58533399861fc2e8f39f0 [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;
Naseer Ahmed74214722013-02-09 08:11:36 -050047#ifdef QCOM_BSP
Ramkumar Radhakrishnan3d4c0ac2012-12-10 15:42:54 -080048 allocSize = gralloc_alloc_size;
Naseer Ahmed74214722013-02-09 08:11:36 -050049#endif
Iliyan Malchev202a77d2012-06-11 14:41:12 -070050 free = gralloc_free;
51
52}
53
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070054int gpu_context_t::gralloc_alloc_buffer(unsigned int size, int usage,
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055 buffer_handle_t* pHandle, int bufferType,
56 int format, int width, int height)
57{
58 int err = 0;
59 int flags = 0;
60 size = roundUpToPageSize(size);
61 alloc_data data;
62 data.offset = 0;
63 data.fd = -1;
64 data.base = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070065 if(format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED)
66 data.align = 8192;
67 else
68 data.align = getpagesize();
Praveen Chavan4e931c12012-11-28 19:43:17 -080069
70 /* force 1MB alignment selectively for secure buffers, MDP5 onwards */
Naseer Ahmed84786722013-06-14 16:29:59 -040071#ifdef MDSS_TARGET
72 if (usage & GRALLOC_USAGE_PROTECTED) {
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080073 data.align = ALIGN((int) data.align, SZ_1M);
Praveen Chavan4e931c12012-11-28 19:43:17 -080074 size = ALIGN(size, data.align);
75 }
Naseer Ahmed84786722013-06-14 16:29:59 -040076#endif
77
Praveen Chavan4e931c12012-11-28 19:43:17 -080078 data.size = size;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080079 data.pHandle = (uintptr_t) pHandle;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070080 err = mAllocCtrl->allocate(data, usage);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070081
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080082 if (!err) {
83 /* allocate memory for enhancement data */
84 alloc_data eData;
85 eData.fd = -1;
86 eData.base = 0;
87 eData.offset = 0;
88 eData.size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
89 eData.pHandle = data.pHandle;
90 eData.align = getpagesize();
91 int eDataUsage = GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP;
92 int eDataErr = mAllocCtrl->allocate(eData, eDataUsage);
93 ALOGE_IF(eDataErr, "gralloc failed for eDataErr=%s",
94 strerror(-eDataErr));
Iliyan Malchev202a77d2012-06-11 14:41:12 -070095
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080096 if (usage & GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY) {
97 flags |= private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080098 }
Naseer Ahmed59802502012-08-21 17:03:27 -040099
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400100 ColorSpace_t colorSpace = ITU_R_601;
101 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601;
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400102 if (bufferType == BUFFER_TYPE_VIDEO) {
103 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
Naseer Ahmed84786722013-06-14 16:29:59 -0400104#ifndef MDSS_TARGET
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400105 colorSpace = ITU_R_601_FR;
Naseer Ahmed84786722013-06-14 16:29:59 -0400106 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
107#else
Naseer Ahmed22fa2d32013-08-14 12:59:24 -0400108 // Per the camera spec ITU 709 format should be set only for
109 // video encoding.
110 // It should be set to ITU 601 full range format for any other
111 // camera buffer
112 //
113 if (usage & GRALLOC_USAGE_HW_CAMERA_MASK) {
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400114 if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) {
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400115 flags |= private_handle_t::PRIV_FLAGS_ITU_R_709;
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400116 colorSpace = ITU_R_709;
117 } else {
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400118 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400119 colorSpace = ITU_R_601_FR;
120 }
Naseer Ahmed22fa2d32013-08-14 12:59:24 -0400121 }
Naseer Ahmed84786722013-06-14 16:29:59 -0400122#endif
Naseer Ahmedfc940ef2013-04-29 15:47:47 -0400123 }
124 }
125
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800126 if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) {
127 flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
128 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400129
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800130 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
131 flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
132 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400133
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800134 if (usage & GRALLOC_USAGE_HW_CAMERA_READ) {
135 flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
136 }
137
Naseer Ahmede41ad9c2013-04-05 17:59:28 -0400138 if (usage & GRALLOC_USAGE_HW_COMPOSER) {
139 flags |= private_handle_t::PRIV_FLAGS_HW_COMPOSER;
140 }
141
Shuzhen Wang46ca2262013-04-10 23:02:22 -0700142 if (usage & GRALLOC_USAGE_HW_TEXTURE) {
143 flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
144 }
145
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700146 if(usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
147 flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
148 }
149
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700150 if(isMacroTileEnabled(format, usage)) {
151 flags |= private_handle_t::PRIV_FLAGS_TILE_RENDERED;
152 }
153
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700154 flags |= data.allocType;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700155 uint64_t eBaseAddr = (uint64_t)(eData.base) + eData.offset;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800156 private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
157 bufferType, format, width, height, eData.fd, eData.offset,
158 eBaseAddr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700159
160 hnd->offset = data.offset;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700161 hnd->base = (uint64_t)(data.base) + data.offset;
Naseer Ahmeda163b732013-02-12 14:53:33 -0500162 hnd->gpuaddr = 0;
Naseer Ahmed42e5dde2014-03-28 19:32:01 -0400163 setMetaData(hnd, UPDATE_COLOR_SPACE, (void*) &colorSpace);
Naseer Ahmeda163b732013-02-12 14:53:33 -0500164
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700165 *pHandle = hnd;
166 }
167
168 ALOGE_IF(err, "gralloc failed err=%s", strerror(-err));
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800169
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700170 return err;
171}
172
173void gpu_context_t::getGrallocInformationFromFormat(int inputFormat,
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700174 int *bufferType)
175{
176 *bufferType = BUFFER_TYPE_VIDEO;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700177
Jesse Hallfbe96d22013-09-20 01:39:43 -0700178 if (inputFormat <= HAL_PIXEL_FORMAT_sRGB_X_8888) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700179 // RGB formats
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700180 *bufferType = BUFFER_TYPE_UI;
181 } else if ((inputFormat == HAL_PIXEL_FORMAT_R_8) ||
182 (inputFormat == HAL_PIXEL_FORMAT_RG_88)) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700183 *bufferType = BUFFER_TYPE_UI;
184 }
185}
186
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800187int gpu_context_t::gralloc_alloc_framebuffer_locked(int usage,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400188 buffer_handle_t* pHandle)
189{
190 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
191
192 // we don't support framebuffer allocations with graphics heap flags
193 if (usage & GRALLOC_HEAP_MASK) {
194 return -EINVAL;
195 }
196
197 if (m->framebuffer == NULL) {
198 ALOGE("%s: Invalid framebuffer", __FUNCTION__);
199 return -EINVAL;
200 }
201
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700202 const unsigned int bufferMask = m->bufferMask;
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400203 const uint32_t numBuffers = m->numBuffers;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700204 unsigned int bufferSize = m->finfo.line_length * m->info.yres;
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400205
206 //adreno needs FB size to be page aligned
207 bufferSize = roundUpToPageSize(bufferSize);
208
209 if (numBuffers == 1) {
210 // If we have only one buffer, we never use page-flipping. Instead,
211 // we return a regular buffer which will be memcpy'ed to the main
212 // screen when post is called.
213 int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D;
214 return gralloc_alloc_buffer(bufferSize, newUsage, pHandle, BUFFER_TYPE_UI,
215 m->fbFormat, m->info.xres, m->info.yres);
216 }
217
218 if (bufferMask >= ((1LU<<numBuffers)-1)) {
219 // We ran out of buffers.
220 return -ENOMEM;
221 }
222
223 // create a "fake" handle for it
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700224 uint64_t vaddr = uint64_t(m->framebuffer->base);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400225 private_handle_t* hnd = new private_handle_t(
226 dup(m->framebuffer->fd), bufferSize,
227 private_handle_t::PRIV_FLAGS_USES_PMEM |
228 private_handle_t::PRIV_FLAGS_FRAMEBUFFER,
229 BUFFER_TYPE_UI, m->fbFormat, m->info.xres,
230 m->info.yres);
231
232 // find a free slot
233 for (uint32_t i=0 ; i<numBuffers ; i++) {
234 if ((bufferMask & (1LU<<i)) == 0) {
235 m->bufferMask |= (1LU<<i);
236 break;
237 }
238 vaddr += bufferSize;
239 }
240 hnd->base = vaddr;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700241 hnd->offset = (unsigned int)(vaddr - m->framebuffer->base);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400242 *pHandle = hnd;
243 return 0;
244}
245
246
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800247int gpu_context_t::gralloc_alloc_framebuffer(int usage,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400248 buffer_handle_t* pHandle)
249{
250 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
251 pthread_mutex_lock(&m->lock);
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800252 int err = gralloc_alloc_framebuffer_locked(usage, pHandle);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400253 pthread_mutex_unlock(&m->lock);
254 return err;
255}
256
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700257int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700258 buffer_handle_t* pHandle, int* pStride,
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700259 unsigned int bufferSize) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700260 if (!pHandle || !pStride)
261 return -EINVAL;
262
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700263 unsigned int size;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700264 int alignedw, alignedh;
Naseer Ahmed59802502012-08-21 17:03:27 -0400265 int grallocFormat = format;
266 int bufferType;
Naseer Ahmed59802502012-08-21 17:03:27 -0400267
Saurabh Shahaedf2362012-09-05 11:30:59 -0700268 //If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
269 //the usage bits, gralloc assigns a format.
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400270 if(format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
271 format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
Saurabh Shahaedf2362012-09-05 11:30:59 -0700272 if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
Naseer Ahmedf2feca92013-08-16 14:48:59 -0400273 grallocFormat = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; //NV12
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700274 else if((usage & GRALLOC_USAGE_HW_CAMERA_MASK)
275 == GRALLOC_USAGE_HW_CAMERA_ZSL)
276 grallocFormat = HAL_PIXEL_FORMAT_NV21_ZSL; //NV21 ZSL
Saurabh Shahaedf2362012-09-05 11:30:59 -0700277 else if(usage & GRALLOC_USAGE_HW_CAMERA_READ)
278 grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
279 else if(usage & GRALLOC_USAGE_HW_CAMERA_WRITE)
280 grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
Manoj Kumar AVMcdb4fd52013-10-25 19:40:45 -0700281 else if(usage & GRALLOC_USAGE_HW_COMPOSER)
282 //XXX: If we still haven't set a format, default to RGBA8888
283 grallocFormat = HAL_PIXEL_FORMAT_RGBA_8888;
Baldev Sahu5f673b42013-12-05 09:49:09 +0530284 }
285
Saurabh Shahaedf2362012-09-05 11:30:59 -0700286 getGrallocInformationFromFormat(grallocFormat, &bufferType);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700287 size = getBufferSizeAndDimensions(w, h, grallocFormat, usage, alignedw,
288 alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700289
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700290 if ((unsigned int)size <= 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700291 return -EINVAL;
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800292 size = (bufferSize >= size)? bufferSize : size;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700293
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400294 bool useFbMem = false;
295 char property[PROPERTY_VALUE_MAX];
296 if((usage & GRALLOC_USAGE_HW_FB) &&
297 (property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
298 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
299 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
300 useFbMem = true;
301 }
302
303 int err = 0;
304 if(useFbMem) {
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800305 err = gralloc_alloc_framebuffer(usage, pHandle);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400306 } else {
307 err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
308 grallocFormat, alignedw, alignedh);
309 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700310
311 if (err < 0) {
312 return err;
313 }
314
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700315 *pStride = alignedw;
316 return 0;
317}
318
319int gpu_context_t::free_impl(private_handle_t const* hnd) {
320 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400321 if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700322 const unsigned int bufferSize = m->finfo.line_length * m->info.yres;
323 unsigned int index = (unsigned int) ((hnd->base - m->framebuffer->base)
324 / bufferSize);
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800325 m->bufferMask &= ~(1LU<<index);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400326 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800327
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400328 terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
329 IMemAlloc* memalloc = mAllocCtrl->getAllocator(hnd->flags);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700330 int err = memalloc->free_buffer((void*)hnd->base, hnd->size,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400331 hnd->offset, hnd->fd);
332 if(err)
333 return err;
334 // free the metadata space
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700335 unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400336 err = memalloc->free_buffer((void*)hnd->base_metadata,
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800337 size, hnd->offset_metadata,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400338 hnd->fd_metadata);
339 if (err)
340 return err;
341 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700342 delete hnd;
343 return 0;
344}
345
346int gpu_context_t::gralloc_alloc(alloc_device_t* dev, int w, int h, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700347 int usage, buffer_handle_t* pHandle,
348 int* pStride)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700349{
350 if (!dev) {
351 return -EINVAL;
352 }
353 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
354 return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, 0);
355}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700356int gpu_context_t::gralloc_alloc_size(alloc_device_t* dev, int w, int h,
357 int format, int usage,
358 buffer_handle_t* pHandle, int* pStride,
359 int bufferSize)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700360{
361 if (!dev) {
362 return -EINVAL;
363 }
364 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
365 return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, bufferSize);
366}
367
368
369int gpu_context_t::gralloc_free(alloc_device_t* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700371{
372 if (private_handle_t::validate(handle) < 0)
373 return -EINVAL;
374
375 private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle);
376 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
377 return gpu->free_impl(hnd);
378}
379
380/*****************************************************************************/
381
382int gpu_context_t::gralloc_close(struct hw_device_t *dev)
383{
384 gpu_context_t* ctx = reinterpret_cast<gpu_context_t*>(dev);
385 if (ctx) {
386 /* TODO: keep a list of all buffer_handle_t created, and free them
387 * all here.
388 */
389 delete ctx;
390 }
391 return 0;
392}
393