blob: 9ee9838b395a53c8811129c74354f63e7705779c [file] [log] [blame]
Dan Stoza1e2a2a02016-01-11 15:21:07 -08001/*
2 * Copyright 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "Gralloc1On0Adapter"
19//#define LOG_NDEBUG 0
20
Mathias Agopianfe2f54f2017-02-15 19:48:58 -080021#include <ui/Gralloc1On0Adapter.h>
22
Chia-I Wua3c428a2017-04-11 10:03:38 -070023#include <algorithm>
24#include <array>
25
Jesse Hall79927812017-03-23 11:03:23 -070026#include <grallocusage/GrallocUsageConversion.h>
Mathias Agopianfe2f54f2017-02-15 19:48:58 -080027
Dan Stoza1e2a2a02016-01-11 15:21:07 -080028#include <hardware/gralloc.h>
29
Mathias Agopiana9347642017-02-13 16:42:28 -080030#include <ui/GraphicBuffer.h>
Mathias Agopianfe2f54f2017-02-15 19:48:58 -080031#include <ui/Gralloc1.h>
Dan Stoza1e2a2a02016-01-11 15:21:07 -080032
33#include <utils/Log.h>
34
35#include <inttypes.h>
36
37template <typename PFN, typename T>
38static gralloc1_function_pointer_t asFP(T function)
39{
40 static_assert(std::is_same<PFN, T>::value, "Incompatible function pointer");
41 return reinterpret_cast<gralloc1_function_pointer_t>(function);
42}
43
44namespace android {
45
46Gralloc1On0Adapter::Gralloc1On0Adapter(const hw_module_t* module)
47 : mModule(reinterpret_cast<const gralloc_module_t*>(module)),
48 mMinorVersion(mModule->common.module_api_version & 0xFF),
49 mDevice(nullptr)
50{
51 ALOGV("Constructing");
52 getCapabilities = getCapabilitiesHook;
53 getFunction = getFunctionHook;
54 int error = ::gralloc_open(&(mModule->common), &mDevice);
55 if (error) {
56 ALOGE("Failed to open gralloc0 module: %d", error);
57 }
58 ALOGV("Opened gralloc0 device %p", mDevice);
59}
60
61Gralloc1On0Adapter::~Gralloc1On0Adapter()
62{
63 ALOGV("Destructing");
64 if (mDevice) {
65 ALOGV("Closing gralloc0 device %p", mDevice);
66 ::gralloc_close(mDevice);
67 }
68}
69
70void Gralloc1On0Adapter::doGetCapabilities(uint32_t* outCount,
71 int32_t* outCapabilities)
72{
Chia-I Wua3c428a2017-04-11 10:03:38 -070073 constexpr std::array<int32_t, 2> supportedCapabilities = {{
74 GRALLOC1_CAPABILITY_ON_ADAPTER,
75 GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE,
76 }};
77
Dan Stoza1e2a2a02016-01-11 15:21:07 -080078 if (outCapabilities == nullptr) {
Chia-I Wua3c428a2017-04-11 10:03:38 -070079 *outCount = supportedCapabilities.size();
80 } else {
81 *outCount = std::min(*outCount, static_cast<uint32_t>(
82 supportedCapabilities.size()));
83 std::copy_n(supportedCapabilities.begin(),
84 *outCount, outCapabilities);
Dan Stoza1e2a2a02016-01-11 15:21:07 -080085 }
86}
87
88gralloc1_function_pointer_t Gralloc1On0Adapter::doGetFunction(
89 int32_t intDescriptor)
90{
91 constexpr auto lastDescriptor =
92 static_cast<int32_t>(GRALLOC1_LAST_ADAPTER_FUNCTION);
93 if (intDescriptor < 0 || intDescriptor > lastDescriptor) {
94 ALOGE("Invalid function descriptor");
95 return nullptr;
96 }
97
98 auto descriptor =
99 static_cast<gralloc1_function_descriptor_t>(intDescriptor);
100 switch (descriptor) {
101 case GRALLOC1_FUNCTION_DUMP:
102 return asFP<GRALLOC1_PFN_DUMP>(dumpHook);
103 case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR:
104 return asFP<GRALLOC1_PFN_CREATE_DESCRIPTOR>(createDescriptorHook);
105 case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR:
106 return asFP<GRALLOC1_PFN_DESTROY_DESCRIPTOR>(destroyDescriptorHook);
107 case GRALLOC1_FUNCTION_SET_CONSUMER_USAGE:
108 return asFP<GRALLOC1_PFN_SET_CONSUMER_USAGE>(setConsumerUsageHook);
109 case GRALLOC1_FUNCTION_SET_DIMENSIONS:
110 return asFP<GRALLOC1_PFN_SET_DIMENSIONS>(setDimensionsHook);
111 case GRALLOC1_FUNCTION_SET_FORMAT:
112 return asFP<GRALLOC1_PFN_SET_FORMAT>(setFormatHook);
Craig Donner6ebc46a2016-10-21 15:23:44 -0700113 case GRALLOC1_FUNCTION_SET_LAYER_COUNT:
114 return asFP<GRALLOC1_PFN_SET_LAYER_COUNT>(setLayerCountHook);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800115 case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE:
116 return asFP<GRALLOC1_PFN_SET_PRODUCER_USAGE>(setProducerUsageHook);
117 case GRALLOC1_FUNCTION_GET_BACKING_STORE:
118 return asFP<GRALLOC1_PFN_GET_BACKING_STORE>(
119 bufferHook<decltype(&Buffer::getBackingStore),
120 &Buffer::getBackingStore, gralloc1_backing_store_t*>);
121 case GRALLOC1_FUNCTION_GET_CONSUMER_USAGE:
122 return asFP<GRALLOC1_PFN_GET_CONSUMER_USAGE>(getConsumerUsageHook);
123 case GRALLOC1_FUNCTION_GET_DIMENSIONS:
124 return asFP<GRALLOC1_PFN_GET_DIMENSIONS>(
125 bufferHook<decltype(&Buffer::getDimensions),
126 &Buffer::getDimensions, uint32_t*, uint32_t*>);
127 case GRALLOC1_FUNCTION_GET_FORMAT:
128 return asFP<GRALLOC1_PFN_GET_FORMAT>(
129 bufferHook<decltype(&Buffer::getFormat),
130 &Buffer::getFormat, int32_t*>);
Craig Donner6ebc46a2016-10-21 15:23:44 -0700131 case GRALLOC1_FUNCTION_GET_LAYER_COUNT:
132 return asFP<GRALLOC1_PFN_GET_LAYER_COUNT>(
133 bufferHook<decltype(&Buffer::getLayerCount),
134 &Buffer::getLayerCount, uint32_t*>);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800135 case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE:
136 return asFP<GRALLOC1_PFN_GET_PRODUCER_USAGE>(getProducerUsageHook);
137 case GRALLOC1_FUNCTION_GET_STRIDE:
138 return asFP<GRALLOC1_PFN_GET_STRIDE>(
139 bufferHook<decltype(&Buffer::getStride),
140 &Buffer::getStride, uint32_t*>);
141 case GRALLOC1_FUNCTION_ALLOCATE:
142 // Not provided, since we'll use ALLOCATE_WITH_ID
143 return nullptr;
144 case GRALLOC1_FUNCTION_ALLOCATE_WITH_ID:
145 if (mDevice != nullptr) {
146 return asFP<GRALLOC1_PFN_ALLOCATE_WITH_ID>(allocateWithIdHook);
147 } else {
148 return nullptr;
149 }
150 case GRALLOC1_FUNCTION_RETAIN:
151 return asFP<GRALLOC1_PFN_RETAIN>(
152 managementHook<&Gralloc1On0Adapter::retain>);
153 case GRALLOC1_FUNCTION_RELEASE:
154 return asFP<GRALLOC1_PFN_RELEASE>(
155 managementHook<&Gralloc1On0Adapter::release>);
156 case GRALLOC1_FUNCTION_RETAIN_GRAPHIC_BUFFER:
157 return asFP<GRALLOC1_PFN_RETAIN_GRAPHIC_BUFFER>(
158 retainGraphicBufferHook);
159 case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES:
160 return asFP<GRALLOC1_PFN_GET_NUM_FLEX_PLANES>(
161 bufferHook<decltype(&Buffer::getNumFlexPlanes),
162 &Buffer::getNumFlexPlanes, uint32_t*>);
163 case GRALLOC1_FUNCTION_LOCK:
164 return asFP<GRALLOC1_PFN_LOCK>(
165 lockHook<void*, &Gralloc1On0Adapter::lock>);
166 case GRALLOC1_FUNCTION_LOCK_FLEX:
167 return asFP<GRALLOC1_PFN_LOCK_FLEX>(
168 lockHook<struct android_flex_layout,
169 &Gralloc1On0Adapter::lockFlex>);
170 case GRALLOC1_FUNCTION_LOCK_YCBCR:
171 return asFP<GRALLOC1_PFN_LOCK_YCBCR>(
172 lockHook<struct android_ycbcr,
173 &Gralloc1On0Adapter::lockYCbCr>);
174 case GRALLOC1_FUNCTION_UNLOCK:
175 return asFP<GRALLOC1_PFN_UNLOCK>(unlockHook);
176 case GRALLOC1_FUNCTION_INVALID:
177 ALOGE("Invalid function descriptor");
178 return nullptr;
179 }
180
181 ALOGE("Unknown function descriptor: %d", intDescriptor);
182 return nullptr;
183}
184
185void Gralloc1On0Adapter::dump(uint32_t* outSize, char* outBuffer)
186{
187 ALOGV("dump(%u (%p), %p", outSize ? *outSize : 0, outSize, outBuffer);
188
189 if (!mDevice->dump) {
190 // dump is optional on gralloc0 implementations
191 *outSize = 0;
192 return;
193 }
194
195 if (!outBuffer) {
196 constexpr int32_t BUFFER_LENGTH = 4096;
197 char buffer[BUFFER_LENGTH] = {};
198 mDevice->dump(mDevice, buffer, BUFFER_LENGTH);
199 buffer[BUFFER_LENGTH - 1] = 0; // Ensure the buffer is null-terminated
200 size_t actualLength = std::strlen(buffer);
201 mCachedDump.resize(actualLength);
202 std::copy_n(buffer, actualLength, mCachedDump.begin());
203 *outSize = static_cast<uint32_t>(actualLength);
204 } else {
205 *outSize = std::min(*outSize,
206 static_cast<uint32_t>(mCachedDump.size()));
207 outBuffer = std::copy_n(mCachedDump.cbegin(), *outSize, outBuffer);
208 }
209}
210
211gralloc1_error_t Gralloc1On0Adapter::createDescriptor(
212 gralloc1_buffer_descriptor_t* outDescriptor)
213{
214 auto descriptorId = sNextBufferDescriptorId++;
Dan Stoza923c0662016-06-21 16:22:06 -0700215 std::lock_guard<std::mutex> lock(mDescriptorMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800216 mDescriptors.emplace(descriptorId,
217 std::make_shared<Descriptor>(this, descriptorId));
218
219 ALOGV("Created descriptor %" PRIu64, descriptorId);
220
221 *outDescriptor = descriptorId;
222 return GRALLOC1_ERROR_NONE;
223}
224
225gralloc1_error_t Gralloc1On0Adapter::destroyDescriptor(
226 gralloc1_buffer_descriptor_t descriptor)
227{
228 ALOGV("Destroying descriptor %" PRIu64, descriptor);
229
Dan Stoza923c0662016-06-21 16:22:06 -0700230 std::lock_guard<std::mutex> lock(mDescriptorMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800231 if (mDescriptors.count(descriptor) == 0) {
232 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
233 }
234
235 mDescriptors.erase(descriptor);
236 return GRALLOC1_ERROR_NONE;
237}
238
239Gralloc1On0Adapter::Buffer::Buffer(buffer_handle_t handle,
240 gralloc1_backing_store_t store, const Descriptor& descriptor,
241 uint32_t stride, bool wasAllocated)
242 : mHandle(handle),
243 mReferenceCount(1),
244 mStore(store),
245 mDescriptor(descriptor),
246 mStride(stride),
247 mWasAllocated(wasAllocated) {}
248
249gralloc1_error_t Gralloc1On0Adapter::allocate(
250 const std::shared_ptr<Descriptor>& descriptor,
251 gralloc1_backing_store_t store,
252 buffer_handle_t* outBufferHandle)
253{
254 ALOGV("allocate(%" PRIu64 ", %#" PRIx64 ")", descriptor->id, store);
255
256 // If this function is being called, it's because we handed out its function
257 // pointer, which only occurs when mDevice has been loaded successfully and
258 // we are permitted to allocate
259
Jesse Hall79927812017-03-23 11:03:23 -0700260 int usage = android_convertGralloc1To0Usage(descriptor->producerUsage,
261 descriptor->consumerUsage);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800262 buffer_handle_t handle = nullptr;
263 int stride = 0;
264 ALOGV("Calling alloc(%p, %u, %u, %i, %u)", mDevice, descriptor->width,
265 descriptor->height, descriptor->format, usage);
266 auto error = mDevice->alloc(mDevice,
267 static_cast<int>(descriptor->width),
268 static_cast<int>(descriptor->height), descriptor->format,
269 usage, &handle, &stride);
270 if (error != 0) {
271 ALOGE("gralloc0 allocation failed: %d (%s)", error,
272 strerror(-error));
273 return GRALLOC1_ERROR_NO_RESOURCES;
274 }
275
276 *outBufferHandle = handle;
277 auto buffer = std::make_shared<Buffer>(handle, store, *descriptor, stride,
278 true);
Dan Stoza923c0662016-06-21 16:22:06 -0700279
280 std::lock_guard<std::mutex> lock(mBufferMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800281 mBuffers.emplace(handle, std::move(buffer));
282
283 return GRALLOC1_ERROR_NONE;
284}
285
286gralloc1_error_t Gralloc1On0Adapter::allocateWithIdHook(
287 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptorId,
288 gralloc1_backing_store_t store, buffer_handle_t* outBuffer)
289{
290 auto adapter = getAdapter(device);
291
292 auto descriptor = adapter->getDescriptor(descriptorId);
293 if (!descriptor) {
294 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
295 }
296
297 buffer_handle_t bufferHandle = nullptr;
298 auto error = adapter->allocate(descriptor, store, &bufferHandle);
299 if (error != GRALLOC1_ERROR_NONE) {
300 return error;
301 }
302
303 *outBuffer = bufferHandle;
304 return error;
305}
306
307gralloc1_error_t Gralloc1On0Adapter::retain(
308 const std::shared_ptr<Buffer>& buffer)
309{
Ajit Kumar56ec3af2016-11-25 12:08:53 +0530310 std::lock_guard<std::mutex> lock(mBufferMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800311 buffer->retain();
312 return GRALLOC1_ERROR_NONE;
313}
314
315gralloc1_error_t Gralloc1On0Adapter::release(
316 const std::shared_ptr<Buffer>& buffer)
317{
Ajit Kumar56ec3af2016-11-25 12:08:53 +0530318 std::lock_guard<std::mutex> lock(mBufferMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800319 if (!buffer->release()) {
320 return GRALLOC1_ERROR_NONE;
321 }
322
323 buffer_handle_t handle = buffer->getHandle();
324 if (buffer->wasAllocated()) {
325 ALOGV("Calling free(%p)", handle);
326 int result = mDevice->free(mDevice, handle);
327 if (result != 0) {
328 ALOGE("gralloc0 free failed: %d", result);
329 }
330 } else {
331 ALOGV("Calling unregisterBuffer(%p)", handle);
332 int result = mModule->unregisterBuffer(mModule, handle);
333 if (result != 0) {
334 ALOGE("gralloc0 unregister failed: %d", result);
335 }
Chia-I Wua3c428a2017-04-11 10:03:38 -0700336
337 native_handle_close(handle);
338 native_handle_delete(const_cast<native_handle_t*>(handle));
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800339 }
Dan Stoza923c0662016-06-21 16:22:06 -0700340
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800341 mBuffers.erase(handle);
342 return GRALLOC1_ERROR_NONE;
343}
344
345gralloc1_error_t Gralloc1On0Adapter::retain(
346 const android::GraphicBuffer* graphicBuffer)
347{
348 ALOGV("retainGraphicBuffer(%p, %#" PRIx64 ")",
349 graphicBuffer->getNativeBuffer()->handle, graphicBuffer->getId());
350
351 buffer_handle_t handle = graphicBuffer->getNativeBuffer()->handle;
Dan Stoza923c0662016-06-21 16:22:06 -0700352 std::lock_guard<std::mutex> lock(mBufferMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800353 if (mBuffers.count(handle) != 0) {
354 mBuffers[handle]->retain();
355 return GRALLOC1_ERROR_NONE;
356 }
357
358 ALOGV("Calling registerBuffer(%p)", handle);
359 int result = mModule->registerBuffer(mModule, handle);
360 if (result != 0) {
361 ALOGE("gralloc0 register failed: %d", result);
362 return GRALLOC1_ERROR_NO_RESOURCES;
363 }
364
365 Descriptor descriptor{this, sNextBufferDescriptorId++};
366 descriptor.setDimensions(graphicBuffer->getWidth(),
367 graphicBuffer->getHeight());
368 descriptor.setFormat(graphicBuffer->getPixelFormat());
369 descriptor.setProducerUsage(
370 static_cast<gralloc1_producer_usage_t>(graphicBuffer->getUsage()));
371 descriptor.setConsumerUsage(
372 static_cast<gralloc1_consumer_usage_t>(graphicBuffer->getUsage()));
373 auto buffer = std::make_shared<Buffer>(handle,
374 static_cast<gralloc1_backing_store_t>(graphicBuffer->getId()),
375 descriptor, graphicBuffer->getStride(), false);
376 mBuffers.emplace(handle, std::move(buffer));
377 return GRALLOC1_ERROR_NONE;
378}
379
380gralloc1_error_t Gralloc1On0Adapter::lock(
381 const std::shared_ptr<Buffer>& buffer,
382 gralloc1_producer_usage_t producerUsage,
383 gralloc1_consumer_usage_t consumerUsage,
384 const gralloc1_rect_t& accessRegion, void** outData,
385 const sp<Fence>& acquireFence)
386{
387 if (mMinorVersion >= 3) {
388 int result = mModule->lockAsync(mModule, buffer->getHandle(),
Jesse Hall79927812017-03-23 11:03:23 -0700389 android_convertGralloc1To0Usage(producerUsage, consumerUsage),
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800390 accessRegion.left, accessRegion.top, accessRegion.width,
391 accessRegion.height, outData, acquireFence->dup());
392 if (result != 0) {
393 return GRALLOC1_ERROR_UNSUPPORTED;
394 }
395 } else {
396 acquireFence->waitForever("Gralloc1On0Adapter::lock");
397 int result = mModule->lock(mModule, buffer->getHandle(),
Jesse Hall79927812017-03-23 11:03:23 -0700398 android_convertGralloc1To0Usage(producerUsage, consumerUsage),
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800399 accessRegion.left, accessRegion.top, accessRegion.width,
400 accessRegion.height, outData);
401 ALOGV("gralloc0 lock returned %d", result);
402 if (result != 0) {
403 return GRALLOC1_ERROR_UNSUPPORTED;
404 }
405 }
406 return GRALLOC1_ERROR_NONE;
407}
408
409gralloc1_error_t Gralloc1On0Adapter::lockFlex(
410 const std::shared_ptr<Buffer>& /*buffer*/,
411 gralloc1_producer_usage_t /*producerUsage*/,
412 gralloc1_consumer_usage_t /*consumerUsage*/,
413 const gralloc1_rect_t& /*accessRegion*/,
414 struct android_flex_layout* /*outData*/,
415 const sp<Fence>& /*acquireFence*/)
416{
417 // TODO
418 return GRALLOC1_ERROR_UNSUPPORTED;
419}
420
421gralloc1_error_t Gralloc1On0Adapter::lockYCbCr(
422 const std::shared_ptr<Buffer>& buffer,
423 gralloc1_producer_usage_t producerUsage,
424 gralloc1_consumer_usage_t consumerUsage,
425 const gralloc1_rect_t& accessRegion, struct android_ycbcr* outData,
426 const sp<Fence>& acquireFence)
427{
428 if (mMinorVersion >= 3 && mModule->lockAsync_ycbcr) {
429 int result = mModule->lockAsync_ycbcr(mModule, buffer->getHandle(),
Jesse Hall79927812017-03-23 11:03:23 -0700430 android_convertGralloc1To0Usage(producerUsage, consumerUsage),
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800431 accessRegion.left, accessRegion.top, accessRegion.width,
432 accessRegion.height, outData, acquireFence->dup());
433 if (result != 0) {
434 return GRALLOC1_ERROR_UNSUPPORTED;
435 }
436 } else if (mModule->lock_ycbcr) {
437 acquireFence->waitForever("Gralloc1On0Adapter::lockYCbCr");
438 int result = mModule->lock_ycbcr(mModule, buffer->getHandle(),
Jesse Hall79927812017-03-23 11:03:23 -0700439 android_convertGralloc1To0Usage(producerUsage, consumerUsage),
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800440 accessRegion.left, accessRegion.top, accessRegion.width,
441 accessRegion.height, outData);
442 ALOGV("gralloc0 lockYCbCr returned %d", result);
443 if (result != 0) {
444 return GRALLOC1_ERROR_UNSUPPORTED;
445 }
446 } else {
447 return GRALLOC1_ERROR_UNSUPPORTED;
448 }
449
450 return GRALLOC1_ERROR_NONE;
451}
452
453gralloc1_error_t Gralloc1On0Adapter::unlock(
454 const std::shared_ptr<Buffer>& buffer,
455 sp<Fence>* outReleaseFence)
456{
457 if (mMinorVersion >= 3) {
458 int fenceFd = -1;
459 int result = mModule->unlockAsync(mModule, buffer->getHandle(),
460 &fenceFd);
461 if (result != 0) {
462 close(fenceFd);
463 ALOGE("gralloc0 unlockAsync failed: %d", result);
464 } else {
465 *outReleaseFence = new Fence(fenceFd);
466 }
467 } else {
468 int result = mModule->unlock(mModule, buffer->getHandle());
469 if (result != 0) {
470 ALOGE("gralloc0 unlock failed: %d", result);
471 }
472 }
473 return GRALLOC1_ERROR_NONE;
474}
475
476std::shared_ptr<Gralloc1On0Adapter::Descriptor>
477Gralloc1On0Adapter::getDescriptor(gralloc1_buffer_descriptor_t descriptorId)
478{
Dan Stoza923c0662016-06-21 16:22:06 -0700479 std::lock_guard<std::mutex> lock(mDescriptorMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800480 if (mDescriptors.count(descriptorId) == 0) {
481 return nullptr;
482 }
483
484 return mDescriptors[descriptorId];
485}
486
487std::shared_ptr<Gralloc1On0Adapter::Buffer> Gralloc1On0Adapter::getBuffer(
488 buffer_handle_t bufferHandle)
489{
Dan Stoza923c0662016-06-21 16:22:06 -0700490 std::lock_guard<std::mutex> lock(mBufferMutex);
Dan Stoza1e2a2a02016-01-11 15:21:07 -0800491 if (mBuffers.count(bufferHandle) == 0) {
492 return nullptr;
493 }
494
495 return mBuffers[bufferHandle];
496}
497
498std::atomic<gralloc1_buffer_descriptor_t>
499 Gralloc1On0Adapter::sNextBufferDescriptorId(1);
500
501} // namespace android