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 plugin interface with info about color management

Dmitry Kazakov94928cfc419e
diff --git a/libs/surfacecolormanagementapi/CMakeLists.txt b/libs/surfacecolormanagementapi/CMakeLists.txt
index 74dca3c188..70260aba86 100644
--- a/libs/surfacecolormanagementapi/CMakeLists.txt
+++ b/libs/surfacecolormanagementapi/CMakeLists.txt
@@ -4,6 +4,7 @@ set(kritasurfacecolormanagementapi_LIB_SRCS
surfacecolormanagement/KisSurfaceColorimetry.cpp
surfacecolormanagement/KisSurfaceColorimetryIccUtils.cpp
surfacecolormanagement/KisSurfaceColorManagerInterface.cpp
+ surfacecolormanagement/KisSurfaceColorManagementInfo.cpp
)
kis_add_library(kritasurfacecolormanagementapi SHARED ${kritasurfacecolormanagementapi_LIB_SRCS})
diff --git a/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagementInfo.cpp b/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagementInfo.cpp
new file mode 100644
index 0000000000..13031c1bb6
--- /dev/null
+++ b/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagementInfo.cpp
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisSurfaceColorManagementInfo.h"
+
+KisSurfaceColorManagementInfo::KisSurfaceColorManagementInfo(QObject *parent)
+ : QObject(parent)
+{
+}
+
+KisSurfaceColorManagementInfo::~KisSurfaceColorManagementInfo()
+{
+}
+
+#include <moc_KisSurfaceColorManagementInfo.cpp>
\ No newline at end of file
diff --git a/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagementInfo.h b/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagementInfo.h
new file mode 100644
index 0000000000..6254409275
--- /dev/null
+++ b/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagementInfo.h
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISSURFACECOLORMANAGEMENTINFO_H
+#define KISSURFACECOLORMANAGEMENTINFO_H
+
+#include <kritasurfacecolormanagementapi_export.h>
+
+#include <QObject>
+
+class KRITASURFACECOLORMANAGEMENTAPI_EXPORT KisSurfaceColorManagementInfo : public QObject
+{
+ Q_OBJECT
+public:
+ KisSurfaceColorManagementInfo(QObject *parent = nullptr);
+ virtual ~KisSurfaceColorManagementInfo();
+
+ /**
+ * If returns true, then KisSurfaceColorManagerInterface must
+ * be implemented by the plugin and all the surfaces's color
+ * space should be managed by OS.
+ */
+ virtual bool surfaceColorManagedByOS() = 0;
+};
+
+#endif /* KISSURFACECOLORMANAGEMENTINFO_H */
\ No newline at end of file
diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp
index c65d2165cb..c12174cd95 100644
--- a/libs/ui/KisApplication.cpp
+++ b/libs/ui/KisApplication.cpp
@@ -270,7 +270,7 @@ KisApplication::KisApplication(const QString &key, int &argc, char **argv)
* Load platform plugin for modifiers fetching
*/
{
- d->extendedModifiersPluginInterface.reset(KisPlatformPluginInterfaceFactory::createExtendedModifiersMapper());
+ d->extendedModifiersPluginInterface.reset(KisPlatformPluginInterfaceFactory::instance()->createExtendedModifiersMapper());
}
// store the style name
diff --git a/libs/ui/KisPlatformPluginInterfaceFactory.cpp b/libs/ui/KisPlatformPluginInterfaceFactory.cpp
index 53f42d2269..61ef836806 100644
--- a/libs/ui/KisPlatformPluginInterfaceFactory.cpp
+++ b/libs/ui/KisPlatformPluginInterfaceFactory.cpp
@@ -18,6 +18,40 @@
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+#include <surfacecolormanagement/KisSurfaceColorManagementInfo.h>
+
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
+Q_GLOBAL_STATIC(KisPlatformPluginInterfaceFactory, s_instance)
+
+KisPlatformPluginInterfaceFactory::KisPlatformPluginInterfaceFactory()
+{
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+
+ auto fetchSurfaceColorManagedByOS = []() {
+ KPluginFactory *factory = KoPluginLoader::instance()->loadSinglePlugin(
+ std::make_pair("X-Krita-PlatformId", QApplication::platformName()),
+ "Krita/PlatformPlugin");
+
+ if (factory) {
+ auto interface = factory->create<KisSurfaceColorManagementInfo>();
+ return interface && interface->surfaceColorManagedByOS();
+ }
+
+ return false;
+ };
+
+ m_surfaceColorManagedByOS = fetchSurfaceColorManagedByOS();
+
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+}
+
+KisPlatformPluginInterfaceFactory* KisPlatformPluginInterfaceFactory::instance()
+{
+ return s_instance;
+}
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
KisSurfaceColorManagerInterface* KisPlatformPluginInterfaceFactory::createSurfaceColorManager(QWindow *nativeWindow)
{
@@ -36,6 +70,11 @@ KisSurfaceColorManagerInterface* KisPlatformPluginInterfaceFactory::createSurfac
return nullptr;
}
+bool KisPlatformPluginInterfaceFactory::surfaceColorManagedByOS()
+{
+ return m_surfaceColorManagedByOS;
+}
+
#endif
KisExtendedModifiersMapperPluginInterface* KisPlatformPluginInterfaceFactory::createExtendedModifiersMapper()
diff --git a/libs/ui/KisPlatformPluginInterfaceFactory.h b/libs/ui/KisPlatformPluginInterfaceFactory.h
index 83afc4141a..e2f9924c27 100644
--- a/libs/ui/KisPlatformPluginInterfaceFactory.h
+++ b/libs/ui/KisPlatformPluginInterfaceFactory.h
@@ -15,23 +15,38 @@ class QWindow;
class KisSurfaceColorManagerInterface;
class KisExtendedModifiersMapperPluginInterface;
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+class KisSurfaceColorManagementInfo;
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
class KRITAUI_EXPORT KisPlatformPluginInterfaceFactory {
public:
+ KisPlatformPluginInterfaceFactory();
+
+ static KisPlatformPluginInterfaceFactory* instance();
+
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
/**
* Creates an instance of the color manager interface using the platform plugin
*
* If the current platform plugin doesn't profide this interface, returns nullptr
*/
- static KisSurfaceColorManagerInterface* createSurfaceColorManager(QWindow *nativeWindow);
-#endif
+ KisSurfaceColorManagerInterface *createSurfaceColorManager(QWindow *nativeWindow);
+
+ bool surfaceColorManagedByOS();
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
/**
* Creates an instance of the extended modifiers interface using the platform plugin
*
* If the current platform plugin doesn't profide this interface, returns nullptr
*/
- static KisExtendedModifiersMapperPluginInterface* createExtendedModifiersMapper();
+ KisExtendedModifiersMapperPluginInterface* createExtendedModifiersMapper();
+
+private:
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ bool m_surfaceColorManagedByOS {false};
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
};
#endif // KISPLATFORMPLUGININTERFACEFACTORY_H
diff --git a/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp b/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp
index 5b7471f861..8932ae3703 100644
--- a/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp
+++ b/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp
@@ -184,7 +184,7 @@ KisSRGBSurfaceColorSpaceManager* KisSRGBSurfaceColorSpaceManager::tryCreateForCu
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(widget->windowHandle(), nullptr);
std::unique_ptr<KisSurfaceColorManagerInterface> iface(
- KisPlatformPluginInterfaceFactory::createSurfaceColorManager(widget->windowHandle()));
+ KisPlatformPluginInterfaceFactory::instance()->createSurfaceColorManager(widget->windowHandle()));
if (iface) {
return new KisSRGBSurfaceColorSpaceManager(iface.release(), nativeWindow);
diff --git a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
index 6af0c4d5bc..c215abb7e0 100644
--- a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
+++ b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
@@ -16,6 +16,7 @@
#include <waylandcolormanagement/KisWaylandSurfaceColorManager.h>
#include <waylandcolormanagement/KisWaylandOutputColorInfo.h>
+#include <surfacecolormanagement/KisSurfaceColorManagementInfo.h>
#include <QWindow>
@@ -35,6 +36,15 @@ public:
} // namespace detail
+class KisWaylandSurfaceColorManagementInfo : public KisSurfaceColorManagementInfo
+{
+public:
+ using KisSurfaceColorManagementInfo::KisSurfaceColorManagementInfo;
+ bool surfaceColorManagedByOS() override {
+ return true;
+ }
+};
+
#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayland.json",
@@ -43,6 +53,7 @@ K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayl
#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
, registerPlugin<detail::KisWaylandSurfaceColorManagerWrapper>()
, registerPlugin<KisWaylandOutputColorInfo>()
+ , registerPlugin<KisWaylandSurfaceColorManagementInfo>()
#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
);)