diff options
| -rw-r--r-- | src/core/ozone/ozone_platform_qt.cpp | 9 | ||||
| -rw-r--r-- | src/core/ozone/ozone_util_qt.cpp | 49 |
2 files changed, 29 insertions, 29 deletions
diff --git a/src/core/ozone/ozone_platform_qt.cpp b/src/core/ozone/ozone_platform_qt.cpp index f4a169a22..3fa7f638e 100644 --- a/src/core/ozone/ozone_platform_qt.cpp +++ b/src/core/ozone/ozone_platform_qt.cpp @@ -47,6 +47,8 @@ extern void *GetQtXDisplay(); #endif +#include <mutex> + namespace ui { namespace { @@ -112,12 +114,11 @@ OzonePlatformQt::~OzonePlatformQt() {} const ui::OzonePlatform::PlatformProperties &OzonePlatformQt::GetPlatformProperties() { static base::NoDestructor<ui::OzonePlatform::PlatformProperties> properties; - static bool initialized = false; - if (!initialized) { + static std::once_flag flag; + std::call_once(flag, [this]() { DCHECK(m_supportsNativePixmaps); properties->fetch_buffer_formats_for_gmb_on_gpu = m_supportsNativePixmaps.value(); - initialized = true; - } + }); return *properties; } diff --git a/src/core/ozone/ozone_util_qt.cpp b/src/core/ozone/ozone_util_qt.cpp index 0e9f871a0..76db63999 100644 --- a/src/core/ozone/ozone_util_qt.cpp +++ b/src/core/ozone/ozone_util_qt.cpp @@ -27,8 +27,6 @@ void *getXDisplay() QOpenGLContext *getQOpenGLContext() { - static QOpenGLContext *tmpGLContext = nullptr; - #if QT_CONFIG(opengl) if (auto *shareContext = QOpenGLContext::globalShareContext()) return shareContext; @@ -36,44 +34,45 @@ QOpenGLContext *getQOpenGLContext() if (auto *currentContext = QOpenGLContext::currentContext()) return currentContext; - if (!tmpGLContext) { - tmpGLContext = new QOpenGLContext(); + static QOpenGLContext *tmpGLContext = []() { + auto tmpGLContext = new QOpenGLContext(); tmpGLContext->create(); - QObject::connect(qGuiApp, &QGuiApplication::aboutToQuit, []() { delete tmpGLContext; }); - } -#endif + QObject::connect(qGuiApp, &QGuiApplication::aboutToQuit, [=]() { delete tmpGLContext; }); + return tmpGLContext; + }(); return tmpGLContext; +#else + return nullptr; +#endif } bool usingGLX() { - static std::optional<bool> result; - #if QT_CONFIG(opengl) && QT_CONFIG(xcb_glx_plugin) - if (result.has_value()) - return result.value(); - - QOpenGLContext *context = getQOpenGLContext(); - result = (context->nativeInterface<QNativeInterface::QGLXContext>() != nullptr); + static bool result = []() { + QOpenGLContext *context = getQOpenGLContext(); + return context->nativeInterface<QNativeInterface::QGLXContext>() != nullptr; + }(); + + return result; +#else + return false; #endif - - return result.value_or(false); } bool usingEGL() { - static std::optional<bool> result; - #if QT_CONFIG(opengl) && QT_CONFIG(egl) - if (result.has_value()) - return result.value(); - - QOpenGLContext *context = getQOpenGLContext(); - result = (context->nativeInterface<QNativeInterface::QEGLContext>() != nullptr); + static bool result = []() { + QOpenGLContext *context = getQOpenGLContext(); + return context->nativeInterface<QNativeInterface::QEGLContext>() != nullptr; + }(); + + return result; +#else + return false; #endif - - return result.value_or(false); } } // namespace OzoneUtilQt |
