diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2011-03-01 13:01:43 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-03-01 13:29:02 (GMT) |
commit | 53741ff1983a9d0085658b96743b125daaa5e680 (patch) | |
tree | 4140ea453c84c0436f8f1ba50a6cbebc556a01a9 | |
parent | ccb623188369be7bf4b991ff8a1f81d27137984c (diff) | |
download | Qt-53741ff1983a9d0085658b96743b125daaa5e680.zip Qt-53741ff1983a9d0085658b96743b125daaa5e680.tar.gz Qt-53741ff1983a9d0085658b96743b125daaa5e680.tar.bz2 |
Lighthouse: Implement the new Native Interface api in the xcb plugin
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 5 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbnativeinterface.cpp | 74 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbnativeinterface.h | 22 |
4 files changed, 87 insertions, 16 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 06e4d13..a2f985e 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -447,13 +447,14 @@ void QXcbConnection::initializeDri2() return; } - QString dri2DeviceName = QString::fromLocal8Bit(xcb_dri2_connect_device_name (connect), + m_dri2_device_name = QByteArray(xcb_dri2_connect_device_name (connect), xcb_dri2_connect_device_name_length (connect)); delete connect; - int fd = open(qPrintable(dri2DeviceName), O_RDWR); + int fd = open(m_dri2_device_name.constData(), O_RDWR); if (fd < 0) { qDebug() << "InitializeDri2: Could'nt open device << dri2DeviceName"; + m_dri2_device_name = QByteArray(); return; } diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 3aa36db..8a0f3d7 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -239,6 +239,7 @@ 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 private slots: @@ -272,6 +273,7 @@ private: bool m_dri2_support_probed; bool m_has_support_for_dri2; void *m_egl_display; + QByteArray m_dri2_device_name; #endif }; diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index 859b6c3..f379580 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -3,8 +3,52 @@ #include "qxcbscreen.h" #include <QtGui/private/qapplication_p.h> +#include <QtCore/QMap> -QXcbScreen *QXcbNativeInterface::screenForWidget(QWidget *widget) +class QXcbResourceMap : public QMap<QByteArray, QXcbNativeInterface::ResourceType> +{ +public: + QXcbResourceMap() + :QMap<QByteArray, QXcbNativeInterface::ResourceType>() + { + insert("display",QXcbNativeInterface::Display); + insert("egldisplay",QXcbNativeInterface::EglDisplay); + insert("connection",QXcbNativeInterface::Connection); + insert("screen",QXcbNativeInterface::Screen); + insert("graphicsdevice",QXcbNativeInterface::GraphicsDevice); + } +}; + +Q_GLOBAL_STATIC(QXcbResourceMap, qXcbResourceMap) + +void *QXcbNativeInterface::nativeResourceForWidget(const QByteArray &resourceString, QWidget *widget) +{ + QByteArray lowerCaseResource = resourceString.toLower(); + ResourceType resource = qXcbResourceMap()->value(lowerCaseResource); + void *result = 0; + switch(resource) { + case Display: + result = displayForWidget(widget); + break; + case EglDisplay: + result = eglDisplayForWidget(widget); + break; + case Connection: + result = connectionForWidget(widget); + break; + case Screen: + result = qPlatformScreenForWidget(widget); + break; + case GraphicsDevice: + result = graphicsDeviceForWidget(widget); + break; + default: + result = 0; + } + return result; +} + +QXcbScreen *QXcbNativeInterface::qPlatformScreenForWidget(QWidget *widget) { QXcbScreen *screen; if (widget) { @@ -15,10 +59,10 @@ QXcbScreen *QXcbNativeInterface::screenForWidget(QWidget *widget) return screen; } -void * QXcbNativeInterface::nativeDisplayForWidget(QWidget *widget) +void *QXcbNativeInterface::displayForWidget(QWidget *widget) { #if defined(XCB_USE_XLIB) - QXcbScreen *screen = screenForWidget(widget); + QXcbScreen *screen = qPlatformScreenForWidget(widget); return screen->connection()->xlib_display(); #else Q_UNUSED(widget); @@ -26,10 +70,10 @@ void * QXcbNativeInterface::nativeDisplayForWidget(QWidget *widget) #endif } -void * QXcbNativeInterface::eglDisplayForWidget(QWidget *widget) +void *QXcbNativeInterface::eglDisplayForWidget(QWidget *widget) { #if defined(XCB_USE_DRI2) - QXcbScreen *screen = screenForWidget(widget); + QXcbScreen *screen = qPlatformScreenForWidget(widget); return screen->connection()->egl_display(); #else Q_UNUSED(widget) @@ -37,14 +81,26 @@ void * QXcbNativeInterface::eglDisplayForWidget(QWidget *widget) #endif } -void * QXcbNativeInterface::nativeConnectionForWidget(QWidget *widget) +void *QXcbNativeInterface::connectionForWidget(QWidget *widget) { - QXcbScreen *screen = screenForWidget(widget); + QXcbScreen *screen = qPlatformScreenForWidget(widget); return screen->xcb_connection(); } -void * QXcbNativeInterface::nativeScreenForWidget(QWidget *widget) +void *QXcbNativeInterface::screenForWidget(QWidget *widget) { - QXcbScreen *screen = screenForWidget(widget); + QXcbScreen *screen = qPlatformScreenForWidget(widget); return screen->screen(); } + +void *QXcbNativeInterface::graphicsDeviceForWidget(QWidget *widget) +{ +#if defined(XCB_USE_DRI2) + QXcbScreen *screen = qPlatformScreenForWidget(widget); + QByteArray deviceName = screen->connection()->dri2DeviceName(); + return deviceName.data(); +#else + return 0; +#endif + +} diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h index fb48833..9815381 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.h +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h @@ -8,13 +8,25 @@ class QXcbScreen; class QXcbNativeInterface : public QPlatformNativeInterface { - void * nativeDisplayForWidget(QWidget *widget); - void * eglDisplayForWidget(QWidget *widget); - void * nativeConnectionForWidget(QWidget *widget); - void * nativeScreenForWidget(QWidget *widget); +public: + enum ResourceType { + Display, + EglDisplay, + Connection, + Screen, + GraphicsDevice + }; + + void *nativeResourceForWidget(const QByteArray &resourceString, QWidget *widget); + + void *displayForWidget(QWidget *widget); + void *eglDisplayForWidget(QWidget *widget); + void *connectionForWidget(QWidget *widget); + void *screenForWidget(QWidget *widget); + void *graphicsDeviceForWidget(QWidget *widget); private: - static QXcbScreen *screenForWidget(QWidget *widget); + static QXcbScreen *qPlatformScreenForWidget(QWidget *widget); }; #endif // QXCBNATIVEINTERFACE_H |