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 <shawn.rutledge@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Gatis Paeglis 2017-05-31 15:36:22 +02:00
parent ac098eef42
commit f09f2f240f
7 changed files with 26 additions and 21 deletions

View File

@ -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<Display *>(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<const QGLXContext*>(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<QXcbScreen *>(screen->handle()));
if (QScreen *screen = QGuiApplication::primaryScreen()) {
QXcbScreen *xcbScreen = static_cast<QXcbScreen *>(screen->handle());
display = static_cast<Display *>(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<QXcbScreen *>(offscreenSurface->screen()->handle()))
, m_format(m_screen->surfaceFormatFor(offscreenSurface->requestedFormat()))
, m_display(static_cast<Display *>(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);
}

View File

@ -108,6 +108,7 @@ public:
private:
QXcbScreen *m_screen;
QSurfaceFormat m_format;
Display *m_display;
GLXPbuffer m_pbuffer;
};

View File

@ -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<Display *>(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;

View File

@ -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<Display *>(connection()->xlib_display());
XVisualInfo *retVisual = XGetVisualInfo(dpy, VisualIDMask, &info, &count);
Q_ASSERT(count < 2);
return retVisual;
}

View File

@ -686,8 +686,6 @@ Q_DECLARE_TYPEINFO(QXcbConnection::TabletData, Q_MOVABLE_TYPE);
#endif
#endif
#define DISPLAY_FROM_XCB(object) (reinterpret_cast<Display *>(object->connection()->xlib_display()))
template<typename T>
xcb_generic_event_t *QXcbConnection::checkEvent(T &checker)
{

View File

@ -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<Display *>(connection()->xlib_display()), cursorId);
if (cursor)
return cursor;
}

View File

@ -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<Display*>(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<Display *>(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());
}