Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2009, The Android Open Source Project |
| 4 | ** |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 8 | ** |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 10 | ** |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Mathias Agopian | 5629eb1 | 2010-04-15 14:57:39 -0700 | [diff] [blame] | 18 | #define LOG_TAG "GraphicBufferAllocator" |
Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 19 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Mathias Agopian | 5629eb1 | 2010-04-15 14:57:39 -0700 | [diff] [blame] | 20 | |
Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 21 | #include <ui/GraphicBufferAllocator.h> |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | |
Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 25 | #include <log/log.h> |
Mathias Agopian | 4243e66 | 2009-04-15 18:34:24 -0700 | [diff] [blame] | 26 | #include <utils/Singleton.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 27 | #include <utils/String8.h> |
Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 28 | #include <utils/Trace.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 29 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 30 | #include <ui/GrallocAllocator.h> |
| 31 | #include <ui/GrallocMapper.h> |
| 32 | #include <ui/GraphicBufferMapper.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 37 | ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator ) |
Mathias Agopian | 4243e66 | 2009-04-15 18:34:24 -0700 | [diff] [blame] | 38 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 39 | Mutex GraphicBufferAllocator::sLock; |
Mathias Agopian | b26af23 | 2009-10-05 18:19:57 -0700 | [diff] [blame] | 40 | KeyedVector<buffer_handle_t, |
| 41 | GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 42 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 43 | GraphicBufferAllocator::GraphicBufferAllocator() |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 44 | : mAllocator(std::make_unique<Gralloc2::Allocator>()), |
| 45 | mMapper(GraphicBufferMapper::getInstance()) |
| 46 | { |
| 47 | if (!mAllocator->valid()) { |
| 48 | mLoader = std::make_unique<Gralloc1::Loader>(); |
| 49 | mDevice = mLoader->getDevice(); |
| 50 | } |
| 51 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 52 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 53 | GraphicBufferAllocator::~GraphicBufferAllocator() {} |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 54 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 55 | void GraphicBufferAllocator::dump(String8& result) const |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 56 | { |
| 57 | Mutex::Autolock _l(sLock); |
| 58 | KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); |
| 59 | size_t total = 0; |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 60 | const size_t SIZE = 4096; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 61 | char buffer[SIZE]; |
| 62 | snprintf(buffer, SIZE, "Allocated buffers:\n"); |
| 63 | result.append(buffer); |
| 64 | const size_t c = list.size(); |
| 65 | for (size_t i=0 ; i<c ; i++) { |
| 66 | const alloc_rec_t& rec(list.valueAt(i)); |
Mathias Agopian | a947de8 | 2011-07-29 16:35:41 -0700 | [diff] [blame] | 67 | if (rec.size) { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 68 | snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64 |
| 69 | ", 0x%" PRIx64 " | %s\n", |
George Burgess IV | 1093cf3 | 2017-01-25 17:09:18 -0800 | [diff] [blame] | 70 | list.keyAt(i), rec.size/1024.0, |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 71 | rec.width, rec.stride, rec.height, rec.layerCount, rec.format, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 72 | rec.producerUsage, rec.consumerUsage, |
| 73 | rec.requestorName.c_str()); |
Mathias Agopian | a947de8 | 2011-07-29 16:35:41 -0700 | [diff] [blame] | 74 | } else { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 75 | snprintf(buffer, SIZE, "%10p: unknown | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64 |
| 76 | ", 0x%" PRIx64 " | %s\n", |
Mathias Agopian | a947de8 | 2011-07-29 16:35:41 -0700 | [diff] [blame] | 77 | list.keyAt(i), |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 78 | rec.width, rec.stride, rec.height, rec.layerCount, rec.format, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 79 | rec.producerUsage, rec.consumerUsage, |
| 80 | rec.requestorName.c_str()); |
Mathias Agopian | a947de8 | 2011-07-29 16:35:41 -0700 | [diff] [blame] | 81 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 82 | result.append(buffer); |
| 83 | total += rec.size; |
| 84 | } |
George Burgess IV | 1093cf3 | 2017-01-25 17:09:18 -0800 | [diff] [blame] | 85 | snprintf(buffer, SIZE, "Total allocated (estimate): %.2f KB\n", total/1024.0); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 86 | result.append(buffer); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 87 | |
| 88 | std::string deviceDump; |
| 89 | if (mAllocator->valid()) { |
| 90 | deviceDump = mAllocator->dumpDebugInfo(); |
| 91 | } else { |
| 92 | deviceDump = mDevice->dump(); |
| 93 | } |
| 94 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 95 | result.append(deviceDump.c_str(), deviceDump.size()); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 98 | void GraphicBufferAllocator::dumpToSystemLog() |
| 99 | { |
| 100 | String8 s; |
| 101 | GraphicBufferAllocator::getInstance().dump(s); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 102 | ALOGD("%s", s.string()); |
Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 105 | namespace { |
| 106 | |
| 107 | class HalBuffer { |
| 108 | public: |
| 109 | HalBuffer(const Gralloc2::Allocator* allocator, |
| 110 | uint32_t width, uint32_t height, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 111 | PixelFormat format, uint32_t layerCount, uint64_t producerUsage, |
| 112 | uint64_t consumerUsage) |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 113 | : mAllocator(allocator), mBufferValid(false) |
| 114 | { |
Chia-I Wu | b018bf0 | 2016-11-22 13:29:49 +0800 | [diff] [blame] | 115 | Gralloc2::IAllocatorClient::BufferDescriptorInfo info = {}; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 116 | info.width = width; |
| 117 | info.height = height; |
| 118 | info.format = static_cast<Gralloc2::PixelFormat>(format); |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 119 | info.layerCount = layerCount; |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 120 | info.producerUsageMask = producerUsage; |
| 121 | info.consumerUsageMask = consumerUsage; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 122 | |
| 123 | Gralloc2::BufferDescriptor descriptor; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 124 | auto error = mAllocator->createBufferDescriptor(info, &descriptor); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 125 | if (error != Gralloc2::Error::NONE) { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 126 | ALOGE("Failed to create desc (%u x %u) layerCount %u format %d producerUsage %" PRIx64 |
| 127 | " consumerUsage %" PRIx64 ": %d", |
| 128 | width, height, layerCount, format, producerUsage, |
| 129 | consumerUsage, error); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 130 | return; |
| 131 | } |
| 132 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 133 | error = mAllocator->allocate(descriptor, &mBuffer); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 134 | if (error == Gralloc2::Error::NOT_SHARED) { |
| 135 | error = Gralloc2::Error::NONE; |
| 136 | } |
| 137 | |
| 138 | if (error != Gralloc2::Error::NONE) { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 139 | ALOGE("Failed to allocate (%u x %u) layerCount %u format %d producerUsage %" PRIx64 |
| 140 | " consumerUsage %" PRIx64 ": %d", |
| 141 | width, height, layerCount, format, producerUsage, |
| 142 | consumerUsage, error); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 143 | mAllocator->destroyBufferDescriptor(descriptor); |
| 144 | return; |
| 145 | } |
| 146 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 147 | error = mAllocator->exportHandle(descriptor, mBuffer, &mHandle); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 148 | if (error != Gralloc2::Error::NONE) { |
| 149 | ALOGE("Failed to export handle"); |
| 150 | mAllocator->free(mBuffer); |
| 151 | mAllocator->destroyBufferDescriptor(descriptor); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | mAllocator->destroyBufferDescriptor(descriptor); |
| 156 | |
| 157 | mBufferValid = true; |
| 158 | } |
| 159 | |
| 160 | ~HalBuffer() |
| 161 | { |
| 162 | if (mBufferValid) { |
| 163 | if (mHandle) { |
| 164 | native_handle_close(mHandle); |
| 165 | native_handle_delete(mHandle); |
| 166 | } |
| 167 | |
| 168 | mAllocator->free(mBuffer); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | bool exportHandle(GraphicBufferMapper& mapper, |
| 173 | buffer_handle_t* handle, uint32_t* stride) |
| 174 | { |
| 175 | if (!mBufferValid) { |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | if (mapper.registerBuffer(mHandle)) { |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | *handle = mHandle; |
| 184 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 185 | auto error = mapper.getGrallocMapper().getStride(mHandle, stride); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 186 | if (error != Gralloc2::Error::NONE) { |
| 187 | ALOGW("Failed to get stride from buffer: %d", error); |
| 188 | *stride = 0; |
| 189 | } |
| 190 | |
| 191 | mHandle = nullptr; |
| 192 | mAllocator->free(mBuffer); |
| 193 | mBufferValid = false; |
| 194 | |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | private: |
| 199 | const Gralloc2::Allocator* mAllocator; |
| 200 | |
| 201 | bool mBufferValid; |
| 202 | Gralloc2::Buffer mBuffer; |
| 203 | native_handle_t* mHandle; |
| 204 | }; |
| 205 | |
| 206 | } // namespace |
| 207 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 208 | status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 209 | PixelFormat format, uint32_t layerCount, uint64_t producerUsage, |
| 210 | uint64_t consumerUsage, buffer_handle_t* handle, uint32_t* stride, |
| 211 | uint64_t graphicBufferId, std::string requestorName) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 212 | { |
Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 213 | ATRACE_CALL(); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 214 | |
Mathias Agopian | 5629eb1 | 2010-04-15 14:57:39 -0700 | [diff] [blame] | 215 | // make sure to not allocate a N x 0 or 0 x N buffer, since this is |
| 216 | // allowed from an API stand-point allocate a 1x1 buffer instead. |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 217 | if (!width || !height) |
| 218 | width = height = 1; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 219 | |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 220 | // Ensure that layerCount is valid. |
| 221 | if (layerCount < 1) |
| 222 | layerCount = 1; |
| 223 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 224 | gralloc1_error_t error; |
| 225 | if (mAllocator->valid()) { |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 226 | HalBuffer buffer(mAllocator.get(), width, height, format, layerCount, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 227 | producerUsage, consumerUsage); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 228 | if (!buffer.exportHandle(mMapper, handle, stride)) { |
| 229 | return NO_MEMORY; |
| 230 | } |
| 231 | error = GRALLOC1_ERROR_NONE; |
| 232 | } else { |
| 233 | auto descriptor = mDevice->createDescriptor(); |
| 234 | error = descriptor->setDimensions(width, height); |
| 235 | if (error != GRALLOC1_ERROR_NONE) { |
| 236 | ALOGE("Failed to set dimensions to (%u, %u): %d", |
| 237 | width, height, error); |
| 238 | return BAD_VALUE; |
| 239 | } |
| 240 | error = descriptor->setFormat( |
| 241 | static_cast<android_pixel_format_t>(format)); |
| 242 | if (error != GRALLOC1_ERROR_NONE) { |
| 243 | ALOGE("Failed to set format to %d: %d", format, error); |
| 244 | return BAD_VALUE; |
| 245 | } |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 246 | if (mDevice->hasCapability(GRALLOC1_CAPABILITY_LAYERED_BUFFERS)) { |
| 247 | error = descriptor->setLayerCount(layerCount); |
| 248 | if (error != GRALLOC1_ERROR_NONE) { |
| 249 | ALOGE("Failed to set layer count to %u: %d", layerCount, error); |
| 250 | return BAD_VALUE; |
| 251 | } |
| 252 | } else if (layerCount > 1) { |
| 253 | ALOGE("Failed to set layer count to %u: capability unsupported", |
| 254 | layerCount); |
| 255 | return BAD_VALUE; |
| 256 | } |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 257 | error = descriptor->setProducerUsage( |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 258 | static_cast<gralloc1_producer_usage_t>(producerUsage)); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 259 | if (error != GRALLOC1_ERROR_NONE) { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 260 | ALOGE("Failed to set producer usage to %" PRIx64 ": %d", |
| 261 | producerUsage, error); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 262 | return BAD_VALUE; |
| 263 | } |
| 264 | error = descriptor->setConsumerUsage( |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 265 | static_cast<gralloc1_consumer_usage_t>(consumerUsage)); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 266 | if (error != GRALLOC1_ERROR_NONE) { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 267 | ALOGE("Failed to set consumer usage to %" PRIx64 ": %d", |
| 268 | consumerUsage, error); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 269 | return BAD_VALUE; |
| 270 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 271 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 272 | error = mDevice->allocate(descriptor, graphicBufferId, handle); |
| 273 | if (error != GRALLOC1_ERROR_NONE) { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 274 | ALOGE("Failed to allocate (%u x %u) layerCount %u format %d " |
| 275 | "producerUsage %" PRIx64 " consumerUsage %" PRIx64 ": %d", |
| 276 | width, height, layerCount, format, producerUsage, |
| 277 | consumerUsage, error); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 278 | return NO_MEMORY; |
| 279 | } |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 280 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 281 | error = mDevice->getStride(*handle, stride); |
| 282 | if (error != GRALLOC1_ERROR_NONE) { |
| 283 | ALOGW("Failed to get stride from buffer: %d", error); |
| 284 | } |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | if (error == NO_ERROR) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 288 | Mutex::Autolock _l(sLock); |
| 289 | KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 290 | uint32_t bpp = bytesPerPixel(format); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 291 | alloc_rec_t rec; |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 292 | rec.width = width; |
| 293 | rec.height = height; |
| 294 | rec.stride = *stride; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 295 | rec.format = format; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 296 | rec.layerCount = layerCount; |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 297 | rec.producerUsage = producerUsage; |
| 298 | rec.consumerUsage = consumerUsage; |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 299 | rec.size = static_cast<size_t>(height * (*stride) * bpp); |
Dan Stoza | 024e931 | 2016-08-24 12:17:29 -0700 | [diff] [blame] | 300 | rec.requestorName = std::move(requestorName); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 301 | list.add(*handle, rec); |
| 302 | } |
| 303 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 304 | return NO_ERROR; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 307 | status_t GraphicBufferAllocator::free(buffer_handle_t handle) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 308 | { |
Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 309 | ATRACE_CALL(); |
Mathias Agopian | 0a75781 | 2010-12-08 16:40:01 -0800 | [diff] [blame] | 310 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 311 | gralloc1_error_t error; |
| 312 | if (mAllocator->valid()) { |
| 313 | error = static_cast<gralloc1_error_t>( |
| 314 | mMapper.unregisterBuffer(handle)); |
| 315 | } else { |
| 316 | error = mDevice->release(handle); |
| 317 | } |
| 318 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 319 | if (error != GRALLOC1_ERROR_NONE) { |
| 320 | ALOGE("Failed to free buffer: %d", error); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 323 | Mutex::Autolock _l(sLock); |
| 324 | KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); |
| 325 | list.removeItem(handle); |
| 326 | |
| 327 | return NO_ERROR; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 330 | // --------------------------------------------------------------------------- |
| 331 | }; // namespace android |