From 6e8c0095d0410a30ffa06bb0b0cb71f979becfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Fri, 12 Mar 2010 12:49:38 +0100 Subject: Made QGLExtensions::glExtensions() thread-safe. Reviewed-by: Gunnar --- src/opengl/qgl.cpp | 37 ++++++++++++++++++------------------- src/opengl/qgl_p.h | 2 -- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 58ac642..e0030ad 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -5060,6 +5060,20 @@ QGLExtensions::Extensions QGLExtensions::currentContextExtensions() return glExtensions; } + +class QGLDefaultExtensions +{ +public: + QGLDefaultExtensions() { + QGLTemporaryContext tempContext; + extensions = QGLExtensions::currentContextExtensions(); + } + + QGLExtensions::Extensions extensions; +}; + +Q_GLOBAL_STATIC(QGLDefaultExtensions, qtDefaultExtensions) + /* Returns the GL extensions for the current QGLContext. If there is no current QGLContext, a default context will be created and the extensions @@ -5067,34 +5081,19 @@ QGLExtensions::Extensions QGLExtensions::currentContextExtensions() */ QGLExtensions::Extensions QGLExtensions::glExtensions() { - QGLTemporaryContext *tmpContext = 0; - static bool cachedDefault = false; - static Extensions defaultExtensions = 0; + Extensions extensionFlags = 0; QGLContext *currentCtx = const_cast(QGLContext::currentContext()); if (currentCtx && currentCtx->d_func()->extension_flags_cached) return currentCtx->d_func()->extension_flags; if (!currentCtx) { - if (cachedDefault) { - return defaultExtensions; - } else { - tmpContext = new QGLTemporaryContext; - cachedDefault = true; - } - } - - Extensions extensionFlags = currentContextExtensions(); - if (currentCtx) { + extensionFlags = qtDefaultExtensions()->extensions; + } else { + extensionFlags = currentContextExtensions(); currentCtx->d_func()->extension_flags_cached = true; currentCtx->d_func()->extension_flags = extensionFlags; - } else { - defaultExtensions = extensionFlags; } - - if (tmpContext) - delete tmpContext; - return extensionFlags; } diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index f66031a..45f8f30 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -278,8 +278,6 @@ public: Q_DECLARE_FLAGS(Extensions, Extension) static Extensions glExtensions(); - -private: static Extensions currentContextExtensions(); }; -- cgit v0.12