summaryrefslogtreecommitdiff
path: root/src/drm.cpp
diff options
context:
space:
mode:
authorPancakeTAS <pancake@mgnet.work>2026-06-25 07:23:27 +0200
committerPancakeTAS <pancake@mgnet.work>2026-06-25 07:23:27 +0200
commit8912828f487129f67a585ea5aab68380aa7c817d (patch)
treee2ca119382451aa2cc924a08f6b5733fb7009d61 /src/drm.cpp
parentImplement GEM objects and dumb buffers (diff)
Large documentation overhaul & main DRM device
Diffstat (limited to 'src/drm.cpp')
-rw-r--r--src/drm.cpp48
1 files changed, 48 insertions, 0 deletions
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 <stdexcept>
+
+#include <drm.h>
+#include <unistd.h>
+
+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;
+}