Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bo buffer mapping #12

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions include/aquamarine/allocator/GBM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ namespace Aquamarine {
public:
virtual ~CGBMBuffer();

virtual eBufferCapability caps();
virtual eBufferType type();
virtual void update(const Hyprutils::Math::CRegion& damage);
virtual bool isSynchronous();
virtual bool good();
virtual SDMABUFAttrs dmabuf();
virtual eBufferCapability caps();
virtual eBufferType type();
virtual void update(const Hyprutils::Math::CRegion& damage);
virtual bool isSynchronous();
virtual bool good();
virtual SDMABUFAttrs dmabuf();
virtual std::tuple<uint8_t*, uint32_t, size_t> beginDataPtr(uint32_t flags);
virtual void endDataPtr();

private:
CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator_, Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain);

Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator;

// gbm stuff
gbm_bo* bo = nullptr;
gbm_bo* bo = nullptr;
void* boBuffer = nullptr;
void* gboMapping = nullptr;
SDMABUFAttrs attrs{.success = false};

friend class CGBMAllocator;
Expand Down
26 changes: 24 additions & 2 deletions src/allocator/GBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor)
}

Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator_,
Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain) : allocator(allocator_) {
Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain) :
allocator(allocator_) {
if (!allocator)
return;

Expand Down Expand Up @@ -158,8 +159,11 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti

Aquamarine::CGBMBuffer::~CGBMBuffer() {
events.destroy.emit();
if (bo)
if (bo) {
if (gboMapping)
gbm_bo_unmap(bo, gboMapping); // FIXME: is it needed before destroy?
gbm_bo_destroy(bo);
}
for (size_t i = 0; i < (size_t)attrs.planes; i++)
close(attrs.fds.at(i));
}
Expand Down Expand Up @@ -188,6 +192,24 @@ SDMABUFAttrs Aquamarine::CGBMBuffer::dmabuf() {
return attrs;
}

std::tuple<uint8_t*, uint32_t, size_t> Aquamarine::CGBMBuffer::beginDataPtr(uint32_t flags) {
uint32_t dst_stride = 0;
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);
Expand Down
Loading