backends/virtual: use DrmDevice

This commit is contained in:
Xaver Hugl 2024-03-21 16:21:22 +01:00
parent 08439957d0
commit 221c6aaf2b
4 changed files with 17 additions and 24 deletions

View file

@ -8,6 +8,7 @@
*/
#include "virtual_backend.h"
#include "core/drmdevice.h"
#include "virtual_egl_backend.h"
#include "virtual_output.h"
#include "virtual_qpainter_backend.h"
@ -19,16 +20,16 @@
namespace KWin
{
static FileDescriptor findRenderDevice()
static std::unique_ptr<DrmDevice> findRenderDevice()
{
const int deviceCount = drmGetDevices2(0, nullptr, 0);
if (deviceCount <= 0) {
return FileDescriptor{};
return nullptr;
}
QList<drmDevice *> devices(deviceCount);
if (drmGetDevices2(0, devices.data(), devices.size()) < 0) {
return FileDescriptor{};
return nullptr;
}
auto deviceCleanup = qScopeGuard([&devices]() {
drmFreeDevices(devices.data(), devices.size());
@ -45,30 +46,23 @@ static FileDescriptor findRenderDevice()
}
if (device->available_nodes & (1 << nodeType)) {
FileDescriptor fd{open(device->nodes[nodeType], O_RDWR | O_CLOEXEC)};
if (fd.isValid()) {
return fd;
if (auto ret = DrmDevice::open(device->nodes[nodeType])) {
return ret;
}
}
}
return FileDescriptor{};
return nullptr;
}
VirtualBackend::VirtualBackend(QObject *parent)
: OutputBackend(parent)
, m_drmDevice(findRenderDevice())
{
m_drmFileDescriptor = findRenderDevice();
if (m_drmFileDescriptor.isValid()) {
m_gbmDevice = gbm_create_device(m_drmFileDescriptor.get());
}
}
VirtualBackend::~VirtualBackend()
{
if (m_gbmDevice) {
gbm_device_destroy(m_gbmDevice);
}
}
bool VirtualBackend::initialize()
@ -79,16 +73,16 @@ bool VirtualBackend::initialize()
QList<CompositingType> VirtualBackend::supportedCompositors() const
{
QList<CompositingType> compositingTypes;
if (m_gbmDevice) {
if (m_drmDevice) {
compositingTypes.append(OpenGLCompositing);
}
compositingTypes.append(QPainterCompositing);
return compositingTypes;
}
gbm_device *VirtualBackend::gbmDevice() const
DrmDevice *VirtualBackend::drmDevice() const
{
return m_gbmDevice;
return m_drmDevice.get();
}
std::unique_ptr<QPainterBackend> VirtualBackend::createQPainterBackend()

View file

@ -19,6 +19,7 @@ namespace KWin
{
class VirtualBackend;
class VirtualOutput;
class DrmDevice;
class KWIN_EXPORT VirtualBackend : public OutputBackend
{
@ -49,7 +50,7 @@ public:
void setEglDisplay(std::unique_ptr<EglDisplay> &&display);
EglDisplay *sceneEglDisplayObject() const override;
gbm_device *gbmDevice() const;
DrmDevice *drmDevice() const;
Q_SIGNALS:
void virtualOutputsSet(bool countChanged);
@ -58,9 +59,8 @@ private:
VirtualOutput *createOutput(const OutputInfo &info);
QList<VirtualOutput *> m_outputs;
std::unique_ptr<DrmDevice> m_drmDevice;
std::unique_ptr<EglDisplay> m_display;
FileDescriptor m_drmFileDescriptor;
gbm_device *m_gbmDevice = nullptr;
};
} // namespace KWin

View file

@ -7,6 +7,7 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "virtual_egl_backend.h"
#include "core/drmdevice.h"
#include "core/gbmgraphicsbufferallocator.h"
#include "opengl/eglswapchain.h"
#include "opengl/glrendertimequery.h"
@ -82,7 +83,6 @@ std::chrono::nanoseconds VirtualEglLayer::queryRenderTime() const
VirtualEglBackend::VirtualEglBackend(VirtualBackend *b)
: AbstractEglBackend()
, m_backend(b)
, m_allocator(std::make_unique<GbmGraphicsBufferAllocator>(b->gbmDevice()))
{
}
@ -99,7 +99,7 @@ VirtualBackend *VirtualEglBackend::backend() const
GraphicsBufferAllocator *VirtualEglBackend::graphicsBufferAllocator() const
{
return m_allocator.get();
return m_backend->drmDevice()->allocator();
}
bool VirtualEglBackend::initializeEgl()
@ -114,7 +114,7 @@ bool VirtualEglBackend::initializeEgl()
}
}
m_backend->setEglDisplay(EglDisplay::create(eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, m_backend->gbmDevice(), nullptr)));
m_backend->setEglDisplay(EglDisplay::create(eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, m_backend->drmDevice()->gbmDevice(), nullptr)));
}
auto display = m_backend->sceneEglDisplayObject();

View file

@ -71,7 +71,6 @@ private:
void removeOutput(Output *output);
VirtualBackend *m_backend;
std::unique_ptr<GraphicsBufferAllocator> m_allocator;
std::map<Output *, std::unique_ptr<VirtualEglLayer>> m_outputs;
};