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

Make per-surface color space API switchable

Dmitry Kazakov699c51007baa
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d7a4924bf4..f968caba74 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -551,6 +551,15 @@ if (TARGET Qt::WaylandClient)
set(HAVE_WAYLAND TRUE)
endif()
+option(KRITA_USE_SURFACE_COLOR_MANAGEMENT_API "Use per-surface color management API (e.g. when using Wayland)" ${HAVE_WAYLAND})
+add_feature_info("Enable per-surface color management API" KRITA_USE_SURFACE_COLOR_MANAGEMENT_API "adds support for an independent color space management for the canvas")
+
+if (NOT HAVE_WAYLAND AND KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
+ message(WARNING "KRITA_USE_SURFACE_COLOR_MANAGEMENT_API was set when there is no Wayland support, surface management will be useless as no plugins are built")
+endif()
+
+configure_file(config-use-surface-color-management-api.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-use-surface-color-management-api.h)
+
#
# Check for the presence of custom patches in Qt
#
diff --git a/config-use-surface-color-management-api.h.cmake b/config-use-surface-color-management-api.h.cmake
new file mode 100644
index 0000000000..5f2a111cd9
--- /dev/null
+++ b/config-use-surface-color-management-api.h.cmake
@@ -0,0 +1 @@
+#cmakedefine01 KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt
index 9bd2684829..d3e4b86d76 100644
--- a/libs/CMakeLists.txt
+++ b/libs/CMakeLists.txt
@@ -24,6 +24,6 @@ add_subdirectory( resourcewidgets )
add_subdirectory( psd )
add_subdirectory( multiarch )
-if (NOT ANDROID AND HAVE_WAYLAND)
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
add_subdirectory( surfacecolormanagementapi )
endif()
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 4fb602bbf9..3c1791718c 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -650,7 +650,7 @@ if(WIN32)
)
endif()
-if (HAVE_WAYLAND)
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
set(kritaui_LIB_SRCS
${kritaui_LIB_SRCS}
@@ -693,7 +693,7 @@ target_link_libraries(kritaui
kritaresources
)
-if (HAVE_WAYLAND)
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
target_link_libraries(kritaui
PRIVATE
kritasurfacecolormanagementapi
diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp
index 0cb81d9152..03d483f3d5 100644
--- a/libs/ui/KisMainWindow.cpp
+++ b/libs/ui/KisMainWindow.cpp
@@ -155,11 +155,18 @@
#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
+
// surface color management
#include <kpluginfactory.h>
#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
#include <KisSRGBSurfaceColorSpaceManager.h>
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
#include <mutex>
class ToolDockerFactory : public KoDockFactoryBase
@@ -314,8 +321,10 @@ 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();
@@ -663,6 +672,7 @@ 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
@@ -686,6 +696,7 @@ KisMainWindow::KisMainWindow(QUuid uuid)
}
}
}
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
}
@@ -3226,7 +3237,11 @@ bool KisMainWindow::checkPaintOpAvailable()
const KoColorProfile* KisMainWindow::managedSurfaceProfile() const
{
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
return d->surfaceColorSpaceManager ? KoColorSpaceRegistry::instance()->p709SRGBProfile() : nullptr;
+#else
+ return nullptr;
+#endif
}
#include <moc_KisMainWindow.cpp>
diff --git a/libs/ui/canvas/kis_canvas2.cpp b/libs/ui/canvas/kis_canvas2.cpp
index 834ddab06f..f9c282ec78 100644
--- a/libs/ui/canvas/kis_canvas2.cpp
+++ b/libs/ui/canvas/kis_canvas2.cpp
@@ -94,11 +94,15 @@
#include "KisDisplayConfig.h"
#include "config-qt-patches-present.h"
+#include <config-use-surface-color-management-api.h>
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+
#include <KoPluginLoader.h>
#include <kpluginfactory.h>
#include <KisCanvasSurfaceColorSpaceManager.h>
#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+#endif
class Q_DECL_HIDDEN KisCanvas2::KisCanvas2Private
{
@@ -198,7 +202,9 @@ public:
QRect renderingLimit;
int isBatchUpdateActive = 0;
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
QScopedPointer<KisCanvasSurfaceColorSpaceManager> surfaceColorManager;
+#endif
bool effectiveLodAllowedInImage() const {
return lodPreferredInImage && !bootstrapLodBlocked;
@@ -392,6 +398,8 @@ void KisCanvas2::setCanvasWidget(KisAbstractCanvasWidget *widget)
controller->changeCanvasWidget(widget->widget());
}
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
/**
* Load platform plugin for surface color management and set
* the surface color space to sRGB exactly
@@ -428,6 +436,7 @@ void KisCanvas2::setCanvasWidget(KisAbstractCanvasWidget *widget)
}
}
}
+#endif
}
bool KisCanvas2::canvasIsOpenGL() const
@@ -830,9 +839,11 @@ void KisCanvas2::updateProofingState()
m_d->proofingConfig->displayFlags = displayFlags;
m_d->proofingConfigUpdated = true;
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
if (m_d->surfaceColorManager) {
m_d->surfaceColorManager->setProofingConfiguration(m_d->proofingConfig);
}
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
}
void KisCanvas2::slotSoftProofing()
@@ -1313,12 +1324,16 @@ void KisCanvas2::slotConfigChanged()
const KoColorProfile* KisCanvas2::effectiveDisplayProfile(int screenNumber, const KisConfig &config) const
{
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
if (m_d->surfaceColorManager) {
/// When the surface's color space is managed locally, the profile is
/// set by the surface color space manager
return m_d->surfaceColorManager->displayConfig().profile;
- } else if (auto *managedProfile = m_d->view->mainWindow()->managedSurfaceProfile()) {
+ } else
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
+ if (auto *managedProfile = m_d->view->mainWindow()->managedSurfaceProfile()) {
/// If surface color space is managed globally, just return the
/// globally managed profile
return managedProfile;
@@ -1329,11 +1344,19 @@ const KoColorProfile* KisCanvas2::effectiveDisplayProfile(int screenNumber, cons
void KisCanvas2::slotScreenChanged(QScreen *screen)
{
- /**
- * In managed surface colorspace mode, the display screen migrations
- * are managed by the manager itself
- */
- if (!m_d->surfaceColorManager) {
+ bool shouldManageScreenMigrations = true;
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ if (m_d->surfaceColorManager) {
+ /**
+ * In managed surface colorspace mode, the display screen migrations
+ * are managed by the manager itself
+ */
+ shouldManageScreenMigrations = false;
+ }
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
+ if (shouldManageScreenMigrations) {
/**
* We cannot use KisPortingUtils::getScreenNumberForWidget(mainWindow) here,
* because this data is not yet ready when screenChanged signal is delivered.
diff --git a/plugins/color/lcms2engine/tests/CMakeLists.txt b/plugins/color/lcms2engine/tests/CMakeLists.txt
index 6d792b936d..e93e32858f 100644
--- a/plugins/color/lcms2engine/tests/CMakeLists.txt
+++ b/plugins/color/lcms2engine/tests/CMakeLists.txt
@@ -14,7 +14,7 @@ kis_add_tests(
LINK_LIBRARIES kritawidgets kritapigment KF${KF_MAJOR}::I18n kritatestsdk ${LCMS2_LIBRARIES}
)
-if (HAVE_WAYLAND)
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
kis_add_test(
TestIccFromColorimetryConversion.cpp
NAME_PREFIX "plugins-lcmsengine-"
diff --git a/plugins/platforms/wayland/CMakeLists.txt b/plugins/platforms/wayland/CMakeLists.txt
index 721fdc66aa..b02b39ae44 100644
--- a/plugins/platforms/wayland/CMakeLists.txt
+++ b/plugins/platforms/wayland/CMakeLists.txt
@@ -39,22 +39,35 @@ set(kritaplatformpluginwayland_LIB_SRCS
KisExtendedModifiersMapperWayland.cpp
KritaPlatformPluginWayland.cpp
- waylandcolormanagement/KisWaylandAPIColorManager.cpp
- waylandcolormanagement/KisWaylandAPIImageDescription.cpp
- waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.cpp
- waylandcolormanagement/KisWaylandAPIOutput.cpp
- waylandcolormanagement/KisWaylandAPISurface.cpp
- waylandcolormanagement/KisWaylandOutputColorInfo.cpp
- waylandcolormanagement/KisWaylandSurfaceColorimetry.cpp
- waylandcolormanagement/KisWaylandSurfaceColorManager.cpp
+
)
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
+ list(APPEND kritaplatformpluginwayland_LIB_SRCS
+ waylandcolormanagement/KisWaylandAPIColorManager.cpp
+ waylandcolormanagement/KisWaylandAPIImageDescription.cpp
+ waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.cpp
+ waylandcolormanagement/KisWaylandAPIOutput.cpp
+ waylandcolormanagement/KisWaylandAPISurface.cpp
+ waylandcolormanagement/KisWaylandOutputColorInfo.cpp
+ waylandcolormanagement/KisWaylandSurfaceColorimetry.cpp
+ waylandcolormanagement/KisWaylandSurfaceColorManager.cpp)
+endif()
+
kis_add_library(kritaplatformpluginwayland MODULE ${kritaplatformpluginwayland_LIB_SRCS})
+set(kritaplatformpluginwayland_WAYLAND_PROTOCOLS
+ "${CMAKE_CURRENT_SOURCE_DIR}/protocols/wayland.xml"
+)
+
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
+ list(APPEND kritaplatformpluginwayland_WAYLAND_PROTOCOLS
+ "${CMAKE_CURRENT_SOURCE_DIR}/protocols/color-management-v1.xml")
+endif()
+
qt6_generate_wayland_protocol_client_sources(kritaplatformpluginwayland
FILES
- "${CMAKE_CURRENT_SOURCE_DIR}/protocols/wayland.xml"
- "${CMAKE_CURRENT_SOURCE_DIR}/protocols/color-management-v1.xml"
+ ${kritaplatformpluginwayland_WAYLAND_PROTOCOLS}
)
set_source_files_properties(
@@ -71,8 +84,14 @@ target_link_libraries(kritaplatformpluginwayland
Qt::WaylandClient
kritaglobal
kritaui
+)
+
+if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
+ target_link_libraries(kritaplatformpluginwayland
+ PRIVATE
kritasurfacecolormanagementapi
)
+endif()
install(TARGETS kritaplatformpluginwayland DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
diff --git a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
index 0dbf168daa..6af0c4d5bc 100644
--- a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
+++ b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
@@ -9,6 +9,11 @@
#include <kis_assert.h>
#include <KisExtendedModifiersMapperWayland.h>
+
+#include <config-use-surface-color-management-api.h>
+
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+
#include <waylandcolormanagement/KisWaylandSurfaceColorManager.h>
#include <waylandcolormanagement/KisWaylandOutputColorInfo.h>
@@ -30,11 +35,15 @@ public:
} // namespace detail
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
+
K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayland.json",
(
- registerPlugin<KisExtendedModifiersMapperWayland>(),
- registerPlugin<detail::KisWaylandSurfaceColorManagerWrapper>(),
- registerPlugin<KisWaylandOutputColorInfo>()
+ registerPlugin<KisExtendedModifiersMapperWayland>()
+#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
+ , registerPlugin<detail::KisWaylandSurfaceColorManagerWrapper>()
+ , registerPlugin<KisWaylandOutputColorInfo>()
+#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
);)
#include <KritaPlatformPluginWayland.moc>