blob: 3b6bf20f5621d50a5f387a8b549943bac64a16ac [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
Duy Truong73d36df2013-02-09 20:33:23 -08002 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07003
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
Duy Truong73d36df2013-02-09 20:33:23 -080013 * * Neither the name of The Linux Foundation nor the names of its
Iliyan Malchev202a77d2012-06-11 14:41:12 -070014 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <cutils/log.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070031#include <fcntl.h>
Naomi Luis01f5c8e2013-02-11 12:46:24 -080032#include <dlfcn.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070033#include "gralloc_priv.h"
34#include "alloc_controller.h"
35#include "memalloc.h"
36#include "ionalloc.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070037#include "gr.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070038#include "comptype.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070039
Sushil Chauhanc6bd6d92012-12-12 12:33:01 -080040#ifdef VENUS_COLOR_FORMAT
41#include <media/msm_media_info.h>
42#else
43#define VENUS_Y_STRIDE(args...) 0
44#define VENUS_Y_SCANLINES(args...) 0
45#define VENUS_BUFFER_SIZE(args...) 0
46#endif
47
Iliyan Malchev202a77d2012-06-11 14:41:12 -070048using namespace gralloc;
Naseer Ahmeda87da602012-07-01 23:54:19 -070049using namespace qdutils;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070050
Naomi Luisa44100c2013-02-08 12:42:03 -080051ANDROID_SINGLETON_STATIC_INSTANCE(AdrenoMemInfo);
52
Iliyan Malchev202a77d2012-06-11 14:41:12 -070053//Common functions
Naseer Ahmed29a26812012-06-14 00:56:20 -070054static bool canFallback(int usage, bool triedSystem)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055{
56 // Fallback to system heap when alloc fails unless
57 // 1. Composition type is MDP
58 // 2. Alloc from system heap was already tried
59 // 3. The heap type is requsted explicitly
60 // 4. The heap type is protected
61 // 5. The buffer is meant for external display only
62
Naseer Ahmeda87da602012-07-01 23:54:19 -070063 if(QCCompositionType::getInstance().getCompositionType() &
64 COMPOSITION_TYPE_MDP)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070065 return false;
66 if(triedSystem)
67 return false;
Sushil Chauhan7651a802013-01-08 16:08:09 -080068 if(usage & (GRALLOC_HEAP_MASK | GRALLOC_USAGE_PROTECTED))
Iliyan Malchev202a77d2012-06-11 14:41:12 -070069 return false;
Naseer Ahmed4c588a22012-07-31 19:12:17 -070070 if(usage & (GRALLOC_HEAP_MASK | GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY))
Iliyan Malchev202a77d2012-06-11 14:41:12 -070071 return false;
72 //Return true by default
73 return true;
74}
75
76static bool useUncached(int usage)
77{
Naseer Ahmed26867882013-08-21 15:16:24 -040078 if (usage & GRALLOC_USAGE_PRIVATE_UNCACHED)
79 return true;
80 if(((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_RARELY)
81 ||((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_RARELY))
Iliyan Malchev202a77d2012-06-11 14:41:12 -070082 return true;
83 return false;
84}
85
Naomi Luisa44100c2013-02-08 12:42:03 -080086//-------------- AdrenoMemInfo-----------------------//
Naomi Luis01f5c8e2013-02-11 12:46:24 -080087AdrenoMemInfo::AdrenoMemInfo()
88{
89 libadreno_utils = ::dlopen("libadreno_utils.so", RTLD_NOW);
90 if (libadreno_utils) {
91 *(void **)&LINK_adreno_compute_padding = ::dlsym(libadreno_utils,
92 "compute_surface_padding");
93 }
94}
95
96AdrenoMemInfo::~AdrenoMemInfo()
97{
98 if (libadreno_utils) {
99 ::dlclose(libadreno_utils);
100 }
101}
102
Naomi Luisa44100c2013-02-08 12:42:03 -0800103int AdrenoMemInfo::getStride(int width, int format)
104{
105 int stride = ALIGN(width, 32);
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800106 // Currently surface padding is only computed for RGB* surfaces.
107 if (format < 0x7) {
Naomi Luis1b379692013-05-06 12:13:07 -0700108 // Don't add any additional padding if debug.gralloc.map_fb_memory
109 // is enabled
110 char property[PROPERTY_VALUE_MAX];
111 if((property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
112 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
113 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
114 return stride;
115 }
116
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800117 int bpp = 4;
118 switch(format)
119 {
120 case HAL_PIXEL_FORMAT_RGB_888:
121 bpp = 3;
122 break;
123 case HAL_PIXEL_FORMAT_RGB_565:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800124 bpp = 2;
125 break;
126 default: break;
127 }
128 if ((libadreno_utils) && (LINK_adreno_compute_padding)) {
129 int surface_tile_height = 1; // Linear surface
Naomi Luisb65b2342013-03-27 23:32:06 -0700130 int raster_mode = 0; // Adreno unknown raster mode.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800131 int padding_threshold = 512; // Threshold for padding surfaces.
132 // the function below expects the width to be a multiple of
133 // 32 pixels, hence we pass stride instead of width.
134 stride = LINK_adreno_compute_padding(stride, bpp,
135 surface_tile_height, raster_mode,
136 padding_threshold);
137 }
138 } else {
139 switch (format)
140 {
141 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400142 case HAL_PIXEL_FORMAT_RAW_SENSOR:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800143 stride = ALIGN(width, 32);
144 break;
145 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
146 stride = ALIGN(width, 128);
147 break;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800148 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
149 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
150 case HAL_PIXEL_FORMAT_YV12:
151 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
152 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700153 case HAL_PIXEL_FORMAT_YCbCr_422_I:
154 case HAL_PIXEL_FORMAT_YCrCb_422_I:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800155 stride = ALIGN(width, 16);
156 break;
157 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400158 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800159 stride = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
160 break;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400161 case HAL_PIXEL_FORMAT_BLOB:
162 stride = width;
163 break;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800164 default: break;
165 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800166 }
167 return stride;
168}
169
170//-------------- IAllocController-----------------------//
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700171IAllocController* IAllocController::sController = NULL;
172IAllocController* IAllocController::getInstance(void)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700173{
174 if(sController == NULL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700175 sController = new IonController();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700176 }
177 return sController;
178}
179
180
181//-------------- IonController-----------------------//
182IonController::IonController()
183{
184 mIonAlloc = new IonAlloc();
185}
186
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700187int IonController::allocate(alloc_data& data, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700188{
189 int ionFlags = 0;
190 int ret;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700191
192 data.uncached = useUncached(usage);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193 data.allocType = 0;
194
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700195 if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP)
196 ionFlags |= ION_HEAP(ION_SF_HEAP_ID);
197
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500198 if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700199 ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700200
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500201 if(usage & GRALLOC_USAGE_PRIVATE_IOMMU_HEAP)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700202 ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
203
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530204 if(usage & GRALLOC_USAGE_PROTECTED) {
Prabhanjan Kandulae8f4bec2013-10-24 16:32:51 +0530205 if (usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500206 ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID);
207 ionFlags |= ION_SECURE;
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530208 } else {
209 // for targets/OEMs which do not need HW level protection
210 // do not set ion secure flag & MM heap. Fallback to IOMMU heap.
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500211 ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
212 }
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530213 } else if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
214 //MM Heap is exclusively a secure heap.
215 //If it is used for non secure cases, fallback to IOMMU heap
216 ALOGW("GRALLOC_USAGE_PRIVATE_MM_HEAP \
217 cannot be used as an insecure heap!\
218 trying to use IOMMU instead !!");
219 ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500220 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700221
Arun Kumar K.Rff78b892013-05-24 12:37:51 -0700222 if(usage & GRALLOC_USAGE_PRIVATE_CAMERA_HEAP)
223 ionFlags |= ION_HEAP(ION_CAMERA_HEAP_ID);
224
Arun Kumar K.R0daaa992013-03-12 15:08:29 -0700225 if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP)
226 ionFlags |= ION_HEAP(ION_ADSP_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700227
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530228 if(ionFlags & ION_SECURE)
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500229 data.allocType |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700230
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700231 // if no flags are set, default to
232 // SF + IOMMU heaps, so that bypass can work
233 // we can fall back to system heap if
234 // we run out.
235 if(!ionFlags)
236 ionFlags = ION_HEAP(ION_SF_HEAP_ID) | ION_HEAP(ION_IOMMU_HEAP_ID);
237
238 data.flags = ionFlags;
239 ret = mIonAlloc->alloc_buffer(data);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700241 // Fallback
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242 if(ret < 0 && canFallback(usage,
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700243 (ionFlags & ION_SYSTEM_HEAP_ID)))
244 {
245 ALOGW("Falling back to system heap");
246 data.flags = ION_HEAP(ION_SYSTEM_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700247 ret = mIonAlloc->alloc_buffer(data);
248 }
249
250 if(ret >= 0 ) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700251 data.allocType |= private_handle_t::PRIV_FLAGS_USES_ION;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700252 }
253
254 return ret;
255}
256
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700257IMemAlloc* IonController::getAllocator(int flags)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700258{
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700259 IMemAlloc* memalloc = NULL;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700260 if (flags & private_handle_t::PRIV_FLAGS_USES_ION) {
261 memalloc = mIonAlloc;
262 } else {
263 ALOGE("%s: Invalid flags passed: 0x%x", __FUNCTION__, flags);
264 }
265
266 return memalloc;
267}
268
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700269size_t getBufferSizeAndDimensions(int width, int height, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270 int& alignedw, int &alignedh)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700271{
272 size_t size;
273
Naomi Luisa44100c2013-02-08 12:42:03 -0800274 alignedw = AdrenoMemInfo::getInstance().getStride(width, format);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700275 alignedh = ALIGN(height, 32);
276 switch (format) {
277 case HAL_PIXEL_FORMAT_RGBA_8888:
278 case HAL_PIXEL_FORMAT_RGBX_8888:
279 case HAL_PIXEL_FORMAT_BGRA_8888:
280 size = alignedw * alignedh * 4;
281 break;
282 case HAL_PIXEL_FORMAT_RGB_888:
283 size = alignedw * alignedh * 3;
284 break;
285 case HAL_PIXEL_FORMAT_RGB_565:
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400286 case HAL_PIXEL_FORMAT_RAW_SENSOR:
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700287 size = alignedw * alignedh * 2;
288 break;
289
290 // adreno formats
291 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21
292 size = ALIGN(alignedw*alignedh, 4096);
293 size += ALIGN(2 * ALIGN(width/2, 32) * ALIGN(height/2, 32), 4096);
294 break;
295 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12
296 // The chroma plane is subsampled,
297 // but the pitch in bytes is unchanged
298 // The GPU needs 4K alignment, but the video decoder needs 8K
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700299 size = ALIGN( alignedw * alignedh, 8192);
300 size += ALIGN( alignedw * ALIGN(height/2, 32), 8192);
301 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700302 case HAL_PIXEL_FORMAT_YV12:
303 if ((format == HAL_PIXEL_FORMAT_YV12) && ((width&1) || (height&1))) {
304 ALOGE("w or h is odd for the YV12 format");
305 return -EINVAL;
306 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700307 alignedh = height;
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400308 size = alignedw*alignedh +
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309 (ALIGN(alignedw/2, 16) * (alignedh/2))*2;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700310 size = ALIGN(size, 4096);
311 break;
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800312 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
313 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
314 alignedh = height;
315 size = ALIGN((alignedw*alignedh) + (alignedw* alignedh)/2, 4096);
316 break;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700317 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
318 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700319 case HAL_PIXEL_FORMAT_YCbCr_422_I:
320 case HAL_PIXEL_FORMAT_YCrCb_422_I:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700321 if(width & 1) {
322 ALOGE("width is odd for the YUV422_SP format");
323 return -EINVAL;
324 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325 alignedh = height;
326 size = ALIGN(alignedw * alignedh * 2, 4096);
327 break;
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700328 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400329 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Sushil Chauhan73dcce42012-11-15 14:25:19 -0800330 alignedh = VENUS_Y_SCANLINES(COLOR_FMT_NV12, height);
Sushil Chauhane8a01792012-11-01 16:25:45 -0700331 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height);
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700332 break;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400333 case HAL_PIXEL_FORMAT_BLOB:
334 if(height != 1) {
335 ALOGE("%s: Buffers with format HAL_PIXEL_FORMAT_BLOB \
336 must have height==1 ", __FUNCTION__);
337 return -EINVAL;
338 }
339 alignedh = height;
340 alignedw = width;
341 size = width;
342 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700343 default:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344 ALOGE("unrecognized pixel format: 0x%x", format);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700345 return -EINVAL;
346 }
347
348 return size;
349}
350
351// Allocate buffer from width, height and format into a
352// private_handle_t. It is the responsibility of the caller
353// to free the buffer using the free_buffer function
354int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
355{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700356 alloc_data data;
357 int alignedw, alignedh;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700358 gralloc::IAllocController* sAlloc =
359 gralloc::IAllocController::getInstance();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700360 data.base = 0;
361 data.fd = -1;
362 data.offset = 0;
363 data.size = getBufferSizeAndDimensions(w, h, format, alignedw, alignedh);
364 data.align = getpagesize();
365 data.uncached = useUncached(usage);
366 int allocFlags = usage;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700367
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700368 int err = sAlloc->allocate(data, allocFlags);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700369 if (0 != err) {
370 ALOGE("%s: allocate failed", __FUNCTION__);
371 return -ENOMEM;
372 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700373
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374 private_handle_t* hnd = new private_handle_t(data.fd, data.size,
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700375 data.allocType, 0, format,
376 alignedw, alignedh);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377 hnd->base = (int) data.base;
378 hnd->offset = data.offset;
379 hnd->gpuaddr = 0;
380 *pHnd = hnd;
381 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700382}
383
384void free_buffer(private_handle_t *hnd)
385{
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700386 gralloc::IAllocController* sAlloc =
387 gralloc::IAllocController::getInstance();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700388 if (hnd && hnd->fd > 0) {
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700389 IMemAlloc* memalloc = sAlloc->getAllocator(hnd->flags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700390 memalloc->free_buffer((void*)hnd->base, hnd->size, hnd->offset, hnd->fd);
391 }
392 if(hnd)
393 delete hnd;
394
395}