blob: fd81c708eabe76521ce12d4994c3bd4d3ea94b74 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
Arun Kumar K.R6c85f052014-01-21 21:47:41 -08002 * Copyright (c) 2011-2014, 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"
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070039#include "mdp_version.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070040
Sushil Chauhanc6bd6d92012-12-12 12:33:01 -080041#ifdef VENUS_COLOR_FORMAT
42#include <media/msm_media_info.h>
43#else
44#define VENUS_Y_STRIDE(args...) 0
45#define VENUS_Y_SCANLINES(args...) 0
46#define VENUS_BUFFER_SIZE(args...) 0
47#endif
48
Naseer Ahmed63326f42013-12-18 02:45:48 -050049#define ASTC_BLOCK_SIZE 16
Naseer Ahmed63326f42013-12-18 02:45:48 -050050
Iliyan Malchev202a77d2012-06-11 14:41:12 -070051using namespace gralloc;
Naseer Ahmeda87da602012-07-01 23:54:19 -070052using namespace qdutils;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070053
Naomi Luisa44100c2013-02-08 12:42:03 -080054ANDROID_SINGLETON_STATIC_INSTANCE(AdrenoMemInfo);
55
Iliyan Malchev202a77d2012-06-11 14:41:12 -070056//Common functions
Naseer Ahmed29a26812012-06-14 00:56:20 -070057static bool canFallback(int usage, bool triedSystem)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070058{
59 // Fallback to system heap when alloc fails unless
60 // 1. Composition type is MDP
61 // 2. Alloc from system heap was already tried
62 // 3. The heap type is requsted explicitly
63 // 4. The heap type is protected
64 // 5. The buffer is meant for external display only
65
Naseer Ahmeda87da602012-07-01 23:54:19 -070066 if(QCCompositionType::getInstance().getCompositionType() &
67 COMPOSITION_TYPE_MDP)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070068 return false;
69 if(triedSystem)
70 return false;
Sushil Chauhan7651a802013-01-08 16:08:09 -080071 if(usage & (GRALLOC_HEAP_MASK | GRALLOC_USAGE_PROTECTED))
Iliyan Malchev202a77d2012-06-11 14:41:12 -070072 return false;
Naseer Ahmed4c588a22012-07-31 19:12:17 -070073 if(usage & (GRALLOC_HEAP_MASK | GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY))
Iliyan Malchev202a77d2012-06-11 14:41:12 -070074 return false;
75 //Return true by default
76 return true;
77}
78
Saurabh Shah1adcafe2014-12-19 10:05:41 -080079/* The default policy is to return cached buffers unless the client explicity
80 * sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely
81 * read or written in software. Any combination with a _RARELY_ flag will be
82 * treated as uncached. */
83static bool useUncached(const int& usage) {
84 if((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) or
85 ((usage & GRALLOC_USAGE_SW_WRITE_MASK) ==
86 GRALLOC_USAGE_SW_WRITE_RARELY) or
87 ((usage & GRALLOC_USAGE_SW_READ_MASK) ==
88 GRALLOC_USAGE_SW_READ_RARELY))
89 return true;
90
91 return false;
92}
93
Naomi Luisa44100c2013-02-08 12:42:03 -080094//-------------- AdrenoMemInfo-----------------------//
Naomi Luis01f5c8e2013-02-11 12:46:24 -080095AdrenoMemInfo::AdrenoMemInfo()
96{
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -080097 LINK_adreno_compute_aligned_width_and_height = NULL;
98 LINK_adreno_compute_padding = NULL;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070099 LINK_adreno_isMacroTilingSupportedByGpu = NULL;
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800100 LINK_adreno_compute_compressedfmt_aligned_width_and_height = NULL;
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800101
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800102 libadreno_utils = ::dlopen("libadreno_utils.so", RTLD_NOW);
103 if (libadreno_utils) {
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800104 *(void **)&LINK_adreno_compute_aligned_width_and_height =
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700105 ::dlsym(libadreno_utils, "compute_aligned_width_and_height");
106 *(void **)&LINK_adreno_compute_padding =
107 ::dlsym(libadreno_utils, "compute_surface_padding");
108 *(void **)&LINK_adreno_isMacroTilingSupportedByGpu =
109 ::dlsym(libadreno_utils, "isMacroTilingSupportedByGpu");
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800110 *(void **)&LINK_adreno_compute_compressedfmt_aligned_width_and_height =
111 ::dlsym(libadreno_utils,
112 "compute_compressedfmt_aligned_width_and_height");
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800113 }
114}
115
116AdrenoMemInfo::~AdrenoMemInfo()
117{
118 if (libadreno_utils) {
119 ::dlclose(libadreno_utils);
120 }
121}
122
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700123int AdrenoMemInfo::isMacroTilingSupportedByGPU()
124{
125 if ((libadreno_utils)) {
126 if(LINK_adreno_isMacroTilingSupportedByGpu) {
127 return LINK_adreno_isMacroTilingSupportedByGpu();
128 }
129 }
130 return 0;
131}
132
133
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800134void AdrenoMemInfo::getAlignedWidthAndHeight(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700135 int tile_enabled, int& aligned_w, int& aligned_h)
Naomi Luisa44100c2013-02-08 12:42:03 -0800136{
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800137 aligned_w = width;
138 aligned_h = height;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800139 // Currently surface padding is only computed for RGB* surfaces.
Jesse Hallfbe96d22013-09-20 01:39:43 -0700140 if (format <= HAL_PIXEL_FORMAT_sRGB_X_8888) {
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800141 aligned_w = ALIGN(width, 32);
142 aligned_h = ALIGN(height, 32);
Naomi Luis1b379692013-05-06 12:13:07 -0700143 // Don't add any additional padding if debug.gralloc.map_fb_memory
144 // is enabled
145 char property[PROPERTY_VALUE_MAX];
146 if((property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
147 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
148 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800149 return;
Naomi Luis1b379692013-05-06 12:13:07 -0700150 }
151
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800152 int bpp = 4;
153 switch(format)
154 {
155 case HAL_PIXEL_FORMAT_RGB_888:
156 bpp = 3;
157 break;
158 case HAL_PIXEL_FORMAT_RGB_565:
Ramkumar Radhakrishnan96439522014-10-09 13:37:52 -0700159 case HAL_PIXEL_FORMAT_RGBA_5551:
160 case HAL_PIXEL_FORMAT_RGBA_4444:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800161 bpp = 2;
162 break;
163 default: break;
164 }
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800165 if (libadreno_utils) {
Naomi Luisb65b2342013-03-27 23:32:06 -0700166 int raster_mode = 0; // Adreno unknown raster mode.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800167 int padding_threshold = 512; // Threshold for padding surfaces.
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800168 // the function below computes aligned width and aligned height
169 // based on linear or macro tile mode selected.
170 if(LINK_adreno_compute_aligned_width_and_height) {
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700171 LINK_adreno_compute_aligned_width_and_height(width,
172 height, bpp, tile_enabled,
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800173 raster_mode, padding_threshold,
174 &aligned_w, &aligned_h);
175
176 } else if(LINK_adreno_compute_padding) {
177 int surface_tile_height = 1; // Linear surface
178 aligned_w = LINK_adreno_compute_padding(width, bpp,
179 surface_tile_height, raster_mode,
180 padding_threshold);
181 ALOGW("%s: Warning!! Old GFX API is used to calculate stride",
182 __FUNCTION__);
183 } else {
184 ALOGW("%s: Warning!! Symbols compute_surface_padding and " \
185 "compute_aligned_width_and_height not found", __FUNCTION__);
186 }
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800187 }
188 } else {
189 switch (format)
190 {
Naseer Ahmed0415b732014-05-29 16:36:34 -0400191 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800192 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400193 case HAL_PIXEL_FORMAT_RAW_SENSOR:
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800194 aligned_w = ALIGN(width, 32);
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800195 break;
196 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800197 aligned_w = ALIGN(width, 128);
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800198 break;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800199 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800200 case HAL_PIXEL_FORMAT_YV12:
201 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
202 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700203 case HAL_PIXEL_FORMAT_YCbCr_422_I:
204 case HAL_PIXEL_FORMAT_YCrCb_422_I:
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800205 aligned_w = ALIGN(width, 16);
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800206 break;
207 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400208 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800209 aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800210 aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12, height);
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800211 break;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400212 case HAL_PIXEL_FORMAT_BLOB:
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400213 break;
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700214 case HAL_PIXEL_FORMAT_NV21_ZSL:
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800215 aligned_w = ALIGN(width, 64);
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800216 aligned_h = ALIGN(height, 64);
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700217 break;
Naseer Ahmed63326f42013-12-18 02:45:48 -0500218 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
219 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500220 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR:
221 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500222 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR:
223 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500224 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR:
225 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500226 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR:
227 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500228 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR:
229 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500230 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR:
231 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500232 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR:
233 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500234 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR:
235 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500236 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR:
237 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500238 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR:
239 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500240 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR:
241 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500242 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR:
243 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500244 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR:
245 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800246 if(LINK_adreno_compute_compressedfmt_aligned_width_and_height) {
247 int bytesPerPixel = 0;
248 int raster_mode = 0; //Adreno unknown raster mode.
249 int padding_threshold = 512; //Threshold for padding
250 //surfaces.
251
252 LINK_adreno_compute_compressedfmt_aligned_width_and_height(
253 width, height, format, 0,raster_mode, padding_threshold,
254 &aligned_w, &aligned_h, &bytesPerPixel);
255
256 } else {
257 ALOGW("%s: Warning!! Symbols" \
258 " compute_compressedfmt_aligned_width_and_height" \
259 " not found", __FUNCTION__);
260 }
Naseer Ahmed63326f42013-12-18 02:45:48 -0500261 break;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800262 default: break;
263 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800264 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800265}
266
267//-------------- IAllocController-----------------------//
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700268IAllocController* IAllocController::sController = NULL;
269IAllocController* IAllocController::getInstance(void)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700270{
271 if(sController == NULL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700272 sController = new IonController();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700273 }
274 return sController;
275}
276
277
278//-------------- IonController-----------------------//
279IonController::IonController()
280{
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530281 allocateIonMem();
282}
283
284void IonController::allocateIonMem()
285{
286 mIonAlloc = new IonAlloc();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700287}
288
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700289int IonController::allocate(alloc_data& data, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700290{
291 int ionFlags = 0;
292 int ret;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700293
294 data.uncached = useUncached(usage);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295 data.allocType = 0;
296
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700297 if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP)
298 ionFlags |= ION_HEAP(ION_SF_HEAP_ID);
299
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500300 if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700301 ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700302
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500303 if(usage & GRALLOC_USAGE_PRIVATE_IOMMU_HEAP)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700304 ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
305
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530306 if(usage & GRALLOC_USAGE_PROTECTED) {
Prabhanjan Kandulae8f4bec2013-10-24 16:32:51 +0530307 if (usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500308 ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID);
309 ionFlags |= ION_SECURE;
Shalaj Jain13cdf812014-12-02 16:20:54 -0800310#ifdef ION_FLAG_ALLOW_NON_CONTIG
311 if (!(usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY)) {
312 ionFlags |= ION_FLAG_ALLOW_NON_CONTIG;
313 }
314#endif
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530315 } else {
316 // for targets/OEMs which do not need HW level protection
317 // do not set ion secure flag & MM heap. Fallback to IOMMU heap.
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500318 ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
Justin Philipd6166602014-08-12 13:42:21 +0530319 data.allocType |= private_handle_t::PRIV_FLAGS_PROTECTED_BUFFER;
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500320 }
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530321 } else if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
322 //MM Heap is exclusively a secure heap.
323 //If it is used for non secure cases, fallback to IOMMU heap
324 ALOGW("GRALLOC_USAGE_PRIVATE_MM_HEAP \
325 cannot be used as an insecure heap!\
326 trying to use IOMMU instead !!");
327 ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500328 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700329
Arun Kumar K.Rff78b892013-05-24 12:37:51 -0700330 if(usage & GRALLOC_USAGE_PRIVATE_CAMERA_HEAP)
331 ionFlags |= ION_HEAP(ION_CAMERA_HEAP_ID);
332
Arun Kumar K.R0daaa992013-03-12 15:08:29 -0700333 if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP)
334 ionFlags |= ION_HEAP(ION_ADSP_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700335
Prabhanjan Kandula92896b82013-05-07 19:58:24 +0530336 if(ionFlags & ION_SECURE)
Naseer Ahmedc5e6fb02013-03-07 13:42:20 -0500337 data.allocType |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700338
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700339 // if no flags are set, default to
340 // SF + IOMMU heaps, so that bypass can work
341 // we can fall back to system heap if
342 // we run out.
343 if(!ionFlags)
344 ionFlags = ION_HEAP(ION_SF_HEAP_ID) | ION_HEAP(ION_IOMMU_HEAP_ID);
345
346 data.flags = ionFlags;
347 ret = mIonAlloc->alloc_buffer(data);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700348
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700349 // Fallback
Naseer Ahmed29a26812012-06-14 00:56:20 -0700350 if(ret < 0 && canFallback(usage,
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700351 (ionFlags & ION_SYSTEM_HEAP_ID)))
352 {
353 ALOGW("Falling back to system heap");
354 data.flags = ION_HEAP(ION_SYSTEM_HEAP_ID);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700355 ret = mIonAlloc->alloc_buffer(data);
356 }
357
358 if(ret >= 0 ) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700359 data.allocType |= private_handle_t::PRIV_FLAGS_USES_ION;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700360 }
361
362 return ret;
363}
364
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700365IMemAlloc* IonController::getAllocator(int flags)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700366{
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700367 IMemAlloc* memalloc = NULL;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700368 if (flags & private_handle_t::PRIV_FLAGS_USES_ION) {
369 memalloc = mIonAlloc;
370 } else {
371 ALOGE("%s: Invalid flags passed: 0x%x", __FUNCTION__, flags);
372 }
373
374 return memalloc;
375}
376
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700377bool isMacroTileEnabled(int format, int usage)
378{
379 bool tileEnabled = false;
380
381 // Check whether GPU & MDSS supports MacroTiling feature
382 if(AdrenoMemInfo::getInstance().isMacroTilingSupportedByGPU() &&
383 qdutils::MDPVersion::getInstance().supportsMacroTile())
384 {
385 // check the format
386 switch(format)
387 {
388 case HAL_PIXEL_FORMAT_RGBA_8888:
389 case HAL_PIXEL_FORMAT_RGBX_8888:
390 case HAL_PIXEL_FORMAT_BGRA_8888:
Manoj Kumar AVM5a5529b2014-02-24 18:16:37 -0800391 case HAL_PIXEL_FORMAT_RGB_565:
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700392 {
393 tileEnabled = true;
394 // check the usage flags
395 if (usage & (GRALLOC_USAGE_SW_READ_MASK |
396 GRALLOC_USAGE_SW_WRITE_MASK)) {
397 // Application intends to use CPU for rendering
398 tileEnabled = false;
399 }
400 break;
401 }
402 default:
403 break;
404 }
405 }
406 return tileEnabled;
407}
408
409// helper function
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700410unsigned int getSize(int format, int width, int height, const int alignedw,
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800411 const int alignedh) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700412 unsigned int size = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700413
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700414 switch (format) {
415 case HAL_PIXEL_FORMAT_RGBA_8888:
416 case HAL_PIXEL_FORMAT_RGBX_8888:
417 case HAL_PIXEL_FORMAT_BGRA_8888:
Naseer Ahmed82fc4b72013-09-20 01:31:37 -0700418 case HAL_PIXEL_FORMAT_sRGB_A_8888:
Jesse Hallfbe96d22013-09-20 01:39:43 -0700419 case HAL_PIXEL_FORMAT_sRGB_X_8888:
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700420 size = alignedw * alignedh * 4;
421 break;
422 case HAL_PIXEL_FORMAT_RGB_888:
423 size = alignedw * alignedh * 3;
424 break;
425 case HAL_PIXEL_FORMAT_RGB_565:
Ramkumar Radhakrishnan96439522014-10-09 13:37:52 -0700426 case HAL_PIXEL_FORMAT_RGBA_5551:
427 case HAL_PIXEL_FORMAT_RGBA_4444:
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400428 case HAL_PIXEL_FORMAT_RAW_SENSOR:
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700429 size = alignedw * alignedh * 2;
430 break;
431
432 // adreno formats
433 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21
434 size = ALIGN(alignedw*alignedh, 4096);
435 size += ALIGN(2 * ALIGN(width/2, 32) * ALIGN(height/2, 32), 4096);
436 break;
437 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12
438 // The chroma plane is subsampled,
439 // but the pitch in bytes is unchanged
440 // The GPU needs 4K alignment, but the video decoder needs 8K
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700441 size = ALIGN( alignedw * alignedh, 8192);
442 size += ALIGN( alignedw * ALIGN(height/2, 32), 8192);
443 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700444 case HAL_PIXEL_FORMAT_YV12:
445 if ((format == HAL_PIXEL_FORMAT_YV12) && ((width&1) || (height&1))) {
446 ALOGE("w or h is odd for the YV12 format");
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800447 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700448 }
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400449 size = alignedw*alignedh +
Naseer Ahmed29a26812012-06-14 00:56:20 -0700450 (ALIGN(alignedw/2, 16) * (alignedh/2))*2;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700451 size = ALIGN(size, (unsigned int)4096);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700452 break;
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800453 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
454 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
Naseer Ahmed2c215292013-09-18 23:47:42 -0400455 size = ALIGN((alignedw*alignedh) + (alignedw* alignedh)/2 + 1, 4096);
Ramkumar Radhakrishnan73f952a2013-03-05 14:14:24 -0800456 break;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700457 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
458 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700459 case HAL_PIXEL_FORMAT_YCbCr_422_I:
460 case HAL_PIXEL_FORMAT_YCrCb_422_I:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700461 if(width & 1) {
462 ALOGE("width is odd for the YUV422_SP format");
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800463 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700464 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700465 size = ALIGN(alignedw * alignedh * 2, 4096);
466 break;
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700467 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
Naseer Ahmedce0c9502013-08-15 13:07:24 -0400468 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
Sushil Chauhane8a01792012-11-01 16:25:45 -0700469 size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height);
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700470 break;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400471 case HAL_PIXEL_FORMAT_BLOB:
472 if(height != 1) {
473 ALOGE("%s: Buffers with format HAL_PIXEL_FORMAT_BLOB \
474 must have height==1 ", __FUNCTION__);
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800475 return 0;
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400476 }
Naseer Ahmed7669dae2013-04-17 20:23:53 -0400477 size = width;
478 break;
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700479 case HAL_PIXEL_FORMAT_NV21_ZSL:
Ramkumar Radhakrishnanff511022013-07-23 16:12:08 -0700480 size = ALIGN((alignedw*alignedh) + (alignedw* alignedh)/2, 4096);
481 break;
Naseer Ahmed63326f42013-12-18 02:45:48 -0500482 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
483 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR:
484 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR:
485 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR:
486 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR:
487 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR:
488 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR:
489 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR:
490 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR:
491 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR:
492 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR:
493 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR:
494 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR:
495 case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR:
496 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
497 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
498 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
499 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
500 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
501 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
502 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
503 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
504 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
505 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
506 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
507 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
508 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
Jeykumar Sankaran8f4585f2014-02-05 15:23:40 -0800509 case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
Naseer Ahmed63326f42013-12-18 02:45:48 -0500510 size = alignedw * alignedh * ASTC_BLOCK_SIZE;
511 break;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700512 default:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700513 ALOGE("unrecognized pixel format: 0x%x", format);
Saurabh Shahd0b0d8f2014-01-31 11:45:56 -0800514 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700515 }
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700516 return size;
517}
518
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700519unsigned int getBufferSizeAndDimensions(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700520 int& alignedw, int &alignedh)
521{
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700522 unsigned int size;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700523
524 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
525 height,
526 format,
527 false,
528 alignedw,
529 alignedh);
530
531 size = getSize(format, width, height, alignedw, alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700532
533 return size;
534}
535
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700536
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700537unsigned int getBufferSizeAndDimensions(int width, int height, int format,
538 int usage, int& alignedw, int &alignedh)
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700539{
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700540 unsigned int size;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700541 int tileEnabled = isMacroTileEnabled(format, usage);
542
543 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
544 height,
545 format,
546 tileEnabled,
547 alignedw,
548 alignedh);
549
550 size = getSize(format, width, height, alignedw, alignedh);
551
552 return size;
553}
554
555
556void getBufferAttributes(int width, int height, int format, int usage,
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700557 int& alignedw, int &alignedh, int& tileEnabled, unsigned int& size)
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700558{
559 tileEnabled = isMacroTileEnabled(format, usage);
560
561 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
562 height,
563 format,
564 tileEnabled,
565 alignedw,
566 alignedh);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800567 size = getSize(format, width, height, alignedw, alignedh);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700568}
569
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400570int getYUVPlaneInfo(private_handle_t* hnd, struct android_ycbcr* ycbcr)
571{
572 int err = 0;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700573 unsigned int ystride, cstride;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400574 memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
575
576 // Get the chroma offsets from the handle width/height. We take advantage
577 // of the fact the width _is_ the stride
578 switch (hnd->format) {
579 //Semiplanar
580 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
581 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
582 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
583 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: //Same as YCbCr_420_SP_VENUS
Naseer Ahmeda28d31c2014-05-29 15:41:34 -0400584 ystride = cstride = hnd->width;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400585 ycbcr->y = (void*)hnd->base;
586 ycbcr->cb = (void*)(hnd->base + ystride * hnd->height);
587 ycbcr->cr = (void*)(hnd->base + ystride * hnd->height + 1);
588 ycbcr->ystride = ystride;
589 ycbcr->cstride = cstride;
590 ycbcr->chroma_step = 2;
591 break;
592
593 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
594 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
595 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
596 case HAL_PIXEL_FORMAT_NV21_ZSL:
597 case HAL_PIXEL_FORMAT_RAW_SENSOR:
Naseer Ahmeda28d31c2014-05-29 15:41:34 -0400598 ystride = cstride = hnd->width;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400599 ycbcr->y = (void*)hnd->base;
600 ycbcr->cr = (void*)(hnd->base + ystride * hnd->height);
601 ycbcr->cb = (void*)(hnd->base + ystride * hnd->height + 1);
602 ycbcr->ystride = ystride;
603 ycbcr->cstride = cstride;
604 ycbcr->chroma_step = 2;
605 break;
606
607 //Planar
608 case HAL_PIXEL_FORMAT_YV12:
609 ystride = hnd->width;
Arun Kumar K.R6e332482014-08-21 10:57:37 -0700610 cstride = ALIGN(hnd->width/2, 16);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400611 ycbcr->y = (void*)hnd->base;
612 ycbcr->cr = (void*)(hnd->base + ystride * hnd->height);
613 ycbcr->cb = (void*)(hnd->base + ystride * hnd->height +
614 cstride * hnd->height/2);
615 ycbcr->ystride = ystride;
616 ycbcr->cstride = cstride;
617 ycbcr->chroma_step = 1;
618
619 break;
620 //Unsupported formats
621 case HAL_PIXEL_FORMAT_YCbCr_422_I:
622 case HAL_PIXEL_FORMAT_YCrCb_422_I:
623 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
624 default:
625 ALOGD("%s: Invalid format passed: 0x%x", __FUNCTION__,
626 hnd->format);
627 err = -EINVAL;
628 }
629 return err;
630
631}
632
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700633
634
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700635// Allocate buffer from width, height and format into a
636// private_handle_t. It is the responsibility of the caller
637// to free the buffer using the free_buffer function
638int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
639{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700640 alloc_data data;
641 int alignedw, alignedh;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700642 gralloc::IAllocController* sAlloc =
643 gralloc::IAllocController::getInstance();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700644 data.base = 0;
645 data.fd = -1;
646 data.offset = 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700647 data.size = getBufferSizeAndDimensions(w, h, format, usage, alignedw,
648 alignedh);
649
Naseer Ahmed29a26812012-06-14 00:56:20 -0700650 data.align = getpagesize();
651 data.uncached = useUncached(usage);
652 int allocFlags = usage;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700653
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700654 int err = sAlloc->allocate(data, allocFlags);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700655 if (0 != err) {
656 ALOGE("%s: allocate failed", __FUNCTION__);
657 return -ENOMEM;
658 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700659
Naseer Ahmed29a26812012-06-14 00:56:20 -0700660 private_handle_t* hnd = new private_handle_t(data.fd, data.size,
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700661 data.allocType, 0, format,
662 alignedw, alignedh);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700663 hnd->base = (uint64_t) data.base;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700664 hnd->offset = data.offset;
665 hnd->gpuaddr = 0;
666 *pHnd = hnd;
667 return 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700668}
669
670void free_buffer(private_handle_t *hnd)
671{
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700672 gralloc::IAllocController* sAlloc =
673 gralloc::IAllocController::getInstance();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700674 if (hnd && hnd->fd > 0) {
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700675 IMemAlloc* memalloc = sAlloc->getAllocator(hnd->flags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700676 memalloc->free_buffer((void*)hnd->base, hnd->size, hnd->offset, hnd->fd);
677 }
678 if(hnd)
679 delete hnd;
680
681}