From cf24d203850cd87e31bc123407e7ae126be9961c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 4 Aug 2017 13:31:20 +0200 Subject: eglfs_kms: Add headless mode for DRM render nodes Attempting to switch /dev/dri/cardX to /dev/dri/renderDY is futile on its own now since many output-related drm operations fail and we eventually crash. Add a new headless mode that skips the real screen stuff and registers a fairly dummy, headless screen, does not bother with the mouse cursor, and disallows rendering to the screen via a QWindow (while keeping the actual rendering still fully functional). Such applications will not need any special privileges and will run even if there is a DRM master (X11, Wayland compositor) active. For example the configuration can look like this: { "device": "/dev/dri/renderD128", "headless": "1024x768" } After this applications have two choices to perform offscreen rendering: 1. Use an ordinary window (and its default framebuffer, meaning the gbm_surface), e.g. a QOpenGLWindow subclass MyOpenGLWindow w; w.show(); // will not actually show on screen w.grabFramebuffer().save("output.png"); Note that there is no vsync-based throttling. Also note that windows are still sized to match the screen size, hence the need for specifying a size in the headless property. 2. Or the typical offscreen approach with an extra FBO QOffscreenSurface s; s.setFormat(ctx.format()); s.create(); ctx.makeCurrent(&s0; QOpenGLFramebufferObject fbo(1024, 768); fbo.bind(); ctx.functions()->glClearColor(1, 0, 0, 1); ctx.functions()->glClear(GL_COLOR_BUFFER_BIT); fbo.toImage().save("output.png"); ctx.doneCurrent(); Task-number: QTBUG-62262 Change-Id: Ic1dbfa2b27b223bd5ef8ba36b665f0f61abf4f06 Reviewed-by: Qt CI Bot Reviewed-by: Andy Nichols --- .../deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp | 11 +++++++++-- .../deviceintegration/eglfs_kms_support/qeglfskmsscreen.h | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp index 533695ea0f..cc70ab5a3c 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp @@ -68,12 +68,13 @@ private: QEglFSKmsScreen *m_screen; }; -QEglFSKmsScreen::QEglFSKmsScreen(QKmsDevice *device, const QKmsOutput &output) +QEglFSKmsScreen::QEglFSKmsScreen(QKmsDevice *device, const QKmsOutput &output, bool headless) : QEglFSScreen(static_cast(QGuiApplicationPrivate::platformIntegration())->display()) , m_device(device) , m_output(output) , m_powerState(PowerStateOn) , m_interruptHandler(new QEglFSKmsInterruptHandler(this)) + , m_headless(headless) { m_siblings << this; // gets overridden later @@ -109,6 +110,9 @@ void QEglFSKmsScreen::setVirtualPosition(const QPoint &pos) // geometry() calls rawGeometry() and may apply additional transforms. QRect QEglFSKmsScreen::rawGeometry() const { + if (m_headless) + return QRect(QPoint(0, 0), m_device->screenConfig()->headlessSize()); + const int mode = m_output.mode; return QRect(m_pos.x(), m_pos.y(), m_output.modes[mode].hdisplay, @@ -177,7 +181,7 @@ Qt::ScreenOrientation QEglFSKmsScreen::orientation() const QString QEglFSKmsScreen::name() const { - return m_output.name; + return !m_headless ? m_output.name : QStringLiteral("qt_Headless"); } QString QEglFSKmsScreen::manufacturer() const @@ -214,6 +218,9 @@ void QEglFSKmsScreen::restoreMode() qreal QEglFSKmsScreen::refreshRate() const { + if (m_headless) + return 60; + quint32 refresh = m_output.modes[m_output.mode].vrefresh; return refresh > 0 ? refresh : 60; } diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.h index a2e3402bf2..aacea90eae 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.h @@ -56,7 +56,7 @@ class QEglFSKmsInterruptHandler; class Q_EGLFS_EXPORT QEglFSKmsScreen : public QEglFSScreen { public: - QEglFSKmsScreen(QKmsDevice *device, const QKmsOutput &output); + QEglFSKmsScreen(QKmsDevice *device, const QKmsOutput &output, bool headless = false); ~QEglFSKmsScreen(); void setVirtualPosition(const QPoint &pos); @@ -113,6 +113,8 @@ protected: PowerState m_powerState; QEglFSKmsInterruptHandler *m_interruptHandler; + + bool m_headless; }; QT_END_NAMESPACE -- cgit v1.2.3