From 2e70a86900962b1f5f6ad79ca3245bc99873d889 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 4 Oct 2016 11:29:26 +0200 Subject: Move DRM/KMS code from eglfs into kmsconvenience The generic DRM code, not involving any GBM or EGLDevice stuff, can now be reused in components outside eglfs, for example linuxfb in order to get support for DRM dumb buffers. Task-number: QTBUG-56306 Change-Id: If7dffdb2415489dbc6470782fa76efcaeccf01c7 Reviewed-by: Oswald Buddenhagen Reviewed-by: Andy Nichols --- .../eglfs_kms_egldevice/eglfs_kms_egldevice.pro | 2 +- .../eglfs_kms_egldevice/qeglfskmsegldevice.cpp | 23 +++++++++++----------- .../eglfs_kms_egldevice/qeglfskmsegldevice.h | 14 ++++++------- .../qeglfskmsegldeviceintegration.cpp | 21 +++++++++----------- .../qeglfskmsegldeviceintegration.h | 7 +++---- .../qeglfskmsegldevicescreen.cpp | 14 +++++++++---- .../eglfs_kms_egldevice/qeglfskmsegldevicescreen.h | 4 +--- 7 files changed, 42 insertions(+), 43 deletions(-) (limited to 'src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro index a625021aba..a2dc9c4a50 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-kms-egldevice-integration -QT += core-private gui-private eglfsdeviceintegration-private eglfs_kms_support-private +QT += core-private gui-private eglfsdeviceintegration-private eglfs_kms_support-private kms_support-private INCLUDEPATH += $$PWD/../../api $$PWD/../eglfs_kms_support diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp index 60989e2bd0..f0bf59466e 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp @@ -40,14 +40,16 @@ #include "qeglfskmsegldevice.h" #include "qeglfskmsegldevicescreen.h" #include "qeglfskmsegldeviceintegration.h" +#include "private/qeglfsintegration_p.h" #include "private/qeglfscursor_p.h" #include QT_BEGIN_NAMESPACE -QEglFSKmsEglDevice::QEglFSKmsEglDevice(QEglFSKmsIntegration *integration, const QString &path) - : QEglFSKmsDevice(integration, path), +QEglFSKmsEglDevice::QEglFSKmsEglDevice(QEglFSKmsEglDeviceIntegration *devInt, QKmsScreenConfig *screenConfig, const QString &path) + : QEglFSKmsDevice(screenConfig, path), + m_devInt(devInt), m_globalCursor(nullptr) { } @@ -56,11 +58,9 @@ bool QEglFSKmsEglDevice::open() { Q_ASSERT(fd() == -1); - qCDebug(qLcEglfsKmsDebug, "Opening DRM device %s", qPrintable(devicePath())); - int fd = drmOpen(devicePath().toLocal8Bit().constData(), Q_NULLPTR); if (Q_UNLIKELY(fd < 0)) - qFatal("Could not open DRM device"); + qFatal("Could not open DRM (NV) device"); setFd(fd); @@ -69,25 +69,24 @@ bool QEglFSKmsEglDevice::open() void QEglFSKmsEglDevice::close() { - qCDebug(qLcEglfsKmsDebug, "Closing DRM device"); + // Note: screens are gone at this stage. if (qt_safe_close(fd()) == -1) - qErrnoWarning("Could not close DRM device"); + qErrnoWarning("Could not close DRM (NV) device"); setFd(-1); } EGLNativeDisplayType QEglFSKmsEglDevice::nativeDisplay() const { - return reinterpret_cast(static_cast(m_integration)->eglDevice()); + return reinterpret_cast(m_devInt->eglDevice()); } -QEglFSKmsScreen *QEglFSKmsEglDevice::createScreen(QEglFSKmsIntegration *integration, QEglFSKmsDevice *device, - QEglFSKmsOutput output) +QPlatformScreen *QEglFSKmsEglDevice::createScreen(const QKmsOutput &output) { - QEglFSKmsScreen *screen = new QEglFSKmsEglDeviceScreen(integration, device, output); + QEglFSKmsScreen *screen = new QEglFSKmsEglDeviceScreen(this, output); - if (!m_globalCursor && !integration->separateScreens()) { + if (!m_globalCursor && !screenConfig()->separateScreens()) { qCDebug(qLcEglfsKmsDebug, "Creating new global mouse cursor"); m_globalCursor = new QEglFSCursor(screen); } diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.h index 8c8f79f70c..b9304b8502 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.h @@ -45,25 +45,25 @@ QT_BEGIN_NAMESPACE class QPlatformCursor; +class QEglFSKmsEglDeviceIntegration; class QEglFSKmsEglDevice: public QEglFSKmsDevice { public: - QEglFSKmsEglDevice(QEglFSKmsIntegration *integration, const QString &path); + QEglFSKmsEglDevice(QEglFSKmsEglDeviceIntegration *devInt, QKmsScreenConfig *screenConfig, const QString &path); - virtual bool open() Q_DECL_OVERRIDE; - virtual void close() Q_DECL_OVERRIDE; + bool open() Q_DECL_OVERRIDE; + void close() Q_DECL_OVERRIDE; - virtual EGLNativeDisplayType nativeDisplay() const Q_DECL_OVERRIDE; + void *nativeDisplay() const Q_DECL_OVERRIDE; - virtual QEglFSKmsScreen *createScreen(QEglFSKmsIntegration *integration, - QEglFSKmsDevice *device, - QEglFSKmsOutput output) Q_DECL_OVERRIDE; + QPlatformScreen *createScreen(const QKmsOutput &output) Q_DECL_OVERRIDE; QPlatformCursor *globalCursor() { return m_globalCursor; } void destroyGlobalCursor(); private: + QEglFSKmsEglDeviceIntegration *m_devInt; QPlatformCursor *m_globalCursor; }; diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp index d0c9c9565e..36fbfbd05c 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp @@ -50,8 +50,7 @@ QT_BEGIN_NAMESPACE QEglFSKmsEglDeviceIntegration::QEglFSKmsEglDeviceIntegration() - : QEglFSKmsIntegration() - , m_egl_device(EGL_NO_DEVICE_EXT) + : m_egl_device(EGL_NO_DEVICE_EXT) , m_funcs(Q_NULLPTR) { qCDebug(qLcEglfsKmsDebug, "New DRM/KMS on EGLDevice integration created"); @@ -101,10 +100,10 @@ bool QEglFSKmsEglDeviceIntegration::supportsPBuffers() const return true; } -class QEglJetsonTK1Window : public QEglFSWindow +class QEglFSKmsEglDeviceWindow : public QEglFSWindow { public: - QEglJetsonTK1Window(QWindow *w, const QEglFSKmsEglDeviceIntegration *integration) + QEglFSKmsEglDeviceWindow(QWindow *w, const QEglFSKmsEglDeviceIntegration *integration) : QEglFSWindow(w) , m_integration(integration) , m_egl_stream(EGL_NO_STREAM_KHR) @@ -118,13 +117,13 @@ public: EGLint m_latency; }; -void QEglJetsonTK1Window::invalidateSurface() +void QEglFSKmsEglDeviceWindow::invalidateSurface() { QEglFSWindow::invalidateSurface(); m_integration->m_funcs->destroy_stream(screen()->display(), m_egl_stream); } -void QEglJetsonTK1Window::resetSurface() +void QEglFSKmsEglDeviceWindow::resetSurface() { qCDebug(qLcEglfsKmsDebug, "Creating stream"); @@ -213,7 +212,7 @@ void QEglJetsonTK1Window::resetSurface() QEglFSWindow *QEglFSKmsEglDeviceIntegration::createWindow(QWindow *window) const { - QEglJetsonTK1Window *eglWindow = new QEglJetsonTK1Window(window, this); + QEglFSKmsEglDeviceWindow *eglWindow = new QEglFSKmsEglDeviceWindow(window, this); m_funcs->initialize(eglWindow->screen()->display()); if (Q_UNLIKELY(!(m_funcs->has_egl_output_base && m_funcs->has_egl_output_drm && m_funcs->has_egl_stream && @@ -223,10 +222,8 @@ QEglFSWindow *QEglFSKmsEglDeviceIntegration::createWindow(QWindow *window) const return eglWindow; } -QEglFSKmsDevice *QEglFSKmsEglDeviceIntegration::createDevice(const QString &devicePath) +QKmsDevice *QEglFSKmsEglDeviceIntegration::createDevice() { - Q_UNUSED(devicePath) - if (Q_UNLIKELY(!query_egl_device())) qFatal("Could not set up EGL device!"); @@ -234,7 +231,7 @@ QEglFSKmsDevice *QEglFSKmsEglDeviceIntegration::createDevice(const QString &devi if (Q_UNLIKELY(!deviceName)) qFatal("Failed to query device name from EGLDevice"); - return new QEglFSKmsEglDevice(this, deviceName); + return new QEglFSKmsEglDevice(this, screenConfig(), deviceName); } bool QEglFSKmsEglDeviceIntegration::query_egl_device() @@ -261,7 +258,7 @@ bool QEglFSKmsEglDeviceIntegration::query_egl_device() QPlatformCursor *QEglFSKmsEglDeviceIntegration::createCursor(QPlatformScreen *screen) const { - return separateScreens() ? new QEglFSCursor(screen) : nullptr; + return screenConfig()->separateScreens() ? new QEglFSCursor(screen) : nullptr; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h index cddfdbd5c6..a274474433 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h @@ -64,7 +64,7 @@ public: EGLDeviceEXT eglDevice() const { return m_egl_device; } protected: - QEglFSKmsDevice *createDevice(const QString &devicePath) Q_DECL_OVERRIDE; + QKmsDevice *createDevice() Q_DECL_OVERRIDE; QPlatformCursor *createCursor(QPlatformScreen *screen) const Q_DECL_OVERRIDE; private: @@ -72,10 +72,9 @@ private: bool query_egl_device(); EGLDeviceEXT m_egl_device; - - friend class QEglJetsonTK1Window; - // EGLStream infrastructure QEGLStreamConvenience *m_funcs; + + friend class QEglFSKmsEglDeviceWindow; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp index 1f672afeb4..532ec0b440 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp @@ -40,11 +40,14 @@ #include "qeglfskmsegldevicescreen.h" #include "qeglfskmsegldevice.h" #include +#include QT_BEGIN_NAMESPACE -QEglFSKmsEglDeviceScreen::QEglFSKmsEglDeviceScreen(QEglFSKmsIntegration *integration, QEglFSKmsDevice *device, QEglFSKmsOutput output) - : QEglFSKmsScreen(integration, device, output) +Q_DECLARE_LOGGING_CATEGORY(qLcEglfsKmsDebug) + +QEglFSKmsEglDeviceScreen::QEglFSKmsEglDeviceScreen(QKmsDevice *device, const QKmsOutput &output) + : QEglFSKmsScreen(device, output) { } @@ -52,7 +55,7 @@ QEglFSKmsEglDeviceScreen::~QEglFSKmsEglDeviceScreen() { const int remainingScreenCount = qGuiApp->screens().count(); qCDebug(qLcEglfsKmsDebug, "Screen dtor. Remaining screens: %d", remainingScreenCount); - if (!remainingScreenCount && !m_integration->separateScreens()) + if (!remainingScreenCount && !device()->screenConfig()->separateScreens()) static_cast(device())->destroyGlobalCursor(); } @@ -62,7 +65,10 @@ QPlatformCursor *QEglFSKmsEglDeviceScreen::cursor() const // in its ctor. With separateScreens just use that. Otherwise // there's a virtual desktop and the device has a global cursor // and the base class has no dedicated cursor at all. - return m_integration->separateScreens() ? QEglFSScreen::cursor() : static_cast(device())->globalCursor(); + // config->hwCursor() is ignored for now, just use the standard OpenGL cursor. + return device()->screenConfig()->separateScreens() + ? QEglFSScreen::cursor() + : static_cast(device())->globalCursor(); } void QEglFSKmsEglDeviceScreen::waitForFlip() diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.h index c57f52c6b7..1655a3f038 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.h @@ -47,9 +47,7 @@ QT_BEGIN_NAMESPACE class QEglFSKmsEglDeviceScreen : public QEglFSKmsScreen { public: - QEglFSKmsEglDeviceScreen(QEglFSKmsIntegration *integration, - QEglFSKmsDevice *device, - QEglFSKmsOutput output); + QEglFSKmsEglDeviceScreen(QKmsDevice *device, const QKmsOutput &output); ~QEglFSKmsEglDeviceScreen(); QPlatformCursor *cursor() const Q_DECL_OVERRIDE; -- cgit v1.2.3