From ddd6285ceb57f5325c7a42b2579b9e33ca700187 Mon Sep 17 00:00:00 2001
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Date: Mon, 25 Nov 2024 10:43:37 +0100
Subject: [PATCH] TI: plugin_store: rename C2DmaBufAllocator ->
 C2CustomHeapDmaBufAllocator

Since this is version of C2DmaBufAllocator will use a different
dmabuf heap, rename it to C2CarveoutDmaBufAllocator to reflect a
different usage.

Having a different name will be helpful when skimming through logcat.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
 ...ator.cpp => C2CarveoutDmaBufAllocator.cpp} | 65 ++++++++++---------
 ...llocator.h => C2CarveoutDmaBufAllocator.h} |  4 +-
 2 files changed, 35 insertions(+), 34 deletions(-)
 rename plugin_store/{C2DmaBufAllocator.cpp => C2CarveoutDmaBufAllocator.cpp} (84%)
 rename plugin_store/include/v4l2_codec2/plugin_store/{C2DmaBufAllocator.h => C2CarveoutDmaBufAllocator.h} (97%)

diff --git a/plugin_store/C2DmaBufAllocator.cpp b/plugin_store/C2CarveoutDmaBufAllocator.cpp
similarity index 84%
rename from plugin_store/C2DmaBufAllocator.cpp
rename to plugin_store/C2CarveoutDmaBufAllocator.cpp
index c470171..3e0e5e6 100644
--- a/plugin_store/C2DmaBufAllocator.cpp
+++ b/plugin_store/C2CarveoutDmaBufAllocator.cpp
@@ -15,12 +15,13 @@
  */
 
 //#define LOG_NDEBUG 0
-#define LOG_TAG "C2DmaBufAllocator"
+#define LOG_TAG "C2CarveoutDmaBufAllocator"
+
+#include <v4l2_codec2/plugin_store/C2CarveoutDmaBufAllocator.h>
 
 #include <BufferAllocator/BufferAllocator.h>
 #include <C2Buffer.h>
 #include <C2Debug.h>
-#include <C2DmaBufAllocator.h>
 #include <C2ErrnoUtils.h>
 
 #include <linux/ion.h>
@@ -100,13 +101,13 @@ bool C2HandleBuf::IsValid(const C2Handle* const o) {
 }
 
 /* =========================== DMABUF ALLOCATION =========================== */
