diff options
-rw-r--r-- | src/gui/kernel/kernel.pri | 6 | ||||
-rw-r--r-- | src/gui/kernel/qeventdispatcher_glib_qpa.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qeventdispatcher_qpa.cpp | 186 | ||||
-rw-r--r-- | src/gui/kernel/qeventdispatcher_qpa_p.h | 6 | ||||
-rw-r--r-- | src/gui/kernel/qplatformeventloopintegration_qpa.cpp | 0 | ||||
-rw-r--r-- | src/gui/kernel/qplatformeventloopintegration_qpa.h | 13 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegration_qpa.cpp | 5 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegration_qpa.h | 5 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/openkode.pro | 6 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp | 29 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/qopenkodeeventloopintegration.h | 17 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/qopenkodeintegration.cpp | 42 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/qopenkodeintegration.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/qopenkodewindow.cpp | 1 | ||||
-rw-r--r-- | src/plugins/platforms/openkode/qopenkodewindowsurface.cpp | 6 |
15 files changed, 272 insertions, 62 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 02badee..ba86c1c 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -219,7 +219,8 @@ qpa { kernel/qplatformwindow_qpa.h \ kernel/qplatformwindowformat_qpa.h \ kernel/qplatformglcontext_qpa.h \ - kernel/qdesktopwidget_qpa_p.h + kernel/qdesktopwidget_qpa_p.h \ + kernel/qplatformeventloopintegration_qpa.h SOURCES += \ kernel/qapplication_qpa.cpp \ @@ -238,7 +239,8 @@ qpa { kernel/qplatformintegrationfactory_qpa.cpp \ kernel/qplatformintegrationplugin_qpa.cpp \ kernel/qplatformwindow_qpa.cpp \ - kernel/qplatformwindowformat_qpa.cpp + kernel/qplatformwindowformat_qpa.cpp \ + kernel/qplatformeventloopintegration_qpa.cpp contains(QT_CONFIG, glib) { SOURCES += \ diff --git a/src/gui/kernel/qeventdispatcher_glib_qpa.cpp b/src/gui/kernel/qeventdispatcher_glib_qpa.cpp index 9585b26..981991d 100644 --- a/src/gui/kernel/qeventdispatcher_glib_qpa.cpp +++ b/src/gui/kernel/qeventdispatcher_glib_qpa.cpp @@ -133,6 +133,14 @@ QPAEventDispatcherGlib::~QPAEventDispatcherGlib() bool QPAEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags) { + static bool init = false; + if (!init) { + if (QApplicationPrivate::platformIntegration()->createEventLoopIntegration()) { + qWarning("Eventloop integration is not supported by the glib event dispatcher"); + qWarning("Use the UNIX event dispatcher by defining environment variable QT_NO_GLIB=1"); + } + init = true; + } return QEventDispatcherGlib::processEvents(flags); } diff --git a/src/gui/kernel/qeventdispatcher_qpa.cpp b/src/gui/kernel/qeventdispatcher_qpa.cpp index 5740548..f7f3db3 100644 --- a/src/gui/kernel/qeventdispatcher_qpa.cpp +++ b/src/gui/kernel/qeventdispatcher_qpa.cpp @@ -44,24 +44,135 @@ #include "qeventdispatcher_qpa_p.h" #include "private/qeventdispatcher_unix_p.h" #include "qapplication_p.h" -#ifndef QT_NO_THREAD -# include "qmutex.h" -#endif +#include "qplatformeventloopintegration_qpa.h" + #include <QWindowSystemInterface> +#include <QtCore/QElapsedTimer> +#include <QtCore/QAtomicInt> +#include <QtCore/QSemaphore> #include <errno.h> + QT_BEGIN_NAMESPACE QT_USE_NAMESPACE +class Rendezvous +{ +public: + void checkpoint() + { + if (state.testAndSetOrdered(0,1)) { + semaphore.acquire(); + } else if (state.testAndSetAcquire(1,0)) { + semaphore.release(); + } else { + qWarning("Barrier internal error"); + } + } +private: + QSemaphore semaphore; + QAtomicInt state; +}; + +class SelectWorker : public QThread +{ +public: + SelectWorker(QEventDispatcherQPAPrivate *eventDispatcherPrivate) + : QThread(), + m_edPrivate(eventDispatcherPrivate), + m_retVal(0) + { + } + + void setSelectValues(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) + { + m_nfds = nfds; + m_readfds = readfds; + m_writefds = writefds; + m_exceptfds = exceptfds; + + + } + + int retVal() const { + return m_retVal; + } + +protected: + void run(); + +private: + QEventDispatcherQPAPrivate *m_edPrivate; + int m_retVal; + + int m_nfds; + fd_set *m_readfds, *m_writefds, *m_exceptfds; +}; + class QEventDispatcherQPAPrivate : public QEventDispatcherUNIXPrivate { Q_DECLARE_PUBLIC(QEventDispatcherQPA) public: - inline QEventDispatcherQPAPrivate() - { } -}; + QEventDispatcherQPAPrivate() + : eventLoopIntegration(0), + barrierBeforeBlocking(0), + barrierReturnValue(0), + selectReturnMutex(0), + selectWorkerNeedsSync(true), + selectWorkerHasResult(false), + m_integrationInitialised(false), + m_hasIntegration(false) + { + } + + ~QEventDispatcherQPAPrivate() + { + delete selectWorker; + delete eventLoopIntegration; + delete barrierBeforeBlocking; + delete barrierReturnValue; + delete selectReturnMutex; + } + + bool hasIntegration() const + { + if (!m_integrationInitialised) { + QEventDispatcherQPAPrivate *that = const_cast<QEventDispatcherQPAPrivate *>(this); + if (qApp && (qApp->thread() == QThread::currentThread())) { // guiThread + if (QApplicationPrivate::platformIntegration()) { + that->eventLoopIntegration = QApplicationPrivate::platformIntegration()->createEventLoopIntegration(); + if (that->eventLoopIntegration) { + that->selectWorker = new SelectWorker(that); + that->barrierBeforeBlocking = new Rendezvous; + that->barrierReturnValue = new Rendezvous; + that->selectReturnMutex = new QMutex; + that->selectWorker->start(); + that->m_hasIntegration = true; + if (!QElapsedTimer::isMonotonic()) + qWarning("Having eventloop integration without monotonic timers can lead to undefined behaviour"); + } + } + } + that->m_integrationInitialised = true; + } + return m_hasIntegration; + } + + QPlatformEventLoopIntegration *eventLoopIntegration; + Rendezvous *barrierBeforeBlocking; + Rendezvous *barrierReturnValue; + + QMutex *selectReturnMutex; + bool selectWorkerNeedsSync; + bool selectWorkerHasResult; + + SelectWorker *selectWorker; +private: + bool m_integrationInitialised; + bool m_hasIntegration; +}; QEventDispatcherQPA::QEventDispatcherQPA(QObject *parent) : QEventDispatcherUNIX(*new QEventDispatcherQPAPrivate, parent) @@ -70,10 +181,6 @@ QEventDispatcherQPA::QEventDispatcherQPA(QObject *parent) QEventDispatcherQPA::~QEventDispatcherQPA() { } - - -//#define ZERO_FOR_THE_MOMENT - bool QEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherQPA); @@ -115,17 +222,24 @@ bool QEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags) bool QEventDispatcherQPA::hasPendingEvents() { extern uint qGlobalPostedEventsCount(); // from qapplication.cpp - return qGlobalPostedEventsCount() || QWindowSystemInterfacePrivate::userEventsQueued();; + return qGlobalPostedEventsCount() || QWindowSystemInterfacePrivate::userEventsQueued(); } -void QEventDispatcherQPA::startingUp() +void QEventDispatcherQPA::registerSocketNotifier(QSocketNotifier *notifier) { + Q_D(QEventDispatcherQPA); + QEventDispatcherUNIX::registerSocketNotifier(notifier); + if (d->hasIntegration()) + wakeUp(); } -void QEventDispatcherQPA::closingDown() +void QEventDispatcherQPA::unregisterSocketNotifier(QSocketNotifier *notifier) { - + Q_D(QEventDispatcherQPA); + QEventDispatcherUNIX::unregisterSocketNotifier(notifier); + if (d->hasIntegration()) + wakeUp(); } void QEventDispatcherQPA::flush() @@ -138,7 +252,49 @@ void QEventDispatcherQPA::flush() int QEventDispatcherQPA::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout) { - return QEventDispatcherUNIX::select(nfds, readfds, writefds, exceptfds, timeout); + Q_D(QEventDispatcherQPA); + int retVal = 0; + if (d->hasIntegration()) { + qint64 timeoutmsec = timeout->tv_sec * 1000 + (timeout->tv_usec/1000); + d->selectReturnMutex->lock(); + if (d->selectWorkerNeedsSync) { + if (d->selectWorkerHasResult) { + retVal = d->selectWorker->retVal(); + d->selectWorkerHasResult = false; + + d->selectReturnMutex->unlock(); + d->barrierReturnValue->checkpoint(); + return retVal; + } else { + d->selectWorkerNeedsSync = false; + d->selectWorker->setSelectValues(nfds,readfds, writefds, exceptfds); + d->barrierBeforeBlocking->checkpoint(); + } + } + d->selectReturnMutex->unlock(); + d->eventLoopIntegration->processEvents(timeoutmsec); + retVal = 0; //is 0 if select has not returned + } else { + retVal = QEventDispatcherUNIX::select(nfds, readfds, writefds, exceptfds, timeout); + } + return retVal; } +void SelectWorker::run() +{ + while(true) { + m_retVal = 0; + m_edPrivate->barrierBeforeBlocking->checkpoint(); // wait for mainthread + int tmpRet = qt_safe_select(m_nfds,m_readfds,m_writefds,m_exceptfds,0); + m_edPrivate->selectReturnMutex->lock(); + m_edPrivate->eventLoopIntegration->wakeup(); + + m_edPrivate->selectWorkerNeedsSync = true; + m_edPrivate->selectWorkerHasResult = true; + m_retVal = tmpRet; + + m_edPrivate->selectReturnMutex->unlock(); + m_edPrivate->barrierReturnValue->checkpoint(); + } +} QT_END_NAMESPACE diff --git a/src/gui/kernel/qeventdispatcher_qpa_p.h b/src/gui/kernel/qeventdispatcher_qpa_p.h index 878daaa..8065c3e 100644 --- a/src/gui/kernel/qeventdispatcher_qpa_p.h +++ b/src/gui/kernel/qeventdispatcher_qpa_p.h @@ -71,10 +71,10 @@ public: bool processEvents(QEventLoop::ProcessEventsFlags flags); bool hasPendingEvents(); - void flush(); + void registerSocketNotifier(QSocketNotifier *notifier); + void unregisterSocketNotifier(QSocketNotifier *notifier); - void startingUp(); - void closingDown(); + void flush(); protected: int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, diff --git a/src/gui/kernel/qplatformeventloopintegration_qpa.cpp b/src/gui/kernel/qplatformeventloopintegration_qpa.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/gui/kernel/qplatformeventloopintegration_qpa.cpp diff --git a/src/gui/kernel/qplatformeventloopintegration_qpa.h b/src/gui/kernel/qplatformeventloopintegration_qpa.h new file mode 100644 index 0000000..5e4c227 --- /dev/null +++ b/src/gui/kernel/qplatformeventloopintegration_qpa.h @@ -0,0 +1,13 @@ +#ifndef QPLATFORMEVENTLOOPINTEGRATION_QPA_H +#define QPLATFORMEVENTLOOPINTEGRATION_QPA_H + +#include <qglobal.h> + +class QPlatformEventLoopIntegration +{ +public: + virtual void processEvents( qint64 msec ) = 0; + virtual void wakeup() = 0; +}; + +#endif // QPLATFORMEVENTLOOPINTEGRATION_QPA_H diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp index 8666911..b3f46ce 100644 --- a/src/gui/kernel/qplatformintegration_qpa.cpp +++ b/src/gui/kernel/qplatformintegration_qpa.cpp @@ -56,6 +56,11 @@ QPixmap QPlatformIntegration::grabWindow(WId window, int x, int y, int width, in return QPixmap(); } +QPlatformEventLoopIntegration *QPlatformIntegration::createEventLoopIntegration() const +{ + return 0; +} + bool QPlatformIntegration::hasOpenGL() const { return false; diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h index 8c1659f..11377e7 100644 --- a/src/gui/kernel/qplatformintegration_qpa.h +++ b/src/gui/kernel/qplatformintegration_qpa.h @@ -55,6 +55,7 @@ class QPlatformWindow; class QWindowSurface; class QBlittable; class QWidget; +class QPlatformEventLoopIntegration; class Q_GUI_EXPORT QPlatformIntegration { @@ -73,8 +74,12 @@ public: virtual bool isVirtualDesktop() { return false; } virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const; +// Experimental + virtual QPlatformEventLoopIntegration *createEventLoopIntegration() const; + virtual bool hasOpenGL() const; + }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/openkode.pro b/src/plugins/platforms/openkode/openkode.pro index c039131..2d90b15 100644 --- a/src/plugins/platforms/openkode/openkode.pro +++ b/src/plugins/platforms/openkode/openkode.pro @@ -10,13 +10,15 @@ SOURCES = main.cpp \ qopenkodewindowsurface.cpp \ qopenkodewindow.cpp \ ../eglconvenience/qeglplatformcontext.cpp \ - ../eglconvenience/qeglconvenience.cpp + ../eglconvenience/qeglconvenience.cpp \ + qopenkodeeventloopintegration.cpp HEADERS = qopenkodeintegration.h \ qopenkodewindowsurface.h \ qopenkodewindow.h \ ../eglconvenience/qeglplatformcontext.h \ - ../eglconvenience/qeglconvenience.h + ../eglconvenience/qeglconvenience.h \ + qopenkodeeventloopintegration.h RESOURCES = resources.qrc diff --git a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp new file mode 100644 index 0000000..467b5b5 --- /dev/null +++ b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp @@ -0,0 +1,29 @@ +#include "qopenkodeeventloopintegration.h" + +#include <KD/kd.h> + +#include <QtCore/QDebug> + +QOpenKODEEventLoopIntegration::QOpenKODEEventLoopIntegration() +{ + m_kdThread = kdThreadSelf(); +} + +void QOpenKODEEventLoopIntegration::processEvents(qint64 msec) +{ + if (msec == 0) + msec = -1; + const KDEvent *event = kdWaitEvent(msec*1000); + if (event) { + kdDefaultEvent(event); + while ((event = kdWaitEvent(0)) != 0) { + kdDefaultEvent(event); + } + } +} + +void QOpenKODEEventLoopIntegration::wakeup() +{ + KDEvent *event = kdCreateEvent(); + kdPostThreadEvent(event,m_kdThread); +} diff --git a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h new file mode 100644 index 0000000..ef04640 --- /dev/null +++ b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h @@ -0,0 +1,17 @@ +#ifndef QOPENKODEEVENTLOOPINTEGRATION_H +#define QOPENKODEEVENTLOOPINTEGRATION_H + +#include <QtGui/QPlatformEventLoopIntegration> + +class KDThread; +class QOpenKODEEventLoopIntegration : public QPlatformEventLoopIntegration +{ +public: + QOpenKODEEventLoopIntegration(); + void processEvents(qint64 msec); + void wakeup(); +private: + KDThread *m_kdThread; +}; + +#endif // QOPENKODEEVENTLOOPINTEGRATION_H diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.cpp b/src/plugins/platforms/openkode/qopenkodeintegration.cpp index 270763b..5dada28 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.cpp +++ b/src/plugins/platforms/openkode/qopenkodeintegration.cpp @@ -42,6 +42,7 @@ #include "qopenkodeintegration.h" #include "qopenkodewindowsurface.h" #include "qopenkodewindow.h" +#include "qopenkodeeventloopintegration.h" #include <QtOpenGL/private/qpixmapdata_gl_p.h> #include <QtOpenGL/private/qwindowsurface_gl_p.h> @@ -184,41 +185,11 @@ static GLuint loadShaders(const QString &vertexShader, const QString &fragmentSh return prog; } -class QOpenKODEEventLoopHelper : public QThread -{ -public: - QOpenKODEEventLoopHelper(QSemaphore *m) - : eventMutex(m) - { - m->acquire(); - } - -protected: - void run() - { - if (kdInitializeNV() == KD_ENOTINITIALIZED) { - qFatal("Did not manage to initialize openkode"); - } - eventMutex->release(); - - const KDEvent *event; - while ((event = kdWaitEvent(-1)) != 0) { - qDebug() << "!!! received event!"; - kdDefaultEvent(event); - } - } - -private: - QSemaphore *eventMutex; -}; - QOpenKODEIntegration::QOpenKODEIntegration() - : eventMutex(1) { - QOpenKODEEventLoopHelper *loop = new QOpenKODEEventLoopHelper(&eventMutex); - loop->start(); - eventMutex.acquire(); // block until initialization done - + if (kdInitializeNV() == KD_ENOTINITIALIZED) { + qFatal("Did not manage to initialize openkode"); + } QOpenKODEScreen *mPrimaryScreen = new QOpenKODEScreen(); mScreens.append(mPrimaryScreen); @@ -265,6 +236,11 @@ bool QOpenKODEIntegration::hasOpenGL() const return true; } +QPlatformEventLoopIntegration *QOpenKODEIntegration::createEventLoopIntegration() const +{ + return new QOpenKODEEventLoopIntegration; +} + GLuint QOpenKODEIntegration::blitterProgram() { static GLuint shaderProgram = 0; diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.h b/src/plugins/platforms/openkode/qopenkodeintegration.h index 9029086..0eaf127 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.h +++ b/src/plugins/platforms/openkode/qopenkodeintegration.h @@ -86,7 +86,8 @@ public: QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; bool hasOpenGL() const; - QPlatformGLContext * createGLContext(); + + QPlatformEventLoopIntegration *createEventLoopIntegration() const; virtual QList<QPlatformScreen *> screens() const { return mScreens; } @@ -94,7 +95,6 @@ public: private: QList<QPlatformScreen *> mScreens; - QSemaphore eventMutex; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/qopenkodewindow.cpp b/src/plugins/platforms/openkode/qopenkodewindow.cpp index 2213a8f..faba2fb 100644 --- a/src/plugins/platforms/openkode/qopenkodewindow.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindow.cpp @@ -60,7 +60,6 @@ QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) : QPlatformWindow(tlw) { - if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenVG) { m_eglApi = EGL_OPENVG_API; } else { diff --git a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp index a349031..84e27f5 100644 --- a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp @@ -93,8 +93,6 @@ void QOpenKODEWindowSurface::flush(QWidget *widget, const QRegion ®ion, const y = boundingRect.y(); } - qDebug() << "flush" << widget << offset << region.boundingRect() << mImage.format() << blitImage.format(); - GLuint shaderProgram = QOpenKODEIntegration::blitterProgram(); glUseProgram(shaderProgram); @@ -125,7 +123,7 @@ void QOpenKODEWindowSurface::flush(QWidget *widget, const QRegion ®ion, const glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage.bits()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, mImage.bits()); // Enable vertex attribute associated with vertex position glEnableVertexAttribArray(posId); @@ -166,7 +164,7 @@ void QOpenKODEWindowSurface::beginPaint(const QRegion ®ion) Q_UNUSED(region); if (mImage.isNull()) { m_platformGLContext = window()->platformWindow()->glContext(); - mImage = QImage(size(),QImage::Format_RGB32); + mImage = QImage(size(),QImage::Format_RGB888); } } |