diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2011-03-07 16:29:24 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-03-07 16:33:28 (GMT) |
commit | d9afcf0e84e438f89c1a8c5e26da51b06d8f61d0 (patch) | |
tree | c5f1bb28b0195b67a47ccf6ed8d007bc7af06435 | |
parent | cf264556fdea0d434e329e36c07a0ae6fa974f8b (diff) | |
download | Qt-d9afcf0e84e438f89c1a8c5e26da51b06d8f61d0.zip Qt-d9afcf0e84e438f89c1a8c5e26da51b06d8f61d0.tar.gz Qt-d9afcf0e84e438f89c1a8c5e26da51b06d8f61d0.tar.bz2 |
Lighthouse: Adding Native interface to getting the native eglcontext
in xcbplugin. I also reoredered how eglInitialize was executed,
(its not so lazy anymore)
-rw-r--r-- | src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp | 5 | ||||
-rw-r--r-- | src/plugins/platforms/eglconvenience/qeglplatformcontext.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qdri2context.cpp | 6 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qdri2context.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 16 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 15 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 12 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbnativeinterface.cpp | 40 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbnativeinterface.h | 4 |
9 files changed, 85 insertions, 17 deletions
diff --git a/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp b/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp index 4b83a22..22e1bdc 100644 --- a/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp +++ b/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp @@ -155,3 +155,8 @@ QPlatformWindowFormat QEGLPlatformContext::platformWindowFormat() const { return m_windowFormat; } + +EGLContext QEGLPlatformContext::eglContext() const +{ + return m_eglContext; +} diff --git a/src/plugins/platforms/eglconvenience/qeglplatformcontext.h b/src/plugins/platforms/eglconvenience/qeglplatformcontext.h index ac53559..9f3aea7 100644 --- a/src/plugins/platforms/eglconvenience/qeglplatformcontext.h +++ b/src/plugins/platforms/eglconvenience/qeglplatformcontext.h @@ -59,6 +59,8 @@ public: void makeDefaultSharedContext(); QPlatformWindowFormat platformWindowFormat() const; + + EGLContext eglContext() const; private: EGLContext m_eglContext; EGLDisplay m_eglDisplay; diff --git a/src/plugins/platforms/xcb/qdri2context.cpp b/src/plugins/platforms/xcb/qdri2context.cpp index 44b8fc2..10c9417 100644 --- a/src/plugins/platforms/xcb/qdri2context.cpp +++ b/src/plugins/platforms/xcb/qdri2context.cpp @@ -222,3 +222,9 @@ xcb_dri2_dri2_buffer_t * QDri2Context::backBuffer() return buffers; } + +void * QDri2Context::eglContext() const +{ + Q_D(QDri2Context); + return d->eglContext; +} diff --git a/src/plugins/platforms/xcb/qdri2context.h b/src/plugins/platforms/xcb/qdri2context.h index 5646565..8e4ac89 100644 --- a/src/plugins/platforms/xcb/qdri2context.h +++ b/src/plugins/platforms/xcb/qdri2context.h @@ -24,6 +24,8 @@ public: QPlatformWindowFormat platformWindowFormat() const; + void *eglContext() const; + protected: xcb_dri2_dri2_buffer_t *backBuffer(); QScopedPointer<QDri2ContextPrivate> d_ptr; diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index a2f985e..da60311 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -58,6 +58,10 @@ #include <X11/Xlib-xcb.h> #endif +#ifdef XCB_USE_EGL //dont pull in eglext prototypes +#include <EGL/egl.h> +#endif + #ifdef XCB_USE_DRI2 #include <xcb/dri2.h> #include <xcb/xfixes.h> @@ -87,6 +91,13 @@ QXcbConnection::QXcbConnection(const char *displayName) m_connection = XGetXCBConnection(dpy); XSetEventQueueOwner(dpy, XCBOwnsEventQueue); m_xlib_display = dpy; +#ifdef XCB_USE_EGL + EGLDisplay eglDisplay = eglGetDisplay(dpy); + m_egl_display = eglDisplay; + EGLint major, minor; + eglBindAPI(EGL_OPENGL_ES_API); + m_has_egl = eglInitialize(eglDisplay,&major,&minor); +#endif //XCB_USE_EGL #else m_connection = xcb_connect(m_displayName.constData(), &primaryScreen); @@ -432,6 +443,11 @@ void QXcbConnection::initializeAllAtoms() { m_allAtoms[i] = xcb_intern_atom_reply(xcb_connection(), cookies[i], 0)->atom; } +bool QXcbConnection::hasEgl() const +{ + return m_has_egl; +} + #ifdef XCB_USE_DRI2 void QXcbConnection::initializeDri2() { diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 8a0f3d7..a7fa7fd 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -238,9 +238,14 @@ public: #ifdef XCB_USE_DRI2 bool hasSupportForDri2() const; - void *egl_display() const { return m_egl_display; } QByteArray dri2DeviceName() const { return m_dri2_device_name; } #endif +#ifdef XCB_USE_EGL + bool hasEgl() const; +#endif +#if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2) + void *egl_display() const { return m_egl_display; } +#endif private slots: void eventDispatcher(); @@ -272,15 +277,17 @@ private: uint32_t m_dri2_minor; bool m_dri2_support_probed; bool m_has_support_for_dri2; - void *m_egl_display; QByteArray m_dri2_device_name; #endif - +#if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2) + void *m_egl_display; + bool m_has_egl; +#endif }; #define DISPLAY_FROM_XCB(object) ((Display *)(object->connection()->xlib_display())) -#ifdef XCB_USE_DRI2 +#if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL) #define EGL_DISPLAY_FROM_XCB(object) ((EGLDisplay)(object->connection()->egl_display())) #endif //endifXCB_USE_DRI2 diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index b6df550..0981655 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -127,17 +127,7 @@ bool QXcbIntegration::hasOpenGL() const #if defined(XCB_USE_GLX) return true; #elif defined(XCB_USE_EGL) - static bool eglHasbeenInitialized = false; - static bool wasEglInitialized = false; - if (!eglHasbeenInitialized) { - eglHasbeenInitialized = true; - const QXcbScreen *screen = static_cast<const QXcbScreen *>(m_screens.at(0)); - EGLint major, minor; - eglBindAPI(EGL_OPENGL_ES_API); - EGLDisplay disp = eglGetDisplay((Display*)screen->connection()->xlib_display()); - wasEglInitialized = eglInitialize(disp,&major,&minor); - } - return wasEglInitialized; + return m_connection->hasEgl(); #elif defined(XCB_USE_DRI2) if (m_connection->hasSupportForDri2()) { return true; diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index f379580..8b6678b 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -5,6 +5,14 @@ #include <QtGui/private/qapplication_p.h> #include <QtCore/QMap> +#include <QtCore/QDebug> + +#if defined(XCB_USE_EGL) +#include "../eglconvenience/qeglplatformcontext.h" +#elif defined (XCB_USE_DRI2) +#include "qdri2context.h" +#endif + class QXcbResourceMap : public QMap<QByteArray, QXcbNativeInterface::ResourceType> { public: @@ -16,6 +24,7 @@ public: insert("connection",QXcbNativeInterface::Connection); insert("screen",QXcbNativeInterface::Screen); insert("graphicsdevice",QXcbNativeInterface::GraphicsDevice); + insert("eglcontext",QXcbNativeInterface::EglContext); } }; @@ -42,6 +51,9 @@ void *QXcbNativeInterface::nativeResourceForWidget(const QByteArray &resourceStr case GraphicsDevice: result = graphicsDeviceForWidget(widget); break; + case EglContext: + result = eglContextForWidget(widget); + break; default: result = 0; } @@ -72,7 +84,7 @@ void *QXcbNativeInterface::displayForWidget(QWidget *widget) void *QXcbNativeInterface::eglDisplayForWidget(QWidget *widget) { -#if defined(XCB_USE_DRI2) +#if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL) QXcbScreen *screen = qPlatformScreenForWidget(widget); return screen->connection()->egl_display(); #else @@ -100,7 +112,33 @@ void *QXcbNativeInterface::graphicsDeviceForWidget(QWidget *widget) QByteArray deviceName = screen->connection()->dri2DeviceName(); return deviceName.data(); #else + Q_UNUSED(widget); return 0; #endif } + +void * QXcbNativeInterface::eglContextForWidget(QWidget *widget) +{ + Q_ASSERT(widget); + if (!widget->platformWindow()) { + qDebug() << "QPlatformWindow does not exist for widget" << widget + << "cannot return EGLContext"; + return 0; + } + QPlatformGLContext *platformContext = widget->platformWindow()->glContext(); + if (!platformContext) { + qDebug() << "QPlatformWindow" << widget->platformWindow() << "does not have a glContext" + << "cannot return EGLContext"; + return 0; + } +#if defined(XCB_USE_EGL) + QEGLPlatformContext *eglPlatformContext = static_cast<QEGLPlatformContext *>(platformContext); + return eglPlatformContext->eglContext(); +#elif defined (XCB_USE_DRI2) + QDri2Context *dri2Context = static_cast<QDri2Context *>(platformContext); + return dri2Context->eglContext(); +#else + return 0; +#endif +} diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h index 9815381..72c27d5 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.h +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h @@ -14,7 +14,8 @@ public: EglDisplay, Connection, Screen, - GraphicsDevice + GraphicsDevice, + EglContext }; void *nativeResourceForWidget(const QByteArray &resourceString, QWidget *widget); @@ -24,6 +25,7 @@ public: void *connectionForWidget(QWidget *widget); void *screenForWidget(QWidget *widget); void *graphicsDeviceForWidget(QWidget *widget); + void *eglContextForWidget(QWidget *widget); private: static QXcbScreen *qPlatformScreenForWidget(QWidget *widget); |