Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 1 | /* |
Rohit Kulkarni | 3ac9839 | 2017-10-20 12:04:34 -0700 | [diff] [blame] | 2 | * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 3 | |
| 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. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * 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> |
| 31 | #include <algorithm> |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 32 | #include <vector> |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 33 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 34 | #include "gr_allocator.h" |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 35 | #include "gr_utils.h" |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 36 | #include "gralloc_priv.h" |
| 37 | |
| 38 | #include "qd_utils.h" |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 39 | |
| 40 | #ifndef ION_FLAG_CP_PIXEL |
| 41 | #define ION_FLAG_CP_PIXEL 0 |
| 42 | #endif |
| 43 | |
| 44 | #ifndef ION_FLAG_ALLOW_NON_CONTIG |
| 45 | #define ION_FLAG_ALLOW_NON_CONTIG 0 |
| 46 | #endif |
| 47 | |
Sushil Chauhan | dfe55a2 | 2016-09-12 15:48:29 -0700 | [diff] [blame] | 48 | #ifndef ION_FLAG_CP_CAMERA_PREVIEW |
| 49 | #define ION_FLAG_CP_CAMERA_PREVIEW 0 |
| 50 | #endif |
| 51 | |
Rohit Kulkarni | 3ac9839 | 2017-10-20 12:04:34 -0700 | [diff] [blame] | 52 | #ifndef ION_SECURE |
| 53 | #define ION_SECURE ION_FLAG_SECURE |
| 54 | #endif |
| 55 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 56 | #ifdef MASTER_SIDE_CP |
| 57 | #define CP_HEAP_ID ION_SECURE_HEAP_ID |
| 58 | #define SD_HEAP_ID ION_SECURE_DISPLAY_HEAP_ID |
| 59 | #define ION_CP_FLAGS (ION_SECURE | ION_FLAG_CP_PIXEL) |
| 60 | #define ION_SD_FLAGS (ION_SECURE | ION_FLAG_CP_SEC_DISPLAY) |
Sushil Chauhan | dfe55a2 | 2016-09-12 15:48:29 -0700 | [diff] [blame] | 61 | #define ION_SC_FLAGS (ION_SECURE | ION_FLAG_CP_CAMERA) |
| 62 | #define ION_SC_PREVIEW_FLAGS (ION_SECURE | ION_FLAG_CP_CAMERA_PREVIEW) |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 63 | #else // SLAVE_SIDE_CP |
| 64 | #define CP_HEAP_ID ION_CP_MM_HEAP_ID |
| 65 | #define SD_HEAP_ID CP_HEAP_ID |
| 66 | #define ION_CP_FLAGS (ION_SECURE | ION_FLAG_ALLOW_NON_CONTIG) |
| 67 | #define ION_SD_FLAGS ION_SECURE |
Sushil Chauhan | dfe55a2 | 2016-09-12 15:48:29 -0700 | [diff] [blame] | 68 | #define ION_SC_FLAGS ION_SECURE |
| 69 | #define ION_SC_PREVIEW_FLAGS ION_SECURE |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 70 | #endif |
| 71 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 72 | using std::shared_ptr; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 73 | using std::vector; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 74 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 75 | namespace gralloc { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 76 | |
Saurabh Shah | 14c8e5b | 2017-04-07 10:37:23 -0700 | [diff] [blame] | 77 | static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) { |
| 78 | return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(), |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 79 | descriptor.GetUsage()); |
Saurabh Shah | 14c8e5b | 2017-04-07 10:37:23 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 82 | Allocator::Allocator() : ion_allocator_(nullptr) {} |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 83 | |
| 84 | bool Allocator::Init() { |
| 85 | ion_allocator_ = new IonAlloc(); |
| 86 | if (!ion_allocator_->Init()) { |
| 87 | return false; |
| 88 | } |
| 89 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 90 | return true; |
| 91 | } |
| 92 | |
| 93 | Allocator::~Allocator() { |
| 94 | if (ion_allocator_) { |
| 95 | delete ion_allocator_; |
| 96 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 97 | } |
| 98 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 99 | int Allocator::AllocateMem(AllocData *alloc_data, uint64_t usage) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 100 | int ret; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 101 | alloc_data->uncached = UseUncached(usage); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 102 | |
| 103 | // After this point we should have the right heap set, there is no fallback |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 104 | GetIonHeapInfo(usage, &alloc_data->heap_id, &alloc_data->alloc_type, &alloc_data->flags); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 105 | |
| 106 | ret = ion_allocator_->AllocBuffer(alloc_data); |
| 107 | if (ret >= 0) { |
| 108 | alloc_data->alloc_type |= private_handle_t::PRIV_FLAGS_USES_ION; |
| 109 | } else { |
| 110 | ALOGE("%s: Failed to allocate buffer - heap: 0x%x flags: 0x%x", __FUNCTION__, |
| 111 | alloc_data->heap_id, alloc_data->flags); |
| 112 | } |
| 113 | |
| 114 | return ret; |
| 115 | } |
| 116 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 117 | int Allocator::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) { |
| 118 | if (ion_allocator_) { |
| 119 | return ion_allocator_->MapBuffer(base, size, offset, fd); |
| 120 | } |
| 121 | |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | |
Naseer Ahmed | 3a9d53a | 2017-03-15 19:21:40 -0400 | [diff] [blame] | 125 | int Allocator::ImportBuffer(int fd) { |
| 126 | if (ion_allocator_) { |
| 127 | return ion_allocator_->ImportBuffer(fd); |
| 128 | } |
| 129 | return -EINVAL; |
| 130 | } |
| 131 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 132 | int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 133 | if (ion_allocator_) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 134 | return ion_allocator_->FreeBuffer(base, size, offset, fd, handle); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | |
Rohit Kulkarni | 3ac9839 | 2017-10-20 12:04:34 -0700 | [diff] [blame] | 140 | int Allocator::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op, |
| 141 | int fd) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 142 | if (ion_allocator_) { |
Rohit Kulkarni | 3ac9839 | 2017-10-20 12:04:34 -0700 | [diff] [blame] | 143 | return ion_allocator_->CleanBuffer(base, size, offset, handle, op, fd); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return -EINVAL; |
| 147 | } |
| 148 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 149 | bool Allocator::CheckForBufferSharing(uint32_t num_descriptors, |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 150 | const vector<shared_ptr<BufferDescriptor>> &descriptors, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 151 | ssize_t *max_index) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 152 | unsigned int cur_heap_id = 0, prev_heap_id = 0; |
| 153 | unsigned int cur_alloc_type = 0, prev_alloc_type = 0; |
| 154 | unsigned int cur_ion_flags = 0, prev_ion_flags = 0; |
| 155 | bool cur_uncached = false, prev_uncached = false; |
| 156 | unsigned int alignedw, alignedh; |
| 157 | unsigned int max_size = 0; |
| 158 | |
| 159 | *max_index = -1; |
| 160 | for (uint32_t i = 0; i < num_descriptors; i++) { |
| 161 | // Check Cached vs non-cached and all the ION flags |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 162 | cur_uncached = UseUncached(descriptors[i]->GetUsage()); |
| 163 | GetIonHeapInfo(descriptors[i]->GetUsage(), &cur_heap_id, &cur_alloc_type, &cur_ion_flags); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 164 | |
| 165 | if (i > 0 && (cur_heap_id != prev_heap_id || cur_alloc_type != prev_alloc_type || |
| 166 | cur_ion_flags != prev_ion_flags)) { |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | // For same format type, find the descriptor with bigger size |
Saurabh Shah | 14c8e5b | 2017-04-07 10:37:23 -0700 | [diff] [blame] | 171 | GetAlignedWidthAndHeight(GetBufferInfo(*descriptors[i]), &alignedw, &alignedh); |
| 172 | unsigned int size = GetSize(GetBufferInfo(*descriptors[i]), alignedw, alignedh); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 173 | if (max_size < size) { |
| 174 | *max_index = INT(i); |
| 175 | max_size = size; |
| 176 | } |
| 177 | |
| 178 | prev_heap_id = cur_heap_id; |
| 179 | prev_uncached = cur_uncached; |
| 180 | prev_ion_flags = cur_ion_flags; |
| 181 | prev_alloc_type = cur_alloc_type; |
| 182 | } |
| 183 | |
| 184 | return true; |
| 185 | } |
| 186 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 187 | int Allocator::GetImplDefinedFormat(uint64_t usage, int format) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 188 | int gr_format = format; |
| 189 | |
| 190 | // If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on |
| 191 | // the usage bits, gralloc assigns a format. |
| 192 | if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED || |
| 193 | format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 194 | if (usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) { |
Rohit Kulkarni | a50206a | 2017-11-13 15:55:24 -0800 | [diff] [blame] | 195 | // Use of 10BIT_TP and 10BIT bits is supposed to be mutually exclusive. |
| 196 | // Each bit maps to only one format. Here we will check one of the bits |
| 197 | // and ignore the other. |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 198 | if (usage & GRALLOC_USAGE_PRIVATE_10BIT_TP) { |
Rohit Kulkarni | 79f279c | 2017-06-28 14:25:25 -0700 | [diff] [blame] | 199 | gr_format = HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 200 | } else if (usage & GRALLOC_USAGE_PRIVATE_10BIT) { |
Rohit Kulkarni | a50206a | 2017-11-13 15:55:24 -0800 | [diff] [blame] | 201 | gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC; |
Rohit Kulkarni | 79f279c | 2017-06-28 14:25:25 -0700 | [diff] [blame] | 202 | } else { |
| 203 | gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC; |
| 204 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 205 | } else if (usage & GRALLOC_USAGE_PRIVATE_10BIT) { |
Rohit Kulkarni | a50206a | 2017-11-13 15:55:24 -0800 | [diff] [blame] | 206 | gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 207 | } else if (usage & BufferUsage::VIDEO_ENCODER) { |
| 208 | if (usage & GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER) { |
Yahui Wang | 55563ca | 2018-01-15 19:50:05 +0800 | [diff] [blame] | 209 | gr_format = HAL_PIXEL_FORMAT_NV21_ENCODEABLE; // NV21 |
| 210 | } else { |
| 211 | gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12 |
| 212 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 213 | } else if (usage & BufferUsage::CAMERA_INPUT) { |
| 214 | if (usage & BufferUsage::CAMERA_OUTPUT) { |
Naseer Ahmed | 1901fa3 | 2017-03-22 20:34:45 -0400 | [diff] [blame] | 215 | // Assumed ZSL if both producer and consumer camera flags set |
| 216 | gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21 |
| 217 | } else { |
| 218 | gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21 |
| 219 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 220 | } else if (usage & BufferUsage::CAMERA_OUTPUT) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 221 | if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
| 222 | gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21 |
| 223 | } else { |
| 224 | gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview |
| 225 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 226 | } else if (usage & BufferUsage::COMPOSER_OVERLAY) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 227 | // XXX: If we still haven't set a format, default to RGBA8888 |
| 228 | gr_format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 229 | } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
| 230 | // If no other usage flags are detected, default the |
| 231 | // flexible YUV format to NV21_ZSL |
| 232 | gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | return gr_format; |
| 237 | } |
| 238 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 239 | /* The default policy is to return cached buffers unless the client explicity |
| 240 | * sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely |
| 241 | * read or written in software. */ |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 242 | bool Allocator::UseUncached(uint64_t usage) { |
| 243 | if ((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) || (usage & BufferUsage::PROTECTED)) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 244 | return true; |
| 245 | } |
| 246 | |
| 247 | // CPU read rarely |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 248 | if ((usage & BufferUsage::CPU_READ_RARELY) && !(usage & BufferUsage::CPU_READ_OFTEN)) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 249 | return true; |
| 250 | } |
| 251 | |
| 252 | // CPU write rarely |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 253 | if ((usage & BufferUsage::CPU_WRITE_RARELY) && !(usage & BufferUsage::CPU_WRITE_OFTEN)) { |
Naseer Ahmed | fe6342e | 2017-04-20 16:52:40 -0400 | [diff] [blame] | 254 | return true; |
| 255 | } |
| 256 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 257 | if ((usage & BufferUsage::SENSOR_DIRECT_DATA) || (usage & BufferUsage::GPU_DATA_BUFFER)) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | |
| 261 | return false; |
| 262 | } |
| 263 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 264 | void Allocator::GetIonHeapInfo(uint64_t usage, unsigned int *ion_heap_id, unsigned int *alloc_type, |
| 265 | unsigned int *ion_flags) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 266 | unsigned int heap_id = 0; |
| 267 | unsigned int type = 0; |
Naseer Ahmed | 7dc06d1 | 2017-03-14 11:13:27 -0400 | [diff] [blame] | 268 | uint32_t flags = 0; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 269 | if (usage & GRALLOC_USAGE_PROTECTED) { |
| 270 | if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 271 | heap_id = ION_HEAP(SD_HEAP_ID); |
| 272 | /* |
| 273 | * There is currently no flag in ION for Secure Display |
| 274 | * VM. Please add it to the define once available. |
| 275 | */ |
Naseer Ahmed | 7dc06d1 | 2017-03-14 11:13:27 -0400 | [diff] [blame] | 276 | flags |= UINT(ION_SD_FLAGS); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 277 | } else if (usage & BufferUsage::CAMERA_OUTPUT) { |
Sushil Chauhan | dfe55a2 | 2016-09-12 15:48:29 -0700 | [diff] [blame] | 278 | heap_id = ION_HEAP(SD_HEAP_ID); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 279 | if (usage & BufferUsage::COMPOSER_OVERLAY) { |
Naseer Ahmed | 7dc06d1 | 2017-03-14 11:13:27 -0400 | [diff] [blame] | 280 | flags |= UINT(ION_SC_PREVIEW_FLAGS); |
Sushil Chauhan | dfe55a2 | 2016-09-12 15:48:29 -0700 | [diff] [blame] | 281 | } else { |
Naseer Ahmed | 7dc06d1 | 2017-03-14 11:13:27 -0400 | [diff] [blame] | 282 | flags |= UINT(ION_SC_FLAGS); |
Sushil Chauhan | dfe55a2 | 2016-09-12 15:48:29 -0700 | [diff] [blame] | 283 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 284 | } else { |
| 285 | heap_id = ION_HEAP(CP_HEAP_ID); |
Naseer Ahmed | 7dc06d1 | 2017-03-14 11:13:27 -0400 | [diff] [blame] | 286 | flags |= UINT(ION_CP_FLAGS); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 287 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 288 | } |
| 289 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 290 | if (usage & BufferUsage::SENSOR_DIRECT_DATA) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 291 | heap_id |= ION_HEAP(ION_ADSP_HEAP_ID); |
| 292 | } |
| 293 | |
Naseer Ahmed | 7dc06d1 | 2017-03-14 11:13:27 -0400 | [diff] [blame] | 294 | if (flags & UINT(ION_SECURE)) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 295 | type |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER; |
| 296 | } |
| 297 | |
| 298 | // if no ion heap flags are set, default to system heap |
| 299 | if (!heap_id) { |
| 300 | heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID); |
| 301 | } |
| 302 | |
| 303 | *alloc_type = type; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 304 | *ion_flags = flags; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 305 | *ion_heap_id = heap_id; |
| 306 | |
| 307 | return; |
| 308 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame^] | 309 | } // namespace gralloc |