1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker **
3*38e8c45fSAndroid Build Coastguard Worker ** Copyright 2009, The Android Open Source Project
4*38e8c45fSAndroid Build Coastguard Worker **
5*38e8c45fSAndroid Build Coastguard Worker ** Licensed under the Apache License, Version 2.0 (the "License");
6*38e8c45fSAndroid Build Coastguard Worker ** you may not use this file except in compliance with the License.
7*38e8c45fSAndroid Build Coastguard Worker ** You may obtain a copy of the License at
8*38e8c45fSAndroid Build Coastguard Worker **
9*38e8c45fSAndroid Build Coastguard Worker ** http://www.apache.org/licenses/LICENSE-2.0
10*38e8c45fSAndroid Build Coastguard Worker **
11*38e8c45fSAndroid Build Coastguard Worker ** Unless required by applicable law or agreed to in writing, software
12*38e8c45fSAndroid Build Coastguard Worker ** distributed under the License is distributed on an "AS IS" BASIS,
13*38e8c45fSAndroid Build Coastguard Worker ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*38e8c45fSAndroid Build Coastguard Worker ** See the License for the specific language governing permissions and
15*38e8c45fSAndroid Build Coastguard Worker ** limitations under the License.
16*38e8c45fSAndroid Build Coastguard Worker */
17*38e8c45fSAndroid Build Coastguard Worker
18*38e8c45fSAndroid Build Coastguard Worker #define LOG_TAG "GraphicBufferAllocator"
19*38e8c45fSAndroid Build Coastguard Worker #define ATRACE_TAG ATRACE_TAG_GRAPHICS
20*38e8c45fSAndroid Build Coastguard Worker
21*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicBufferAllocator.h>
22*38e8c45fSAndroid Build Coastguard Worker
23*38e8c45fSAndroid Build Coastguard Worker #include <limits.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <stdio.h>
25*38e8c45fSAndroid Build Coastguard Worker
26*38e8c45fSAndroid Build Coastguard Worker #include <grallocusage/GrallocUsageConversion.h>
27*38e8c45fSAndroid Build Coastguard Worker
28*38e8c45fSAndroid Build Coastguard Worker #include <android-base/stringprintf.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <log/log.h>
30*38e8c45fSAndroid Build Coastguard Worker #include <utils/Singleton.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <utils/Trace.h>
32*38e8c45fSAndroid Build Coastguard Worker
33*38e8c45fSAndroid Build Coastguard Worker #include <ui/Gralloc.h>
34*38e8c45fSAndroid Build Coastguard Worker #include <ui/Gralloc2.h>
35*38e8c45fSAndroid Build Coastguard Worker #include <ui/Gralloc3.h>
36*38e8c45fSAndroid Build Coastguard Worker #include <ui/Gralloc4.h>
37*38e8c45fSAndroid Build Coastguard Worker #include <ui/Gralloc5.h>
38*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicBufferMapper.h>
39*38e8c45fSAndroid Build Coastguard Worker
40*38e8c45fSAndroid Build Coastguard Worker namespace android {
41*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
42*38e8c45fSAndroid Build Coastguard Worker
43*38e8c45fSAndroid Build Coastguard Worker using base::StringAppendF;
44*38e8c45fSAndroid Build Coastguard Worker
45*38e8c45fSAndroid Build Coastguard Worker ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator )
46*38e8c45fSAndroid Build Coastguard Worker
47*38e8c45fSAndroid Build Coastguard Worker Mutex GraphicBufferAllocator::sLock;
48*38e8c45fSAndroid Build Coastguard Worker KeyedVector<buffer_handle_t,
49*38e8c45fSAndroid Build Coastguard Worker GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
50*38e8c45fSAndroid Build Coastguard Worker
GraphicBufferAllocator()51*38e8c45fSAndroid Build Coastguard Worker GraphicBufferAllocator::GraphicBufferAllocator() : mMapper(GraphicBufferMapper::getInstance()) {
52*38e8c45fSAndroid Build Coastguard Worker switch (mMapper.getMapperVersion()) {
53*38e8c45fSAndroid Build Coastguard Worker case GraphicBufferMapper::GRALLOC_5:
54*38e8c45fSAndroid Build Coastguard Worker mAllocator = std::make_unique<const Gralloc5Allocator>(
55*38e8c45fSAndroid Build Coastguard Worker reinterpret_cast<const Gralloc5Mapper&>(mMapper.getGrallocMapper()));
56*38e8c45fSAndroid Build Coastguard Worker break;
57*38e8c45fSAndroid Build Coastguard Worker case GraphicBufferMapper::GRALLOC_4:
58*38e8c45fSAndroid Build Coastguard Worker mAllocator = std::make_unique<const Gralloc4Allocator>(
59*38e8c45fSAndroid Build Coastguard Worker reinterpret_cast<const Gralloc4Mapper&>(mMapper.getGrallocMapper()));
60*38e8c45fSAndroid Build Coastguard Worker break;
61*38e8c45fSAndroid Build Coastguard Worker case GraphicBufferMapper::GRALLOC_3:
62*38e8c45fSAndroid Build Coastguard Worker mAllocator = std::make_unique<const Gralloc3Allocator>(
63*38e8c45fSAndroid Build Coastguard Worker reinterpret_cast<const Gralloc3Mapper&>(mMapper.getGrallocMapper()));
64*38e8c45fSAndroid Build Coastguard Worker break;
65*38e8c45fSAndroid Build Coastguard Worker case GraphicBufferMapper::GRALLOC_2:
66*38e8c45fSAndroid Build Coastguard Worker mAllocator = std::make_unique<const Gralloc2Allocator>(
67*38e8c45fSAndroid Build Coastguard Worker reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper()));
68*38e8c45fSAndroid Build Coastguard Worker break;
69*38e8c45fSAndroid Build Coastguard Worker }
70*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!mAllocator->isLoaded(),
71*38e8c45fSAndroid Build Coastguard Worker "Failed to load matching allocator for mapper version %d",
72*38e8c45fSAndroid Build Coastguard Worker mMapper.getMapperVersion());
73*38e8c45fSAndroid Build Coastguard Worker }
74*38e8c45fSAndroid Build Coastguard Worker
~GraphicBufferAllocator()75*38e8c45fSAndroid Build Coastguard Worker GraphicBufferAllocator::~GraphicBufferAllocator() {}
76*38e8c45fSAndroid Build Coastguard Worker
getTotalSize() const77*38e8c45fSAndroid Build Coastguard Worker uint64_t GraphicBufferAllocator::getTotalSize() const {
78*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(sLock);
79*38e8c45fSAndroid Build Coastguard Worker uint64_t total = 0;
80*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < sAllocList.size(); ++i) {
81*38e8c45fSAndroid Build Coastguard Worker total += sAllocList.valueAt(i).size;
82*38e8c45fSAndroid Build Coastguard Worker }
83*38e8c45fSAndroid Build Coastguard Worker return total;
84*38e8c45fSAndroid Build Coastguard Worker }
85*38e8c45fSAndroid Build Coastguard Worker
dump(std::string & result,bool less) const86*38e8c45fSAndroid Build Coastguard Worker void GraphicBufferAllocator::dump(std::string& result, bool less) const {
87*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(sLock);
88*38e8c45fSAndroid Build Coastguard Worker KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
89*38e8c45fSAndroid Build Coastguard Worker uint64_t total = 0;
90*38e8c45fSAndroid Build Coastguard Worker result.append("GraphicBufferAllocator buffers:\n");
91*38e8c45fSAndroid Build Coastguard Worker const size_t count = list.size();
92*38e8c45fSAndroid Build Coastguard Worker StringAppendF(&result, "%18s | %12s | %18s | %s | %8s | %10s | %s\n", "Handle", "Size",
93*38e8c45fSAndroid Build Coastguard Worker "W (Stride) x H", "Layers", "Format", "Usage", "Requestor");
94*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < count; i++) {
95*38e8c45fSAndroid Build Coastguard Worker const alloc_rec_t& rec(list.valueAt(i));
96*38e8c45fSAndroid Build Coastguard Worker std::string sizeStr = (rec.size)
97*38e8c45fSAndroid Build Coastguard Worker ? base::StringPrintf("%7.2f KiB", static_cast<double>(rec.size) / 1024.0)
98*38e8c45fSAndroid Build Coastguard Worker : "unknown";
99*38e8c45fSAndroid Build Coastguard Worker StringAppendF(&result, "%18p | %12s | %4u (%4u) x %4u | %6u | %8X | 0x%8" PRIx64 " | %s\n",
100*38e8c45fSAndroid Build Coastguard Worker list.keyAt(i), sizeStr.c_str(), rec.width, rec.stride, rec.height,
101*38e8c45fSAndroid Build Coastguard Worker rec.layerCount, rec.format, rec.usage, rec.requestorName.c_str());
102*38e8c45fSAndroid Build Coastguard Worker total += rec.size;
103*38e8c45fSAndroid Build Coastguard Worker }
104*38e8c45fSAndroid Build Coastguard Worker StringAppendF(&result, "Total allocated by GraphicBufferAllocator (estimate): %.2f KB\n",
105*38e8c45fSAndroid Build Coastguard Worker static_cast<double>(total) / 1024.0);
106*38e8c45fSAndroid Build Coastguard Worker
107*38e8c45fSAndroid Build Coastguard Worker result.append(mAllocator->dumpDebugInfo(less));
108*38e8c45fSAndroid Build Coastguard Worker }
109*38e8c45fSAndroid Build Coastguard Worker
dumpToSystemLog(bool less)110*38e8c45fSAndroid Build Coastguard Worker void GraphicBufferAllocator::dumpToSystemLog(bool less) {
111*38e8c45fSAndroid Build Coastguard Worker std::string s;
112*38e8c45fSAndroid Build Coastguard Worker GraphicBufferAllocator::getInstance().dump(s, less);
113*38e8c45fSAndroid Build Coastguard Worker ALOGD("%s", s.c_str());
114*38e8c45fSAndroid Build Coastguard Worker }
115*38e8c45fSAndroid Build Coastguard Worker
allocate(const AllocationRequest & request)116*38e8c45fSAndroid Build Coastguard Worker auto GraphicBufferAllocator::allocate(const AllocationRequest& request) -> AllocationResult {
117*38e8c45fSAndroid Build Coastguard Worker ATRACE_CALL();
118*38e8c45fSAndroid Build Coastguard Worker if (!request.width || !request.height) {
119*38e8c45fSAndroid Build Coastguard Worker return AllocationResult(BAD_VALUE);
120*38e8c45fSAndroid Build Coastguard Worker }
121*38e8c45fSAndroid Build Coastguard Worker
122*38e8c45fSAndroid Build Coastguard Worker const auto width = request.width;
123*38e8c45fSAndroid Build Coastguard Worker const auto height = request.height;
124*38e8c45fSAndroid Build Coastguard Worker
125*38e8c45fSAndroid Build Coastguard Worker const uint32_t bpp = bytesPerPixel(request.format);
126*38e8c45fSAndroid Build Coastguard Worker if (std::numeric_limits<size_t>::max() / width / height < static_cast<size_t>(bpp)) {
127*38e8c45fSAndroid Build Coastguard Worker ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
128*38e8c45fSAndroid Build Coastguard Worker "usage %" PRIx64 ": Requesting too large a buffer size",
129*38e8c45fSAndroid Build Coastguard Worker request.width, request.height, request.layerCount, request.format, request.usage);
130*38e8c45fSAndroid Build Coastguard Worker return AllocationResult(BAD_VALUE);
131*38e8c45fSAndroid Build Coastguard Worker }
132*38e8c45fSAndroid Build Coastguard Worker
133*38e8c45fSAndroid Build Coastguard Worker if (request.layerCount < 1) {
134*38e8c45fSAndroid Build Coastguard Worker return AllocationResult(BAD_VALUE);
135*38e8c45fSAndroid Build Coastguard Worker }
136*38e8c45fSAndroid Build Coastguard Worker
137*38e8c45fSAndroid Build Coastguard Worker auto result = mAllocator->allocate(request);
138*38e8c45fSAndroid Build Coastguard Worker if (result.status == UNKNOWN_TRANSACTION) {
139*38e8c45fSAndroid Build Coastguard Worker if (!request.extras.empty()) {
140*38e8c45fSAndroid Build Coastguard Worker ALOGE("Failed to allocate with additional options, allocator version mis-match? "
141*38e8c45fSAndroid Build Coastguard Worker "gralloc version = %d",
142*38e8c45fSAndroid Build Coastguard Worker (int)mMapper.getMapperVersion());
143*38e8c45fSAndroid Build Coastguard Worker return result;
144*38e8c45fSAndroid Build Coastguard Worker }
145*38e8c45fSAndroid Build Coastguard Worker // If there's no additional options, fall back to previous allocate version
146*38e8c45fSAndroid Build Coastguard Worker result.status = mAllocator->allocate(request.requestorName, request.width, request.height,
147*38e8c45fSAndroid Build Coastguard Worker request.format, request.layerCount, request.usage,
148*38e8c45fSAndroid Build Coastguard Worker &result.stride, &result.handle, request.importBuffer);
149*38e8c45fSAndroid Build Coastguard Worker }
150*38e8c45fSAndroid Build Coastguard Worker
151*38e8c45fSAndroid Build Coastguard Worker if (result.status != NO_ERROR) {
152*38e8c45fSAndroid Build Coastguard Worker ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
153*38e8c45fSAndroid Build Coastguard Worker "usage %" PRIx64 ": %d",
154*38e8c45fSAndroid Build Coastguard Worker request.width, request.height, request.layerCount, request.format, request.usage,
155*38e8c45fSAndroid Build Coastguard Worker result.status);
156*38e8c45fSAndroid Build Coastguard Worker return result;
157*38e8c45fSAndroid Build Coastguard Worker }
158*38e8c45fSAndroid Build Coastguard Worker
159*38e8c45fSAndroid Build Coastguard Worker if (!request.importBuffer) {
160*38e8c45fSAndroid Build Coastguard Worker return result;
161*38e8c45fSAndroid Build Coastguard Worker }
162*38e8c45fSAndroid Build Coastguard Worker size_t bufSize;
163*38e8c45fSAndroid Build Coastguard Worker
164*38e8c45fSAndroid Build Coastguard Worker // if stride has no meaning or is too large,
165*38e8c45fSAndroid Build Coastguard Worker // approximate size with the input width instead
166*38e8c45fSAndroid Build Coastguard Worker if ((result.stride) != 0 &&
167*38e8c45fSAndroid Build Coastguard Worker std::numeric_limits<size_t>::max() / height / (result.stride) < static_cast<size_t>(bpp)) {
168*38e8c45fSAndroid Build Coastguard Worker bufSize = static_cast<size_t>(width) * height * bpp;
169*38e8c45fSAndroid Build Coastguard Worker } else {
170*38e8c45fSAndroid Build Coastguard Worker bufSize = static_cast<size_t>((result.stride)) * height * bpp;
171*38e8c45fSAndroid Build Coastguard Worker }
172*38e8c45fSAndroid Build Coastguard Worker
173*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(sLock);
174*38e8c45fSAndroid Build Coastguard Worker KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
175*38e8c45fSAndroid Build Coastguard Worker alloc_rec_t rec;
176*38e8c45fSAndroid Build Coastguard Worker rec.width = width;
177*38e8c45fSAndroid Build Coastguard Worker rec.height = height;
178*38e8c45fSAndroid Build Coastguard Worker rec.stride = result.stride;
179*38e8c45fSAndroid Build Coastguard Worker rec.format = request.format;
180*38e8c45fSAndroid Build Coastguard Worker rec.layerCount = request.layerCount;
181*38e8c45fSAndroid Build Coastguard Worker rec.usage = request.usage;
182*38e8c45fSAndroid Build Coastguard Worker rec.size = bufSize;
183*38e8c45fSAndroid Build Coastguard Worker rec.requestorName = request.requestorName;
184*38e8c45fSAndroid Build Coastguard Worker list.add(result.handle, rec);
185*38e8c45fSAndroid Build Coastguard Worker
186*38e8c45fSAndroid Build Coastguard Worker return result;
187*38e8c45fSAndroid Build Coastguard Worker }
188*38e8c45fSAndroid Build Coastguard Worker
allocateHelper(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,buffer_handle_t * handle,uint32_t * stride,std::string requestorName,bool importBuffer)189*38e8c45fSAndroid Build Coastguard Worker status_t GraphicBufferAllocator::allocateHelper(uint32_t width, uint32_t height, PixelFormat format,
190*38e8c45fSAndroid Build Coastguard Worker uint32_t layerCount, uint64_t usage,
191*38e8c45fSAndroid Build Coastguard Worker buffer_handle_t* handle, uint32_t* stride,
192*38e8c45fSAndroid Build Coastguard Worker std::string requestorName, bool importBuffer) {
193*38e8c45fSAndroid Build Coastguard Worker ATRACE_CALL();
194*38e8c45fSAndroid Build Coastguard Worker
195*38e8c45fSAndroid Build Coastguard Worker // make sure to not allocate a N x 0 or 0 x N buffer, since this is
196*38e8c45fSAndroid Build Coastguard Worker // allowed from an API stand-point allocate a 1x1 buffer instead.
197*38e8c45fSAndroid Build Coastguard Worker if (!width || !height)
198*38e8c45fSAndroid Build Coastguard Worker width = height = 1;
199*38e8c45fSAndroid Build Coastguard Worker
200*38e8c45fSAndroid Build Coastguard Worker const uint32_t bpp = bytesPerPixel(format);
201*38e8c45fSAndroid Build Coastguard Worker if (std::numeric_limits<size_t>::max() / width / height < static_cast<size_t>(bpp)) {
202*38e8c45fSAndroid Build Coastguard Worker ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
203*38e8c45fSAndroid Build Coastguard Worker "usage %" PRIx64 ": Requesting too large a buffer size",
204*38e8c45fSAndroid Build Coastguard Worker width, height, layerCount, format, usage);
205*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
206*38e8c45fSAndroid Build Coastguard Worker }
207*38e8c45fSAndroid Build Coastguard Worker
208*38e8c45fSAndroid Build Coastguard Worker // Ensure that layerCount is valid.
209*38e8c45fSAndroid Build Coastguard Worker if (layerCount < 1) {
210*38e8c45fSAndroid Build Coastguard Worker layerCount = 1;
211*38e8c45fSAndroid Build Coastguard Worker }
212*38e8c45fSAndroid Build Coastguard Worker
213*38e8c45fSAndroid Build Coastguard Worker // TODO(b/72323293, b/72703005): Remove these invalid bits from callers
214*38e8c45fSAndroid Build Coastguard Worker usage &= ~static_cast<uint64_t>((1 << 10) | (1 << 13));
215*38e8c45fSAndroid Build Coastguard Worker
216*38e8c45fSAndroid Build Coastguard Worker status_t error = mAllocator->allocate(requestorName, width, height, format, layerCount, usage,
217*38e8c45fSAndroid Build Coastguard Worker stride, handle, importBuffer);
218*38e8c45fSAndroid Build Coastguard Worker if (error != NO_ERROR) {
219*38e8c45fSAndroid Build Coastguard Worker ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
220*38e8c45fSAndroid Build Coastguard Worker "usage %" PRIx64 ": %d",
221*38e8c45fSAndroid Build Coastguard Worker width, height, layerCount, format, usage, error);
222*38e8c45fSAndroid Build Coastguard Worker return error;
223*38e8c45fSAndroid Build Coastguard Worker }
224*38e8c45fSAndroid Build Coastguard Worker
225*38e8c45fSAndroid Build Coastguard Worker if (!importBuffer) {
226*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
227*38e8c45fSAndroid Build Coastguard Worker }
228*38e8c45fSAndroid Build Coastguard Worker size_t bufSize;
229*38e8c45fSAndroid Build Coastguard Worker
230*38e8c45fSAndroid Build Coastguard Worker // if stride has no meaning or is too large,
231*38e8c45fSAndroid Build Coastguard Worker // approximate size with the input width instead
232*38e8c45fSAndroid Build Coastguard Worker if ((*stride) != 0 &&
233*38e8c45fSAndroid Build Coastguard Worker std::numeric_limits<size_t>::max() / height / (*stride) < static_cast<size_t>(bpp)) {
234*38e8c45fSAndroid Build Coastguard Worker bufSize = static_cast<size_t>(width) * height * bpp;
235*38e8c45fSAndroid Build Coastguard Worker } else {
236*38e8c45fSAndroid Build Coastguard Worker bufSize = static_cast<size_t>((*stride)) * height * bpp;
237*38e8c45fSAndroid Build Coastguard Worker }
238*38e8c45fSAndroid Build Coastguard Worker
239*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(sLock);
240*38e8c45fSAndroid Build Coastguard Worker KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
241*38e8c45fSAndroid Build Coastguard Worker alloc_rec_t rec;
242*38e8c45fSAndroid Build Coastguard Worker rec.width = width;
243*38e8c45fSAndroid Build Coastguard Worker rec.height = height;
244*38e8c45fSAndroid Build Coastguard Worker rec.stride = *stride;
245*38e8c45fSAndroid Build Coastguard Worker rec.format = format;
246*38e8c45fSAndroid Build Coastguard Worker rec.layerCount = layerCount;
247*38e8c45fSAndroid Build Coastguard Worker rec.usage = usage;
248*38e8c45fSAndroid Build Coastguard Worker rec.size = bufSize;
249*38e8c45fSAndroid Build Coastguard Worker rec.requestorName = std::move(requestorName);
250*38e8c45fSAndroid Build Coastguard Worker list.add(*handle, rec);
251*38e8c45fSAndroid Build Coastguard Worker
252*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
253*38e8c45fSAndroid Build Coastguard Worker }
allocate(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,buffer_handle_t * handle,uint32_t * stride,std::string requestorName)254*38e8c45fSAndroid Build Coastguard Worker status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, PixelFormat format,
255*38e8c45fSAndroid Build Coastguard Worker uint32_t layerCount, uint64_t usage,
256*38e8c45fSAndroid Build Coastguard Worker buffer_handle_t* handle, uint32_t* stride,
257*38e8c45fSAndroid Build Coastguard Worker std::string requestorName) {
258*38e8c45fSAndroid Build Coastguard Worker return allocateHelper(width, height, format, layerCount, usage, handle, stride, requestorName,
259*38e8c45fSAndroid Build Coastguard Worker true);
260*38e8c45fSAndroid Build Coastguard Worker }
261*38e8c45fSAndroid Build Coastguard Worker
allocateRawHandle(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,buffer_handle_t * handle,uint32_t * stride,std::string requestorName)262*38e8c45fSAndroid Build Coastguard Worker status_t GraphicBufferAllocator::allocateRawHandle(uint32_t width, uint32_t height,
263*38e8c45fSAndroid Build Coastguard Worker PixelFormat format, uint32_t layerCount,
264*38e8c45fSAndroid Build Coastguard Worker uint64_t usage, buffer_handle_t* handle,
265*38e8c45fSAndroid Build Coastguard Worker uint32_t* stride, std::string requestorName) {
266*38e8c45fSAndroid Build Coastguard Worker return allocateHelper(width, height, format, layerCount, usage, handle, stride, requestorName,
267*38e8c45fSAndroid Build Coastguard Worker false);
268*38e8c45fSAndroid Build Coastguard Worker }
269*38e8c45fSAndroid Build Coastguard Worker
270*38e8c45fSAndroid Build Coastguard Worker // DEPRECATED
allocate(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,buffer_handle_t * handle,uint32_t * stride,uint64_t,std::string requestorName)271*38e8c45fSAndroid Build Coastguard Worker status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, PixelFormat format,
272*38e8c45fSAndroid Build Coastguard Worker uint32_t layerCount, uint64_t usage,
273*38e8c45fSAndroid Build Coastguard Worker buffer_handle_t* handle, uint32_t* stride,
274*38e8c45fSAndroid Build Coastguard Worker uint64_t /*graphicBufferId*/, std::string requestorName) {
275*38e8c45fSAndroid Build Coastguard Worker return allocateHelper(width, height, format, layerCount, usage, handle, stride, requestorName,
276*38e8c45fSAndroid Build Coastguard Worker true);
277*38e8c45fSAndroid Build Coastguard Worker }
278*38e8c45fSAndroid Build Coastguard Worker
free(buffer_handle_t handle)279*38e8c45fSAndroid Build Coastguard Worker status_t GraphicBufferAllocator::free(buffer_handle_t handle)
280*38e8c45fSAndroid Build Coastguard Worker {
281*38e8c45fSAndroid Build Coastguard Worker ATRACE_CALL();
282*38e8c45fSAndroid Build Coastguard Worker
283*38e8c45fSAndroid Build Coastguard Worker // We allocated a buffer from the allocator and imported it into the
284*38e8c45fSAndroid Build Coastguard Worker // mapper to get the handle. We just need to free the handle now.
285*38e8c45fSAndroid Build Coastguard Worker mMapper.freeBuffer(handle);
286*38e8c45fSAndroid Build Coastguard Worker
287*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(sLock);
288*38e8c45fSAndroid Build Coastguard Worker KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
289*38e8c45fSAndroid Build Coastguard Worker list.removeItem(handle);
290*38e8c45fSAndroid Build Coastguard Worker
291*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
292*38e8c45fSAndroid Build Coastguard Worker }
293*38e8c45fSAndroid Build Coastguard Worker
supportsAdditionalOptions() const294*38e8c45fSAndroid Build Coastguard Worker bool GraphicBufferAllocator::supportsAdditionalOptions() const {
295*38e8c45fSAndroid Build Coastguard Worker return mAllocator->supportsAdditionalOptions();
296*38e8c45fSAndroid Build Coastguard Worker }
297*38e8c45fSAndroid Build Coastguard Worker
298*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
299*38e8c45fSAndroid Build Coastguard Worker }; // namespace android
300