This commit is contained in:
Vaxry 2024-11-10 22:43:49 +00:00
parent ce8047e19e
commit da61640608
2 changed files with 9 additions and 8 deletions

View file

@ -29,7 +29,7 @@ namespace Aquamarine {
// //
Hyprutils::Math::Vector2D pixelSize; Hyprutils::Math::Vector2D pixelSize;
uint32_t stride = 0, handle = 0; uint32_t stride = 0, handle = 0;
uint64_t size = 0; uint64_t bufferLen = 0;
uint8_t* data = nullptr; uint8_t* data = nullptr;
int primeFD = -1; int primeFD = -1;

View file

@ -21,7 +21,7 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params,
Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain) : allocator(allocator_) { Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain) : allocator(allocator_) {
attrs.format = params.format; attrs.format = params.format;
if (int ret = drmModeCreateDumbBuffer(allocator->drmFD(), params.size.x, params.size.y, 32, 0, &handle, &stride, &size); ret < 0) { if (int ret = drmModeCreateDumbBuffer(allocator->drmFD(), params.size.x, params.size.y, 32, 0, &handle, &stride, &bufferLen); ret < 0) {
allocator->backend->log(AQ_LOG_ERROR, std::format("failed to create a drm_dumb buffer: {}", strerror(-ret))); allocator->backend->log(AQ_LOG_ERROR, std::format("failed to create a drm_dumb buffer: {}", strerror(-ret)));
return; return;
} }
@ -31,6 +31,7 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params,
attrs.size = pixelSize; attrs.size = pixelSize;
attrs.strides.at(0) = stride; attrs.strides.at(0) = stride;
attrs.planes = 1; attrs.planes = 1;
size = pixelSize;
uint64_t offset = 0; uint64_t offset = 0;
if (int ret = drmModeMapDumbBuffer(allocator->drmFD(), handle, &offset); ret < 0) { if (int ret = drmModeMapDumbBuffer(allocator->drmFD(), handle, &offset); ret < 0) {
@ -38,14 +39,14 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params,
return; return;
} }
data = (uint8_t*)mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, allocator->drmFD(), offset); data = (uint8_t*)mmap(nullptr, bufferLen, PROT_READ | PROT_WRITE, MAP_SHARED, allocator->drmFD(), offset);
if (data == MAP_FAILED) { if (data == MAP_FAILED) {
allocator->backend->log(AQ_LOG_ERROR, "failed to mmap a drm_dumb buffer"); allocator->backend->log(AQ_LOG_ERROR, "failed to mmap a drm_dumb buffer");
return; return;
} }
// set the entire buffer so we dont get garbage // set the entire buffer so we dont get garbage
memset(data, 0xFF, size); memset(data, 0xFF, bufferLen);
if (int ret = drmPrimeHandleToFD(allocator->drmFD(), handle, DRM_CLOEXEC, &primeFD); ret < 0) { if (int ret = drmPrimeHandleToFD(allocator->drmFD(), handle, DRM_CLOEXEC, &primeFD); ret < 0) {
allocator->backend->log(AQ_LOG_ERROR, std::format("failed to map a drm_dumb buffer: {}", strerror(-ret))); allocator->backend->log(AQ_LOG_ERROR, std::format("failed to map a drm_dumb buffer: {}", strerror(-ret)));
@ -68,7 +69,7 @@ Aquamarine::CDRMDumbBuffer::~CDRMDumbBuffer() {
return; return;
if (data) if (data)
munmap(data, size); munmap(data, bufferLen);
drmModeDestroyDumbBuffer(allocator->drmFD(), handle); drmModeDestroyDumbBuffer(allocator->drmFD(), handle);
} }
@ -98,7 +99,7 @@ SDMABUFAttrs Aquamarine::CDRMDumbBuffer::dmabuf() {
} }
std::tuple<uint8_t*, uint32_t, size_t> Aquamarine::CDRMDumbBuffer::beginDataPtr(uint32_t flags) { std::tuple<uint8_t*, uint32_t, size_t> Aquamarine::CDRMDumbBuffer::beginDataPtr(uint32_t flags) {
return {data, attrs.format, size}; return {data, attrs.format, bufferLen};
} }
void Aquamarine::CDRMDumbBuffer::endDataPtr() { void Aquamarine::CDRMDumbBuffer::endDataPtr() {