diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-11 22:22:56 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-11 22:22:56 +0000 |
commit | b9a9675bb4fae4bffb83af74284d7a6efe841203 (patch) | |
tree | 27cb135b776aa065dd684ec65bdb41738c8dc4ec | |
parent | 883e4857672d5cafc33035870aebe4c467c8c854 (diff) | |
parent | fe2292dcb7fe55f2604feea7f69d22649254300a (diff) | |
download | libdmabufheap-android14-qpr2-s1-release.tar.gz |
Snap for 11086585 from fe2292dcb7fe55f2604feea7f69d22649254300a to 24Q1-releaseandroid-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Change-Id: Id6499660f7db72bbab415d8c15f79a48d9cceef6
-rw-r--r-- | BufferAllocator.cpp | 23 | ||||
-rw-r--r-- | include/BufferAllocator/BufferAllocator.h | 2 |
2 files changed, 15 insertions, 10 deletions
diff --git a/BufferAllocator.cpp b/BufferAllocator.cpp index a360cfd..0c625f6 100644 --- a/BufferAllocator.cpp +++ b/BufferAllocator.cpp @@ -210,8 +210,7 @@ int BufferAllocator::GetIonConfig(const std::string& heap_name, IonHeapConfig& h return ret; } -int BufferAllocator::DmabufAlloc(const std::string& heap_name, size_t len) { - int fd = OpenDmabufHeap(heap_name); +int BufferAllocator::DmabufAlloc(const std::string& heap_name, size_t len, int fd) { if (fd < 0) return fd; struct dma_heap_allocation_data heap_data{ @@ -263,12 +262,14 @@ int BufferAllocator::IonAlloc(const std::string& heap_name, size_t len, int BufferAllocator::Alloc(const std::string& heap_name, size_t len, unsigned int heap_flags, size_t legacy_align) { - int fd = DmabufAlloc(heap_name, len); + int dma_buf_heap_fd = OpenDmabufHeap(heap_name); + if (dma_buf_heap_fd >= 0) return DmabufAlloc(heap_name, len, dma_buf_heap_fd); - if (fd < 0) - fd = IonAlloc(heap_name, len, heap_flags, legacy_align); - - return fd; + /* + * Swap back to ion only if we failed to allocate for a dma-buffer heap + * that doesn't exist. + */ + return IonAlloc(heap_name, len, heap_flags, legacy_align); } int BufferAllocator::AllocSystem(bool cpu_access_needed, size_t len, unsigned int heap_flags, @@ -283,8 +284,12 @@ int BufferAllocator::AllocSystem(bool cpu_access_needed, size_t len, unsigned in return (dmabuf_heap_list.find(kDmabufSystemUncachedHeapName) != dmabuf_heap_list.end()); }(); - if (uncached_dmabuf_system_heap_support) - return DmabufAlloc(kDmabufSystemUncachedHeapName, len); + if (uncached_dmabuf_system_heap_support) { + int dma_buf_heap_fd = OpenDmabufHeap(kDmabufSystemUncachedHeapName); + return (dma_buf_heap_fd < 0) + ? dma_buf_heap_fd + : DmabufAlloc(kDmabufSystemUncachedHeapName, len, dma_buf_heap_fd); + } static bool uncached_ion_system_heap_support = [this]() -> bool { IonHeapConfig heap_config; diff --git a/include/BufferAllocator/BufferAllocator.h b/include/BufferAllocator/BufferAllocator.h index 95ffdf5..bcc63a0 100644 --- a/include/BufferAllocator/BufferAllocator.h +++ b/include/BufferAllocator/BufferAllocator.h @@ -195,7 +195,7 @@ class BufferAllocator { unsigned int ion_heap_flags = 0); void LogInterface(const std::string& interface); int IonAlloc(const std::string& heap_name, size_t len, unsigned int heap_flags = 0, size_t legacy_align = 0); - int DmabufAlloc(const std::string& heap_name, size_t len); + int DmabufAlloc(const std::string& heap_name, size_t len, int fd); struct IonHeapConfig { unsigned int mask; |