From 584fd4e99a36f02efa1f06199060954e53e46e0b Mon Sep 17 00:00:00 2001 From: UjinT34 Date: Fri, 26 Jul 2024 20:59:52 +0300 Subject: [PATCH] clean unneeded stuff --- include/aquamarine/allocator/Dumb.hpp | 13 ++------- src/allocator/Dumb.cpp | 41 +++++++-------------------- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/include/aquamarine/allocator/Dumb.hpp b/include/aquamarine/allocator/Dumb.hpp index bdea040..40c8aea 100644 --- a/include/aquamarine/allocator/Dumb.hpp +++ b/include/aquamarine/allocator/Dumb.hpp @@ -2,8 +2,6 @@ #include "Allocator.hpp" -struct gbm_device; - namespace Aquamarine { class CDumbAllocator; class CBackend; @@ -28,8 +26,8 @@ namespace Aquamarine { Hyprutils::Memory::CWeakPointer allocator; // dumb stuff - int drmFd; - uint32_t handle; + int drmFd = -1; + uint32_t handle = 0; void* data = nullptr; size_t length = 0; @@ -51,7 +49,7 @@ namespace Aquamarine { Hyprutils::Memory::CWeakPointer self; private: - CDumbAllocator(int fd_, Hyprutils::Memory::CWeakPointer backend_); + CDumbAllocator(int drmfd_, Hyprutils::Memory::CWeakPointer backend_); // a vector purely for tracking (debugging) the buffers and nothing more std::vector> buffers; @@ -59,11 +57,6 @@ namespace Aquamarine { int fd = -1; Hyprutils::Memory::CWeakPointer backend; - // gbm stuff - gbm_device* gbmDevice = nullptr; - std::string gbmDeviceBackendName = ""; - std::string drmName = ""; - friend class CDumbBuffer; friend class CDRMRenderer; }; diff --git a/src/allocator/Dumb.cpp b/src/allocator/Dumb.cpp index f78f9e0..2154199 100644 --- a/src/allocator/Dumb.cpp +++ b/src/allocator/Dumb.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include using namespace Aquamarine; @@ -27,22 +26,22 @@ Aquamarine::CDumbBuffer::CDumbBuffer(const SAllocatorBufferParams& params, Hypru }; TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("DUMB: Allocating a dumb buffer: size {}, format {}", params.size, fourccToName(params.format)))); - if (drmIoctl(gbm_device_get_fd(allocator->gbmDevice), DRM_IOCTL_MODE_CREATE_DUMB, &createArgs) != 0) { + if (drmIoctl(allocator->drmFD(), DRM_IOCTL_MODE_CREATE_DUMB, &createArgs) != 0) { allocator->backend->log(AQ_LOG_ERROR, std::format("DUMB: DRM_IOCTL_MODE_CREATE_DUMB failed {}", strerror(errno))); return; } int primeFd; - if (drmPrimeHandleToFD(gbm_device_get_fd(allocator->gbmDevice), createArgs.handle, DRM_CLOEXEC, &primeFd) != 0) { + if (drmPrimeHandleToFD(allocator->drmFD(), createArgs.handle, DRM_CLOEXEC, &primeFd) != 0) { allocator->backend->log(AQ_LOG_ERROR, std::format("DUMB: drmPrimeHandleToFD() failed {}", strerror(errno))); drm_mode_destroy_dumb destroyArgs{ .handle = createArgs.handle, }; - drmIoctl(gbm_device_get_fd(allocator->gbmDevice), DRM_IOCTL_MODE_DESTROY_DUMB, &destroyArgs); + drmIoctl(allocator->drmFD(), DRM_IOCTL_MODE_DESTROY_DUMB, &destroyArgs); return; } - drmFd = gbm_device_get_fd(allocator->gbmDevice); + drmFd = allocator->drmFD(); handle = createArgs.handle; length = createArgs.pitch * params.size.y; @@ -83,7 +82,7 @@ void Aquamarine::CDumbBuffer::update(const Hyprutils::Math::CRegion& damage) { } bool Aquamarine::CDumbBuffer::isSynchronous() { - return false; // FIXME is it correct? + return true; } bool Aquamarine::CDumbBuffer::good() { @@ -124,44 +123,24 @@ void Aquamarine::CDumbBuffer::endDataPtr() { } } -CDumbAllocator::~CDumbAllocator() { - if (gbmDevice) - gbm_device_destroy(gbmDevice); -} +CDumbAllocator::~CDumbAllocator() {} SP Aquamarine::CDumbAllocator::create(int drmfd_, Hyprutils::Memory::CWeakPointer backend_) { - uint64_t capabilities = 0; - if (drmGetCap(drmfd_, DRM_CAP_PRIME, &capabilities) || !(capabilities & DRM_PRIME_CAP_EXPORT)) { - backend_->log(AQ_LOG_ERROR, "Cannot create a Dumb Allocator: PRIME export is not supported by the gpu."); - return nullptr; - } - auto allocator = SP(new CDumbAllocator(drmfd_, backend_)); - if (!allocator->gbmDevice) { - backend_->log(AQ_LOG_ERROR, "Cannot create a Dumb Allocator: gbm failed to create a device."); + if (allocator->drmFD() < 0) { + backend_->log(AQ_LOG_ERROR, "Cannot create a Dumb Allocator: drm fd is required."); return nullptr; } - backend_->log(AQ_LOG_DEBUG, std::format("Created a Dumb Allocator with drm fd {}", drmfd_)); + backend_->log(AQ_LOG_DEBUG, std::format("Created a Dumb Allocator")); allocator->self = allocator; return allocator; } -Aquamarine::CDumbAllocator::CDumbAllocator(int fd_, Hyprutils::Memory::CWeakPointer backend_) : fd(fd_), backend(backend_) { - gbmDevice = gbm_create_device(fd_); - if (!gbmDevice) { - backend->log(AQ_LOG_ERROR, std::format("Couldn't open a GBM device at fd {}", fd_)); - return; - } - - gbmDeviceBackendName = gbm_device_get_backend_name(gbmDevice); - auto drmName_ = drmGetDeviceNameFromFd2(fd_); - drmName = drmName_; - free(drmName_); -} +Aquamarine::CDumbAllocator::CDumbAllocator(int drmfd_, Hyprutils::Memory::CWeakPointer backend_) : fd(drmfd_), backend(backend_) {} SP Aquamarine::CDumbAllocator::acquire(const SAllocatorBufferParams& params, Hyprutils::Memory::CSharedPointer swapchain_) { if (params.size.x < 1 || params.size.y < 1) {