From 29d8159c4478a5275d2ea102daf270a91ed7e92e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 29 Jan 2016 10:43:35 +0100 Subject: Avoid repeated QByteArray creation when resolving opengl functions Add an getProcAddress(const char *) overload to QOpenGLContext, and refactor the QPA interface to take a const char *. Like this we can avoid lots of mallocs when resoving GL methods. Change-Id: Ic45b985fbaa0da8d32ba3e3b485351173352ca6f Reviewed-by: Laszlo Agocs Reviewed-by: Sean Harmer --- src/plugins/platforms/cocoa/qcocoaglcontext.h | 2 +- src/plugins/platforms/cocoa/qcocoaglcontext.mm | 2 +- src/plugins/platforms/directfb/qdirectfbglcontext.cpp | 4 ++-- src/plugins/platforms/ios/qioscontext.h | 2 +- src/plugins/platforms/ios/qioscontext.mm | 4 ++-- src/plugins/platforms/mirclient/qmirclientglcontext.cpp | 4 ++-- src/plugins/platforms/mirclient/qmirclientglcontext.h | 2 +- src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp | 4 ++-- src/plugins/platforms/offscreen/qoffscreenintegration_x11.h | 2 +- src/plugins/platforms/openwfd/qopenwfdglcontext.cpp | 4 ++-- src/plugins/platforms/openwfd/qopenwfdglcontext.h | 2 +- src/plugins/platforms/qnx/qqnxglcontext.cpp | 4 ++-- src/plugins/platforms/qnx/qqnxglcontext.h | 2 +- src/plugins/platforms/windows/qwindowseglcontext.cpp | 8 ++++---- src/plugins/platforms/windows/qwindowseglcontext.h | 2 +- src/plugins/platforms/windows/qwindowsglcontext.cpp | 8 ++++---- src/plugins/platforms/windows/qwindowsglcontext.h | 2 +- src/plugins/platforms/winrt/qwinrteglcontext.cpp | 4 ++-- src/plugins/platforms/winrt/qwinrteglcontext.h | 2 +- .../platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp | 6 +++--- .../platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h | 2 +- 21 files changed, 36 insertions(+), 36 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h index cca541e0e3..5bee708b76 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.h +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h @@ -63,7 +63,7 @@ public: bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE; void doneCurrent() Q_DECL_OVERRIDE; - void (*getProcAddress(const QByteArray &procName)) () Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; void update(); diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index e4712d88bc..c004f26d02 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -335,7 +335,7 @@ void QCocoaGLContext::doneCurrent() [NSOpenGLContext clearCurrentContext]; } -void (*QCocoaGLContext::getProcAddress(const QByteArray &procName))() +QFunctionPointer QCocoaGLContext::getProcAddress(const char *procName) { return qcgl_getProcAddress(procName); } diff --git a/src/plugins/platforms/directfb/qdirectfbglcontext.cpp b/src/plugins/platforms/directfb/qdirectfbglcontext.cpp index 1136591c78..e1607b131a 100644 --- a/src/plugins/platforms/directfb/qdirectfbglcontext.cpp +++ b/src/plugins/platforms/directfb/qdirectfbglcontext.cpp @@ -80,10 +80,10 @@ void QDirectFbGLContext::doneCurrent() m_dfbGlContext->Unlock(m_dfbGlContext); } -void *QDirectFbGLContext::getProcAddress(const QString &procName) +void *QDirectFbGLContext::getProcAddress(const char *procName) { void *proc; - DFBResult result = m_dfbGlContext->GetProcAddress(m_dfbGlContext,qPrintable(procName),&proc); + DFBResult result = m_dfbGlContext->GetProcAddress(m_dfbGlContext, procName, &proc); if (result == DFB_OK) return proc; return 0; diff --git a/src/plugins/platforms/ios/qioscontext.h b/src/plugins/platforms/ios/qioscontext.h index 53ef1d7b54..c8a4fae20c 100644 --- a/src/plugins/platforms/ios/qioscontext.h +++ b/src/plugins/platforms/ios/qioscontext.h @@ -64,7 +64,7 @@ public: void doneCurrent() Q_DECL_OVERRIDE; GLuint defaultFramebufferObject(QPlatformSurface *) const Q_DECL_OVERRIDE; - QFunctionPointer getProcAddress(const QByteArray &procName) Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; bool isSharing() const Q_DECL_OVERRIDE; bool isValid() const Q_DECL_OVERRIDE; diff --git a/src/plugins/platforms/ios/qioscontext.mm b/src/plugins/platforms/ios/qioscontext.mm index b7ca88b9ee..546b003d14 100644 --- a/src/plugins/platforms/ios/qioscontext.mm +++ b/src/plugins/platforms/ios/qioscontext.mm @@ -266,9 +266,9 @@ void QIOSContext::windowDestroyed(QObject *object) } } -QFunctionPointer QIOSContext::getProcAddress(const QByteArray& functionName) +QFunctionPointer QIOSContext::getProcAddress(const char *functionName) { - return QFunctionPointer(dlsym(RTLD_DEFAULT, functionName.constData())); + return QFunctionPointer(dlsym(RTLD_DEFAULT, functionName)); } bool QIOSContext::isValid() const diff --git a/src/plugins/platforms/mirclient/qmirclientglcontext.cpp b/src/plugins/platforms/mirclient/qmirclientglcontext.cpp index e1e7727486..7a288af6ff 100644 --- a/src/plugins/platforms/mirclient/qmirclientglcontext.cpp +++ b/src/plugins/platforms/mirclient/qmirclientglcontext.cpp @@ -143,12 +143,12 @@ void QMirClientOpenGLContext::swapBuffers(QPlatformSurface* surface) ubuntuWindow->onSwapBuffersDone(); } -void (*QMirClientOpenGLContext::getProcAddress(const QByteArray& procName)) () +QFunctionPointer QMirClientOpenGLContext::getProcAddress(const char *procName) { #if defined(QT_NO_DEBUG) eglBindAPI(api_in_use()); #else ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE); #endif - return eglGetProcAddress(procName.constData()); + return eglGetProcAddress(procName); } diff --git a/src/plugins/platforms/mirclient/qmirclientglcontext.h b/src/plugins/platforms/mirclient/qmirclientglcontext.h index 29c196ce5c..9278cc7beb 100644 --- a/src/plugins/platforms/mirclient/qmirclientglcontext.h +++ b/src/plugins/platforms/mirclient/qmirclientglcontext.h @@ -53,7 +53,7 @@ public: bool makeCurrent(QPlatformSurface* surface) override; void doneCurrent() override; bool isValid() const override { return mEglContext != EGL_NO_CONTEXT; } - void (*getProcAddress(const QByteArray& procName)) () override; + QFunctionPointer getProcAddress(const char *procName) override; EGLContext eglContext() const { return mEglContext; } diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp index bec7fc9c96..2187eceed4 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp @@ -227,9 +227,9 @@ void QOffscreenX11GLXContext::swapBuffers(QPlatformSurface *) { } -void (*QOffscreenX11GLXContext::getProcAddress(const QByteArray &procName)) () +QFunctionPointer QOffscreenX11GLXContext::getProcAddress(const char *procName) { - return (void (*)())glXGetProcAddressARB(reinterpret_cast(procName.constData())); + return (QFunctionPointer)glXGetProcAddressARB(reinterpret_cast(procName)); } QSurfaceFormat QOffscreenX11GLXContext::format() const diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h index a19ded7c11..aaca74d2fb 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h +++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h @@ -91,7 +91,7 @@ public: bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE; void doneCurrent() Q_DECL_OVERRIDE; void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE; - QFunctionPointer getProcAddress(const QByteArray &procName) Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; QSurfaceFormat format() const Q_DECL_OVERRIDE; bool isSharing() const Q_DECL_OVERRIDE; diff --git a/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp b/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp index d76c56db65..e57be90870 100644 --- a/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp +++ b/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp @@ -84,9 +84,9 @@ void QOpenWFDGLContext::swapBuffers(QPlatformSurface *surface) screen->swapBuffers(); } -void (*QOpenWFDGLContext::getProcAddress(const QByteArray &procName)) () +QFunctionPointer QOpenWFDGLContext::getProcAddress(const char *procName) { - return eglGetProcAddress(procName.data()); + return eglGetProcAddress(procName); } EGLContext QOpenWFDGLContext::eglContext() const diff --git a/src/plugins/platforms/openwfd/qopenwfdglcontext.h b/src/plugins/platforms/openwfd/qopenwfdglcontext.h index 7b5a003253..1c2541e098 100644 --- a/src/plugins/platforms/openwfd/qopenwfdglcontext.h +++ b/src/plugins/platforms/openwfd/qopenwfdglcontext.h @@ -56,7 +56,7 @@ public: void swapBuffers(QPlatformSurface *surface); - void (*getProcAddress(const QByteArray &procName)) (); + QFunctionPointer getProcAddress(const char *procName); EGLContext eglContext() const; private: diff --git a/src/plugins/platforms/qnx/qqnxglcontext.cpp b/src/plugins/platforms/qnx/qqnxglcontext.cpp index 8207de4cbe..0d3076a743 100644 --- a/src/plugins/platforms/qnx/qqnxglcontext.cpp +++ b/src/plugins/platforms/qnx/qqnxglcontext.cpp @@ -252,7 +252,7 @@ void QQnxGLContext::swapBuffers(QPlatformSurface *surface) platformWindow->swapEGLBuffers(); } -QFunctionPointer QQnxGLContext::getProcAddress(const QByteArray &procName) +QFunctionPointer QQnxGLContext::getProcAddress(const char *procName) { qGLContextDebug(); @@ -262,7 +262,7 @@ QFunctionPointer QQnxGLContext::getProcAddress(const QByteArray &procName) qFatal("QQNX: failed to set EGL API, err=%d", eglGetError()); // Lookup EGL extension function pointer - return static_cast(eglGetProcAddress(procName.constData())); + return static_cast(eglGetProcAddress(procName)); } bool QQnxGLContext::isSharing() const diff --git a/src/plugins/platforms/qnx/qqnxglcontext.h b/src/plugins/platforms/qnx/qqnxglcontext.h index 897dbefc38..74cd3b4c48 100644 --- a/src/plugins/platforms/qnx/qqnxglcontext.h +++ b/src/plugins/platforms/qnx/qqnxglcontext.h @@ -67,7 +67,7 @@ public: bool makeCurrent(QPlatformSurface *surface); void doneCurrent(); void swapBuffers(QPlatformSurface *surface); - QFunctionPointer getProcAddress(const QByteArray &procName); + QFunctionPointer getProcAddress(const char *procName); virtual QSurfaceFormat format() const { return m_windowFormat; } bool isSharing() const; diff --git a/src/plugins/platforms/windows/qwindowseglcontext.cpp b/src/plugins/platforms/windows/qwindowseglcontext.cpp index a11196d1d2..253fa1d217 100644 --- a/src/plugins/platforms/windows/qwindowseglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowseglcontext.cpp @@ -683,7 +683,7 @@ void QWindowsEGLContext::swapBuffers(QPlatformSurface *surface) } } -QFunctionPointer QWindowsEGLContext::getProcAddress(const QByteArray &procName) +QFunctionPointer QWindowsEGLContext::getProcAddress(const char *procName) { // We support AllGLFunctionsQueryable, which means this function must be able to // return a function pointer for standard GLES2 functions too. These are not @@ -838,15 +838,15 @@ QFunctionPointer QWindowsEGLContext::getProcAddress(const QByteArray &procName) { "glDepthRangef", (void *) QWindowsEGLStaticContext::libGLESv2.glDepthRangef } }; for (size_t i = 0; i < sizeof(standardFuncs) / sizeof(StdFunc); ++i) - if (procName == standardFuncs[i].name) + if (!qstrcmp(procName, standardFuncs[i].name)) return reinterpret_cast(standardFuncs[i].func); QWindowsEGLStaticContext::libEGL.eglBindAPI(m_api); - QFunctionPointer procAddress = reinterpret_cast(QWindowsEGLStaticContext::libEGL.eglGetProcAddress(procName.constData())); + QFunctionPointer procAddress = reinterpret_cast(QWindowsEGLStaticContext::libEGL.eglGetProcAddress(procName)); if (QWindowsContext::verbose > 1) qCDebug(lcQpaGl) << __FUNCTION__ << procName << QWindowsEGLStaticContext::libEGL.eglGetCurrentContext() << "returns" << procAddress; if (!procAddress && QWindowsContext::verbose) - qWarning("%s: Unable to resolve '%s'", __FUNCTION__, procName.constData()); + qWarning("%s: Unable to resolve '%s'", __FUNCTION__, procName); return procAddress; } diff --git a/src/plugins/platforms/windows/qwindowseglcontext.h b/src/plugins/platforms/windows/qwindowseglcontext.h index ccc2cdcad1..e49d1da9c5 100644 --- a/src/plugins/platforms/windows/qwindowseglcontext.h +++ b/src/plugins/platforms/windows/qwindowseglcontext.h @@ -292,7 +292,7 @@ public: bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE; void doneCurrent() Q_DECL_OVERRIDE; void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE; - QFunctionPointer getProcAddress(const QByteArray &procName) Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; QSurfaceFormat format() const Q_DECL_OVERRIDE { return m_format; } bool isSharing() const Q_DECL_OVERRIDE { return m_shareContext != EGL_NO_CONTEXT; } diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 48f2e3aaef..8eac7cca9e 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -1381,7 +1381,7 @@ void QWindowsGLContext::doneCurrent() releaseDCs(); } -QFunctionPointer QWindowsGLContext::getProcAddress(const QByteArray &procName) +QFunctionPointer QWindowsGLContext::getProcAddress(const char *procName) { // We support AllGLFunctionsQueryable, which means this function must be able to // return a function pointer even for functions that are in GL.h and exported @@ -1444,17 +1444,17 @@ QFunctionPointer QWindowsGLContext::getProcAddress(const QByteArray &procName) { "glDepthRange", (void *) QOpenGLStaticContext::opengl32.glDepthRange }, }; for (size_t i = 0; i < sizeof(standardFuncs) / sizeof(StdFunc); ++i) - if (procName == standardFuncs[i].name) + if (!qstrcmp(procName, standardFuncs[i].name)) return reinterpret_cast(standardFuncs[i].func); // Even though we use QFunctionPointer, it does not mean the function can be called. // It will need to be cast to the proper function type with the correct calling // convention. QFunctionPointer is nothing more than a glorified void* here. - QFunctionPointer procAddress = reinterpret_cast(QOpenGLStaticContext::opengl32.wglGetProcAddress(procName.constData())); + QFunctionPointer procAddress = reinterpret_cast(QOpenGLStaticContext::opengl32.wglGetProcAddress(procName)); if (QWindowsContext::verbose > 1) qCDebug(lcQpaGl) << __FUNCTION__ << procName << QOpenGLStaticContext::opengl32.wglGetCurrentContext() << "returns" << procAddress; if (!procAddress && QWindowsContext::verbose) - qWarning("%s: Unable to resolve '%s'", __FUNCTION__, procName.constData()); + qWarning("%s: Unable to resolve '%s'", __FUNCTION__, procName); return procAddress; } diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h index 3acfed1ccf..a0fc31227e 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.h +++ b/src/plugins/platforms/windows/qwindowsglcontext.h @@ -251,7 +251,7 @@ public: typedef void (*GL_Proc) (); - QFunctionPointer getProcAddress(const QByteArray &procName) Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; HGLRC renderingContext() const { return m_renderingContext; } diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.cpp b/src/plugins/platforms/winrt/qwinrteglcontext.cpp index 34f439b70f..dfc9e31f14 100644 --- a/src/plugins/platforms/winrt/qwinrteglcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrteglcontext.cpp @@ -195,7 +195,7 @@ QSurfaceFormat QWinRTEGLContext::format() const return d->format; } -QFunctionPointer QWinRTEGLContext::getProcAddress(const QByteArray &procName) +QFunctionPointer QWinRTEGLContext::getProcAddress(const char *procName) { static QHash standardFuncs; if (standardFuncs.isEmpty()) { @@ -347,7 +347,7 @@ QFunctionPointer QWinRTEGLContext::getProcAddress(const QByteArray &procName) if (i != standardFuncs.end()) return i.value(); - return eglGetProcAddress(procName.constData()); + return eglGetProcAddress(procName); } EGLDisplay QWinRTEGLContext::display() diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.h b/src/plugins/platforms/winrt/qwinrteglcontext.h index 49b289cd79..6f38e2535d 100644 --- a/src/plugins/platforms/winrt/qwinrteglcontext.h +++ b/src/plugins/platforms/winrt/qwinrteglcontext.h @@ -56,7 +56,7 @@ public: void swapBuffers(QPlatformSurface *windowSurface) Q_DECL_OVERRIDE; QSurfaceFormat format() const Q_DECL_OVERRIDE; - QFunctionPointer getProcAddress(const QByteArray &procName) Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; static EGLDisplay display(); private: diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index ff624d9755..4290ec54fc 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -550,10 +550,10 @@ void QGLXContext::swapBuffers(QPlatformSurface *surface) } } -void (*QGLXContext::getProcAddress(const QByteArray &procName)) () +QFunctionPointer QGLXContext::getProcAddress(const char *procName) { #ifdef QT_STATIC - return glXGetProcAddressARB(reinterpret_cast(procName.constData())); + return glXGetProcAddressARB(reinterpret_cast(procName)); #else typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *); static qt_glXGetProcAddressARB glXGetProcAddressARB = 0; @@ -585,7 +585,7 @@ void (*QGLXContext::getProcAddress(const QByteArray &procName)) () } if (!glXGetProcAddressARB) return 0; - return (void (*)())glXGetProcAddressARB(reinterpret_cast(procName.constData())); + return (void (*)())glXGetProcAddressARB(reinterpret_cast(procName)); #endif } diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h index e5cbee3363..f00d96e6d5 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h @@ -63,7 +63,7 @@ public: bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE; void doneCurrent() Q_DECL_OVERRIDE; void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE; - QFunctionPointer getProcAddress(const QByteArray &procName) Q_DECL_OVERRIDE; + QFunctionPointer getProcAddress(const char *procName) Q_DECL_OVERRIDE; QSurfaceFormat format() const Q_DECL_OVERRIDE; bool isSharing() const Q_DECL_OVERRIDE; -- cgit v1.2.3