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
|
@ -14,12 +14,14 @@ 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);
|
||||
|
@ -27,7 +29,9 @@ namespace Aquamarine {
|
|||
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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue