From cdc2161b6f87deaac6a256885fd6ecdccad6eb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 1 Oct 2012 10:17:21 +0200 Subject: Made xcb plugin work when the GLX extension is not present. Change-Id: I9285d7524586ff404206c088019ece33335137d9 Reviewed-by: Lars Knoll --- src/plugins/platforms/xcb/README | 6 ++--- src/plugins/platforms/xcb/qxcbconnection.cpp | 33 +++++++++++++++++++++++++++ src/plugins/platforms/xcb/qxcbconnection.h | 3 +++ src/plugins/platforms/xcb/qxcbintegration.cpp | 10 +++++++- src/plugins/platforms/xcb/qxcbwindow.cpp | 4 +--- src/plugins/platforms/xcb/xcb.pro | 4 ++++ 6 files changed, 53 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/README b/src/plugins/platforms/xcb/README index 264d28c6b4..59d9ffe39b 100644 --- a/src/plugins/platforms/xcb/README +++ b/src/plugins/platforms/xcb/README @@ -1,14 +1,14 @@ Requires libxcb >= 1.5. Required packages: -libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm1 libxcb-icccm1-dev libxcb-sync0 libxcb-sync0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev +libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm1 libxcb-icccm1-dev libxcb-sync0 libxcb-sync0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev On Ubuntu 11.10 icccm1 is replaced by icccm4 and xcb-render-util is not available: -libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev +libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev The packages for xcb-render-util can be installed manually from http://packages.ubuntu.com/natty/libxcb-render-util0 and http://packages.ubuntu.com/natty/libxcb-render-util0-dev On Ubuntu 12.04 icccm1 is replaced by icccm4 and xcb-render-util can be installed automatically: -libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0 libxcb-render-util0-dev +libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-glx0-dev On Fedora, the following packages are required: diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index ad9fb1d19c..bb5f301fea 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -72,6 +72,10 @@ #include #endif +#if defined(XCB_HAS_XCB_GLX) +#include +#endif + #ifdef XCB_USE_EGL //don't pull in eglext prototypes #include #endif @@ -263,6 +267,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, const char #endif , xfixes_first_event(0) , xrandr_first_event(0) + , has_glx_extension(false) , has_shape_extension(false) , has_randr_extension(false) , has_input_shape(false) @@ -320,6 +325,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, const char 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY, m_screens.at(0)->screen()->root_visual, 0, 0); + initializeGLX(); initializeXFixes(); initializeXRender(); m_xi2Enabled = false; @@ -1312,6 +1318,33 @@ void QXcbConnection::initializeXRender() #endif } +void QXcbConnection::initializeGLX() +{ +#ifdef XCB_HAS_XCB_GLX + const xcb_query_extension_reply_t *reply = xcb_get_extension_data(m_connection, &xcb_glx_id); + if (!reply || !reply->present) + return; + + has_glx_extension = true; + + xcb_generic_error_t *error = 0; + xcb_glx_query_version_cookie_t xglx_query_cookie = xcb_glx_query_version(m_connection, + XCB_GLX_MAJOR_VERSION, + XCB_GLX_MINOR_VERSION); + xcb_glx_query_version_reply_t *xglx_query = xcb_glx_query_version_reply(m_connection, + xglx_query_cookie, &error); + if (!xglx_query || error) { + qWarning("QXcbConnection: Failed to initialize GLX"); + free(error); + has_glx_extension = false; + } + free(xglx_query); +#else + // no way to check, assume GLX is present + has_glx_extension = true; +#endif +} + void QXcbConnection::initializeXRandr() { const xcb_query_extension_reply_t *reply = xcb_get_extension_data(m_connection, &xcb_randr_id); diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 8a6c418788..cbfdd803f2 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -374,6 +374,7 @@ public: inline xcb_timestamp_t time() const { return m_time; } inline void setTime(xcb_timestamp_t t) { if (t > m_time) m_time = t; } + bool hasGLX() const { return has_glx_extension; } bool hasXFixes() const { return xfixes_first_event > 0; } bool hasXShape() const { return has_shape_extension; } bool hasXRandr() const { return has_randr_extension; } @@ -387,6 +388,7 @@ private slots: private: void initializeAllAtoms(); void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0); + void initializeGLX(); void initializeXFixes(); void initializeXRender(); void initializeXRandr(); @@ -507,6 +509,7 @@ private: uint32_t xfixes_first_event; uint32_t xrandr_first_event; + bool has_glx_extension; bool has_shape_extension; bool has_randr_extension; bool has_input_shape; diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 2ace68036b..f6077316e6 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -192,9 +192,11 @@ QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLCont screen->connection()->egl_display(), screen->connection()); #elif defined(XCB_USE_DRI2) return new QDri2Context(context->format(), context->shareHandle()); -#endif +#else + Q_UNUSED(screen); qWarning("QXcbIntegration: Cannot create platform OpenGL context, none of GLX, EGL, or DRI2 are enabled"); return 0; +#endif } #endif @@ -207,7 +209,13 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const { switch (cap) { case ThreadedPixmaps: return true; +#if defined(XCB_USE_GLX) + case OpenGL: return m_connections.at(0)->hasGLX(); +#elif defined(XCB_USE_EGL) || defined(XCB_USE_DRI2) case OpenGL: return true; +#else + case OpenGL: return false; +#endif case ThreadedOpenGL: return false; case WindowMasks: return true; default: return QPlatformIntegration::hasCapability(cap); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index bab1884a9a..30f833012c 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -233,9 +233,7 @@ void QXcbWindow::create() m_format = window()->requestedFormat(); #if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB) - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL) - || m_format.hasAlpha()) - { + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) { #if defined(XCB_USE_GLX) XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), &m_format); if (!visualInfo && window()->surfaceType() == QSurface::OpenGLSurface) diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro index 116951d36d..617f2e685c 100644 --- a/src/plugins/platforms/xcb/xcb.pro +++ b/src/plugins/platforms/xcb/xcb.pro @@ -98,6 +98,10 @@ contains(DEFINES, XCB_USE_DRI2) { HEADERS += qglxintegration.h SOURCES += qglxintegration.cpp LIBS += $$QMAKE_LIBS_DYNLOAD + contains(QT_CONFIG, xcb-glx) { + DEFINES += XCB_HAS_XCB_GLX + LIBS += -lxcb-glx + } } } -- cgit v1.2.3