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++
Move canvas bit depth selection to Krita startup stage
Dmitry Kazakov72b835e400f7
diff --git a/krita/main.cc b/krita/main.ccindex 0102c199c6..8cec7c1967 100644--- a/krita/main.cc+++ b/krita/main.cc@@ -428,8 +428,11 @@ extern "C" MAIN_EXPORT int MAIN_FN(int argc, char **argv)#endifpreferredRenderer = KisOpenGL::convertConfigToOpenGLRenderer(preferredRendererString);+ const KisConfig::CanvasSurfaceBitDepthMode bitDepthMode =+ KisConfig::canvasSurfaceBitDepthMode(&kritarc);+const KisOpenGL::RendererConfig config =- KisOpenGL::selectSurfaceConfig(preferredRenderer, rootSurfaceFormat, enableOpenGLDebug);+ KisOpenGL::selectSurfaceConfig(preferredRenderer, rootSurfaceFormat, bitDepthMode, enableOpenGLDebug);KisOpenGL::setDefaultSurfaceConfig(config);KisOpenGL::setDebugSynchronous(openGLDebugSynchronous);diff --git a/libs/ui/canvas/kis_canvas2.cpp b/libs/ui/canvas/kis_canvas2.cppindex 69fcb316c2..27c3cf8dbb 100644--- a/libs/ui/canvas/kis_canvas2.cpp+++ b/libs/ui/canvas/kis_canvas2.cpp@@ -93,6 +93,7 @@#include "KisSnapPixelStrategy.h"#include "KisDisplayConfig.h"#include "config-qt-patches-present.h"+#include <KoIcon.h>#include <config-use-surface-color-management-api.h>#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API@@ -220,16 +221,6 @@ public:void setActiveShapeManager(KoShapeManager *shapeManager);QRect docUpdateRectToWidget(const QRectF &docRect);-- KisOpenGLCanvas2::BitDepthMode preferredBitDepthMode(bool compositorPrefersHdr) const {- KisConfig cfg(true);-- if (!cfg.enableCanvasSurfaceColorSpaceManagement()) return KisOpenGLCanvas2::BitDepthMode::Depth8Bit;-- return KisOpenGLCanvas2::bitDepthForUserSetting(cfg.canvasSurfaceColorSpaceManagementMode(),- cfg.canvasSurfaceBitDepthMode(),- compositorPrefersHdr);- }};namespace {@@ -290,12 +281,10 @@ void KisCanvas2::setup()m_d->lodPreferredInImage = cfg.levelOfDetailEnabled();m_d->regionOfInterestMargin = KisImageConfig(true).animationCacheRegionOfInterestMargin();- // we don't yet have a surface, so ask main window about- // compositor's preferences- createCanvas(cfg.useOpenGL(), m_d->view->mainWindow()->compositorPrefersHDR());+ createCanvas(cfg.useOpenGL());setLodPreferredInCanvas(m_d->lodPreferredInImage);-+connect(m_d->view->canvasController()->proxyObject, SIGNAL(moveViewportOffset(QPointF, QPointF)), SLOT(viewportOffsetMoved(QPointF, QPointF)));connect(m_d->view->canvasController()->proxyObject, SIGNAL(effectiveZoomChanged(qreal)), SLOT(slotEffectiveZoomChanged(qreal)));connect(m_d->view->canvasController()->proxyObject, &KoCanvasControllerProxyObject::canvasStateChanged, this, &KisCanvas2::slotCanvasStateChanged);@@ -626,24 +615,30 @@ void KisCanvas2::createQPainterCanvas()setCanvasWidget(canvasWidget);}-void KisCanvas2::createOpenGLCanvas(bool compositorPrefersHdr)+void KisCanvas2::createOpenGLCanvas(){KisConfig cfg(true);m_d->openGLFilterMode = cfg.openGLFilteringMode();m_d->currentCanvasIsOpenGL = true;+ auto bitDepthMode =+ cfg.effectiveCanvasSurfaceBitDepthMode(QSurfaceFormat::defaultFormat())+ == KisConfig::CanvasSurfaceBitDepthMode::Depth10Bit ?+ KisOpenGLCanvas2::BitDepthMode::Depth10Bit :+ KisOpenGLCanvas2::BitDepthMode::Depth8Bit;+KisOpenGLCanvas2 *canvasWidget = new KisOpenGLCanvas2(this,m_d->coordinatesConverter,0,m_d->view->image(),&m_d->displayColorConverter,- m_d->preferredBitDepthMode(compositorPrefersHdr));+ bitDepthMode);m_d->frameCache = KisAnimationFrameCache::getFrameCache(canvasWidget->openGLImageTextures());setCanvasWidget(canvasWidget);}-void KisCanvas2::createCanvas(bool useOpenGL, bool compositorPrefersHdr)+void KisCanvas2::createCanvas(bool useOpenGL){// deinitialize previous canvas structuresm_d->prescaledProjection = 0;@@ -669,7 +664,7 @@ void KisCanvas2::createCanvas(bool useOpenGL, bool compositorPrefersHdr)m_d->displayColorConverter.notifyOpenGLCanvasIsActive(useOpenGL);if (useOpenGL) {- createOpenGLCanvas(compositorPrefersHdr);+ createOpenGLCanvas();if (cfg.canvasState() == "OPENGL_FAILED") {// Creating the opengl canvas failed, fall backwarnKrita << "OpenGL Canvas initialization returned OPENGL_FAILED. Falling back to QPainter.";@@ -741,7 +736,7 @@ void KisCanvas2::connectCurrentCanvas()Q_EMIT sigCanvasEngineChanged();}-void KisCanvas2::resetCanvas(bool useOpenGL, bool compositorPrefersHdr)+void KisCanvas2::resetCanvas(bool useOpenGL){// we cannot reset the canvas before it's created, but this method might be called,// for instance when setting the monitor profile.@@ -755,16 +750,14 @@ void KisCanvas2::resetCanvas(bool useOpenGL, bool compositorPrefersHdr)const bool canvasNeedsNativeSurface =cfg.enableCanvasSurfaceColorSpaceManagement() &&bool(m_d->view->mainWindow()->managedSurfaceProfile());- const bool bitDepthModeIsInconsistent =- m_d->canvasWidget->currentBitDepthMode() != m_d->preferredBitDepthMode(compositorPrefersHdr);bool needReset = (m_d->currentCanvasIsOpenGL != useOpenGL) ||(m_d->currentCanvasIsOpenGL &&- (m_d->openGLFilterMode != cfg.openGLFilteringMode() || bitDepthModeIsInconsistent)) ||+ m_d->openGLFilterMode != cfg.openGLFilteringMode()) ||canvasHasNativeSurface != canvasNeedsNativeSurface;if (needReset) {- createCanvas(useOpenGL, compositorPrefersHdr);+ createCanvas(useOpenGL);connectCurrentCanvas();slotEffectiveZoomChanged(m_d->coordinatesConverter->effectiveZoom());}@@ -1338,16 +1331,7 @@ void KisCanvas2::slotConfigChanged()KisConfig cfg(true);m_d->regionOfInterestMargin = KisImageConfig(true).animationCacheRegionOfInterestMargin();- // when config is changed we might either have or not have the- // surface, so request the value from wherever it is possible- auto effectiveCompositorPrefersHdr =-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API- m_d->surfaceColorManager && m_d->surfaceColorManager->isReady() ?- m_d->surfaceColorManager->displayConfig().isHDR :-#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */- m_d->view->mainWindow()->compositorPrefersHDR();-- resetCanvas(cfg.useOpenGL(), effectiveCompositorPrefersHdr);+ resetCanvas(cfg.useOpenGL());QWidget *mainWindow = m_d->view->mainWindow();KIS_SAFE_ASSERT_RECOVER_RETURN(mainWindow);@@ -1425,17 +1409,17 @@ void KisCanvas2::setDisplayConfig(const KisDisplayConfig &config)if (m_d->displayColorConverter.displayConfig() == config) return;if (m_d->currentCanvasIsOpenGL) {- if (m_d->canvasWidget->currentBitDepthMode() < m_d->preferredBitDepthMode(config.isHDR)) {- // 1) When bit depth mode has changed, there is no use in- // updating the config, just recreate the widget; the config- // will be updated automatically during the widget initialization- // process- // 2) Since the call to setDisplayConfig() can come directly from- // the surface color manager, we shouldn't try to destroy the canvas- // (and its manager) directly from this function. Just postpone it- // till we exit the call- QTimer::singleShot(0, this, [this, isHDR = config.isHDR]() { resetCanvas(true, isHDR); });- return;+ if (config.isHDR &&+ m_d->canvasWidget->currentBitDepthMode() < KisOpenGLCanvas2::BitDepthMode::Depth10Bit) {++ const QString warningMessage = i18n(+ "WARNING: HDR mode was activated on surface working in 8-bit mode!\n"+ "Please activate 10-bit mode in Krita's Preferences dialog and restart"+ "Krita to avoid color banding!");++ m_d->view->showFloatingMessage(warningMessage, koIcon("warning"), 7000, KisFloatingMessage::High);+ warnOpenGL.noquote() << QString(warningMessage).replace('\n', ' ');+ warnOpenGL << ppVar(QSurfaceFormat::defaultFormat());}}diff --git a/libs/ui/canvas/kis_canvas2.h b/libs/ui/canvas/kis_canvas2.hindex 32099c3cfe..5fad6cc6cb 100644--- a/libs/ui/canvas/kis_canvas2.h+++ b/libs/ui/canvas/kis_canvas2.h@@ -322,12 +322,12 @@ private:void requestCanvasUpdateMaybeCompressed();void connectCurrentCanvas();- void createCanvas(bool useOpenGL, bool compositorPrefersHdr);+ void createCanvas(bool useOpenGL);void createQPainterCanvas();- void createOpenGLCanvas(bool compositorPrefersHdr);+ void createOpenGLCanvas();void updateCanvasWidgetImpl(const QRect &rc = QRect());void setCanvasWidget(KisAbstractCanvasWidget *widget);- void resetCanvas(bool useOpenGL, bool compositorPrefersHdr);+ void resetCanvas(bool useOpenGL);void setDisplayConfig(const KisDisplayConfig &config);const KoColorProfile* effectiveDisplayProfile(int screenNumber, const KisConfig &config) const;diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.ccindex 13718a0679..11c64ba167 100644--- a/libs/ui/dialogs/kis_dlg_preferences.cc+++ b/libs/ui/dialogs/kis_dlg_preferences.cc@@ -1217,7 +1217,7 @@ ColorSettingsTab::ColorSettingsTab(QWidget *parent, const char *name)// surface bit depthm_canvasSurfaceBitDepth = new KisSqueezedComboBox();m_canvasSurfaceBitDepth->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);- QLabel *canvasSurfaceBitDepthLbl = new QLabel(i18n("Canvas surface bit depth:"), this);+ QLabel *canvasSurfaceBitDepthLbl = new QLabel(i18n("Canvas surface bit depth (needs restart):"), this);monitorProfileGrid->addRow(canvasSurfaceBitDepthLbl, m_canvasSurfaceBitDepth);m_canvasSurfaceBitDepth->addSqueezedItem(i18n("Auto"), QVariant::fromValue(CanvasSurfaceBitDepthMode::DepthAuto));@@ -1226,8 +1226,13 @@ ColorSettingsTab::ColorSettingsTab(QWidget *parent, const char *name)m_canvasSurfaceBitDepth->setToolTip(i18n("<p>The bit depth of the color that is passed to the window "- "compositor. When using \"Auto\" Krita will automatically select "- "10-bit for HDR modes and will keep 8-bit in SDR mode</p>"));+ "compositor. You should switch into 10-bit mode if you want to use "+ "HDR capabilities of your display</p>"));++ const QString currentBitBepthString = QSurfaceFormat::defaultFormat().redBufferSize() == 10 ? i18n("10-bit") : i18n("8-bit");+ QLabel *currentCanvasSurfaceBitDepthLbl = new QLabel(i18n("Current canvas surface bit depth:"), this);+ QLabel *currentCanvasSurfaceBitDepth = new QLabel(currentBitBepthString, this);+ monitorProfileGrid->addRow(currentCanvasSurfaceBitDepthLbl, currentCanvasSurfaceBitDepth);vboxLayout->addItem(new QSpacerItem(20,20));diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.ccindex b1270e6d61..f1d163f12a 100644--- a/libs/ui/kis_config.cc+++ b/libs/ui/kis_config.cc@@ -41,6 +41,7 @@#include <KisUsageLogger.h>#include <kis_image_config.h>#include <KisCumulativeUndoData.h>+#include <QSurfaceFormat>#if defined Q_OS_WIN && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)# include <QtGui/private/qguiapplication_p.h>@@ -621,8 +622,9 @@ void KisConfig::setCanvasSurfaceColorSpaceManagementMode(KisConfig::CanvasSurfac}-KisConfig::CanvasSurfaceBitDepthMode KisConfig::canvasSurfaceBitDepthMode(bool defaultValue) const {- QString modeStr = defaultValue ? "auto" : m_cfg.readEntry("canvasSurfaceBitDepthMode", "auto");+KisConfig::CanvasSurfaceBitDepthMode KisConfig::canvasSurfaceBitDepthMode(QSettings *settings, bool defaultValue)+{+ QString modeStr = defaultValue ? "auto" : settings->value("canvasSurfaceBitDepthMode", "auto").toString();if (modeStr == "auto") {return CanvasSurfaceBitDepthMode::DepthAuto;@@ -635,7 +637,8 @@ KisConfig::CanvasSurfaceBitDepthMode KisConfig::canvasSurfaceBitDepthMode(bool dreturn CanvasSurfaceBitDepthMode::DepthAuto;}-void KisConfig::setCanvasSurfaceBitDepthMode(CanvasSurfaceBitDepthMode value) {+void KisConfig::setCanvasSurfaceBitDepthMode(QSettings *settings, CanvasSurfaceBitDepthMode value)+{QString modeStr;switch (value) {@@ -650,9 +653,42 @@ void KisConfig::setCanvasSurfaceBitDepthMode(CanvasSurfaceBitDepthMode value) {break;}- m_cfg.writeEntry("canvasSurfaceBitDepthMode", modeStr);+ settings->setValue("canvasSurfaceBitDepthMode", modeStr);}+KisConfig::CanvasSurfaceBitDepthMode KisConfig::canvasSurfaceBitDepthMode(bool defaultValue) const+{+ const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);+ QSettings kritarc(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);+ return canvasSurfaceBitDepthMode(&kritarc, defaultValue);+}++void KisConfig::setCanvasSurfaceBitDepthMode(CanvasSurfaceBitDepthMode value)+{+ const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);+ QSettings kritarc(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);+ setCanvasSurfaceBitDepthMode(&kritarc, value);+}++KisConfig::CanvasSurfaceBitDepthMode KisConfig::effectiveCanvasSurfaceBitDepthMode(const QSurfaceFormat &format) const+{+ auto mode = canvasSurfaceBitDepthMode();++ if (mode == CanvasSurfaceBitDepthMode::DepthAuto) {+ if (format.redBufferSize() == 10 &&+ format.greenBufferSize() == 10 &&+ format.blueBufferSize() == 10) {++ mode = CanvasSurfaceBitDepthMode::Depth10Bit;+ } else {+ mode = CanvasSurfaceBitDepthMode::Depth8Bit;+ }+ }++ return mode;+}++QString KisConfig::monitorProfile(int screen) const{// Note: keep this in sync with the default profile for the RGB colorspaces!diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.hindex dbcfc346ac..0025760aca 100644--- a/libs/ui/kis_config.h+++ b/libs/ui/kis_config.h@@ -25,6 +25,7 @@ class KisSnapConfig;class QSettings;class KisOcioConfiguration;struct KisCumulativeUndoData;+class QSurfaceFormat;class KRITAUI_EXPORT KisConfig{@@ -162,9 +163,14 @@ public:Depth10Bit};+ static CanvasSurfaceBitDepthMode canvasSurfaceBitDepthMode(QSettings *settings, bool defaultValue = false);+ static void setCanvasSurfaceBitDepthMode(QSettings *settings, CanvasSurfaceBitDepthMode value);+CanvasSurfaceBitDepthMode canvasSurfaceBitDepthMode(bool defaultValue = false) const;void setCanvasSurfaceBitDepthMode(CanvasSurfaceBitDepthMode value);+ CanvasSurfaceBitDepthMode effectiveCanvasSurfaceBitDepthMode(const QSurfaceFormat &format) const;+/// get the profile the user has selected for the given screenQString monitorProfile(int screen) const;void setMonitorProfile(int screen, const QString & monitorProfile, bool override) const;diff --git a/libs/ui/opengl/KisOpenGLModeProber.cpp b/libs/ui/opengl/KisOpenGLModeProber.cppindex f5154a9c92..f5d4054b2d 100644--- a/libs/ui/opengl/KisOpenGLModeProber.cpp+++ b/libs/ui/opengl/KisOpenGLModeProber.cpp@@ -215,6 +215,14 @@ KisOpenGLModeProber::probeFormat(const KisOpenGL::RendererConfig &rendererConfigreturn boost::none;}+ if (context.format().redBufferSize() != format.redBufferSize() ||+ context.format().greenBufferSize() != format.greenBufferSize() ||+ context.format().blueBufferSize() != format.blueBufferSize()) {++ dbgOpenGL << "Failed to create an OpenGL context with requested bit depth. Requested:" << format.redBufferSize() << "Actual:" << context.format().redBufferSize();+ return boost::none;+ }+Result result(context);dbgOpenGL << "Probe returned" << result.rendererString() << result.driverVersionString() << result.isOpenGLES();@@ -231,18 +239,23 @@ bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const KisSurfaceColorSpaceWraprhs == KisSurfaceColorSpaceWrapper::sRGBColorSpace));}-void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,+void KisOpenGLModeProber::initSurfaceFormatFromConfig(std::pair<KisSurfaceColorSpaceWrapper, int> rootSurfaceFormat,QSurfaceFormat *format){-#ifdef HAVE_HDR- if (config == KisConfig::BT2020_PQ) {+if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {+ KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 10);+}+#ifdef HAVE_HDR+ if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {+ KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 10);format->setRedBufferSize(10);format->setGreenBufferSize(10);format->setBlueBufferSize(10);format->setAlphaBufferSize(2);format->setColorSpace(KisSurfaceColorSpaceWrapper(KisSurfaceColorSpaceWrapper::bt2020PQColorSpace));- } else if (config == KisConfig::BT709_G10) {+ } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {+ KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 16);format->setRedBufferSize(16);format->setGreenBufferSize(16);format->setBlueBufferSize(16);@@ -250,14 +263,26 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormformat->setColorSpace(KisSurfaceColorSpaceWrapper(KisSurfaceColorSpaceWrapper::scRGBColorSpace));} else#else- if (config == KisConfig::BT2020_PQ) {+ if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {qWarning() << "WARNING: Bt.2020 PQ surface type is not supported by this build of Krita";- } else if (config == KisConfig::BT709_G10) {+ rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;+ } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {qWarning() << "WARNING: scRGB surface type is not supported by this build of Krita";+ rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;}#endif- {+ KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::DefaultColorSpace);+ KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8 || rootSurfaceFormat.second == 10);++ if (rootSurfaceFormat.second == 10) {+ format->setRedBufferSize(10);+ format->setGreenBufferSize(10);+ format->setBlueBufferSize(10);+ format->setAlphaBufferSize(2);+ // TODO: check if we can use real sRGB space here+ format->setColorSpace(KisSurfaceColorSpaceWrapper());+ } else {format->setRedBufferSize(8);format->setGreenBufferSize(8);format->setBlueBufferSize(8);diff --git a/libs/ui/opengl/KisOpenGLModeProber.h b/libs/ui/opengl/KisOpenGLModeProber.hindex a428eeb1ca..e2363a9315 100644--- a/libs/ui/opengl/KisOpenGLModeProber.h+++ b/libs/ui/opengl/KisOpenGLModeProber.h@@ -41,7 +41,7 @@ public:static QString angleRendererToString(KisOpenGL::AngleRenderer renderer);public:- static void initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,+ static void initSurfaceFormatFromConfig(std::pair<KisSurfaceColorSpaceWrapper, int> rootSurfaceFormat,QSurfaceFormat *format);static bool isFormatHDR(const QSurfaceFormat &format);};diff --git a/libs/ui/opengl/kis_opengl.cpp b/libs/ui/opengl/kis_opengl.cppindex 51fe231633..448a9ac922 100644--- a/libs/ui/opengl/kis_opengl.cpp+++ b/libs/ui/opengl/kis_opengl.cpp@@ -42,6 +42,7 @@#include "opengl/kis_opengl.h"#include <config-hdr.h>+#include <config-use-surface-color-management-api.h>#ifndef GL_RENDERER# define GL_RENDERER 0x1F01@@ -405,7 +406,7 @@ bool KisOpenGL::needsFenceWorkaround()void KisOpenGL::testingInitializeDefaultSurfaceFormat(){- setDefaultSurfaceConfig(selectSurfaceConfig(KisOpenGL::RendererAuto, KisConfig::BT709_G22, false));+ setDefaultSurfaceConfig(selectSurfaceConfig(KisOpenGL::RendererAuto, KisConfig::BT709_G22, KisConfig::CanvasSurfaceBitDepthMode::DepthAuto, false));}void KisOpenGL::setDebugSynchronous(bool value)@@ -576,7 +577,7 @@ QOpenGLContext::OpenGLModuleType determineOpenGLImplementation(const RendererInf}KisOpenGL::RendererConfig generateSurfaceConfig(KisOpenGL::OpenGLRenderer renderer,- KisConfig::RootSurfaceFormat rootSurfaceFormat,+ std::pair<KisSurfaceColorSpaceWrapper, int> rootSurfaceFormat,bool debugContext){RendererInfo info = getRendererInfo(renderer);@@ -753,6 +754,9 @@ public:ORDER_BY(lhs.rendererId() == m_preferredRendererByQt,rhs.rendererId() == m_preferredRendererByQt);+ ORDER_BY(lhs.format.redBufferSize() == m_userPreferredBitDepth,+ rhs.format.redBufferSize() == m_userPreferredBitDepth);+return false;}@@ -782,6 +786,10 @@ public:m_openGLESBlacklisted = openGLESBlacklisted;}+ void setUserPreferredBitDepth(int value) {+ m_userPreferredBitDepth = value;+ }+bool isOpenGLBlacklisted() const {return m_openGLBlacklisted;}@@ -798,6 +806,10 @@ public:return m_preferredRendererByUser;}+ int userPreferredBitDepth() const {+ return m_userPreferredBitDepth;+ }+private:bool isHDRFormat(const QSurfaceFormat &f) const {#ifdef HAVE_HDR@@ -847,6 +859,7 @@ private:KisOpenGL::OpenGLRenderer m_preferredRendererByHDR = KisOpenGL::RendererAuto;bool m_openGLBlacklisted = false;bool m_openGLESBlacklisted = false;+ int m_userPreferredBitDepth = 8;};struct DetectionDebug : public QDebug@@ -867,6 +880,7 @@ struct DetectionDebug : public QDebugKisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRenderer preferredRenderer,KisConfig::RootSurfaceFormat preferredRootSurfaceFormat,+ KisConfig::CanvasSurfaceBitDepthMode preferredCanvasSurfaceBitMode,bool enableDebug){QVector<KLocalizedString> warningMessages;@@ -883,15 +897,33 @@ KisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRenderrenderersToTest.insert(RendererSoftware, Info());#endif+ auto makeDefaultSurfaceFormatPair = [] () -> std::pair<KisSurfaceColorSpaceWrapper, int> {+ return {KisSurfaceColorSpaceWrapper::DefaultColorSpace, 8};+ };-#ifdef HAVE_HDR- QVector<KisConfig::RootSurfaceFormat> formatSymbols({KisConfig::BT709_G22, KisConfig::BT709_G10, KisConfig::BT2020_PQ});+#if defined HAVE_HDR+ std::vector<std::pair<KisSurfaceColorSpaceWrapper, int>> formatSymbolPairs(+ {+ // TODO: check if we can use real sRGB space here+ {KisSurfaceColorSpaceWrapper::DefaultColorSpace, 8},+ {KisSurfaceColorSpaceWrapper::scRGBColorSpace, 16},+ {KisSurfaceColorSpaceWrapper::bt2020PQColorSpace, 10}+ });+#elif KRITA_USE_SURFACE_COLOR_MANAGEMENT_API+ std::vector<std::pair<KisSurfaceColorSpaceWrapper, int>> formatSymbolPairs(+ {+ {KisSurfaceColorSpaceWrapper::DefaultColorSpace, 8},+ {KisSurfaceColorSpaceWrapper::DefaultColorSpace, 10},+ });#else- QVector<KisConfig::RootSurfaceFormat> formatSymbols({KisConfig::BT709_G22});+ std::vector<std::pair<KisSurfaceColorSpaceWrapper, int>> formatSymbolPairs(+ {+ {KisSurfaceColorSpaceWrapper::DefaultColorSpace, 8},+ });#endifKisOpenGL::RendererConfig defaultConfig = generateSurfaceConfig(KisOpenGL::RendererAuto,- KisConfig::BT709_G22, false);+ makeDefaultSurfaceFormatPair(), false);Info info = KisOpenGLModeProber::instance()->probeFormat(defaultConfig);#ifdef Q_OS_WIN@@ -941,6 +973,12 @@ KisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRendercompareOp.setPreferredRendererByUser(preferredRenderer);compareOp.setOpenGLESBlacklisted(false); // We cannot blacklist ES drivers atm+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API+ // 10-bit is the default, 8-bit is set explicitly by the user+ compareOp.setUserPreferredBitDepth(preferredCanvasSurfaceBitMode == KisConfig::CanvasSurfaceBitDepthMode::Depth8Bit ? 8 : 10);+#else+ Q_UNUSED(preferredCanvasSurfaceBitMode)+#endifrenderersToTest[defaultRenderer] = info;@@ -948,7 +986,7 @@ KisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRenderInfo info = it.value();if (!info) {- const RendererConfig config = generateSurfaceConfig(it.key(), KisConfig::BT709_G22, false);+ const RendererConfig config = generateSurfaceConfig(it.key(), makeDefaultSurfaceFormatPair(), false);dbgOpenGL << "Probing" << it.key() << "from default:" << config.format << config.angleRenderer<< config.rendererId();info = KisOpenGLModeProber::instance()->probeFormat(config);@@ -999,8 +1037,8 @@ KisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRender// if default mode of the renderer doesn't work, then custom won't eitherif (!it.value()) continue;- Q_FOREACH (const KisConfig::RootSurfaceFormat formatSymbol, formatSymbols) {- preferredConfigs << generateSurfaceConfig(it.key(), formatSymbol, enableDebug);+ Q_FOREACH (const auto &formatPair, formatSymbolPairs) {+ preferredConfigs << generateSurfaceConfig(it.key(), formatPair, enableDebug);}}diff --git a/libs/ui/opengl/kis_opengl.h b/libs/ui/opengl/kis_opengl.hindex bb03e46c1c..7705ca8210 100644--- a/libs/ui/opengl/kis_opengl.h+++ b/libs/ui/opengl/kis_opengl.h@@ -63,6 +63,7 @@ public:public:static RendererConfig selectSurfaceConfig(KisOpenGL::OpenGLRenderer preferredRenderer,KisConfig::RootSurfaceFormat preferredRootSurfaceFormat,+ KisConfig::CanvasSurfaceBitDepthMode preferredCanvasSurfaceBitMode,bool enableDebug);static void setDefaultSurfaceConfig(const RendererConfig &config);diff --git a/libs/ui/opengl/kis_opengl_canvas2.cpp b/libs/ui/opengl/kis_opengl_canvas2.cppindex 763f24486c..c988ba26fd 100644--- a/libs/ui/opengl/kis_opengl_canvas2.cpp+++ b/libs/ui/opengl/kis_opengl_canvas2.cpp@@ -7,6 +7,8 @@#define GL_GLEXT_PROTOTYPES+#include <QWindow>+#include "opengl/kis_opengl_canvas2.h"#include "opengl/KisOpenGLCanvasRenderer.h"#include "opengl/KisOpenGLSync.h"@@ -76,27 +78,6 @@ public:KisRepaintDebugger repaintDbg;};-KisOpenGLCanvas2::BitDepthMode-KisOpenGLCanvas2::bitDepthForUserSetting(KisConfig::CanvasSurfaceMode surfaceMode,- KisConfig::CanvasSurfaceBitDepthMode bitDepthMode,- bool surfaceIsHDR)-{- switch (bitDepthMode) {- case KisConfig::CanvasSurfaceBitDepthMode::DepthAuto:-if (surfaceMode == KisConfig::CanvasSurfaceMode::Preferred) {- return surfaceIsHDR ? BitDepthMode::Depth10Bit : BitDepthMode::Depth8Bit;-} else {- return BitDepthMode::Depth8Bit;- }- case KisConfig::CanvasSurfaceBitDepthMode::Depth8Bit:- return BitDepthMode::Depth8Bit;- case KisConfig::CanvasSurfaceBitDepthMode::Depth10Bit:- return BitDepthMode::Depth10Bit;- }-- Q_UNREACHABLE_RETURN(BitDepthMode::Depth8Bit);-}-KisOpenGLCanvas2::KisOpenGLCanvas2(KisCanvas2 *canvas,KisCoordinatesConverter *coordinatesConverter,QWidget *parent,@@ -150,28 +131,28 @@ KisOpenGLCanvas2::KisOpenGLCanvas2(KisCanvas2 *canvas,setTextureFormat(GL_RGBA16F);} else {if (bitDepthRequest == BitDepthMode::Depth10Bit) {- QSurfaceFormat format = QSurfaceFormat::defaultFormat();- format.setRedBufferSize(10);- format.setGreenBufferSize(10);- format.setBlueBufferSize(10);- format.setAlphaBufferSize(2);- setFormat(format);+ if (QSurfaceFormat::defaultFormat().redBufferSize() < 10) {+ warnOpenGL <<+ "WARNING: KisOpenGLCanvas2 was created with a 10-bit surface, "+ "while the global surface format is still set to 8-bit. Expect "+ "color banding to appear";+ }setTextureFormat(GL_RGB10_A2);} else {- /**- * When in pure OpenGL mode, the canvas surface will have alpha- * channel. Therefore, if our canvas blending algorithm produces- * semi-transparent pixels (and it does), then Krita window itself- * will become transparent. Which is not good.- *- * In Angle mode, GL_RGB8 is not available (and the transparence effect- * doesn't exist at all).- */- if (!KisOpenGL::hasOpenGLES()) {- setTextureFormat(GL_RGB8);+ /**+ * When in pure OpenGL mode, the canvas surface will have alpha+ * channel. Therefore, if our canvas blending algorithm produces+ * semi-transparent pixels (and it does), then Krita window itself+ * will become transparent. Which is not good.+ *+ * In Angle mode, GL_RGB8 is not available (and the transparence effect+ * doesn't exist at all).+ */+ if (!KisOpenGL::hasOpenGLES()) {+ setTextureFormat(GL_RGB8);+ }}}- }connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged()));connect(KisConfigNotifier::instance(), SIGNAL(pixelGridModeChanged()), SLOT(slotPixelGridModeChanged()));@@ -531,10 +512,28 @@ QString KisOpenGLCanvas2::currentBitDepthUserReport() const {}str << Qt::endl;- str << "Red Buffer Size: " << format().redBufferSize() << Qt::endl;- str << "Green Buffer Size: " << format().greenBufferSize() << Qt::endl;- str << "Blue Buffer Size: " << format().blueBufferSize() << Qt::endl;- str << "Alpha Buffer Size: " << format().alphaBufferSize() << Qt::endl;+ str << "FBO Buffer Size: "+ << "R: " << format().redBufferSize() << " "+ << "G: " << format().greenBufferSize() << " "+ << "B: " << format().blueBufferSize() << " "+ << "A: " << format().alphaBufferSize() << Qt::endl;++ QWindow *win = windowHandle();+ if (win) {+ str << "Window Buffer Size: "+ << "R: " << win->format().redBufferSize() << " "+ << "G: " << win->format().greenBufferSize() << " "+ << "B: " << win->format().blueBufferSize() << " "+ << "A: " << win->format().alphaBufferSize() << Qt::endl;+ }++ if (win) {+ str << "Global Buffer Size: "+ << "R: " << QSurfaceFormat::defaultFormat().redBufferSize() << " "+ << "G: " << QSurfaceFormat::defaultFormat().greenBufferSize() << " "+ << "B: " << QSurfaceFormat::defaultFormat().blueBufferSize() << " "+ << "A: " << QSurfaceFormat::defaultFormat().alphaBufferSize() << Qt::endl;+ }return report;}\ No newline at end of filediff --git a/libs/ui/opengl/kis_opengl_canvas2.h b/libs/ui/opengl/kis_opengl_canvas2.hindex d799213eea..93fd8da1dc 100644--- a/libs/ui/opengl/kis_opengl_canvas2.h+++ b/libs/ui/opengl/kis_opengl_canvas2.h@@ -34,11 +34,6 @@ class KRITAUI_EXPORT KisOpenGLCanvas2{Q_OBJECT-public:- static BitDepthMode bitDepthForUserSetting(KisConfig::CanvasSurfaceMode surfaceMode,- KisConfig::CanvasSurfaceBitDepthMode bitDepthMode,- bool surfaceIsHDR);-public:KisOpenGLCanvas2(KisCanvas2 *canvas,