parent
831ca28f93
commit
3c82d5a919
3 changed files with 123 additions and 0 deletions
@ -0,0 +1,76 @@ |
|||||||
|
/*
|
||||||
|
KWin - the KDE window manager |
||||||
|
This file is part of the KDE project. |
||||||
|
|
||||||
|
SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com> |
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-2.0-or-later |
||||||
|
*/ |
||||||
|
#include "drmdevice.h" |
||||||
|
|
||||||
|
#include "gbmgraphicsbufferallocator.h" |
||||||
|
|
||||||
|
#include <fcntl.h> |
||||||
|
#include <gbm.h> |
||||||
|
#include <sys/stat.h> |
||||||
|
|
||||||
|
namespace KWin |
||||||
|
{ |
||||||
|
|
||||||
|
DrmDevice::DrmDevice(const QString &path, dev_t id, FileDescriptor &&fd, gbm_device *gbmDevice) |
||||||
|
: m_path(path) |
||||||
|
, m_id(id) |
||||||
|
, m_fd(std::move(fd)) |
||||||
|
, m_gbmDevice(gbmDevice) |
||||||
|
, m_allocator(std::make_unique<GbmGraphicsBufferAllocator>(gbmDevice)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
DrmDevice::~DrmDevice() |
||||||
|
{ |
||||||
|
gbm_device_destroy(m_gbmDevice); |
||||||
|
} |
||||||
|
|
||||||
|
QString DrmDevice::path() const |
||||||
|
{ |
||||||
|
return m_path; |
||||||
|
} |
||||||
|
|
||||||
|
dev_t DrmDevice::deviceId() const |
||||||
|
{ |
||||||
|
return m_id; |
||||||
|
} |
||||||
|
|
||||||
|
gbm_device *DrmDevice::gbmDevice() const |
||||||
|
{ |
||||||
|
return m_gbmDevice; |
||||||
|
} |
||||||
|
|
||||||
|
GraphicsBufferAllocator *DrmDevice::allocator() const |
||||||
|
{ |
||||||
|
return m_allocator.get(); |
||||||
|
} |
||||||
|
|
||||||
|
int DrmDevice::fileDescriptor() const |
||||||
|
{ |
||||||
|
return m_fd.get(); |
||||||
|
} |
||||||
|
|
||||||
|
std::unique_ptr<DrmDevice> DrmDevice::open(const QString &path) |
||||||
|
{ |
||||||
|
FileDescriptor fd{::open(path.toLocal8Bit(), O_RDWR | O_CLOEXEC)}; |
||||||
|
if (!fd.isValid()) { |
||||||
|
return nullptr; |
||||||
|
} |
||||||
|
struct stat buf; |
||||||
|
if (fstat(fd.get(), &buf) == -1) { |
||||||
|
return nullptr; |
||||||
|
} |
||||||
|
gbm_device *device = gbm_create_device(fd.get()); |
||||||
|
if (!device) { |
||||||
|
return nullptr; |
||||||
|
} |
||||||
|
return std::unique_ptr<DrmDevice>(new DrmDevice(path, buf.st_rdev, std::move(fd), device)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,45 @@ |
|||||||
|
/*
|
||||||
|
KWin - the KDE window manager |
||||||
|
This file is part of the KDE project. |
||||||
|
|
||||||
|
SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com> |
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-2.0-or-later |
||||||
|
*/ |
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <QString> |
||||||
|
|
||||||
|
#include "graphicsbufferallocator.h" |
||||||
|
#include "kwin_export.h" |
||||||
|
#include "utils/filedescriptor.h" |
||||||
|
|
||||||
|
struct gbm_device; |
||||||
|
|
||||||
|
namespace KWin |
||||||
|
{ |
||||||
|
|
||||||
|
class KWIN_EXPORT DrmDevice |
||||||
|
{ |
||||||
|
public: |
||||||
|
~DrmDevice(); |
||||||
|
|
||||||
|
QString path() const; |
||||||
|
dev_t deviceId() const; |
||||||
|
gbm_device *gbmDevice() const; |
||||||
|
GraphicsBufferAllocator *allocator() const; |
||||||
|
int fileDescriptor() const; |
||||||
|
|
||||||
|
static std::unique_ptr<DrmDevice> open(const QString &path); |
||||||
|
|
||||||
|
private: |
||||||
|
explicit DrmDevice(const QString &path, dev_t id, FileDescriptor &&fd, gbm_device *gbmDevice); |
||||||
|
|
||||||
|
const QString m_path; |
||||||
|
const dev_t m_id; |
||||||
|
const FileDescriptor m_fd; |
||||||
|
gbm_device *const m_gbmDevice; |
||||||
|
const std::unique_ptr<GraphicsBufferAllocator> m_allocator; |
||||||
|
}; |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue