blob: c1d77884cf35ca83951dc38b52c80425d30b1c6c [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>
Shalaj Jain1f9725a2015-03-04 17:53:49 -080029#include <linux/msm_ion.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070030
31using namespace gralloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070032
33gpu_context_t::gpu_context_t(const private_module_t* module,
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070034 IAllocController* alloc_ctrl ) :
Iliyan Malchev202a77d2012-06-11 14:41:12 -070035 mAllocCtrl(alloc_ctrl)
36{
37 // Zero out the alloc_device_t
38 memset(static_cast<alloc_device_t*>(this), 0, sizeof(alloc_device_t));
39
Iliyan Malchev202a77d2012-06-11 14:41:12 -070040 // Initialize the procs
41 common.tag = HARDWARE_DEVICE_TAG;
42 common.version = 0;
43 common.module = const_cast<hw_module_t*>(&module->base.common);
44 common.close = gralloc_close;
45 alloc = gralloc_alloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070046 free = gralloc_free;
47
48}
49
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070050int gpu_context_t::gralloc_alloc_buffer(unsigned int size, int usage,
Iliyan Malchev202a77d2012-06-11 14:41:12 -070051 buffer_handle_t* pHandle, int bufferType,
52 int format, int width, int height)
53{
54 int err = 0;
55 int flags = 0;
56 size = roundUpToPageSize(size);
57 alloc_data data;
58 data.offset = 0;
59 data.fd = -1;
60 data.base = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070061 if(format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED)
62 data.align = 8192;
63 else
64 data.align = getpagesize();
Praveen Chavan4e931c12012-11-28 19:43:17 -080065
Naseer Ahmedde758fd2016-05-03 15:10:23 -040066 if (usage & GRALLOC_USAGE_PROTECTED) {
Shalaj Jain1f9725a2015-03-04 17:53:49 -080067 if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
68 /* The alignment here reflects qsee mmu V7L/V8L requirement */
69 data.align = SZ_2M;
70 } else {
71 data.align = SECURE_ALIGN;
72 }
Praveen Chavan4e931c12012-11-28 19:43:17 -080073 size = ALIGN(size, data.align);
74 }
Naseer Ahmed84786722013-06-14 16:29:59 -040075
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();
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -050089 int eDataUsage = 0;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080090 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 }
Saurabh Shahbddb9522015-09-30 13:31:55 -070097
Arun Kumar K.R48a57552015-09-03 11:37:35 -070098 if (usage & GRALLOC_USAGE_PRIVATE_INTERNAL_ONLY) {
99 flags |= private_handle_t::PRIV_FLAGS_INTERNAL_ONLY;
100 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400101
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800102 if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) {
103 flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
104 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400105
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800106 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
107 flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
108 }
Naseer Ahmed59802502012-08-21 17:03:27 -0400109
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800110 if (usage & GRALLOC_USAGE_HW_CAMERA_READ) {
111 flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
112 }
113
Naseer Ahmede41ad9c2013-04-05 17:59:28 -0400114 if (usage & GRALLOC_USAGE_HW_COMPOSER) {
115 flags |= private_handle_t::PRIV_FLAGS_HW_COMPOSER;
116 }
117
Shuzhen Wang46ca2262013-04-10 23:02:22 -0700118 if (usage & GRALLOC_USAGE_HW_TEXTURE) {
119 flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
120 }
121
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700122 if(usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
123 flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
124 }
125
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700126 if(isMacroTileEnabled(format, usage)) {
127 flags |= private_handle_t::PRIV_FLAGS_TILE_RENDERED;
128 }
129
Sushil Chauhan7807d192015-08-13 10:10:48 -0700130 if (isUBwcEnabled(format, usage)) {
Sushil Chauhan65e26302015-01-14 10:48:57 -0800131 flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
132 }
133
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800134 if(usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
135 flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
136 }
137
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800138 if (usage & (GRALLOC_USAGE_HW_VIDEO_ENCODER |
139 GRALLOC_USAGE_HW_CAMERA_WRITE |
140 GRALLOC_USAGE_HW_RENDER |
141 GRALLOC_USAGE_HW_FB)) {
142 flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
143 }
144
Surajit Podder074314d2015-06-25 01:43:20 +0530145 if(usage & GRALLOC_USAGE_HW_COMPOSER) {
146 flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER;
147 }
148
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800149 if(false == data.uncached) {
150 flags |= private_handle_t::PRIV_FLAGS_CACHED;
151 }
152
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700153 flags |= data.allocType;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700154 uint64_t eBaseAddr = (uint64_t)(eData.base) + eData.offset;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800155 private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
156 bufferType, format, width, height, eData.fd, eData.offset,
157 eBaseAddr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700158
159 hnd->offset = data.offset;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700160 hnd->base = (uint64_t)(data.base) + data.offset;
Naseer Ahmeda163b732013-02-12 14:53:33 -0500161 hnd->gpuaddr = 0;
Arun Kumar K.Rf2a64662016-05-03 12:07:31 -0700162 ColorSpace_t colorSpace = ITU_R_601_FR;
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
Naomi Luiscffc5bd2015-08-28 14:57:31 -0700178 if (isUncompressedRgbFormat(inputFormat) == TRUE) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700179 // RGB formats
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700180 *bufferType = BUFFER_TYPE_UI;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700181 }
182}
183
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800184int gpu_context_t::gralloc_alloc_framebuffer_locked(int usage,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400185 buffer_handle_t* pHandle)
186{
187 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
188
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -0500189 // This allocation will only happen when gralloc is in fb mode
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400190
191 if (m->framebuffer == NULL) {
192 ALOGE("%s: Invalid framebuffer", __FUNCTION__);
193 return -EINVAL;
194 }
195
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700196 const unsigned int bufferMask = m->bufferMask;
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400197 const uint32_t numBuffers = m->numBuffers;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700198 unsigned int bufferSize = m->finfo.line_length * m->info.yres;
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400199
200 //adreno needs FB size to be page aligned
201 bufferSize = roundUpToPageSize(bufferSize);
202
203 if (numBuffers == 1) {
204 // If we have only one buffer, we never use page-flipping. Instead,
205 // we return a regular buffer which will be memcpy'ed to the main
206 // screen when post is called.
207 int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D;
208 return gralloc_alloc_buffer(bufferSize, newUsage, pHandle, BUFFER_TYPE_UI,
209 m->fbFormat, m->info.xres, m->info.yres);
210 }
211
212 if (bufferMask >= ((1LU<<numBuffers)-1)) {
213 // We ran out of buffers.
214 return -ENOMEM;
215 }
216
217 // create a "fake" handle for it
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700218 uint64_t vaddr = uint64_t(m->framebuffer->base);
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700219 // As GPU needs ION FD, the private handle is created
220 // using ION fd and ION flags are set
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400221 private_handle_t* hnd = new private_handle_t(
222 dup(m->framebuffer->fd), bufferSize,
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700223 private_handle_t::PRIV_FLAGS_USES_ION |
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400224 private_handle_t::PRIV_FLAGS_FRAMEBUFFER,
225 BUFFER_TYPE_UI, m->fbFormat, m->info.xres,
226 m->info.yres);
227
228 // find a free slot
229 for (uint32_t i=0 ; i<numBuffers ; i++) {
230 if ((bufferMask & (1LU<<i)) == 0) {
Shalaj Jaina70b4352014-06-15 13:47:47 -0700231 m->bufferMask |= (uint32_t)(1LU<<i);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400232 break;
233 }
234 vaddr += bufferSize;
235 }
236 hnd->base = vaddr;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700237 hnd->offset = (unsigned int)(vaddr - m->framebuffer->base);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400238 *pHandle = hnd;
239 return 0;
240}
241
242
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800243int gpu_context_t::gralloc_alloc_framebuffer(int usage,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400244 buffer_handle_t* pHandle)
245{
246 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
247 pthread_mutex_lock(&m->lock);
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800248 int err = gralloc_alloc_framebuffer_locked(usage, pHandle);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400249 pthread_mutex_unlock(&m->lock);
250 return err;
251}
252
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700253int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254 buffer_handle_t* pHandle, int* pStride,
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700255 unsigned int bufferSize) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700256 if (!pHandle || !pStride)
257 return -EINVAL;
258
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700259 unsigned int size;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700260 int alignedw, alignedh;
Naseer Ahmed59802502012-08-21 17:03:27 -0400261 int grallocFormat = format;
262 int bufferType;
Naseer Ahmed59802502012-08-21 17:03:27 -0400263
Saurabh Shahaedf2362012-09-05 11:30:59 -0700264 //If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
265 //the usage bits, gralloc assigns a format.
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400266 if(format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
267 format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
Sushil Chauhan32333292015-02-04 18:56:32 -0800268 if (usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC)
269 grallocFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
270 else if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
Naseer Ahmedf2feca92013-08-16 14:48:59 -0400271 grallocFormat = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; //NV12
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700272 else if((usage & GRALLOC_USAGE_HW_CAMERA_MASK)
273 == GRALLOC_USAGE_HW_CAMERA_ZSL)
274 grallocFormat = HAL_PIXEL_FORMAT_NV21_ZSL; //NV21 ZSL
Saurabh Shahaedf2362012-09-05 11:30:59 -0700275 else if(usage & GRALLOC_USAGE_HW_CAMERA_READ)
276 grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
Ranjith Kagathi Ananda330b21d2015-08-17 16:41:08 -0700277 else if(usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
278 if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
Nagesh Subba Reddy81a519f2015-08-29 18:01:49 -0700279 grallocFormat = HAL_PIXEL_FORMAT_NV21_ZSL; //NV21
Ranjith Kagathi Ananda330b21d2015-08-17 16:41:08 -0700280 } else {
281 grallocFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; //NV12 preview
282 }
283 } else if(usage & GRALLOC_USAGE_HW_COMPOSER)
Manoj Kumar AVMcdb4fd52013-10-25 19:40:45 -0700284 //XXX: If we still haven't set a format, default to RGBA8888
285 grallocFormat = HAL_PIXEL_FORMAT_RGBA_8888;
Nagesh Subba Reddy81a519f2015-08-29 18:01:49 -0700286 else if(format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
287 //If no other usage flags are detected, default the
288 //flexible YUV format to NV21_ZSL
289 grallocFormat = HAL_PIXEL_FORMAT_NV21_ZSL;
290 }
Baldev Sahu5f673b42013-12-05 09:49:09 +0530291 }
292
Sushil Chauhan68c793a2015-04-16 16:31:22 -0700293 bool useFbMem = false;
294 char property[PROPERTY_VALUE_MAX];
295 char isUBWC[PROPERTY_VALUE_MAX];
296 if (usage & GRALLOC_USAGE_HW_FB) {
297 if ((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 } else {
Sushil Chauhanc9853b52015-09-30 18:43:11 -0700302 usage &= ~GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
Sushil Chauhan68c793a2015-04-16 16:31:22 -0700303 if (property_get("debug.gralloc.enable_fb_ubwc", isUBWC, NULL) > 0){
304 if ((!strncmp(isUBWC, "1", PROPERTY_VALUE_MAX)) ||
305 (!strncasecmp(isUBWC, "true", PROPERTY_VALUE_MAX))) {
306 // Allocate UBWC aligned framebuffer
307 usage |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
308 }
309 }
310 }
311 }
312
Saurabh Shahaedf2362012-09-05 11:30:59 -0700313 getGrallocInformationFromFormat(grallocFormat, &bufferType);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700314 size = getBufferSizeAndDimensions(w, h, grallocFormat, usage, alignedw,
315 alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700316
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700317 if ((unsigned int)size <= 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700318 return -EINVAL;
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800319 size = (bufferSize >= size)? bufferSize : size;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700320
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400321 int err = 0;
322 if(useFbMem) {
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800323 err = gralloc_alloc_framebuffer(usage, pHandle);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400324 } else {
325 err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
326 grallocFormat, alignedw, alignedh);
327 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700328
329 if (err < 0) {
330 return err;
331 }
332
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700333 *pStride = alignedw;
334 return 0;
335}
336
337int gpu_context_t::free_impl(private_handle_t const* hnd) {
338 private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400339 if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700340 const unsigned int bufferSize = m->finfo.line_length * m->info.yres;
341 unsigned int index = (unsigned int) ((hnd->base - m->framebuffer->base)
342 / bufferSize);
Shalaj Jaina70b4352014-06-15 13:47:47 -0700343 m->bufferMask &= (uint32_t)~(1LU<<index);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400344 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800345
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400346 terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
347 IMemAlloc* memalloc = mAllocCtrl->getAllocator(hnd->flags);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700348 int err = memalloc->free_buffer((void*)hnd->base, hnd->size,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400349 hnd->offset, hnd->fd);
350 if(err)
351 return err;
352 // free the metadata space
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700353 unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400354 err = memalloc->free_buffer((void*)hnd->base_metadata,
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800355 size, hnd->offset_metadata,
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400356 hnd->fd_metadata);
357 if (err)
358 return err;
359 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700360 delete hnd;
361 return 0;
362}
363
364int gpu_context_t::gralloc_alloc(alloc_device_t* dev, int w, int h, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365 int usage, buffer_handle_t* pHandle,
366 int* pStride)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700367{
368 if (!dev) {
369 return -EINVAL;
370 }
371 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
372 return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, 0);
373}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374int gpu_context_t::gralloc_alloc_size(alloc_device_t* dev, int w, int h,
375 int format, int usage,
376 buffer_handle_t* pHandle, int* pStride,
377 int bufferSize)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700378{
379 if (!dev) {
380 return -EINVAL;
381 }
382 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
383 return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, bufferSize);
384}
385
386
387int gpu_context_t::gralloc_free(alloc_device_t* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700389{
390 if (private_handle_t::validate(handle) < 0)
391 return -EINVAL;
392
393 private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle);
394 gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
395 return gpu->free_impl(hnd);
396}
397
398/*****************************************************************************/
399
400int gpu_context_t::gralloc_close(struct hw_device_t *dev)
401{
402 gpu_context_t* ctx = reinterpret_cast<gpu_context_t*>(dev);
403 if (ctx) {
404 /* TODO: keep a list of all buffer_handle_t created, and free them
405 * all here.
406 */
407 delete ctx;
408 }
409 return 0;
410}
411