Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Implement a switch between EGL and GLX API on X11/XWayland

Dmitry Kazakovbd6975bd3843
diff --git a/krita/main.cc b/krita/main.cc
index 929dbf052c..a330f0e601 100644
--- a/krita/main.cc
+++ b/krita/main.cc
@@ -385,7 +385,15 @@ extern "C" MAIN_EXPORT int MAIN_FN(int argc, char **argv)
}
#endif
- if (!qEnvironmentVariableIsEmpty("KRITA_OPENGL_DEBUG")) {
+#ifdef HAVE_X11
+ if (!qEnvironmentVariableIsSet("QT_XCB_GL_INTEGRATION")) {
+ if (KisConfig::preferXcbEglProvider(&kritarc)) {
+ qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl");
+ }
+ }
+#endif
+
+if (!qEnvironmentVariableIsEmpty("KRITA_OPENGL_DEBUG")) {
enableOpenGLDebug = true;
} else {
enableOpenGLDebug = kritarc.value("EnableOpenGLDebug", false).toBool();
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index cca88d2cdf..2c4bf40cd8 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -726,6 +726,14 @@ if(WIN32)
)
endif()
+if (HAVE_X11)
+ set_source_files_properties(
+ opengl/KisOpenGLModeProber.cpp
+ PROPERTIES
+ INCLUDE_DIRECTORIES "${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS}"
+ )
+endif()
+
if (QT_MAJOR_VERSION STREQUAL "6")
target_link_libraries(kritaui
PRIVATE
diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc
index c60c38a707..9464103ab3 100644
--- a/libs/ui/dialogs/kis_dlg_preferences.cc
+++ b/libs/ui/dialogs/kis_dlg_preferences.cc
@@ -2159,6 +2159,37 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
}
}
+ {
+ std::optional<KisOpenGL::XcbGLProviderProtocol> currentXcbGlProvider = KisOpenGL::xcbGlProviderProtocol();
+
+ lblPreferredXcbGlApi->setVisible(currentXcbGlProvider.has_value());
+ cmbPreferredXcbGlApi->setVisible(currentXcbGlProvider.has_value());
+
+ if (currentXcbGlProvider.has_value()) {
+ const QString glxCurrent = i18nc("@item:inlistbox", "GLX (current)");
+ const QString glxNotCurrent = i18nc("@item:inlistbox", "GLX");
+ const QString eglCurrent = i18nc("@item:inlistbox", "EGL (current)");
+ const QString eglNotCurrent = i18nc("@item:inlistbox", "EGL");
+
+ cmbPreferredXcbGlApi->addItem(*currentXcbGlProvider == KisOpenGL::XCB_GLX ? glxCurrent : glxNotCurrent, KisOpenGL::XCB_GLX);
+ cmbPreferredXcbGlApi->addItem(*currentXcbGlProvider == KisOpenGL::XCB_EGL ? eglCurrent : eglNotCurrent, KisOpenGL::XCB_EGL);
+
+ cmbPreferredXcbGlApi->setToolTip(i18nc("@info:tooltip",
+ "<p>If you are using Krita on X11 or XWayland and experience slowness, "
+ "try switching between EGL and GLX</p>"));
+
+ KisOpenGL::XcbGLProviderProtocol preferredValue =
+ cfg.preferXcbEglProvider() ? KisOpenGL::XCB_EGL : KisOpenGL::XCB_GLX;
+
+ int index = cmbPreferredXcbGlApi->findData(preferredValue);
+
+ KIS_SAFE_ASSERT_RECOVER(index >= 0) {
+ index = 0;
+ }
+ cmbPreferredXcbGlApi->setCurrentIndex(index);
+ }
+ }
+
lblCurrentDisplayFormat->setText("");
lblCurrentRootSurfaceFormat->setText("");
grpHDRWarning->setVisible(false);
@@ -2897,6 +2928,10 @@ bool KisDlgPreferences::editPreferences()
KisOpenGL::setUserPreferredOpenGLRendererConfig(KisOpenGL::RendererNone);
}
+ if (KisOpenGL::xcbGlProviderProtocol().has_value()) {
+ cfg.setPreferXcbEglProvider(m_displaySettings->cmbPreferredXcbGlApi->currentData().value<KisOpenGL::XcbGLProviderProtocol>() == KisOpenGL::XCB_EGL);
+ }
+
cfg.setUseOpenGLTextureBuffer(m_displaySettings->chkUseTextureBuffer->isChecked());
cfg.setOpenGLFilteringMode(m_displaySettings->cmbFilterMode->currentIndex());
cfg.setRootSurfaceFormat(&kritarc, indexToFormat(m_displaySettings->cmbPreferedRootSurfaceFormat->currentIndex()));
diff --git a/libs/ui/forms/wdgdisplaysettings.ui b/libs/ui/forms/wdgdisplaysettings.ui
index 3340f549aa..bb90c70b1c 100644
--- a/libs/ui/forms/wdgdisplaysettings.ui
+++ b/libs/ui/forms/wdgdisplaysettings.ui
@@ -11,7 +11,7 @@
<x>0</x>
<y>0</y>
<width>674</width>
- <height>413</height>
+ <height>454</height>
</rect>
</property>
<property name="sizePolicy">
@@ -61,8 +61,38 @@
<bool>true</bool>
</property>
<layout class="QGridLayout">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Current Renderer:</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="KisWarningBlock" name="grpOpenGLWarnings">
+ <property name="title">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0" colspan="2">
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Orientation::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
<item row="5" column="1">
- <widget class="QCheckBox" name="chkUseTextureBuffer">
+ <widget class="QComboBox" name="cmbAssistantsDrawMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -70,18 +100,27 @@
</sizepolicy>
</property>
<property name="toolTip">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use Texture Buffering. This can be faster on some GPU/Driver combinations (like Intel) or broken on some others (like AMD/Radeon).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="text">
- <string>Use texture buffer</string>
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Can be used to troubleshoot performance or artifacting problems with drawing assistants.
+ &lt;/p&gt;&lt;p&gt;Changing the pixmap cache size requires a restart.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
- </widget>
- </item>
- <item row="6" column="1">
- <widget class="KisWarningBlock" name="grpOpenGLWarnings">
- <property name="title">
- <string/>
+ <property name="currentIndex">
+ <number>0</number>
</property>
+ <item>
+ <property name="text">
+ <string>Direct (Recommended)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Pixmap Cache</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Large Pixmap Cache</string>
+ </property>
+ </item>
</widget>
</item>
<item row="2" column="1">
@@ -94,7 +133,7 @@
</property>
</widget>
</item>
- <item row="3" column="1">
+ <item row="4" column="1">
<widget class="QComboBox" name="cmbFilterMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -127,40 +166,31 @@
</item>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QLabel" name="label">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <item row="1" column="1">
+ <widget class="QLabel" name="lblCurrentRenderer">
<property name="text">
- <string>Scaling Mode:</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
+ <string>Unknown</string>
</property>
</widget>
</item>
- <item row="4" column="0">
- <widget class="QLabel" name="lblAssistantsDrawMode">
+ <item row="2" column="0">
+ <widget class="QLabel" name="lblPreferredRenderer">
<property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
- <string>Assistants Mode:</string>
+ <string>Preferred Renderer (needs restart):</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
- <item row="4" column="1">
- <widget class="QComboBox" name="cmbAssistantsDrawMode">
+ <item row="7" column="1">
+ <widget class="QCheckBox" name="chkUseTextureBuffer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -168,74 +198,55 @@
</sizepolicy>
</property>
<property name="toolTip">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Can be used to troubleshoot performance or artifacting problems with drawing assistants.
- &lt;/p&gt;&lt;p&gt;Changing the pixmap cache size requires a restart.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use Texture Buffering. This can be faster on some GPU/Driver combinations (like Intel) or broken on some others (like AMD/Radeon).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
- <property name="currentIndex">
- <number>0</number>
+ <property name="text">
+ <string>Use texture buffer</string>
</property>
- <item>
- <property name="text">
- <string>Direct (Recommended)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Pixmap Cache</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Large Pixmap Cache</string>
- </property>
- </item>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="lblPreferredRenderer">
+ <item row="4" column="0">
+ <widget class="QLabel" name="label">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Minimum">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
- <string>Preferred Renderer (needs restart):</string>
+ <string>Scaling Mode:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
- <item row="1" column="1">
- <widget class="QLabel" name="lblCurrentRenderer">
- <property name="text">
- <string>Unknown</string>
+ <item row="5" column="0">
+ <widget class="QLabel" name="lblAssistantsDrawMode">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_6">
<property name="text">
- <string>Current Renderer:</string>
+ <string>Assistants Mode:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
- <item row="7" column="0" colspan="2">
- <spacer name="verticalSpacer_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
+ <item row="3" column="0">
+ <widget class="QLabel" name="lblPreferredXcbGlApi">
+ <property name="text">
+ <string>Preferred openGL interface
+(needs restart):</string>
</property>
- </spacer>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="cmbPreferredXcbGlApi"/>
</item>
</layout>
</widget>
@@ -298,7 +309,7 @@
<item row="4" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
- <enum>Qt::Vertical</enum>
+ <enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -384,7 +395,7 @@
<string>Canvas Border Color:</string>
</property>
<property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
@@ -459,7 +470,7 @@
<string>Outline opacity:</string>
</property>
<property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
@@ -516,7 +527,7 @@
<item row="6" column="0" colspan="2">
<spacer name="verticalSpacer_5">
<property name="orientation">
- <enum>Qt::Vertical</enum>
+ <enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.cc
index 27a427ac23..3a1c2b8cf2 100644
--- a/libs/ui/kis_config.cc
+++ b/libs/ui/kis_config.cc
@@ -1113,6 +1113,25 @@ void KisConfig::setUseOpenGLTextureBuffer(bool useBuffer)
m_cfg.writeEntry("useOpenGLTextureBuffer", useBuffer);
}
+bool KisConfig::preferXcbEglProvider(const QSettings *settings, bool defaultValue)
+{
+ return (defaultValue ? false : settings->value("preferXcbEglProvider", false).toBool());
+}
+
+bool KisConfig::preferXcbEglProvider(bool defaultValue) const
+{
+ const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
+ QSettings kritarc(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);
+ return preferXcbEglProvider(&kritarc, defaultValue);
+}
+
+void KisConfig::setPreferXcbEglProvider(bool value)
+{
+ const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
+ QSettings kritarc(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);
+ kritarc.setValue("preferXcbEglProvider", value);
+}
+
int KisConfig::openGLTextureSize(bool defaultValue) const
{
return (defaultValue ? 256 : m_cfg.readEntry("textureSize", 256));
diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.h
index 6df002e384..250f2d512c 100644
--- a/libs/ui/kis_config.h
+++ b/libs/ui/kis_config.h
@@ -276,6 +276,10 @@ public:
bool useOpenGLTextureBuffer(bool defaultValue = false) const;
void setUseOpenGLTextureBuffer(bool useBuffer);
+ static bool preferXcbEglProvider(const QSettings *settings, bool defaultValue = false);
+ bool preferXcbEglProvider(bool defaultValue = false) const;
+ void setPreferXcbEglProvider(bool value);
+
bool forceOpenGLFenceWorkaround(bool defaultValue = false) const;
int numMipmapLevels(bool defaultValue = false) const;
diff --git a/libs/ui/opengl/KisOpenGLModeProber.cpp b/libs/ui/opengl/KisOpenGLModeProber.cpp
index d78d1a28d7..f1a46ebb98 100644
--- a/libs/ui/opengl/KisOpenGLModeProber.cpp
+++ b/libs/ui/opengl/KisOpenGLModeProber.cpp
@@ -14,6 +14,10 @@
#include <QWindow>
#include <QColorSpace>
+#ifdef HAVE_X11
+#include <qpa/qplatformnativeinterface.h>
+#endif
+
#include <QGlobalStatic>
#include <KisSurfaceColorSpaceWrapper.h>
@@ -380,6 +384,19 @@ KisOpenGLModeProber::Result::Result(QOpenGLContext &context) {
context.hasExtension("GL_ARB_invalidate_subdata"));
m_supportsLod = context.format().majorVersion() >= 3 || (m_isOpenGLES && context.hasExtension("GL_EXT_shader_texture_lod"));
+#ifdef HAVE_X11
+ if (QApplication::platformName() == "xcb") {
+ QPlatformNativeInterface *native = qApp->platformNativeInterface();
+ if (native->nativeResourceFunctionForContext("eglcontext")) {
+ m_xcbGlProviderProtocol = KisOpenGL::XCB_EGL;
+ } else if (native->nativeResourceFunctionForContext("glxcontext")) {
+ m_xcbGlProviderProtocol = KisOpenGL::XCB_GLX;
+ } else {
+ qWarning() << "WARNING: Failed to detect QXcbGlIntegration type!";
+ }
+ }
+#endif /* HAVE_X11 */
+
m_extensions = context.extensions();
// Remove empty name extension that sometimes appears on NVIDIA output
m_extensions.remove("");
diff --git a/libs/ui/opengl/KisOpenGLModeProber.h b/libs/ui/opengl/KisOpenGLModeProber.h
index e2363a9315..e2a8caabe0 100644
--- a/libs/ui/opengl/KisOpenGLModeProber.h
+++ b/libs/ui/opengl/KisOpenGLModeProber.h
@@ -149,6 +149,10 @@ public:
return m_extensions;
}
+ std::optional<KisOpenGL::XcbGLProviderProtocol> xcbGlProviderProtocol() {
+ return m_xcbGlProviderProtocol;
+ }
+
private:
int m_glMajorVersion = 0;
int m_glMinorVersion = 0;
@@ -164,6 +168,7 @@ private:
QString m_shadingLanguageString;
QSurfaceFormat m_format;
QSet<QByteArray> m_extensions;
+ std::optional<KisOpenGL::XcbGLProviderProtocol> m_xcbGlProviderProtocol;
};
#endif // KISOPENGLMODEPROBER_H
diff --git a/libs/ui/opengl/kis_opengl.cpp b/libs/ui/opengl/kis_opengl.cpp
index c858c4f4b8..856bb4dd64 100644
--- a/libs/ui/opengl/kis_opengl.cpp
+++ b/libs/ui/opengl/kis_opengl.cpp
@@ -398,6 +398,12 @@ bool KisOpenGL::useFBOForToolOutlineRendering()
return openGLCheckResult && openGLCheckResult->supportsFBO();
}
+std::optional<KisOpenGL::XcbGLProviderProtocol> KisOpenGL::xcbGlProviderProtocol()
+{
+ initialize();
+ return openGLCheckResult ? openGLCheckResult->xcbGlProviderProtocol() : std::nullopt;
+}
+
bool KisOpenGL::needsFenceWorkaround()
{
initialize();
diff --git a/libs/ui/opengl/kis_opengl.h b/libs/ui/opengl/kis_opengl.h
index 7705ca8210..958c057ca0 100644
--- a/libs/ui/opengl/kis_opengl.h
+++ b/libs/ui/opengl/kis_opengl.h
@@ -60,6 +60,11 @@ public:
OpenGLRenderer rendererId() const;
};
+ enum XcbGLProviderProtocol {
+ XCB_GLX = 0,
+ XCB_EGL
+ };
+
public:
static RendererConfig selectSurfaceConfig(KisOpenGL::OpenGLRenderer preferredRenderer,
KisConfig::RootSurfaceFormat preferredRootSurfaceFormat,
@@ -127,6 +132,8 @@ public:
static void glInvalidateBufferData(uint buffer);
+ static std::optional<XcbGLProviderProtocol> xcbGlProviderProtocol();
+
private:
static void fakeInitWindowsOpenGL(KisOpenGL::OpenGLRenderers supportedRenderers, KisOpenGL::OpenGLRenderer preferredByQt);