From f09f2f240f008151c560bfb9cfe5cfe3d7889ac4 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Wed, 31 May 2017 15:36:22 +0200 Subject: [PATCH] xcb: remove DISPLAY_FROM_XCB macro ... as it does not add much value and is not widely used. and cleanup code: - where we repeatedly (for no good reason) call DISPLAY_FROM_XCB, instead of storing display as a (member) variable. - inconsistency where we (in the same function) alternatingly use DISPLAY_FROM_XCB and variable holding pointer to Display (when both refer to the same display). In other places this patch replaces macros with code they would translate to (or with minor adjustments to keep sensible line length). Change-Id: Ieb2a3e055892dcf31f132891f83ed4a665e3fa6e Reviewed-by: Shawn Rutledge Reviewed-by: Laszlo Agocs --- .../xcb_glx/qglxintegration.cpp | 27 ++++++++++--------- .../gl_integrations/xcb_glx/qglxintegration.h | 1 + .../gl_integrations/xcb_glx/qxcbglxwindow.cpp | 5 ++-- src/plugins/platforms/xcb/qxcbconnection.cpp | 3 ++- src/plugins/platforms/xcb/qxcbconnection.h | 2 -- src/plugins/platforms/xcb/qxcbcursor.cpp | 2 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 7 ++--- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index bcd6e46fc6..947ac4776c 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -167,7 +167,7 @@ static void updateFormatFromContext(QSurfaceFormat &format) QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share, const QVariant &nativeHandle) : QPlatformOpenGLContext() - , m_display(DISPLAY_FROM_XCB(screen)) + , m_display(static_cast(screen->connection()->xlib_display())) , m_config(0) , m_context(0) , m_shareContext(0) @@ -196,7 +196,7 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share) if (share) m_shareContext = static_cast(share)->glxContext(); - GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),m_format); + GLXFBConfig config = qglx_findConfig(m_display, screen->screenNumber(), m_format); m_config = config; XVisualInfo *visualInfo = 0; Window window = 0; // Temporary window used to query OpenGL context @@ -304,10 +304,10 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share) // Get the basic surface format details if (m_context) - qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(screen), config); + qglx_surfaceFormatFromGLXFBConfig(&m_format, m_display, config); // Create a temporary window so that we can make the new context current - window = createDummyWindow(DISPLAY_FROM_XCB(screen), config, screen->screenNumber(), screen->root()); + window = createDummyWindow(m_display, config, screen->screenNumber(), screen->root()); } else { // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out if (m_format.renderableType() == QSurfaceFormat::OpenGLES) @@ -325,7 +325,7 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share) } // Create a temporary window so that we can make the new context current - window = createDummyWindow(DISPLAY_FROM_XCB(screen), visualInfo, screen->screenNumber(), screen->root()); + window = createDummyWindow(m_display, visualInfo, screen->screenNumber(), screen->root()); XFree(visualInfo); } @@ -360,7 +360,7 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const // Use the provided Display, if available. If not, use our own. It may still work. Display *dpy = handle.display(); if (!dpy) - dpy = DISPLAY_FROM_XCB(screen); + dpy = m_display; // Legacy contexts created using glXCreateContext are created using a visual // and the FBConfig cannot be queried. The only way to adapt these contexts @@ -665,8 +665,10 @@ void QGLXContext::queryDummyContext() Display *display = glXGetCurrentDisplay(); if (!display) { // FIXME: Since Qt 5.6 we don't need to check whether primary screen is NULL - if (QScreen *screen = QGuiApplication::primaryScreen()) - display = DISPLAY_FROM_XCB(static_cast(screen->handle())); + if (QScreen *screen = QGuiApplication::primaryScreen()) { + QXcbScreen *xcbScreen = static_cast(screen->handle()); + display = static_cast(xcbScreen->connection()->xlib_display()); + } } const char *glxvendor = glXGetClientString(display, GLX_VENDOR); if (glxvendor && !strcmp(glxvendor, "ATI")) { @@ -737,9 +739,10 @@ QGLXPbuffer::QGLXPbuffer(QOffscreenSurface *offscreenSurface) : QPlatformOffscreenSurface(offscreenSurface) , m_screen(static_cast(offscreenSurface->screen()->handle())) , m_format(m_screen->surfaceFormatFor(offscreenSurface->requestedFormat())) + , m_display(static_cast(m_screen->connection()->xlib_display())) , m_pbuffer(0) { - GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), m_format); + GLXFBConfig config = qglx_findConfig(m_display, m_screen->screenNumber(), m_format); if (config) { const int attributes[] = { @@ -750,17 +753,17 @@ QGLXPbuffer::QGLXPbuffer(QOffscreenSurface *offscreenSurface) None }; - m_pbuffer = glXCreatePbuffer(DISPLAY_FROM_XCB(m_screen), config, attributes); + m_pbuffer = glXCreatePbuffer(m_display, config, attributes); if (m_pbuffer) - qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(m_screen), config); + qglx_surfaceFormatFromGLXFBConfig(&m_format, m_display, config); } } QGLXPbuffer::~QGLXPbuffer() { if (m_pbuffer) - glXDestroyPbuffer(DISPLAY_FROM_XCB(m_screen), m_pbuffer); + glXDestroyPbuffer(m_display, m_pbuffer); } diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h index 3dfe0ac618..f6372582db 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h @@ -108,6 +108,7 @@ public: private: QXcbScreen *m_screen; QSurfaceFormat m_format; + Display *m_display; GLXPbuffer m_pbuffer; }; diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp index 61fed6f5e3..145a11a5e3 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp @@ -62,7 +62,8 @@ const xcb_visualtype_t *QXcbGlxWindow::createVisual() qDebug(lcQpaGl) << "Requested format before FBConfig/Visual selection:" << m_format; - const char *glxExts = glXQueryExtensionsString(DISPLAY_FROM_XCB(scr), scr->screenNumber()); + Display *dpy = static_cast(scr->connection()->xlib_display()); + const char *glxExts = glXQueryExtensionsString(dpy, scr->screenNumber()); int flags = 0; if (glxExts) { qCDebug(lcQpaGl, "Available GLX extensions: %s", glxExts); @@ -70,7 +71,7 @@ const xcb_visualtype_t *QXcbGlxWindow::createVisual() flags |= QGLX_SUPPORTS_SRGB; } - XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(scr), scr->screenNumber(), &m_format, GLX_WINDOW_BIT, flags); + XVisualInfo *visualInfo = qglx_findVisualInfo(dpy, scr->screenNumber(), &m_format, GLX_WINDOW_BIT, flags); if (!visualInfo) { qWarning() << "No XVisualInfo for format" << m_format; return Q_NULLPTR; diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index dff1f7c396..b4cefd07ed 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -1500,7 +1500,8 @@ void *QXcbConnection::createVisualInfoForDefaultVisualId() const info.visualid = m_defaultVisualId; int count = 0; - XVisualInfo *retVisual = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &info, &count); + Display *dpy = static_cast(connection()->xlib_display()); + XVisualInfo *retVisual = XGetVisualInfo(dpy, VisualIDMask, &info, &count); Q_ASSERT(count < 2); return retVisual; } diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index cb97a0be18..8e67621e9b 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -686,8 +686,6 @@ Q_DECLARE_TYPEINFO(QXcbConnection::TabletData, Q_MOVABLE_TYPE); #endif #endif -#define DISPLAY_FROM_XCB(object) (reinterpret_cast(object->connection()->xlib_display())) - template xcb_generic_event_t *QXcbConnection::checkEvent(T &checker) { diff --git a/src/plugins/platforms/xcb/qxcbcursor.cpp b/src/plugins/platforms/xcb/qxcbcursor.cpp index d522e593fe..b05a3535b6 100644 --- a/src/plugins/platforms/xcb/qxcbcursor.cpp +++ b/src/plugins/platforms/xcb/qxcbcursor.cpp @@ -579,7 +579,7 @@ xcb_cursor_t QXcbCursor::createFontCursor(int cshape) if (cursor) return cursor; if (!cursor && cursorId) { - cursor = XCreateFontCursor(DISPLAY_FROM_XCB(this), cursorId); + cursor = XCreateFontCursor(static_cast(connection()->xlib_display()), cursorId); if (cursor) return cursor; } diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 9921ed5da5..e5fb6fb9ad 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -590,7 +590,7 @@ void QXcbWindow::create() #ifdef XCB_USE_XLIB // force sync to read outstanding requests - see QTBUG-29106 - XSync(DISPLAY_FROM_XCB(platformScreen), false); + XSync(static_cast(platformScreen->connection()->xlib_display()), false); #endif #ifndef QT_NO_DRAGANDDROP @@ -1502,9 +1502,10 @@ void QXcbWindow::setWindowTitle(const QString &title) ba.constData()); #ifdef XCB_USE_XLIB - XTextProperty *text = qstringToXTP(DISPLAY_FROM_XCB(this), title); + Display *dpy = static_cast(connection()->xlib_display()); + XTextProperty *text = qstringToXTP(dpy, title); if (text) - XSetWMName(DISPLAY_FROM_XCB(this), m_window, text); + XSetWMName(dpy, m_window, text); #endif xcb_flush(xcb_connection()); }