Skip to content

Commit

Permalink
clean unneeded stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
UjinT34 committed Jul 26, 2024
1 parent 36e4934 commit 584fd4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
13 changes: 3 additions & 10 deletions include/aquamarine/allocator/Dumb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "Allocator.hpp"

struct gbm_device;

namespace Aquamarine {
class CDumbAllocator;
class CBackend;
Expand All @@ -28,8 +26,8 @@ namespace Aquamarine {
Hyprutils::Memory::CWeakPointer<CDumbAllocator> allocator;

// dumb stuff
int drmFd;
uint32_t handle;
int drmFd = -1;
uint32_t handle = 0;
void* data = nullptr;
size_t length = 0;

Expand All @@ -51,19 +49,14 @@ namespace Aquamarine {
Hyprutils::Memory::CWeakPointer<CDumbAllocator> self;

private:
CDumbAllocator(int fd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_);
CDumbAllocator(int drmfd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_);

// a vector purely for tracking (debugging) the buffers and nothing more
std::vector<Hyprutils::Memory::CWeakPointer<CDumbBuffer>> buffers;

int fd = -1;
Hyprutils::Memory::CWeakPointer<CBackend> backend;

// gbm stuff
gbm_device* gbmDevice = nullptr;
std::string gbmDeviceBackendName = "";
std::string drmName = "";

friend class CDumbBuffer;
friend class CDRMRenderer;
};
Expand Down
41 changes: 10 additions & 31 deletions src/allocator/Dumb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <xf86drm.h>
#include <gbm.h>
#include <unistd.h>

using namespace Aquamarine;
Expand All @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -124,44 +123,24 @@ void Aquamarine::CDumbBuffer::endDataPtr() {
}
}

CDumbAllocator::~CDumbAllocator() {
if (gbmDevice)
gbm_device_destroy(gbmDevice);
}
CDumbAllocator::~CDumbAllocator() {}

SP<CDumbAllocator> Aquamarine::CDumbAllocator::create(int drmfd_, Hyprutils::Memory::CWeakPointer<CBackend> 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<CDumbAllocator>(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<CBackend> 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<CBackend> backend_) : fd(drmfd_), backend(backend_) {}

SP<IBuffer> Aquamarine::CDumbAllocator::acquire(const SAllocatorBufferParams& params, Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain_) {
if (params.size.x < 1 || params.size.y < 1) {
Expand Down

0 comments on commit 584fd4e

Please sign in to comment.