From 301d2bd2e0f45f791c3cd9b8a5c84f021d017890 Mon Sep 17 00:00:00 2001 From: UjinT34 Date: Fri, 12 Jul 2024 15:03:13 +0300 Subject: [PATCH] implement endDataPtr to unmap gbm buffer --- include/aquamarine/allocator/GBM.hpp | 1 + src/allocator/GBM.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/aquamarine/allocator/GBM.hpp b/include/aquamarine/allocator/GBM.hpp index 1f52b0f..5033187 100644 --- a/include/aquamarine/allocator/GBM.hpp +++ b/include/aquamarine/allocator/GBM.hpp @@ -21,6 +21,7 @@ namespace Aquamarine { virtual bool good(); virtual SDMABUFAttrs dmabuf(); virtual std::tuple beginDataPtr(uint32_t flags); + virtual void endDataPtr(); private: CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer allocator_, Hyprutils::Memory::CSharedPointer swapchain); diff --git a/src/allocator/GBM.cpp b/src/allocator/GBM.cpp index ec1f326..a78a243 100644 --- a/src/allocator/GBM.cpp +++ b/src/allocator/GBM.cpp @@ -194,12 +194,22 @@ SDMABUFAttrs Aquamarine::CGBMBuffer::dmabuf() { std::tuple Aquamarine::CGBMBuffer::beginDataPtr(uint32_t flags) { uint32_t dst_stride = 0; - if (!boBuffer) + if (boBuffer) + allocator->backend->log(AQ_LOG_ERROR, "beginDataPtr is called a second time without calling endDataPtr first. Returning old mapping"); + else boBuffer = gbm_bo_map(bo, 0, 0, attrs.size.x, attrs.size.y, flags, &dst_stride, &gboMapping); // FIXME: assumes a 32-bit pixel format return {(uint8_t*)boBuffer, attrs.format, attrs.size.x * attrs.size.y * 4}; } +void Aquamarine::CGBMBuffer::endDataPtr() { + if (gboMapping) { + gbm_bo_unmap(bo, gboMapping); + gboMapping = nullptr; + boBuffer = nullptr; + } +} + CGBMAllocator::~CGBMAllocator() { if (gbmDevice) gbm_device_destroy(gbmDevice);