From 8912828f487129f67a585ea5aab68380aa7c817d Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Thu, 25 Jun 2026 07:23:27 +0200 Subject: Large documentation overhaul & main DRM device --- src/drm.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gem.cpp | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/drm.cpp (limited to 'src') diff --git a/src/drm.cpp b/src/drm.cpp new file mode 100644 index 0000000..6bb0a3a --- /dev/null +++ b/src/drm.cpp @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: MIT */ + +#include "drm++/drm.hpp" +#include "drm++/helper.hpp" +#include "drm++/ioctl.hpp" + +#include + +#include +#include + +using namespace drm; + +Device::Device(int fd) : m_fd(fd) { + if (this->m_fd < 0) { + throw std::invalid_argument("invalid file descriptor"); + } + + drm_auth args{ + + }; + ioctl::perform(this->m_fd, DRM_IOCTL_GET_MAGIC, args); + this->m_magic = args.magic; +} + +void Device::acquireMaster() const { + ioctl::perform(this->m_fd, DRM_IOCTL_SET_MASTER); +} + +void Device::releaseMaster() const { + ioctl::perform(this->m_fd, DRM_IOCTL_DROP_MASTER); +} + +void Device::authenticate(u32 magic) const { + drm_auth args{ + .magic = magic + }; + ioctl::perform(this->m_fd, DRM_IOCTL_AUTH_MAGIC, args); +} + +void Device::destruct() noexcept { + if (this->m_fd < 0) { + return; + } + + ::close(this->m_fd); + this->m_fd = -1; +} diff --git a/src/gem.cpp b/src/gem.cpp index 4b81703..0572c3b 100644 --- a/src/gem.cpp +++ b/src/gem.cpp @@ -78,7 +78,7 @@ void Object::destruct() noexcept { /* Dumb buffer class */ DumbBuffer::DumbBuffer(int fd, u32 width, u32 height, u32 bpp) - : Object(fd, -1), m_width(width), m_height(height), m_bpp(bpp) { + : Object(fd), m_width(width), m_height(height), m_bpp(bpp) { drm_mode_create_dumb args{ .height = height, .width = width, -- cgit v1.3.1