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++

Qt6: Work around QSurfaceFormat::colroSpace() having changed

Halla Rempt2a19d9efeb72
diff --git a/libs/ui/opengl/KisOpenGLModeProber.cpp b/libs/ui/opengl/KisOpenGLModeProber.cpp
index 6c369f8963..9320cb5e90 100644
--- a/libs/ui/opengl/KisOpenGLModeProber.cpp
+++ b/libs/ui/opengl/KisOpenGLModeProber.cpp
@@ -12,8 +12,10 @@
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QWindow>
+#include <QColorSpace>
#include <QGlobalStatic>
+
Q_GLOBAL_STATIC(KisOpenGLModeProber, s_instance)
@@ -47,7 +49,7 @@ QSurfaceFormat KisOpenGLModeProber::surfaceformatInUse() const
const KoColorProfile *KisOpenGLModeProber::rootSurfaceColorProfile() const
{
const KoColorProfile *profile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
-
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
const QSurfaceFormat::ColorSpace surfaceColorSpace = surfaceformatInUse().colorSpace();
if (surfaceColorSpace == QSurfaceFormat::ColorSpace::sRGBColorSpace) {
// use the default one!
@@ -58,6 +60,21 @@ const KoColorProfile *KisOpenGLModeProber::rootSurfaceColorProfile() const
profile = KoColorSpaceRegistry::instance()->p2020PQProfile();
#endif
}
+#else
+ const QColorSpace surfaceColorSpace = surfaceformatInUse().colorSpace();
+ if (surfaceColorSpace == QColorSpace(QColorSpace::NamedColorSpace::SRgb)) {
+ // use the default one!
+// XXX: Fix this when fixing HDR!!!
+// #ifdef HAVE_HDR
+// } else if (surfaceColorSpace == QSurfaceFormat::ColorSpace::scRGBColorSpace) {
+// profile = KoColorSpaceRegistry::instance()->p709G10Profile();
+// } else if (surfaceColorSpace == QSurfaceFormat::ColorSpace::bt2020PQColorSpace) {
+// profile = KoColorSpaceRegistry::instance()->p2020PQProfile();
+// #endif
+ }
+#endif
+
+
return profile;
}
@@ -211,6 +228,8 @@ KisOpenGLModeProber::probeFormat(const KisOpenGL::RendererConfig &rendererConfig
return result;
}
+
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpace &lhs, const QSurfaceFormat::ColorSpace &rhs)
{
return lhs == rhs ||
@@ -220,6 +239,17 @@ bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpa
rhs == QSurfaceFormat::ColorSpace::sRGBColorSpace));
}
+#else
+bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QColorSpace &lhs, const QColorSpace &rhs)
+{
+ return lhs == rhs ||
+ (( lhs == QColorSpace() ||
+ lhs == QColorSpace(QColorSpace::NamedColorSpace::SRgb)) &&
+ ( rhs == QColorSpace() ||
+ rhs == QColorSpace(QColorSpace::NamedColorSpace::SRgb)));
+
+}
+#endif
void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,
QSurfaceFormat *format)
{
@@ -230,13 +260,21 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceForm
format->setGreenBufferSize(10);
format->setBlueBufferSize(10);
format->setAlphaBufferSize(2);
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
format->setColorSpace(QSurfaceFormat::ColorSpace::bt2020PQColorSpace);
+#else
+ format->setColorSpace(QColorSpace(QColorSpace::NamedColorSpace::Bt2100Pq);
+#endif
} else if (config == KisConfig::BT709_G10) {
format->setRedBufferSize(16);
format->setGreenBufferSize(16);
format->setBlueBufferSize(16);
format->setAlphaBufferSize(16);
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
format->setColorSpace(QSurfaceFormat::ColorSpace::scRGBColorSpace);
+#else
+ format->setColorSpace(QColorSpace(QColorSpace::NamedColorSpace::SRgb);
+#endif
} else
#else
if (config == KisConfig::BT2020_PQ) {
@@ -252,7 +290,11 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceForm
format->setBlueBufferSize(8);
format->setAlphaBufferSize(8);
// TODO: check if we can use real sRGB space here
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
format->setColorSpace(QSurfaceFormat::ColorSpace::DefaultColorSpace);
+#else
+ format->setColorSpace(QColorSpace());
+#endif
}
}
@@ -261,14 +303,22 @@ bool KisOpenGLModeProber::isFormatHDR(const QSurfaceFormat &format)
#ifdef HAVE_HDR
bool isBt2020PQ =
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
format.colorSpace() == QSurfaceFormat::ColorSpace::bt2020PQColorSpace &&
+#else
+ format.colorSpace() == QColorSpace(QColorSpace::NamedColorSpace::Bt2100Pq) &&
+#endif
format.redBufferSize() == 10 &&
format.greenBufferSize() == 10 &&
format.blueBufferSize() == 10 &&
format.alphaBufferSize() == 2;
bool isBt709G10 =
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
format.colorSpace() == QSurfaceFormat::ColorSpace::scRGBColorSpace &&
+#else
+ format.colorSpace() == QColorSpace(QColorSpace::NamedColorSpace::SRgb) &&
+#endif
format.redBufferSize() == 16 &&
format.greenBufferSize() == 16 &&
format.blueBufferSize() == 16 &&
diff --git a/libs/ui/opengl/KisOpenGLModeProber.h b/libs/ui/opengl/KisOpenGLModeProber.h
index 49ee04672c..21f2d95530 100644
--- a/libs/ui/opengl/KisOpenGLModeProber.h
+++ b/libs/ui/opengl/KisOpenGLModeProber.h
@@ -12,11 +12,22 @@
#include "kritaui_export.h"
#include "kis_config.h"
#include <QSurfaceFormat>
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+#include <QColorSpace>
+#endif
#include <boost/optional.hpp>
#include "kis_opengl.h"
class KoColorProfile;
+/**
+ * WARNING WARNING WARNING!!!!
+ *
+ * The use of QColorSpace for HDR in this file after porting to Qt6 is GUARANTEED TO BE WRONG.
+ *
+ * This needs porting once we know how to integrate our HDR patches into Qt6
+ *
+ */
class KRITAUI_EXPORT KisOpenGLModeProber
{
public:
@@ -34,10 +45,14 @@ public:
const KoColorProfile *rootSurfaceColorProfile() const;
boost::optional<Result> probeFormat(const KisOpenGL::RendererConfig &rendererConfig,
- bool adjustGlobalState = true);
-
+ bool adjustGlobalState = true);;;;
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
static bool fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpace &lhs,
const QSurfaceFormat::ColorSpace &rhs);
+#else
+ static bool fuzzyCompareColorSpaces(const QColorSpace &lhs,
+ const QColorSpace &rhs);
+#endif
static QString angleRendererToString(KisOpenGL::AngleRenderer renderer);
public: