Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOpenGLContextSwitchLock.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QOpenGLContext>
10#include <QOpenGLWidget>
11
12
13namespace {
14
15#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
16inline bool shouldUseLock()
17{
18# if defined(Q_OS_MACOS) || defined(Q_OS_ANDROID)
25 return true;
26# else
27 static const bool s_shouldUseLock = qEnvironmentVariableIsSet("KRITA_USE_STRICT_OPENGL_CONTEXT_SWITCH");
28 return s_shouldUseLock;
29# endif
30}
31#endif
32}
33
35 : m_targetWidget(targetWidget)
36{
37}
38
40 m_oldContext = QOpenGLContext::currentContext();
41 m_oldSurface = m_oldContext ? m_oldContext->surface() : nullptr;
42 m_targetWidget->makeCurrent();
43}
44
46 if (m_oldContext) {
47 m_oldContext->makeCurrent(m_oldSurface);
48 } else {
49 m_targetWidget->doneCurrent();
50 }
51}
52
54{
55#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
56 if (!shouldUseLock()) return;
57#endif
59}
60
62{
63#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
64 if (!shouldUseLock()) return;
65#endif
67}
KisOpenGLContextSwitchLockAdapter(QOpenGLWidget *targetWidget)