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 KisRootSurfaceInfoProxy to get managed surface profile

Dmitry Kazakove88a0e6109af
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 6855a3aa0c..85718db743 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -658,6 +658,7 @@ if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
KisSRGBSurfaceColorSpaceManager.cpp
KisCanvasSurfaceColorSpaceManager.cpp
+ KisRootSurfaceInfoProxy.cpp
)
endif()
diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp
index a62b1ec542..fb2ce907b8 100644
--- a/libs/ui/KisMainWindow.cpp
+++ b/libs/ui/KisMainWindow.cpp
@@ -155,15 +155,6 @@
#include "KisToolBarStateModel.h"
#include <config-qmdiarea-always-show-subwindow-title.h>
-
-#include <config-use-surface-color-management-api.h>
-
-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
-
-#include <KisSRGBSurfaceColorSpaceManager.h>
-
-#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
-
#include <mutex>
class ToolDockerFactory : public KoDockFactoryBase
@@ -318,11 +309,6 @@ public:
KateCommandBar *commandBar {nullptr};
-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
- // lifetime is managed by the QObject hierarchy
- QPointer<KisSRGBSurfaceColorSpaceManager> surfaceColorSpaceManager;
-#endif
-
KisActionManager * actionManager() {
return viewManager->actionManager();
}
@@ -359,10 +345,6 @@ KisMainWindow::KisMainWindow(QUuid uuid)
: KXmlGuiWindow()
, d(new Private(this, uuid))
{
- // Krita's main window handles sRGB space itself, exclude that
- // from auto-srgb-assignment
- setProperty("krita_skip_srgb_surface_manager_assignment", true);
-
KAcceleratorManager::setNoAccel(this);
d->workspacemodel = new KisResourceModel(ResourceType::Workspaces, this);
@@ -672,16 +654,6 @@ KisMainWindow::KisMainWindow(QUuid uuid)
}
applyMainWindowSettings(d->windowStateConfig);
-
-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
- /**
- * Load platform plugin for surface color management and set
- * the surface color space to sRGB exactly
- */
-
- d->surfaceColorSpaceManager = KisSRGBSurfaceColorSpaceManager::tryCreateForCurrentPlatform(this);
-#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
-
}
KisMainWindow::~KisMainWindow()
@@ -3219,35 +3191,4 @@ bool KisMainWindow::checkPaintOpAvailable()
return (rserver->resourceCount() > 0);
}
-const KoColorProfile* KisMainWindow::managedSurfaceProfile() const
-{
-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
- return d->surfaceColorSpaceManager ? KoColorSpaceRegistry::instance()->p709SRGBProfile() : nullptr;
-#else
- return nullptr;
-#endif
-}
-
-QString KisMainWindow::colorManagementReport() const
-{
-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
- return d->surfaceColorSpaceManager ?
- d->surfaceColorSpaceManager->colorManagementReport() :
- QString("Surface color management is not supported on this platform\n");
-#else
- return "Surface color management is disabled\n";
-#endif
-}
-
-QString KisMainWindow::osPreferredColorSpaceReport() const
-{
-#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
- return d->surfaceColorSpaceManager ?
- d->surfaceColorSpaceManager->osPreferredColorSpaceReport() :
- QString("Surface color management is not supported on this platform\n");
-#else
- return "Surface color management is disabled\n";
-#endif
-}
-
#include <moc_KisMainWindow.cpp>
diff --git a/libs/ui/KisMainWindow.h b/libs/ui/KisMainWindow.h
index d4d4733d7a..d552be9906 100644
--- a/libs/ui/KisMainWindow.h
+++ b/libs/ui/KisMainWindow.h
@@ -178,36 +178,6 @@ public:
*/
QImage layoutThumbnail();
- /**
- * If Krita runs under a system that manages surface color space
- * for us, then managedSurfaceProfile() returns the profile associated
- * with the surface of the main window (and, therefore, of all its non-native
- * widgets).
- *
- * Krita will usually just select sRGB for the surface of the main
- * window, if the surface is managed. And the canvas will create its
- * own surface with the custom space. Though this behavior is a subject
- * to change in the future.
- *
- * If Krita runs in an unmanaged environment (e.g. X11 or Windows with
- * ACM disabled), then the function returns nullptr.
- */
- const KoColorProfile* managedSurfaceProfile() const;
-
- /**
- * Return user-facing information about color management status of the
- * main window surface. The information is intentionally left untranslated,
- * since it is supposed to be used for bugreports.
- */
- QString colorManagementReport() const;
-
- /**
- * Return user-facing information about the preferred color space of the
- * operating system. This information is supposed to be used in the
- * preferences dialog, so it is supposed to be translated.
- */
- QString osPreferredColorSpaceReport() const;
-
Q_SIGNALS:
/**
diff --git a/libs/ui/KisMultiSurfaceStateManager.cpp b/libs/ui/KisMultiSurfaceStateManager.cpp
index 3dd0ee74e8..3de5c3ec94 100644
--- a/libs/ui/KisMultiSurfaceStateManager.cpp
+++ b/libs/ui/KisMultiSurfaceStateManager.cpp
@@ -11,14 +11,22 @@
#include <opengl/KisOpenGLModeProber.h>
#include <KisPlatformPluginInterfaceFactory.h>
-// TODO: remove
-#include <KisMainWindow.h>
+#include <KisRootSurfaceInfoProxy.h>
-KisMultiSurfaceStateManager::KisMultiSurfaceStateManager(KisView *view)
- : m_view(view)
+
+KisMultiSurfaceStateManager::KisMultiSurfaceStateManager()
{
}
+KisMultiSurfaceStateManager::~KisMultiSurfaceStateManager()
+{
+}
+
+void KisMultiSurfaceStateManager::setRootSurfaceInfoProxy(KisRootSurfaceInfoProxy *proxy)
+{
+ m_rootSurfaceInfoProxy = proxy;
+}
+
KisMultiSurfaceStateManager::State KisMultiSurfaceStateManager::createInitializingConfig(bool isCanvasOpenGL, int screenId, KisProofingConfigurationSP proofingConfig) const
{
State state;
@@ -39,8 +47,17 @@ KisMultiSurfaceStateManager::State KisMultiSurfaceStateManager::createInitializi
multiConfig.uiProfile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
} else if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS()) {
- multiConfig.canvasProfile = this->m_view->mainWindow()->managedSurfaceProfile();
- multiConfig.uiProfile = this->m_view->mainWindow()->managedSurfaceProfile(); // TODO: updates
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ KIS_SAFE_ASSERT_RECOVER_NOOP(m_rootSurfaceInfoProxy);
+ if (m_rootSurfaceInfoProxy) {
+ multiConfig.canvasProfile = m_rootSurfaceInfoProxy->rootSurfaceProfile();
+ multiConfig.uiProfile = m_rootSurfaceInfoProxy->rootSurfaceProfile();
+ }
+#else
+ KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "managed surface mode is active, but Krita is compiled without it!");
+ multiConfig.canvasProfile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
+ multiConfig.uiProfile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
} else {
const KoColorProfile *profile = cfg.displayProfile(screenId);
KIS_SAFE_ASSERT_RECOVER(profile) {
diff --git a/libs/ui/KisMultiSurfaceStateManager.h b/libs/ui/KisMultiSurfaceStateManager.h
index d8fa5f38aa..b6a610d3e5 100644
--- a/libs/ui/KisMultiSurfaceStateManager.h
+++ b/libs/ui/KisMultiSurfaceStateManager.h
@@ -10,7 +10,16 @@
#include <KisDisplayConfig.h>
#include <KisProofingConfiguration.h>
-class KisView;
+#include <config-use-surface-color-management-api.h>
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+
+#include <QPointer>
+class KisRootSurfaceInfoProxy;
+
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
+
/**
* On some systems the canvas may have a surface format different
@@ -64,7 +73,12 @@ public:
};
public:
- KisMultiSurfaceStateManager(KisView *view);
+ KisMultiSurfaceStateManager();
+ ~KisMultiSurfaceStateManager();
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ void setRootSurfaceInfoProxy(KisRootSurfaceInfoProxy *proxy);
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
State createInitializingConfig(bool isCanvasOpenGL, int screenId, KisProofingConfigurationSP proofingConfig) const;
@@ -87,7 +101,9 @@ private:
KisDisplayConfig::Options overriddenWithProofingConfig(const KisDisplayConfig::Options &options, KisProofingConfigurationSP proofingConfig) const;
private:
- KisView *m_view { nullptr };
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ QPointer<KisRootSurfaceInfoProxy> m_rootSurfaceInfoProxy;
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
};
diff --git a/libs/ui/KisPlatformPluginInterfaceFactory.cpp b/libs/ui/KisPlatformPluginInterfaceFactory.cpp
index 68244ea16f..bc9371ff3f 100644
--- a/libs/ui/KisPlatformPluginInterfaceFactory.cpp
+++ b/libs/ui/KisPlatformPluginInterfaceFactory.cpp
@@ -17,6 +17,7 @@
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+#include <KisRootSurfaceInfoProxy.h>
#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
#include <surfacecolormanagement/KisSurfaceColorManagementInfo.h>
@@ -77,6 +78,35 @@ bool KisPlatformPluginInterfaceFactory::surfaceColorManagedByOS()
return m_surfaceColorManagedByOS;
}
+QString KisPlatformPluginInterfaceFactory::colorManagementReport(QWidget *widget)
+{
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS()) {
+ KisRootSurfaceInfoProxy proxy(widget);
+ KIS_SAFE_ASSERT_RECOVER_NOOP(proxy.isReady());
+ return proxy.colorManagementReport();
+ } else {
+ return "Surface color management is not supported on this platform\n";
+ }
+#else
+ return "Surface color management is disabled\n";
+#endif
+}
+
+QString KisPlatformPluginInterfaceFactory::osPreferredColorSpaceReport(QWidget *widget)
+{
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS()) {
+ KisRootSurfaceInfoProxy proxy(widget);
+ KIS_SAFE_ASSERT_RECOVER_NOOP(proxy.isReady());
+ return proxy.osPreferredColorSpaceReport();
+ } else {
+ return "Surface color management is not supported on this platform\n";
+ }
+#else
+ return "Surface color management is disabled\n";
+#endif
+}
KisExtendedModifiersMapperPluginInterface* KisPlatformPluginInterfaceFactory::createExtendedModifiersMapper()
diff --git a/libs/ui/KisPlatformPluginInterfaceFactory.h b/libs/ui/KisPlatformPluginInterfaceFactory.h
index ca172db74d..92b484d5c7 100644
--- a/libs/ui/KisPlatformPluginInterfaceFactory.h
+++ b/libs/ui/KisPlatformPluginInterfaceFactory.h
@@ -11,7 +11,10 @@
#include <config-use-surface-color-management-api.h>
+class QString;
+class QWidget;
class QWindow;
+
class KisSurfaceColorManagerInterface;
class KisExtendedModifiersMapperPluginInterface;
@@ -34,8 +37,28 @@ public:
KisSurfaceColorManagerInterface *createSurfaceColorManager(QWindow *nativeWindow);
#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+ /**
+ * Returns true if Krita is running on a system that manages the color
+ * space of the underlying surface. If it is true, the canvas should use
+ * KisCanvasSurfaceColorSpaceManager and all other windows should use
+ * KisSRGBSurfaceColorSpaceManager to set up the color space properly.
+ */
bool surfaceColorManagedByOS();
+ /**
+ * Return user-facing information about color management status of the
+ * main window surface. The information is intentionally left untranslated,
+ * since it is supposed to be used for bugreports.
+ */
+ QString colorManagementReport(QWidget *widget);
+
+ /**
+ * Return user-facing information about the preferred color space of the
+ * operating system. This information is supposed to be used in the
+ * preferences dialog, so it is supposed to be translated.
+ */
+ QString osPreferredColorSpaceReport(QWidget *widget);
+
/**
* Creates an instance of the extended modifiers interface using the platform plugin
*
diff --git a/libs/ui/KisRootSurfaceInfoProxy.cpp b/libs/ui/KisRootSurfaceInfoProxy.cpp
new file mode 100644
index 0000000000..69a7e0a7d5
--- /dev/null
+++ b/libs/ui/KisRootSurfaceInfoProxy.cpp
@@ -0,0 +1,210 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisRootSurfaceInfoProxy.h"
+
+#include <QTimer>
+
+#include <QEvent>
+#include <QWidget>
+#include <QWindow>
+#include <KisPlatformPluginInterfaceFactory.h>
+#include <KisSRGBSurfaceColorSpaceManager.h>
+
+
+namespace {
+class ChildChangedEventFilter : public QObject
+{
+ Q_OBJECT
+public:
+ ChildChangedEventFilter(QObject *watched, QObject *parent)
+ : QObject(parent)
+ , m_watched(watched)
+ {
+ }
+
+ bool eventFilter(QObject *watched, QEvent *event) override {
+ if (watched == m_watched &&
+ (event->type() == QEvent::ChildAdded || event->type() == QEvent::ChildRemoved)) {
+ /**
+ * Upon receiving QChildEvent, the child object is not yet
+ * fully constructed, so we need to postpone the event handling
+ * till the next event loop cycle.
+ */
+ QTimer::singleShot(0, this, &ChildChangedEventFilter::sigChildrenChanged);
+ }
+
+ return false;
+ }
+
+ QObject *m_watched {nullptr};
+
+Q_SIGNALS:
+ void sigChildrenChanged();
+};
+}
+
+KisRootSurfaceInfoProxy::KisRootSurfaceInfoProxy(QWidget *watched, QObject *parent)
+ : QObject(parent)
+ , m_watched(watched)
+{
+ KIS_SAFE_ASSERT_RECOVER_RETURN(KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS());
+ m_rootSurfaceProfile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
+ tryUpdateHierarchy();
+}
+
+KisRootSurfaceInfoProxy::~KisRootSurfaceInfoProxy()
+{
+}
+
+const KoColorProfile *KisRootSurfaceInfoProxy::rootSurfaceProfile() const
+{
+ return m_rootSurfaceProfile;
+}
+
+bool KisRootSurfaceInfoProxy::isReady() const
+{
+ return m_topLevelSurfaceManager && m_topLevelSurfaceManager->isReady();
+}
+
+QString KisRootSurfaceInfoProxy::colorManagementReport() const
+{
+ return m_topLevelSurfaceManager ? m_topLevelSurfaceManager->colorManagementReport()
+ : QString("Top level surface color manager is not found!\n");
+}
+
+QString KisRootSurfaceInfoProxy::osPreferredColorSpaceReport() const
+{
+ return m_topLevelSurfaceManager ? m_topLevelSurfaceManager->osPreferredColorSpaceReport()
+ : QString("Top level surface color manager is not found!\n");
+}
+
+bool KisRootSurfaceInfoProxy::eventFilter(QObject *watched, QEvent *event)
+{
+ if (event->type() == QEvent::ParentChange && m_watchedHierarchy.contains(watched)) {
+ tryUpdateHierarchy();
+ }
+
+ if (event->type() == QEvent::PlatformSurface && watched == m_watchedHierarchy.last().data()) {
+ tryReconnectSurfaceManager();
+ }
+
+ return false;
+}
+
+void KisRootSurfaceInfoProxy::tryUpdateHierarchy()
+{
+ auto newHierarchy = getCurrentHierarchy(m_watched);
+ if (newHierarchy != m_watchedHierarchy) {
+ reconnectToHierarchy(newHierarchy);
+ QWidget *topLevel = static_cast<QWidget *>(newHierarchy.last().data());
+ if (topLevel != m_topLevelWidgetWithSurface) {
+ m_topLevelWidgetWithSurface = topLevel;
+ tryReconnectSurfaceManager();
+ }
+ }
+}
+
+void KisRootSurfaceInfoProxy::tryReconnectSurfaceManager()
+{
+ auto disconnectExistingManager = [this]() {
+ m_topLevelSurfaceManager.clear();
+ if (m_surfaceManagerConnection) {
+ disconnect(m_surfaceManagerConnection);
+ }
+ };
+
+ if (!m_topLevelWidgetWithSurface) {
+ disconnectExistingManager();
+ tryUpdateRootSurfaceProfile();
+ return;
+ }
+
+ QWindow *nativeWindow = m_topLevelWidgetWithSurface->windowHandle();
+
+ if (nativeWindow != m_topLevelNativeWindow) {
+ if (m_childChangedFilter && m_topLevelNativeWindow) {
+ m_topLevelNativeWindow->removeEventFilter(m_childChangedFilter);
+ m_childChangedFilter->deleteLater();
+ m_childChangedFilter.clear();
+ }
+
+ m_topLevelNativeWindow = nativeWindow;
+
+ if (m_topLevelNativeWindow) {
+ auto *filter = new ChildChangedEventFilter(m_topLevelNativeWindow, m_topLevelNativeWindow);
+ connect(filter,
+ &ChildChangedEventFilter::sigChildrenChanged,
+ this,
+ &KisRootSurfaceInfoProxy::tryReconnectSurfaceManager);
+ m_childChangedFilter = filter;
+ m_topLevelNativeWindow->installEventFilter(m_childChangedFilter);
+ }
+ }
+
+ if (nativeWindow) {
+ if (auto manager = nativeWindow->findChild<KisSRGBSurfaceColorSpaceManager *>()) {
+ if (manager != m_topLevelSurfaceManager) {
+ disconnectExistingManager();
+ m_topLevelSurfaceManager = manager;
+ m_surfaceManagerConnection = connect(m_topLevelSurfaceManager,
+ &KisSRGBSurfaceColorSpaceManager::sigDisplayConfigChanged,
+ this,
+ &KisRootSurfaceInfoProxy::tryUpdateRootSurfaceProfile);
+ tryUpdateRootSurfaceProfile();
+ }
+ }
+ } else {
+ disconnectExistingManager();
+ tryUpdateRootSurfaceProfile();
+ }
+}
+
+void KisRootSurfaceInfoProxy::tryUpdateRootSurfaceProfile()
+{
+ const KoColorProfile *newProfile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
+
+ if (m_topLevelSurfaceManager) {
+ newProfile = m_topLevelSurfaceManager->displayConfig().profile;
+ }
+
+ KIS_SAFE_ASSERT_RECOVER_RETURN(newProfile);
+
+ if (newProfile != m_rootSurfaceProfile) {
+ m_rootSurfaceProfile = newProfile;
+ Q_EMIT sigRootSurfaceProfileChanged(m_rootSurfaceProfile);
+ }
+}
+
+QVector<QPointer<QObject>> KisRootSurfaceInfoProxy::getCurrentHierarchy(QWidget *wdg)
+{
+ QVector<QPointer<QObject>> result;
+
+ while (wdg) {
+ result.append(wdg);
+ wdg = wdg->parentWidget();
+ }
+
+ return result;
+}
+
+void KisRootSurfaceInfoProxy::reconnectToHierarchy(const QVector<QPointer<QObject>> newHierarchy)
+{
+ Q_FOREACH (QPointer<QObject> widget, m_watchedHierarchy) {
+ KIS_SAFE_ASSERT_RECOVER(widget) continue;
+ widget->removeEventFilter(this);
+ }
+
+ m_watchedHierarchy.clear();
+
+ Q_FOREACH (QPointer<QObject> widget, newHierarchy) {
+ widget->installEventFilter(this);
+ }
+
+ m_watchedHierarchy = newHierarchy;
+}
+
+#include <KisRootSurfaceInfoProxy.moc>
\ No newline at end of file
diff --git a/libs/ui/KisRootSurfaceInfoProxy.h b/libs/ui/KisRootSurfaceInfoProxy.h
new file mode 100644
index 0000000000..5238f62425
--- /dev/null
+++ b/libs/ui/KisRootSurfaceInfoProxy.h
@@ -0,0 +1,63 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISROOTSURFACEINFOPROXY_H
+#define KISROOTSURFACEINFOPROXY_H
+
+#include <kritaui_export.h>
+
+#include <QObject>
+#include <QPointer>
+
+class KisSRGBSurfaceColorSpaceManager;
+class QWidget;
+class QWindow;
+class QEvent;
+class KoColorProfile;
+
+class KRITAUI_EXPORT KisRootSurfaceInfoProxy : public QObject
+{
+ Q_OBJECT
+public:
+ KisRootSurfaceInfoProxy(QWidget *watched, QObject *parent = nullptr);
+ ~KisRootSurfaceInfoProxy();
+ const KoColorProfile* rootSurfaceProfile() const;
+ bool isReady() const;
+
+ QString colorManagementReport() const;
+ QString osPreferredColorSpaceReport() const;
+
+Q_SIGNALS:
+ void sigRootSurfaceProfileChanged(const KoColorProfile *profile) const;
+
+private:
+
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
+ void tryUpdateHierarchy();
+ void tryReconnectSurfaceManager();
+ void tryUpdateRootSurfaceProfile();
+
+ QVector<QPointer<QObject>> getCurrentHierarchy(QWidget *wdg);
+
+ void reconnectToHierarchy(const QVector<QPointer<QObject>> newHierarchy);
+
+private:
+ QWidget *m_watched {nullptr};
+ QVector<QPointer<QObject>> m_watchedHierarchy;
+
+ QPointer<QWidget> m_topLevelWidgetWithSurface;
+
+ QPointer<QWindow> m_topLevelNativeWindow;
+ QPointer<QObject> m_childChangedFilter;
+
+ QPointer<KisSRGBSurfaceColorSpaceManager> m_topLevelSurfaceManager;
+ QMetaObject::Connection m_surfaceManagerConnection;
+
+ const KoColorProfile* m_rootSurfaceProfile {nullptr};
+
+};
+
+#endif /* KISROOTSURFACEINFOPROXY_H */
diff --git a/libs/ui/KisSRGBSurfaceColorSpaceManager.h b/libs/ui/KisSRGBSurfaceColorSpaceManager.h
index 5a8ad503eb..d2c649468c 100644
--- a/libs/ui/KisSRGBSurfaceColorSpaceManager.h
+++ b/libs/ui/KisSRGBSurfaceColorSpaceManager.h
@@ -9,7 +9,7 @@
#include <KisCanvasSurfaceColorSpaceManager.h>
-class KisSRGBSurfaceColorSpaceManager : public KisCanvasSurfaceColorSpaceManager
+class KRITAUI_EXPORT KisSRGBSurfaceColorSpaceManager : public KisCanvasSurfaceColorSpaceManager
{
Q_OBJECT
public:
diff --git a/libs/ui/canvas/kis_canvas2.cpp b/libs/ui/canvas/kis_canvas2.cpp
index 2784275ab3..879c12399e 100644
--- a/libs/ui/canvas/kis_canvas2.cpp
+++ b/libs/ui/canvas/kis_canvas2.cpp
@@ -101,6 +101,7 @@
#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
#include <KisCanvasSurfaceColorSpaceManager.h>
#include <KisPlatformPluginInterfaceFactory.h>
+#include <KisRootSurfaceInfoProxy.h>
#endif
@@ -134,8 +135,10 @@ class Q_DECL_HIDDEN KisCanvas2::KisCanvas2Private
}; // class CanvasInputActionGroupsMask
public:
-
- KisCanvas2Private(KisCanvas2 *parent, KisCoordinatesConverter* coordConverter, QPointer<KisView> view, KoCanvasResourceProvider* resourceManager)
+ KisCanvas2Private(KisCanvas2 *parent,
+ KisCoordinatesConverter *coordConverter,
+ QPointer<KisView> view,
+ KoCanvasResourceProvider *resourceManager)
: q(parent)
, coordinatesConverter(coordConverter)
, view(view)
@@ -147,8 +150,22 @@ public:
, inputActionGroupsMaskInterface(new CanvasInputActionGroupsMaskInterface(this))
, regionOfInterestUpdateCompressor(100, KisSignalCompressor::FIRST_INACTIVE)
, referencesBoundsUpdateCompressor(100, KisSignalCompressor::FIRST_INACTIVE)
- , multiSurfaceSetupManager(view)
{
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS()) {
+ rootSurfaceInfoProxy = new KisRootSurfaceInfoProxy(view, q);
+ multiSurfaceSetupManager.setRootSurfaceInfoProxy(rootSurfaceInfoProxy);
+ connect(rootSurfaceInfoProxy,
+ &KisRootSurfaceInfoProxy::sigRootSurfaceProfileChanged,
+ parent,
+ [this](const KoColorProfile *profile) {
+ if (!multiSurfaceState)
+ return;
+ auto newState = multiSurfaceSetupManager.onGuiSurfaceFormatChanged(*multiSurfaceState, profile);
+ assignChangedMultiSurfaceState(newState);
+ });
+ }
+#endif
}
~KisCanvas2Private()
@@ -208,11 +225,13 @@ public:
QRect renderingLimit;
int isBatchUpdateActive = 0;
- KisMultiSurfaceStateManager multiSurfaceSetupManager;
- std::optional<KisMultiSurfaceStateManager::State> multiSurfaceState;
+
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
QScopedPointer<KisCanvasSurfaceColorSpaceManager> surfaceColorManager;
+ KisRootSurfaceInfoProxy *rootSurfaceInfoProxy;
#endif
+ KisMultiSurfaceStateManager multiSurfaceSetupManager;
+ std::optional<KisMultiSurfaceStateManager::State> multiSurfaceState;
bool effectiveLodAllowedInImage() const {
return lodPreferredInImage && !bootstrapLodBlocked;
@@ -1364,9 +1383,6 @@ void KisCanvas2::slotConfigChanged()
QWidget *topLevelWidget = mainWindow->topLevelWidget();
KIS_SAFE_ASSERT_RECOVER_RETURN(topLevelWidget);
- auto options = KisDisplayConfig::optionsFromKisConfig(cfg);
- ENTER_FUNCTION() << ppVar(options);
-
KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->multiSurfaceState);
auto newState = m_d->multiSurfaceSetupManager.onConfigChanged(*m_d->multiSurfaceState,
m_d->currentScreenId(),
diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc
index d9e8ea4abb..2f0fca3b70 100644
--- a/libs/ui/dialogs/kis_dlg_preferences.cc
+++ b/libs/ui/dialogs/kis_dlg_preferences.cc
@@ -1237,7 +1237,7 @@ ColorSettingsTab::ColorSettingsTab(QWidget *parent, const char *name)
vboxLayout->addItem(new QSpacerItem(20,20));
KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow();
- QLabel *preferredLbl = new QLabel(i18n("Color space preferred by the operating system:\n%1", mainWindow->osPreferredColorSpaceReport()), this);
+ QLabel *preferredLbl = new QLabel(i18n("Color space preferred by the operating system:\n%1", KisPlatformPluginInterfaceFactory::instance()->osPreferredColorSpaceReport(mainWindow)), this);
vboxLayout->addWidget(preferredLbl);
m_chkEnableCanvasColorSpaceManagement->setChecked(cfg.enableCanvasSurfaceColorSpaceManagement());
diff --git a/plugins/dockers/smallcolorselector/kis_small_color_widget.cc b/plugins/dockers/smallcolorselector/kis_small_color_widget.cc
index d905a26b16..bb2da7776d 100644
--- a/plugins/dockers/smallcolorselector/kis_small_color_widget.cc
+++ b/plugins/dockers/smallcolorselector/kis_small_color_widget.cc
@@ -33,6 +33,7 @@
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
#include <KisPlatformPluginInterfaceFactory.h>
+#include <KisRootSurfaceInfoProxy.h>
#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
@@ -57,6 +58,10 @@ struct KisSmallColorWidget::Private {
bool hasHDR = false;
bool hasHardwareHDR = false;
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ KisRootSurfaceInfoProxy *rootSurfaceInfoProxy = nullptr;
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
qreal effectiveRelativeDynamicRange() const {
return hasHDR ? currentRelativeDynamicRange : 1.0;
}
@@ -68,8 +73,8 @@ struct KisSmallColorWidget::Private {
profile = KisOpenGLModeProber::instance()->rootSurfaceColorProfile();
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
} else if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS()) {
- // TODO: actually fetch from the main window
- profile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(rootSurfaceInfoProxy, profile);
+ profile = rootSurfaceInfoProxy->rootSurfaceProfile();
#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
} else {
// we are a normal QWidget's surface
@@ -164,6 +169,9 @@ KisSmallColorWidget::KisSmallColorWidget(QWidget* parent)
* If the platform is managed, then it can potentially be HDR
*/
d->hasHardwareHDR = true;
+ d->rootSurfaceInfoProxy = new KisRootSurfaceInfoProxy(this, this);
+ connect(d->rootSurfaceInfoProxy, &KisRootSurfaceInfoProxy::sigRootSurfaceProfileChanged,
+ this, &KisSmallColorWidget::slotDisplayConfigurationChanged);
}
#endif
diff --git a/plugins/extensions/buginfo/DlgColorManagementInfo.cpp b/plugins/extensions/buginfo/DlgColorManagementInfo.cpp
index 265ebfeb70..a44145c674 100644
--- a/plugins/extensions/buginfo/DlgColorManagementInfo.cpp
+++ b/plugins/extensions/buginfo/DlgColorManagementInfo.cpp
@@ -67,6 +67,15 @@ QString DlgColorManagementInfo::replacementWarningText()
#include <KisViewManager.h>
#include <KisDocument.h>
#include <kis_canvas2.h>
+#include <KisPlatformPluginInterfaceFactory.h>
+
+#include <config-use-surface-color-management-api.h>
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+
+#include <KisRootSurfaceInfoProxy.h>
+
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
QString DlgColorManagementInfo::infoText(QSettings& kritarc)
{
@@ -84,7 +93,7 @@ QString DlgColorManagementInfo::infoText(QSettings& kritarc)
s << "Native window handle:" << mainWindow->windowHandle() << Qt::endl;
s << Qt::endl;
- s.noquote().nospace() << mainWindow->colorManagementReport();
+ s.noquote().nospace() << KisPlatformPluginInterfaceFactory::instance()->colorManagementReport(mainWindow);
s.space().quote();
s << Qt::endl;
@@ -99,7 +108,7 @@ QString DlgColorManagementInfo::infoText(QSettings& kritarc)
s << "Native window handle:" << canvas->canvasWidget()->windowHandle() << Qt::endl;
- if (mainWindow->managedSurfaceProfile() &&
+ if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS() &&
canvas->canvasWidget()->windowHandle() == mainWindow->windowHandle()) {
s << "WARNING: the canvas shares the surface with the main window on a platform with managed surface color space!";