summaryrefslogtreecommitdiff
path: root/libs/ui/Gralloc2.cpp
diff options
context:
space:
mode:
author Marissa Wall <marissaw@google.com> 2019-11-27 10:36:29 -0800
committer Marissa Ikonomidis <marissaw@google.com> 2019-12-05 22:56:59 +0000
commitbfcf81fd5e77b262dd789011e5f8a9900dbf7d81 (patch)
tree864de08b1676ed0990f2c2c529ab2dfa3f272f9f /libs/ui/Gralloc2.cpp
parent15375f9262b0574cfd21f5d4983843ee4170dade (diff)
gralloc: Support allocate buffer without import
Media allocates buffers but doesn't import until they absolutely need to. In order to support codec2 moving to GraphicBufferAllocator, add a function that allows them to allocate without import. Bug: 145139476 Test: VtsHalMediaC2V1_0Host && cherry pick ag/9741096 and run android.media.cts.MediaMetadataRetrieverTest#testThumbnailVP9Hdr Change-Id: Icbd5943d45f20cb796204f816e5aac446d402979
Diffstat (limited to 'libs/ui/Gralloc2.cpp')
-rw-r--r--libs/ui/Gralloc2.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp
index 5dc453005d..0e23ddf74a 100644
--- a/libs/ui/Gralloc2.cpp
+++ b/libs/ui/Gralloc2.cpp
@@ -381,7 +381,8 @@ std::string Gralloc2Allocator::dumpDebugInfo() const {
status_t Gralloc2Allocator::allocate(uint32_t width, uint32_t height, PixelFormat format,
uint32_t layerCount, uint64_t usage, uint32_t bufferCount,
- uint32_t* outStride, buffer_handle_t* outBufferHandles) const {
+ uint32_t* outStride, buffer_handle_t* outBufferHandles,
+ bool importBuffers) const {
IMapper::BufferDescriptorInfo descriptorInfo = {};
descriptorInfo.width = width;
descriptorInfo.height = height;
@@ -404,19 +405,33 @@ status_t Gralloc2Allocator::allocate(uint32_t width, uint32_t height, PixelForma
return;
}
- // import buffers
- for (uint32_t i = 0; i < bufferCount; i++) {
- error = mMapper.importBuffer(tmpBuffers[i],
- &outBufferHandles[i]);
- if (error != NO_ERROR) {
- for (uint32_t j = 0; j < i; j++) {
- mMapper.freeBuffer(outBufferHandles[j]);
- outBufferHandles[j] = nullptr;
+ if (importBuffers) {
+ for (uint32_t i = 0; i < bufferCount; i++) {
+ error = mMapper.importBuffer(tmpBuffers[i],
+ &outBufferHandles[i]);
+ if (error != NO_ERROR) {
+ for (uint32_t j = 0; j < i; j++) {
+ mMapper.freeBuffer(outBufferHandles[j]);
+ outBufferHandles[j] = nullptr;
+ }
+ return;
+ }
+ }
+ } else {
+ for (uint32_t i = 0; i < bufferCount; i++) {
+ outBufferHandles[i] = native_handle_clone(
+ tmpBuffers[i].getNativeHandle());
+ if (!outBufferHandles[i]) {
+ for (uint32_t j = 0; j < i; j++) {
+ auto buffer = const_cast<native_handle_t*>(
+ outBufferHandles[j]);
+ native_handle_close(buffer);
+ native_handle_delete(buffer);
+ outBufferHandles[j] = nullptr;
+ }
}
- return;
}
}
-
*outStride = tmpStride;
});