From b14527f529e7889319440125b717e6677746eaac Mon Sep 17 00:00:00 2001 From: James McDonnell Date: Tue, 1 May 2018 12:26:05 -0400 Subject: Make QQnxIntegration a singleton Turn all the static members and functions into regular members and functions. Change-Id: Ib37d9bdd1a84e512013af7d334e04cd2b1da640e Reviewed-by: Dan Cape Reviewed-by: Rafael Roquetto --- src/plugins/platforms/qnx/qqnxglobal.cpp | 6 +-- src/plugins/platforms/qnx/qqnxintegration.cpp | 48 +++++++++++----------- src/plugins/platforms/qnx/qqnxintegration.h | 22 ++++++---- .../platforms/qnx/qqnxscreeneventhandler.cpp | 14 +++---- src/plugins/platforms/qnx/qqnxwindow.cpp | 8 ++-- 5 files changed, 50 insertions(+), 48 deletions(-) (limited to 'src/plugins/platforms/qnx') diff --git a/src/plugins/platforms/qnx/qqnxglobal.cpp b/src/plugins/platforms/qnx/qqnxglobal.cpp index 6b3cc6bebf..c17f6a7546 100644 --- a/src/plugins/platforms/qnx/qqnxglobal.cpp +++ b/src/plugins/platforms/qnx/qqnxglobal.cpp @@ -45,9 +45,9 @@ QT_BEGIN_NAMESPACE void qScreenCheckError(int rc, const char *funcInfo, const char *message, bool critical) { - if (!rc && (QQnxIntegration::options() & QQnxIntegration::AlwaysFlushScreenContext) - && QQnxIntegration::screenContext() != 0) { - rc = screen_flush_context(QQnxIntegration::screenContext(), 0); + if (!rc && (QQnxIntegration::instance()->options() & QQnxIntegration::AlwaysFlushScreenContext) + && QQnxIntegration::instance()->screenContext() != 0) { + rc = screen_flush_context(QQnxIntegration::instance()->screenContext(), 0); } if (Q_UNLIKELY(rc)) { diff --git a/src/plugins/platforms/qnx/qqnxintegration.cpp b/src/plugins/platforms/qnx/qqnxintegration.cpp index 4aaade402a..0b6a7f197a 100644 --- a/src/plugins/platforms/qnx/qqnxintegration.cpp +++ b/src/plugins/platforms/qnx/qqnxintegration.cpp @@ -99,8 +99,7 @@ QT_BEGIN_NAMESPACE -QQnxWindowMapper QQnxIntegration::ms_windowMapper; -QMutex QQnxIntegration::ms_windowMapperMutex; +QQnxIntegration *QQnxIntegration::ms_instance; static inline QQnxIntegration::Options parseOptions(const QStringList ¶mList) { @@ -159,11 +158,12 @@ QQnxIntegration::QQnxIntegration(const QStringList ¶mList) , m_drag(new QSimpleDrag()) #endif { - ms_options = parseOptions(paramList); + ms_instance = this; + m_options = parseOptions(paramList); qIntegrationDebug(); // Open connection to QNX composition manager - if (screen_create_context(&ms_screenContext, getContextCapabilities(paramList))) { + if (screen_create_context(&m_screenContext, getContextCapabilities(paramList))) { qFatal("%s - Screen: Failed to create screen context - Error: %s (%i)", Q_FUNC_INFO, strerror(errno), errno); } @@ -183,7 +183,7 @@ QQnxIntegration::QQnxIntegration(const QStringList ¶mList) #endif // Create/start event thread - m_screenEventThread = new QQnxScreenEventThread(ms_screenContext); + m_screenEventThread = new QQnxScreenEventThread(m_screenContext); m_screenEventHandler->setScreenEventThread(m_screenEventThread); m_screenEventThread->start(); @@ -260,7 +260,7 @@ QQnxIntegration::~QQnxIntegration() destroyDisplays(); // Close connection to QNX composition manager - screen_destroy_context(ms_screenContext); + screen_destroy_context(m_screenContext); #if !defined(QT_NO_OPENGL) // Cleanup global OpenGL resources @@ -284,6 +284,8 @@ QQnxIntegration::~QQnxIntegration() // Destroy navigator interface delete m_navigator; + ms_instance = nullptr; + qIntegrationDebug("platform plugin shutdown end"); } @@ -312,10 +314,10 @@ QPlatformWindow *QQnxIntegration::createPlatformWindow(QWindow *window) const const bool needRootWindow = options() & RootWindow; switch (surfaceType) { case QSurface::RasterSurface: - return new QQnxRasterWindow(window, ms_screenContext, needRootWindow); + return new QQnxRasterWindow(window, m_screenContext, needRootWindow); #if !defined(QT_NO_OPENGL) case QSurface::OpenGLSurface: - return new QQnxEglWindow(window, ms_screenContext, needRootWindow); + return new QQnxEglWindow(window, m_screenContext, needRootWindow); #endif default: qFatal("QQnxWindow: unsupported window API"); @@ -449,7 +451,7 @@ QPlatformDrag *QQnxIntegration::drag() const QVariant QQnxIntegration::styleHint(QPlatformIntegration::StyleHint hint) const { qIntegrationDebug(); - if ((hint == ShowIsFullScreen) && (ms_options & FullScreenApplication)) + if ((hint == ShowIsFullScreen) && (m_options & FullScreenApplication)) return true; return QPlatformIntegration::styleHint(hint); @@ -463,25 +465,25 @@ QPlatformServices * QQnxIntegration::services() const QWindow *QQnxIntegration::window(screen_window_t qnxWindow) { qIntegrationDebug(); - QMutexLocker locker(&ms_windowMapperMutex); + QMutexLocker locker(&m_windowMapperMutex); Q_UNUSED(locker); - return ms_windowMapper.value(qnxWindow, 0); + return m_windowMapper.value(qnxWindow, 0); } void QQnxIntegration::addWindow(screen_window_t qnxWindow, QWindow *window) { qIntegrationDebug(); - QMutexLocker locker(&ms_windowMapperMutex); + QMutexLocker locker(&m_windowMapperMutex); Q_UNUSED(locker); - ms_windowMapper.insert(qnxWindow, window); + m_windowMapper.insert(qnxWindow, window); } void QQnxIntegration::removeWindow(screen_window_t qnxWindow) { qIntegrationDebug(); - QMutexLocker locker(&ms_windowMapperMutex); + QMutexLocker locker(&m_windowMapperMutex); Q_UNUSED(locker); - ms_windowMapper.remove(qnxWindow); + m_windowMapper.remove(qnxWindow); } void QQnxIntegration::createDisplays() @@ -489,7 +491,7 @@ void QQnxIntegration::createDisplays() qIntegrationDebug(); // Query number of displays int displayCount = 0; - int result = screen_get_context_property_iv(ms_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, + int result = screen_get_context_property_iv(m_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount); Q_SCREEN_CRITICALERROR(result, "Failed to query display count"); @@ -500,7 +502,7 @@ void QQnxIntegration::createDisplays() // Get all displays screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount); - result = screen_get_context_property_pv(ms_screenContext, SCREEN_PROPERTY_DISPLAYS, + result = screen_get_context_property_pv(m_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)displays); Q_SCREEN_CRITICALERROR(result, "Failed to query displays"); @@ -526,7 +528,7 @@ void QQnxIntegration::createDisplays() void QQnxIntegration::createDisplay(screen_display_t display, bool isPrimary) { - QQnxScreen *screen = new QQnxScreen(ms_screenContext, display, isPrimary); + QQnxScreen *screen = new QQnxScreen(m_screenContext, display, isPrimary); m_screens.append(screen); screenAdded(screen); screen->adjustOrientation(); @@ -575,14 +577,14 @@ QQnxScreen *QQnxIntegration::primaryDisplay() const return m_screens.first(); } -QQnxIntegration::Options QQnxIntegration::options() +QQnxIntegration::Options QQnxIntegration::options() const { - return ms_options; + return m_options; } screen_context_t QQnxIntegration::screenContext() { - return ms_screenContext; + return m_screenContext; } QQnxNavigatorEventHandler *QQnxIntegration::navigatorEventHandler() @@ -590,10 +592,6 @@ QQnxNavigatorEventHandler *QQnxIntegration::navigatorEventHandler() return m_navigatorEventHandler; } -screen_context_t QQnxIntegration::ms_screenContext = 0; - -QQnxIntegration::Options QQnxIntegration::ms_options = 0; - bool QQnxIntegration::supportsNavigatorEvents() const { // If QQNX_PPS is defined then we have navigator diff --git a/src/plugins/platforms/qnx/qqnxintegration.h b/src/plugins/platforms/qnx/qqnxintegration.h index f11afa1748..89654f588f 100644 --- a/src/plugins/platforms/qnx/qqnxintegration.h +++ b/src/plugins/platforms/qnx/qqnxintegration.h @@ -87,6 +87,8 @@ public: explicit QQnxIntegration(const QStringList ¶mList); ~QQnxIntegration(); + static QQnxIntegration *instance() { return ms_instance; } + bool hasCapability(QPlatformIntegration::Capability cap) const override; QPlatformWindow *createPlatformWindow(QWindow *window) const override; @@ -120,15 +122,15 @@ public: QPlatformServices *services() const override; - static QWindow *window(screen_window_t qnxWindow); + QWindow *window(screen_window_t qnxWindow); QQnxScreen *screenForNative(screen_display_t qnxScreen) const; void createDisplay(screen_display_t display, bool isPrimary); void removeDisplay(QQnxScreen *screen); QQnxScreen *primaryDisplay() const; - static Options options(); - static screen_context_t screenContext(); + Options options() const; + screen_context_t screenContext(); QQnxNavigatorEventHandler *navigatorEventHandler(); @@ -136,10 +138,10 @@ private: void createDisplays(); void destroyDisplays(); - static void addWindow(screen_window_t qnxWindow, QWindow *window); - static void removeWindow(screen_window_t qnxWindow); + void addWindow(screen_window_t qnxWindow, QWindow *window); + void removeWindow(screen_window_t qnxWindow); - static screen_context_t ms_screenContext; + screen_context_t m_screenContext; QQnxScreenEventThread *m_screenEventThread; QQnxNavigatorEventHandler *m_navigatorEventHandler; QQnxAbstractVirtualKeyboard *m_virtualKeyboard; @@ -161,10 +163,12 @@ private: #if QT_CONFIG(draganddrop) QSimpleDrag *m_drag; #endif - static QQnxWindowMapper ms_windowMapper; - static QMutex ms_windowMapperMutex; + QQnxWindowMapper m_windowMapper; + QMutex m_windowMapperMutex; + + Options m_options; - static Options ms_options; + static QQnxIntegration *ms_instance; friend class QQnxWindow; }; diff --git a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp index 2a5c2087fb..e4843cb438 100644 --- a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp +++ b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp @@ -326,11 +326,11 @@ void QQnxScreenEventHandler::handlePointerEvent(screen_event_t event) "Failed to query event wheel delta"); // Map window handle to top-level QWindow - QWindow *w = QQnxIntegration::window(qnxWindow); + QWindow *w = QQnxIntegration::instance()->window(qnxWindow); // Generate enter and leave events as needed. if (qnxWindow != m_lastMouseWindow) { - QWindow *wOld = QQnxIntegration::window(m_lastMouseWindow); + QWindow *wOld = QQnxIntegration::instance()->window(m_lastMouseWindow); if (wOld) { QWindowSystemInterface::handleLeaveEvent(wOld); @@ -438,11 +438,11 @@ void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType) if (touchId < MaximumTouchPoints) { // Map window handle to top-level QWindow - QWindow *w = QQnxIntegration::window(qnxWindow); + QWindow *w = QQnxIntegration::instance()->window(qnxWindow); // Generate enter and leave events as needed. if (qnxWindow != m_lastMouseWindow) { - QWindow *wOld = QQnxIntegration::window(m_lastMouseWindow); + QWindow *wOld = QQnxIntegration::instance()->window(m_lastMouseWindow); if (wOld) { QWindowSystemInterface::handleLeaveEvent(wOld); @@ -532,7 +532,7 @@ void QQnxScreenEventHandler::handleCloseEvent(screen_event_t event) Q_EMIT windowClosed(window); // Map window handle to top-level QWindow - QWindow *w = QQnxIntegration::window(window); + QWindow *w = QQnxIntegration::instance()->window(window); if (w != 0) QWindowSystemInterface::handleCloseEvent(w); } @@ -632,7 +632,7 @@ void QQnxScreenEventHandler::handleKeyboardFocusPropertyEvent(screen_window_t wi if (Q_UNLIKELY(window && screen_get_window_property_iv(window, SCREEN_PROPERTY_FOCUS, &focus) != 0)) qFatal("QQnx: failed to query keyboard focus property, errno=%d", errno); - QWindow *focusWindow = QQnxIntegration::window(window); + QWindow *focusWindow = QQnxIntegration::instance()->window(window); if (m_focusLostTimer != -1) { killTimer(m_focusLostTimer); @@ -658,7 +658,7 @@ void QQnxScreenEventHandler::handleGeometryPropertyEvent(screen_window_t window) } QRect rect(pos[0], pos[1], size[0], size[1]); - QWindow *qtWindow = QQnxIntegration::window(window); + QWindow *qtWindow = QQnxIntegration::instance()->window(window); if (qtWindow) { qtWindow->setGeometry(rect); QWindowSystemInterface::handleGeometryChange(qtWindow, rect); diff --git a/src/plugins/platforms/qnx/qqnxwindow.cpp b/src/plugins/platforms/qnx/qqnxwindow.cpp index fd46f624a9..5d9eaaa3ea 100644 --- a/src/plugins/platforms/qnx/qqnxwindow.cpp +++ b/src/plugins/platforms/qnx/qqnxwindow.cpp @@ -271,7 +271,7 @@ QQnxWindow::~QQnxWindow() Q_ASSERT(m_childWindows.size() == 0); // Remove from plugin's window mapper - QQnxIntegration::removeWindow(m_window); + QQnxIntegration::instance()->removeWindow(m_window); // Remove from parent's Hierarchy. removeFromParent(); @@ -480,7 +480,7 @@ void QQnxWindow::setScreen(QQnxScreen *platformScreen) qWindowDebug("Moving window to different screen"); m_screen->removeWindow(this); - if ((QQnxIntegration::options() & QQnxIntegration::RootWindow)) { + if ((QQnxIntegration::instance()->options() & QQnxIntegration::RootWindow)) { screen_leave_window_group(m_window); } } @@ -735,7 +735,7 @@ void QQnxWindow::initWindow() m_exposed = false; // Add window to plugin's window mapper - QQnxIntegration::addWindow(m_window, window()); + QQnxIntegration::instance()->addWindow(m_window, window()); // Qt never calls these setters after creating the window, so we need to do that ourselves here setWindowState(window()->windowState()); @@ -832,7 +832,7 @@ void QQnxWindow::windowPosted() bool QQnxWindow::shouldMakeFullScreen() const { return ((static_cast(screen())->rootWindow() == this) - && (QQnxIntegration::options() & QQnxIntegration::FullScreenApplication)); + && (QQnxIntegration::instance()->options() & QQnxIntegration::FullScreenApplication)); } QT_END_NAMESPACE -- cgit v1.2.3