From e309e7a3e8227647f64b8c1e5eb3fa893c4a4b61 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Sun, 22 Jan 2012 21:05:06 +0100 Subject: XCB: Introduce enumeration for event filter types. Remove QByteArray-construction and hash lookup in the event handling; use an enumeration indexing an array instead. Change-Id: I4d272b32a5ff71c8da58197cf3a0b38c1e61d489 Reviewed-by: Simon Hausmann --- src/plugins/platforms/xcb/qxcbconnection.cpp | 2 +- src/plugins/platforms/xcb/qxcbnativeinterface.cpp | 22 +++++++++++++++------- src/plugins/platforms/xcb/qxcbnativeinterface.h | 11 +++++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index c77eae284b..3af6b5ad10 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -498,7 +498,7 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event) #endif bool handled = false; - if (QPlatformNativeInterface::EventFilter filter = m_nativeInterface->eventFilterForEventType(QByteArrayLiteral("xcb_generic_event_t"))) + if (QPlatformNativeInterface::EventFilter filter = m_nativeInterface->eventFilter(QXcbNativeInterface::GenericEventFilter)) handled = filter(event, 0); uint response_type = event->response_type & ~0x80; diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index bb95584bbf..556d173959 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -76,6 +76,11 @@ public: Q_GLOBAL_STATIC(QXcbResourceMap, qXcbResourceMap) +QXcbNativeInterface::QXcbNativeInterface() +{ + qFill(m_eventFilters, m_eventFilters + EventFilterCount, EventFilter(0)); +} + void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) { QByteArray lowerCaseResource = resourceString.toLower(); @@ -120,16 +125,19 @@ void *QXcbNativeInterface::nativeResourceForWindow(const QByteArray &resourceStr QPlatformNativeInterface::EventFilter QXcbNativeInterface::setEventFilter(const QByteArray &eventType, QPlatformNativeInterface::EventFilter filter) { - EventFilter oldFilter = m_eventFilters.value(eventType); - m_eventFilters.insert(eventType, filter); + int type = -1; + if (eventType == QByteArrayLiteral("xcb_generic_event_t")) + type = GenericEventFilter; + if (type == -1) { + qWarning("%s: Attempt to set invalid event filter type '%s'.", + Q_FUNC_INFO, eventType.constData()); + return 0; + } + const EventFilter oldFilter = m_eventFilters[type]; + m_eventFilters[type] = filter; return oldFilter; } -QPlatformNativeInterface::EventFilter QXcbNativeInterface::eventFilterForEventType(const QByteArray& eventType) const -{ - return m_eventFilters.value(eventType); -} - QXcbScreen *QXcbNativeInterface::qPlatformScreenForWindow(QWindow *window) { QXcbScreen *screen; diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h index 1bb83fd031..521528670b 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.h +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h @@ -61,11 +61,18 @@ public: EglContext }; + enum EventFilterType { + GenericEventFilter, + EventFilterCount + }; + + QXcbNativeInterface(); + void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context); void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window); EventFilter setEventFilter(const QByteArray &eventType, EventFilter filter); - EventFilter eventFilterForEventType(const QByteArray& eventType) const; + EventFilter eventFilter(EventFilterType type) const { return m_eventFilters[type]; } void *displayForWindow(QWindow *window); void *eglDisplayForWindow(QWindow *window); @@ -76,7 +83,7 @@ public: void *eglContextForContext(QOpenGLContext *context); private: - QHash m_eventFilters; + EventFilter m_eventFilters[EventFilterCount]; static QXcbScreen *qPlatformScreenForWindow(QWindow *window); }; -- cgit v1.2.3