mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-11-17 04:56:00 +01:00
gbm: Expose bo buffer mapping (#12)
* expose bo buffer mapping * update comment * implement endDataPtr to unmap gbm buffer
This commit is contained in:
parent
47d95b8a73
commit
815df06da2
2 changed files with 35 additions and 9 deletions
|
@ -20,6 +20,8 @@ namespace Aquamarine {
|
||||||
virtual bool isSynchronous();
|
virtual bool isSynchronous();
|
||||||
virtual bool good();
|
virtual bool good();
|
||||||
virtual SDMABUFAttrs dmabuf();
|
virtual SDMABUFAttrs dmabuf();
|
||||||
|
virtual std::tuple<uint8_t*, uint32_t, size_t> beginDataPtr(uint32_t flags);
|
||||||
|
virtual void endDataPtr();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator_, Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain);
|
CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator_, Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain);
|
||||||
|
@ -28,6 +30,8 @@ namespace Aquamarine {
|
||||||
|
|
||||||
// gbm stuff
|
// gbm stuff
|
||||||
gbm_bo* bo = nullptr;
|
gbm_bo* bo = nullptr;
|
||||||
|
void* boBuffer = nullptr;
|
||||||
|
void* gboMapping = nullptr;
|
||||||
SDMABUFAttrs attrs{.success = false};
|
SDMABUFAttrs attrs{.success = false};
|
||||||
|
|
||||||
friend class CGBMAllocator;
|
friend class CGBMAllocator;
|
||||||
|
|
|
@ -53,7 +53,8 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator_,
|
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)
|
if (!allocator)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -158,8 +159,11 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
|
||||||
|
|
||||||
Aquamarine::CGBMBuffer::~CGBMBuffer() {
|
Aquamarine::CGBMBuffer::~CGBMBuffer() {
|
||||||
events.destroy.emit();
|
events.destroy.emit();
|
||||||
if (bo)
|
if (bo) {
|
||||||
|
if (gboMapping)
|
||||||
|
gbm_bo_unmap(bo, gboMapping); // FIXME: is it needed before destroy?
|
||||||
gbm_bo_destroy(bo);
|
gbm_bo_destroy(bo);
|
||||||
|
}
|
||||||
for (size_t i = 0; i < (size_t)attrs.planes; i++)
|
for (size_t i = 0; i < (size_t)attrs.planes; i++)
|
||||||
close(attrs.fds.at(i));
|
close(attrs.fds.at(i));
|
||||||
}
|
}
|
||||||
|
@ -188,6 +192,24 @@ SDMABUFAttrs Aquamarine::CGBMBuffer::dmabuf() {
|
||||||
return attrs;
|
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() {
|
CGBMAllocator::~CGBMAllocator() {
|
||||||
if (gbmDevice)
|
if (gbmDevice)
|
||||||
gbm_device_destroy(gbmDevice);
|
gbm_device_destroy(gbmDevice);
|
||||||
|
|
Loading…
Reference in a new issue