From e0e6cbdacb7520a6d9906e16a517c9932702d1aa Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Mon, 13 Mar 2017 20:35:24 +0100 Subject: xcb: prevent dangling pointer when window focus changes With the current implementation, the QXcbConnection::m_focusWindow was holding a dangling pointer during the focus transition from a dying modal window to other modal window. 1) QXcbConnection::m_focusWindow holds a pointer to A; 2) A is closed; 3) relayFocusToModalWindow B; => m_focusWindow now points to a dead window. 4) We get a reply back from WM in a respone to relayFocusToModalWindow (_NET_ACTIVE_WINDOW) => m_focusWindow now points to a valid window. The fix is to update m_focusWindow to nullptr, when the current focus window was destroyed and the new focus window has not been set yet by WM. This patch actually solves a more general case - whenever we get a focus-out event, we should set m_focusWindow to nullptr. It is ok for none of the windows to be in-focus while focus transition is happening. The focusInPeeker will make sure to "optimize out" (when possible) this no-window-in-focus state, and GUI won't be bothered by this extra event. This is how things were working before relayFocusToModalWindow was introduced. Having a focus-relay mechanism in-between is ok, but it should not have changed the original behavior. Task-number: QTBUG-48391 Task-number: QTBUG-55197 Change-Id: I6fdda9de73f999dad84000059ce4b89c0d1a964c Reviewed-by: Laszlo Agocs --- src/plugins/platforms/xcb/qxcbconnection.cpp | 4 ++-- src/plugins/platforms/xcb/qxcbconnection.h | 2 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 20 +++++++++----------- 3 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 5e600c740b..5e52d4d80f 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -1382,9 +1382,9 @@ void QXcbEventReader::unlock() m_mutex.unlock(); } -void QXcbConnection::setFocusWindow(QXcbWindow *w) +void QXcbConnection::setFocusWindow(QWindow *w) { - m_focusWindow = w; + m_focusWindow = w ? static_cast(w->handle()) : nullptr; } void QXcbConnection::setMouseGrabber(QXcbWindow *w) { diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 01a97a187a..22c7d1aa8e 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -480,7 +480,7 @@ public: Qt::MouseButton translateMouseButton(xcb_button_t s); QXcbWindow *focusWindow() const { return m_focusWindow; } - void setFocusWindow(QXcbWindow *); + void setFocusWindow(QWindow *); QXcbWindow *mouseGrabber() const { return m_mouseGrabber; } void setMouseGrabber(QXcbWindow *); QXcbWindow *mousePressWindow() const { return m_mousePressWindow; } diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 15ca68c663..509bc9b038 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -941,7 +941,7 @@ void QXcbWindow::doFocusIn() if (relayFocusToModalWindow()) return; QWindow *w = static_cast(QObjectPrivate::get(window()))->eventReceiver(); - connection()->setFocusWindow(static_cast(w->handle())); + connection()->setFocusWindow(w); QWindowSystemInterface::handleWindowActivated(w, Qt::ActiveWindowFocusReason); } @@ -949,7 +949,7 @@ static bool focusInPeeker(QXcbConnection *connection, xcb_generic_event_t *event { if (!event) { // FocusIn event is not in the queue, proceed with FocusOut normally. - QWindowSystemInterface::handleWindowActivated(0, Qt::ActiveWindowFocusReason); + QWindowSystemInterface::handleWindowActivated(nullptr, Qt::ActiveWindowFocusReason); return true; } uint response_type = event->response_type & ~0x80; @@ -974,12 +974,10 @@ static bool focusInPeeker(QXcbConnection *connection, xcb_generic_event_t *event void QXcbWindow::doFocusOut() { - if (relayFocusToModalWindow()) - return; - connection()->setFocusWindow(0); - // Do not set the active window to 0 if there is a FocusIn coming. - // There is however no equivalent for XPutBackEvent so register a - // callback for QXcbConnection instead. + connection()->setFocusWindow(nullptr); + relayFocusToModalWindow(); + // Do not set the active window to nullptr if there is a FocusIn coming. + // The FocusIn handler will update QXcbConnection::setFocusWindow() accordingly. connection()->addPeekFunc(focusInPeeker); } @@ -2834,14 +2832,14 @@ void QXcbWindow::handleXEmbedMessage(const xcb_client_message_event_t *event) reason = Qt::OtherFocusReason; break; } - connection()->setFocusWindow(static_cast(window()->handle())); + connection()->setFocusWindow(window()); QWindowSystemInterface::handleWindowActivated(window(), reason); break; case XEMBED_FOCUS_OUT: if (window() == QGuiApplication::focusWindow() && !activeWindowChangeQueued(window())) { - connection()->setFocusWindow(0); - QWindowSystemInterface::handleWindowActivated(0); + connection()->setFocusWindow(nullptr); + QWindowSystemInterface::handleWindowActivated(nullptr); } break; } -- cgit v1.2.3 From c9f5607500a998d1f00737aca17ff73fb16775b8 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Tue, 21 Feb 2017 13:32:00 +0100 Subject: xcb: fix build when xlib is not present Remove Xutil.h include from qxcbmime.cpp as it does not use any Xlib APIs. Using API from Xutil.h requires Xlib as noted in Xutil.h: /* You must include before including this file */ Everywhere else we do check for presence of Xlib, before including Xutil.h And remove some useless #undef(s) Task-number: QTBUG-39665 Change-Id: Ibfd2341338fe7e902b47eae2df6b9dafe4ab962d Reviewed-by: Alexander Volkov Reviewed-by: Laszlo Agocs --- src/plugins/platforms/xcb/qxcbmime.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 7592eb2887..3ec8fa491f 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -44,12 +44,6 @@ #include #include -#include - -#undef XCB_ATOM_STRING -#undef XCB_ATOM_PIXMAP -#undef XCB_ATOM_BITMAP - QT_BEGIN_NAMESPACE #if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD)) -- cgit v1.2.3 From 9ae028f507a22bd03c861e9d14c2efc4aa2efeda Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 10 Feb 2017 15:00:23 +0100 Subject: Environment variable enabling the workaround FBO readback bug On some ARM devices the font glyph generation is broken Add an environment variable to enable workaround_brokenFBOReadBack in QOpenGLContext, to fix font rendering on such devices as Mali and Adreno Change-Id: I9cc99ecb8b71a35bc369ec9dd11b877016b1179e Reviewed-by: Laszlo Agocs --- .../android/qandroidplatformopenglcontext.cpp | 31 ---------------------- .../android/qandroidplatformopenglcontext.h | 1 - 2 files changed, 32 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 4d52085a83..6f979f614c 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -65,42 +65,11 @@ void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface) QEGLPlatformContext::swapBuffers(surface); } -bool QAndroidPlatformOpenGLContext::needsFBOReadBackWorkaround() -{ - static bool set = false; - static bool needsWorkaround = false; - - if (!set) { - QByteArray env = qgetenv("QT_ANDROID_DISABLE_GLYPH_CACHE_WORKAROUND"); - needsWorkaround = env.isEmpty() || env == "0" || env == "false"; - - if (!needsWorkaround) { - const char *rendererString = reinterpret_cast(glGetString(GL_RENDERER)); - needsWorkaround = - qstrncmp(rendererString, "Mali-4xx", 6) == 0 // Mali-400, Mali-450 - || qstrncmp(rendererString, "Adreno (TM) 2xx", 13) == 0 // Adreno 200, 203, 205 - || qstrncmp(rendererString, "Adreno 2xx", 8) == 0 // Same as above but without the '(TM)' - || qstrncmp(rendererString, "Adreno (TM) 30x", 14) == 0 // Adreno 302, 305 - || qstrncmp(rendererString, "Adreno 30x", 9) == 0 // Same as above but without the '(TM)' - || qstrcmp(rendererString, "GC800 core") == 0 - || qstrcmp(rendererString, "GC1000 core") == 0 - || qstrcmp(rendererString, "Immersion.16") == 0; - } - - set = true; - } - - return needsWorkaround; -} - bool QAndroidPlatformOpenGLContext::makeCurrent(QPlatformSurface *surface) { bool ret = QEGLPlatformContext::makeCurrent(surface); QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(context()); - if (!ctx_d->workaround_brokenFBOReadBack && needsFBOReadBackWorkaround()) - ctx_d->workaround_brokenFBOReadBack = true; - return ret; } diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.h b/src/plugins/platforms/android/qandroidplatformopenglcontext.h index 3897b3166b..8e65b4cc36 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.h +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.h @@ -55,7 +55,6 @@ public: private: EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override; - static bool needsFBOReadBackWorkaround(); }; QT_END_NAMESPACE -- cgit v1.2.3