-class C2DmaBufAllocation : public C2LinearAllocation {
+class C2CarveoutDmaBufAllocation : public C2LinearAllocation {
    public:
     /* Interface methods */
     virtual c2_status_t map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence* fence,
                             void** addr /* nonnull */) override;
     virtual c2_status_t unmap(void* addr, size_t size, C2Fence* fenceFd) override;
-    virtual ~C2DmaBufAllocation() override;
+    virtual ~C2CarveoutDmaBufAllocation() override;
     virtual const C2Handle* handle() const override;
     virtual id_t getAllocatorId() const override;
     virtual bool equals(const std::shared_ptr<C2LinearAllocation>& other) const override;
@@ -123,7 +124,7 @@ class C2DmaBufAllocation : public C2LinearAllocation {
       * @param flags     flags
       * @param id        allocator id
       */
-    C2DmaBufAllocation(BufferAllocator& alloc, size_t allocSize, size_t capacity,
+    C2CarveoutDmaBufAllocation(BufferAllocator& alloc, size_t allocSize, size_t capacity,
                        C2String heap_name, unsigned flags, C2Allocator::id_t id);
 
     /**
@@ -133,7 +134,7 @@ class C2DmaBufAllocation : public C2LinearAllocation {
       * @param shareFd dmabuf fd of the wrapped allocation
       * @param id      allocator id
       */
-    C2DmaBufAllocation(size_t size, int shareFd, C2Allocator::id_t id);
+    C2CarveoutDmaBufAllocation(size_t size, int shareFd, C2Allocator::id_t id);
 
     c2_status_t status() const;
 
@@ -165,10 +166,10 @@ class C2DmaBufAllocation : public C2LinearAllocation {
     Mutexed<std::list<Mapping>> mMappings;
 
     // TODO: we could make this encapsulate shared_ptr and copiable
-    C2_DO_NOT_COPY(C2DmaBufAllocation);
+    C2_DO_NOT_COPY(C2CarveoutDmaBufAllocation);
 };
 
-c2_status_t C2DmaBufAllocation::map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence* fence,
+c2_status_t C2CarveoutDmaBufAllocation::map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence* fence,
                                     void** addr) {
     (void)fence;  // TODO: wait for fence
     *addr = nullptr;
@@ -205,7 +206,7 @@ c2_status_t C2DmaBufAllocation::map(size_t offset, size_t size, C2MemoryUsage us
     return err;
 }
 
-c2_status_t C2DmaBufAllocation::unmap(void* addr, size_t size, C2Fence* fence) {
+c2_status_t C2CarveoutDmaBufAllocation::unmap(void* addr, size_t size, C2Fence* fence) {
     Mutexed<std::list<Mapping>>::Locked mappings(mMappings);
     if (mappings->empty()) {
         ALOGD("tried to unmap unmapped buffer");
@@ -232,29 +233,29 @@ c2_status_t C2DmaBufAllocation::unmap(void* addr, size_t size, C2Fence* fence) {
     return C2_BAD_VALUE;
 }
 
-c2_status_t C2DmaBufAllocation::status() const {
+c2_status_t C2CarveoutDmaBufAllocation::status() const {
     return mInit;
 }
 
-C2Allocator::id_t C2DmaBufAllocation::getAllocatorId() const {
+C2Allocator::id_t C2CarveoutDmaBufAllocation::getAllocatorId() const {
     return mId;
 }
 
-bool C2DmaBufAllocation::equals(const std::shared_ptr<C2LinearAllocation>& other) const {
+bool C2CarveoutDmaBufAllocation::equals(const std::shared_ptr<C2LinearAllocation>& other) const {
     if (!other || other->getAllocatorId() != getAllocatorId()) {
         return false;
     }
     // get user handle to compare objects
-    std::shared_ptr<C2DmaBufAllocation> otherAsBuf =
-            std::static_pointer_cast<C2DmaBufAllocation>(other);
+    std::shared_ptr<C2CarveoutDmaBufAllocation> otherAsBuf =
+            std::static_pointer_cast<C2CarveoutDmaBufAllocation>(other);
     return mHandle.bufferFd() == otherAsBuf->mHandle.bufferFd();
 }
 
-const C2Handle* C2DmaBufAllocation::handle() const {
+const C2Handle* C2CarveoutDmaBufAllocation::handle() const {
     return &mHandle;
 }
 
-C2DmaBufAllocation::~C2DmaBufAllocation() {
+C2CarveoutDmaBufAllocation::~C2CarveoutDmaBufAllocation() {
     Mutexed<std::list<Mapping>>::Locked mappings(mMappings);
     if (!mappings->empty()) {
         ALOGD("Dangling mappings!");
@@ -268,7 +269,7 @@ C2DmaBufAllocation::~C2DmaBufAllocation() {
     }
 }
 
-C2DmaBufAllocation::C2DmaBufAllocation(BufferAllocator& alloc, size_t allocSize, size_t capacity,
+C2CarveoutDmaBufAllocation::C2CarveoutDmaBufAllocation(BufferAllocator& alloc, size_t allocSize, size_t capacity,
                                        C2String heap_name, unsigned flags, C2Allocator::id_t id)
     : C2LinearAllocation(capacity), mHandle(-1, 0) {
     int bufferFd = -1;
@@ -285,7 +286,7 @@ C2DmaBufAllocation::C2DmaBufAllocation(BufferAllocator& alloc, size_t allocSize,
     mInit = c2_status_t(c2_map_errno<ENOMEM, EACCES, EINVAL>(ret));
 }
 
-C2DmaBufAllocation::C2DmaBufAllocation(size_t size, int shareFd, C2Allocator::id_t id)
+C2CarveoutDmaBufAllocation::C2CarveoutDmaBufAllocation(size_t size, int shareFd, C2Allocator::id_t id)
     : C2LinearAllocation(size), mHandle(-1, 0) {
     mHandle = C2HandleBuf(shareFd, size);
     mId = id;
@@ -293,29 +294,29 @@ C2DmaBufAllocation::C2DmaBufAllocation(size_t size, int shareFd, C2Allocator::id
 }
 
 /* =========================== DMABUF ALLOCATOR =========================== */
-C2DmaBufAllocator::C2DmaBufAllocator(id_t id) : mInit(C2_OK) {
+C2CarveoutDmaBufAllocator::C2CarveoutDmaBufAllocator(id_t id) : mInit(C2_OK) {
     C2MemoryUsage minUsage = {0, 0};
     C2MemoryUsage maxUsage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};
     Traits traits = {"android.allocator.dmabuf", id, LINEAR, minUsage, maxUsage};
     mTraits = std::make_shared<Traits>(traits);
 }
 
-C2Allocator::id_t C2DmaBufAllocator::getId() const {
+C2Allocator::id_t C2CarveoutDmaBufAllocator::getId() const {
     std::lock_guard<std::mutex> lock(mUsageMapperLock);
     return mTraits->id;
 }
 
-C2String C2DmaBufAllocator::getName() const {
+C2String C2CarveoutDmaBufAllocator::getName() const {
     std::lock_guard<std::mutex> lock(mUsageMapperLock);
     return mTraits->name;
 }
 
-std::shared_ptr<const C2Allocator::Traits> C2DmaBufAllocator::getTraits() const {
+std::shared_ptr<const C2Allocator::Traits> C2CarveoutDmaBufAllocator::getTraits() const {
     std::lock_guard<std::mutex> lock(mUsageMapperLock);
     return mTraits;
 }
 
-void C2DmaBufAllocator::setUsageMapper(const UsageMapperFn& mapper __unused, uint64_t minUsage,
+void C2CarveoutDmaBufAllocator::setUsageMapper(const UsageMapperFn& mapper __unused, uint64_t minUsage,
                                        uint64_t maxUsage, uint64_t blockSize) {
     std::lock_guard<std::mutex> lock(mUsageMapperLock);
     mUsageMapperCache.clear();
@@ -327,11 +328,11 @@ void C2DmaBufAllocator::setUsageMapper(const UsageMapperFn& mapper __unused, uin
     mBlockSize = blockSize;
 }
 
-std::size_t C2DmaBufAllocator::MapperKeyHash::operator()(const MapperKey& k) const {
+std::size_t C2CarveoutDmaBufAllocator::MapperKeyHash::operator()(const MapperKey& k) const {
     return std::hash<uint64_t>{}(k.first) ^ std::hash<size_t>{}(k.second);
 }
 
-c2_status_t C2DmaBufAllocator::mapUsage(C2MemoryUsage usage, size_t capacity, C2String* heap_name,
+c2_status_t C2CarveoutDmaBufAllocator::mapUsage(C2MemoryUsage usage, size_t capacity, C2String* heap_name,
                                         unsigned* flags) {
     std::lock_guard<std::mutex> lock(mUsageMapperLock);
     c2_status_t res = C2_OK;
@@ -343,7 +344,7 @@ c2_status_t C2DmaBufAllocator::mapUsage(C2MemoryUsage usage, size_t capacity, C2
         if (mUsageMapper) {
             res = mUsageMapper(usage, capacity, heap_name, flags);
         } else {
-            if (C2DmaBufAllocator::system_uncached_supported() &&
+            if (C2CarveoutDmaBufAllocator::system_uncached_supported() &&
                 !(usage.expected & (C2MemoryUsage::CPU_READ | C2MemoryUsage::CPU_WRITE)))
                 *heap_name = "system-uncached";
             else
@@ -370,7 +371,7 @@ c2_status_t C2DmaBufAllocator::mapUsage(C2MemoryUsage usage, size_t capacity, C2
     return res;
 }
 
-c2_status_t C2DmaBufAllocator::newLinearAllocation(
+c2_status_t C2CarveoutDmaBufAllocator::newLinearAllocation(
         uint32_t capacity, C2MemoryUsage usage, std::shared_ptr<C2LinearAllocation>* allocation) {
     if (allocation == nullptr) {
         return C2_BAD_VALUE;
@@ -402,7 +403,7 @@ c2_status_t C2DmaBufAllocator::newLinearAllocation(
 
     size_t allocSize = (size_t)capacity + sPadding;
     // TODO: should we align allocation size to mBlockSize to reflect the true allocation size?
-    std::shared_ptr<C2DmaBufAllocation> alloc = std::make_shared<C2DmaBufAllocation>(
+    std::shared_ptr<C2CarveoutDmaBufAllocation> alloc = std::make_shared<C2CarveoutDmaBufAllocation>(
             mBufferAllocator, allocSize, allocSize - sPadding, heap_name, flags, getId());
     ret = alloc->status();
     if (ret == C2_OK) {
@@ -411,7 +412,7 @@ c2_status_t C2DmaBufAllocator::newLinearAllocation(
     return ret;
 }
 
-c2_status_t C2DmaBufAllocator::priorLinearAllocation(
+c2_status_t C2CarveoutDmaBufAllocator::priorLinearAllocation(
         const C2Handle* handle, std::shared_ptr<C2LinearAllocation>* allocation) {
     *allocation = nullptr;
     if (mInit != C2_OK) {
@@ -424,8 +425,8 @@ c2_status_t C2DmaBufAllocator::priorLinearAllocation(
 
     // TODO: get capacity and validate it
     const C2HandleBuf* h = static_cast<const C2HandleBuf*>(handle);
-    std::shared_ptr<C2DmaBufAllocation> alloc =
-            std::make_shared<C2DmaBufAllocation>(h->size(), h->bufferFd(), getId());
+    std::shared_ptr<C2CarveoutDmaBufAllocation> alloc =
+            std::make_shared<C2CarveoutDmaBufAllocation>(h->size(), h->bufferFd(), getId());
     c2_status_t ret = alloc->status();
     if (ret == C2_OK) {
         *allocation = alloc;
@@ -436,7 +437,7 @@ c2_status_t C2DmaBufAllocator::priorLinearAllocation(
 }
 
 // static
-bool C2DmaBufAllocator::CheckHandle(const C2Handle* const o) {
+bool C2CarveoutDmaBufAllocator::CheckHandle(const C2Handle* const o) {
     return C2HandleBuf::IsValid(o);
 }
 
diff --git a/plugin_store/include/v4l2_codec2/plugin_store/C2DmaBufAllocator.h b/plugin_store/include/v4l2_codec2/plugin_store/C2CarveoutDmaBufAllocator.h
similarity index 97%
rename from plugin_store/include/v4l2_codec2/plugin_store/C2DmaBufAllocator.h
rename to plugin_store/include/v4l2_codec2/plugin_store/C2CarveoutDmaBufAllocator.h
index d84c8c6..b3b59a6 100644
--- a/plugin_store/include/v4l2_codec2/plugin_store/C2DmaBufAllocator.h
+++ b/plugin_store/include/v4l2_codec2/plugin_store/C2CarveoutDmaBufAllocator.h
@@ -29,7 +29,7 @@
 
 namespace android {
 
-class C2DmaBufAllocator : public C2Allocator {
+class C2CarveoutDmaBufAllocator : public C2Allocator {
    public:
     virtual c2_status_t newLinearAllocation(
             uint32_t capacity, C2MemoryUsage usage,
@@ -38,7 +38,7 @@ class C2DmaBufAllocator : public C2Allocator {
     virtual c2_status_t priorLinearAllocation(
             const C2Handle* handle, std::shared_ptr<C2LinearAllocation>* allocation) override;
 
-    C2DmaBufAllocator(id_t id);
+    C2CarveoutDmaBufAllocator(id_t id);
 
     virtual c2_status_t status() const { return mInit; }
 
-- 
GitLab