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

Initial implementation of Wayland-based color management

Dmitry Kazakova31918248cd8
diff --git a/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagerInterface.h b/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagerInterface.h
index df0fe9532a..f7a838602f 100644
--- a/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagerInterface.h
+++ b/libs/surfacecolormanagementapi/surfacecolormanagement/KisSurfaceColorManagerInterface.h
@@ -102,6 +102,14 @@ public:
*/
virtual std::optional<KisSurfaceColorimetry::SurfaceDescription> surfaceDescription() const = 0;
+ /**
+ * \return the current rendering intent assign to the surface
+ *
+ * It can return std::nullopt if the surface discription is unset or
+ * if the connection to the compositor has been lost.
+ */
+ virtual std::optional<KisSurfaceColorimetry::RenderIntent> renderingIntent() const = 0;
+
/**
* \return the preferred description for the underlying surface
* from the viewpoint of the compositor
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 6448dfd4c2..4fb602bbf9 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -650,6 +650,15 @@ if(WIN32)
)
endif()
+if (HAVE_WAYLAND)
+ set(kritaui_LIB_SRCS
+ ${kritaui_LIB_SRCS}
+
+ KisSRGBSurfaceColorSpaceManager.cpp
+ KisCanvasSurfaceColorSpaceManager.cpp
+ )
+endif()
+
kis_add_library(kritaui SHARED ${kritaui_HEADERS_MOC} ${kritaui_LIB_SRCS})
@@ -684,6 +693,13 @@ target_link_libraries(kritaui
kritaresources
)
+if (HAVE_WAYLAND)
+ target_link_libraries(kritaui
+ PRIVATE
+ kritasurfacecolormanagementapi
+ )
+endif()
+
if(WIN32)
# Private headers are needed for:
# * KisDlgCustomTabletResolution
diff --git a/libs/ui/KisCanvasSurfaceColorSpaceManager.cpp b/libs/ui/KisCanvasSurfaceColorSpaceManager.cpp
new file mode 100644
index 0000000000..36c5134cd6
--- /dev/null
+++ b/libs/ui/KisCanvasSurfaceColorSpaceManager.cpp
@@ -0,0 +1,278 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisCanvasSurfaceColorSpaceManager.h"
+
+#include <KoColorSpaceRegistry.h>
+
+#include <kis_config.h>
+#include <kis_config_notifier.h>
+
+#include <KisDisplayConfig.h>
+#include <KisProofingConfiguration.h>
+
+#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+
+KisCanvasSurfaceColorSpaceManager::KisCanvasSurfaceColorSpaceManager(KisSurfaceColorManagerInterface *interface, QObject *parent)
+ : QObject(parent)
+ , m_interface(interface)
+{
+ KisConfig cfg(true);
+ m_currentConfig = KisDisplayConfig(-1, cfg);
+ m_currentConfig.profile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
+
+ connect(m_interface.data(), &KisSurfaceColorManagerInterface::sigReadyChanged, this, &KisCanvasSurfaceColorSpaceManager::slotInterfaceReadyChanged);
+ connect(m_interface.data(), &KisSurfaceColorManagerInterface::sigPreferredSurfaceDescriptionChanged, this, &KisCanvasSurfaceColorSpaceManager::slotInterfacePreferredDescriptionChanged);
+ connect(KisConfigNotifier::instance(), &KisConfigNotifier::configChanged, this, &KisCanvasSurfaceColorSpaceManager::slotConfigChanged);
+}
+
+KisCanvasSurfaceColorSpaceManager::~KisCanvasSurfaceColorSpaceManager()
+{
+}
+
+KisSurfaceColorimetry::RenderIntent KisCanvasSurfaceColorSpaceManager::calculateConfigIntent(int kritaIntent, bool useBlackPointCompensation)
+{
+ using KisSurfaceColorimetry::RenderIntent;
+
+ KisConfig cfg(true);
+ RenderIntent intent = RenderIntent::render_intent_perceptual;
+
+ switch (kritaIntent) {
+ case INTENT_PERCEPTUAL:
+ // default value
+ break;
+ case INTENT_RELATIVE_COLORIMETRIC:
+ intent =
+ useBlackPointCompensation ?
+ RenderIntent::render_intent_relative_bpc :
+ RenderIntent::render_intent_relative;
+ break;
+ case INTENT_SATURATION:
+ intent =
+ RenderIntent::render_intent_saturation;
+ break;
+ case INTENT_ABSOLUTE_COLORIMETRIC:
+ intent =
+ RenderIntent::render_intent_absolute;
+ break;
+ }
+ return intent;
+}
+
+KisSurfaceColorimetry::RenderIntent KisCanvasSurfaceColorSpaceManager::calculateConfigIntent(const KisDisplayConfig &config)
+{
+ return calculateConfigIntent(config.intent,
+ config.conversionFlags.testFlag(KoColorConversionTransformation::BlackpointCompensation));
+}
+
+void KisCanvasSurfaceColorSpaceManager::slotConfigChanged()
+{
+ KisDisplayConfig oldDisplayConfig = m_currentConfig;
+
+ KisConfig cfg(true);
+ KisDisplayConfig config(-1, cfg);
+
+ KisSurfaceColorimetry::RenderIntent newIntent =
+ calculateConfigIntent(config.intent,
+ config.conversionFlags.testFlag(KoColorConversionTransformation::BlackpointCompensation));
+
+ if (newIntent != m_interface->renderingIntent()) {
+ m_currentConfig.intent = config.intent;
+ m_currentConfig.conversionFlags = config.conversionFlags;
+
+ if (m_interface->isReady()) {
+ reinitializeSurfaceDescription();
+ }
+ }
+
+ config.profile = m_currentConfig.profile;
+
+ if (config != oldDisplayConfig) {
+ m_currentConfig = config;
+ Q_EMIT sigDisplayConfigChanged(m_currentConfig);
+ }
+}
+
+void KisCanvasSurfaceColorSpaceManager::setProofingConfiguration(KisProofingConfigurationSP proofingConfig)
+{
+ /**
+ * WARNING: this code duplicates logic from KisOpenGLUpdateInfoBuilder::buildUpdateInfo()
+ * and KisProofingConfiguration::determineDisplayIntent() and
+ * KisProofingConfiguration::determineDisplayFlags. Ideally, they should be unified.
+ */
+
+ std::optional<KisSurfaceColorimetry::RenderIntent> newRenderingIntent;
+
+ if (proofingConfig && proofingConfig->displayFlags.testFlag(KoColorConversionTransformation::SoftProofing)) {
+ if (proofingConfig->displayMode == KisProofingConfiguration::Paper) {
+ newRenderingIntent = KisSurfaceColorimetry::RenderIntent::render_intent_absolute;
+ } else if (proofingConfig->displayMode == KisProofingConfiguration::Custom) {
+ newRenderingIntent =
+ calculateConfigIntent(proofingConfig->displayIntent,
+ proofingConfig->displayFlags.testFlag(KoColorConversionTransformation::BlackpointCompensation));
+ }
+ }
+
+ if (m_proofingIntentOverride != newRenderingIntent) {
+ m_proofingIntentOverride = newRenderingIntent;
+
+ if (m_interface->isReady()) {
+ reinitializeSurfaceDescription();
+ }
+ }
+}
+
+void KisCanvasSurfaceColorSpaceManager::slotInterfaceReadyChanged(bool isReady)
+{
+ if (isReady) {
+ reinitializeSurfaceDescription();
+ }
+}
+
+void KisCanvasSurfaceColorSpaceManager::slotInterfacePreferredDescriptionChanged()
+{
+ reinitializeSurfaceDescription();
+}
+
+#include <KoColorProfile.h>
+#include <surfacecolormanagement/KisSurfaceColorimetryIccUtils.h>
+
+void KisCanvasSurfaceColorSpaceManager::reinitializeSurfaceDescription()
+{
+ using KisSurfaceColorimetry::RenderIntent;
+ using KisSurfaceColorimetry::SurfaceDescription;
+ using KisSurfaceColorimetry::NamedPrimaries;
+ using KisSurfaceColorimetry::NamedTransferFunction;
+
+ RenderIntent preferredIntent =
+ m_proofingIntentOverride ?
+ *m_proofingIntentOverride :
+ calculateConfigIntent(m_currentConfig);
+
+ if (!m_interface->supportsRenderIntent(preferredIntent)) {
+ qWarning() << "WARNING: failed to set user preferred rendering"
+ << "intent for the surface, intent \""
+ << preferredIntent << "\" is unsupported, falling back to \"perceptual\"";
+
+ preferredIntent = RenderIntent::render_intent_perceptual;
+
+ // perceptual intent is guaranteed to be supported by the compositor
+ KIS_SAFE_ASSERT_RECOVER_RETURN(m_interface->supportsRenderIntent(preferredIntent));
+ }
+
+ SurfaceDescription requestedDescription;
+ const KoColorProfile *profile = nullptr;
+
+ {
+ using namespace KisSurfaceColorimetry;
+
+ auto compositorPreferred = m_interface->preferredSurfaceDescription();
+ KIS_SAFE_ASSERT_RECOVER_RETURN(compositorPreferred);
+
+ // we don't copy mastering properties, since they mean a different thing
+ // for the preferred space and outputs
+ requestedDescription.colorSpace = compositorPreferred->colorSpace;
+
+ bool unknownPreferredDescription = false;
+
+ if (std::holds_alternative<NamedPrimaries>(requestedDescription.colorSpace.primaries) &&
+ std::get<NamedPrimaries>(requestedDescription.colorSpace.primaries) == NamedPrimaries::primaries_unknown) {
+
+ requestedDescription.colorSpace.primaries = NamedPrimaries::primaries_srgb;
+ unknownPreferredDescription = true;
+ }
+
+ if (std::holds_alternative<NamedTransferFunction>(requestedDescription.colorSpace.transferFunction) &&
+ std::get<NamedTransferFunction>(requestedDescription.colorSpace.transferFunction) == NamedTransferFunction::transfer_function_unknown) {
+
+ requestedDescription.colorSpace.transferFunction = NamedTransferFunction::transfer_function_gamma22;
+ unknownPreferredDescription = true;
+ }
+
+ if (unknownPreferredDescription &&
+ !m_interface->supportsSurfaceDescription(requestedDescription)) {
+
+ // try pure sRGB
+ requestedDescription.colorSpace.primaries = NamedPrimaries::primaries_srgb;
+ requestedDescription.colorSpace.transferFunction = NamedTransferFunction::transfer_function_srgb;
+
+ if (!m_interface->supportsSurfaceDescription(requestedDescription)) {
+ qWarning() << "WARNING: failed to find a suitable surface format for the compositor";
+ return; // TODO: extra signals?
+ }
+ }
+
+ {
+ auto request = colorSpaceToRequest(requestedDescription.colorSpace);
+ if (request.isValid()) {
+ profile = KoColorSpaceRegistry::instance()->profileFor(request.colorants,
+ request.colorPrimariesType,
+ request.transferFunction);
+ }
+ }
+
+ if (!profile) {
+ // keep primaries, but change the transfer function to gamma22
+ requestedDescription.colorSpace.transferFunction = NamedTransferFunction::transfer_function_gamma22;
+ if (m_interface->supportsSurfaceDescription(requestedDescription)) {
+ auto request = colorSpaceToRequest(requestedDescription.colorSpace);
+ if (request.isValid()) {
+ profile = KoColorSpaceRegistry::instance()->profileFor(request.colorants,
+ request.colorPrimariesType,
+ request.transferFunction);
+ }
+ }
+ }
+
+ if (!profile) {
+ // keep primaries, but change the transfer function to srgb
+ requestedDescription.colorSpace.transferFunction = NamedTransferFunction::transfer_function_srgb;
+ if (m_interface->supportsSurfaceDescription(requestedDescription)) {
+ auto request = colorSpaceToRequest(requestedDescription.colorSpace);
+ if (request.isValid()) {
+ profile = KoColorSpaceRegistry::instance()->profileFor(request.colorants,
+ request.colorPrimariesType,
+ request.transferFunction);
+ }
+ }
+ }
+
+ if (!profile) {
+ qWarning() << "WARNING: failed to to create a profile for the compositor's preferred color space";
+ qWarning() << " " << ppVar(compositorPreferred);
+ qWarning() << " " << ppVar(requestedDescription);
+ // TODO: debug all supported values for the compositor
+ return; // TODO: extra signals?
+ }
+ }
+
+ KIS_SAFE_ASSERT_RECOVER_RETURN(profile);
+ KIS_SAFE_ASSERT_RECOVER_RETURN(m_interface->supportsSurfaceDescription(requestedDescription));
+
+ if (m_interface->surfaceDescription() != requestedDescription ||
+ m_interface->renderingIntent() != preferredIntent) {
+
+ auto future = m_interface->setSurfaceDescription(requestedDescription, preferredIntent);
+ future.then([] (QFuture<bool> result) {
+ if (!result.isValid() || !result.result()) {
+ qWarning() << "WARNING: failed to set color space for the surface, setSurfaceDescription() returned false";
+ }
+ });
+ }
+
+ KIS_SAFE_ASSERT_RECOVER_RETURN(m_currentConfig.profile);
+
+ if (*m_currentConfig.profile != *profile) {
+ m_currentConfig.profile = profile;
+ Q_EMIT sigDisplayConfigChanged(m_currentConfig);
+ }
+
+}
+
+KisDisplayConfig KisCanvasSurfaceColorSpaceManager::displayConfig() const
+{
+ return m_currentConfig;
+}
diff --git a/libs/ui/KisCanvasSurfaceColorSpaceManager.h b/libs/ui/KisCanvasSurfaceColorSpaceManager.h
new file mode 100644
index 0000000000..57191744c0
--- /dev/null
+++ b/libs/ui/KisCanvasSurfaceColorSpaceManager.h
@@ -0,0 +1,52 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISCANVASSURFACECOLORSPACEMANAGER_H
+#define KISCANVASSURFACECOLORSPACEMANAGER_H
+
+#include <QObject>
+
+#include <surfacecolormanagement/KisSurfaceColorimetry.h>
+
+#include <KisDisplayConfig.h>
+#include <kis_types.h>
+
+
+class KoColorProfile;
+class KisSurfaceColorManagerInterface;
+
+class KisCanvasSurfaceColorSpaceManager : public QObject
+{
+ Q_OBJECT
+public:
+ KisCanvasSurfaceColorSpaceManager(KisSurfaceColorManagerInterface *interface, QObject *parent = nullptr);
+ ~KisCanvasSurfaceColorSpaceManager();
+
+ KisDisplayConfig displayConfig() const;
+
+ void setProofingConfiguration(KisProofingConfigurationSP proofingConfig);
+
+Q_SIGNALS:
+ void sigDisplayConfigChanged(const KisDisplayConfig &config);
+
+private:
+ static KisSurfaceColorimetry::RenderIntent calculateConfigIntent(int intent, bool useBlackPointCompensation);
+ static KisSurfaceColorimetry::RenderIntent calculateConfigIntent(const KisDisplayConfig &config);
+
+private Q_SLOTS:
+ void slotConfigChanged();
+ void slotInterfaceReadyChanged(bool isReady);
+ void slotInterfacePreferredDescriptionChanged();
+
+private:
+ void reinitializeSurfaceDescription();
+
+private:
+ QScopedPointer<KisSurfaceColorManagerInterface> m_interface;
+ KisDisplayConfig m_currentConfig;
+ std::optional<KisSurfaceColorimetry::RenderIntent> m_proofingIntentOverride;
+};
+
+#endif /* KISCANVASSURFACECOLORSPACEMANAGER_H */
diff --git a/libs/ui/KisDisplayConfig.cpp b/libs/ui/KisDisplayConfig.cpp
index 499dc1aa14..64e68a7b8d 100644
--- a/libs/ui/KisDisplayConfig.cpp
+++ b/libs/ui/KisDisplayConfig.cpp
@@ -44,6 +44,13 @@ KisDisplayConfig::KisDisplayConfig(int screen, const KisConfig &config)
{
}
+KisDisplayConfig::KisDisplayConfig(const KoColorProfile *_profileOverride, const KisConfig &config)
+ : profile(_profileOverride)
+ , intent(renderingIntentFromConfig(config))
+ , conversionFlags(conversionFlagsFromConfig(config))
+{
+}
+
KisDisplayConfig::KisDisplayConfig(const KoColorProfile *_profile,
KoColorConversionTransformation::Intent _intent,
KoColorConversionTransformation::ConversionFlags _conversionFlags)
diff --git a/libs/ui/KisDisplayConfig.h b/libs/ui/KisDisplayConfig.h
index ab32e56191..953f08adc3 100644
--- a/libs/ui/KisDisplayConfig.h
+++ b/libs/ui/KisDisplayConfig.h
@@ -26,6 +26,7 @@ public:
KisDisplayConfig(const KoColorProfile *_profile,
KoColorConversionTransformation::Intent _intent,
KoColorConversionTransformation::ConversionFlags _conversionFlags);
+ KisDisplayConfig(const KoColorProfile *_profileOverride, const KisConfig &config);
bool operator==(const KisDisplayConfig &rhs) const;
const KoColorProfile *profile;
diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp
index feebb27fb0..0cb81d9152 100644
--- a/libs/ui/KisMainWindow.cpp
+++ b/libs/ui/KisMainWindow.cpp
@@ -155,6 +155,11 @@
#include "KisToolBarStateModel.h"
#include <config-qmdiarea-always-show-subwindow-title.h>
+// surface color management
+#include <kpluginfactory.h>
+#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+#include <KisSRGBSurfaceColorSpaceManager.h>
+
#include <mutex>
class ToolDockerFactory : public KoDockFactoryBase
@@ -309,6 +314,9 @@ public:
KateCommandBar *commandBar {nullptr};
+ // lifetime is managed by the QObject hierarchy
+ QPointer<KisSRGBSurfaceColorSpaceManager> surfaceColorSpaceManager;
+
KisActionManager * actionManager() {
return viewManager->actionManager();
}
@@ -655,6 +663,30 @@ KisMainWindow::KisMainWindow(QUuid uuid)
applyMainWindowSettings(d->windowStateConfig);
+ /**
+ * Load platform plugin for surface color management and set
+ * the surface color space to sRGB exactly
+ */
+ {
+ KPluginFactory *factory = KoPluginLoader::instance()->loadSinglePlugin(
+ std::make_pair("X-Krita-PlatformId", QGuiApplication::platformName()),
+ "Krita/PlatformPlugin");
+
+ if (factory) {
+ QWindow *nativeWindow = this->window()->windowHandle();
+ KIS_SAFE_ASSERT_RECOVER_RETURN(nativeWindow);
+
+ QVariantList args = {QVariant::fromValue(nativeWindow)};
+
+ std::unique_ptr<KisSurfaceColorManagerInterface> iface(
+ factory->create<KisSurfaceColorManagerInterface>(nullptr, args));
+
+ if (iface) {
+ d->surfaceColorSpaceManager = new KisSRGBSurfaceColorSpaceManager(iface.release(), this);
+ }
+ }
+ }
+
}
KisMainWindow::~KisMainWindow()
@@ -3192,4 +3224,9 @@ bool KisMainWindow::checkPaintOpAvailable()
return (rserver->resourceCount() > 0);
}
+const KoColorProfile* KisMainWindow::managedSurfaceProfile() const
+{
+ return d->surfaceColorSpaceManager ? KoColorSpaceRegistry::instance()->p709SRGBProfile() : nullptr;
+}
+
#include <moc_KisMainWindow.cpp>
diff --git a/libs/ui/KisMainWindow.h b/libs/ui/KisMainWindow.h
index d552be9906..d79a169d49 100644
--- a/libs/ui/KisMainWindow.h
+++ b/libs/ui/KisMainWindow.h
@@ -178,6 +178,22 @@ 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;
+
Q_SIGNALS:
/**
diff --git a/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp b/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp
new file mode 100644
index 0000000000..b5355617ec
--- /dev/null
+++ b/libs/ui/KisSRGBSurfaceColorSpaceManager.cpp
@@ -0,0 +1,104 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisSRGBSurfaceColorSpaceManager.h"
+
+#include <kis_assert.h>
+#include <kis_config.h>
+#include <kis_config_notifier.h>
+
+#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+
+
+KisSRGBSurfaceColorSpaceManager::KisSRGBSurfaceColorSpaceManager(KisSurfaceColorManagerInterface *interface, QObject *parent)
+ : QObject(parent)
+ , m_interface(interface)
+{
+ connect(m_interface.data(), &KisSurfaceColorManagerInterface::sigReadyChanged, this, &KisSRGBSurfaceColorSpaceManager::slotInterfaceReadyChanged);
+ connect(KisConfigNotifier::instance(), &KisConfigNotifier::configChanged, this, &KisSRGBSurfaceColorSpaceManager::slotConfigChanged);
+}
+
+KisSRGBSurfaceColorSpaceManager::~KisSRGBSurfaceColorSpaceManager()
+{
+}
+
+KisSurfaceColorimetry::RenderIntent KisSRGBSurfaceColorSpaceManager::calculateConfigIntent() {
+ using KisSurfaceColorimetry::RenderIntent;
+
+ KisConfig cfg(true);
+ RenderIntent intent = RenderIntent::render_intent_perceptual;
+
+ switch (cfg.monitorRenderIntent()) {
+ case INTENT_PERCEPTUAL:
+ // default value
+ break;
+ case INTENT_RELATIVE_COLORIMETRIC:
+ intent =
+ cfg.useBlackPointCompensation() ?
+ RenderIntent::render_intent_relative_bpc :
+ RenderIntent::render_intent_relative;
+ break;
+ case INTENT_SATURATION:
+ intent =
+ RenderIntent::render_intent_saturation;
+ break;
+ case INTENT_ABSOLUTE_COLORIMETRIC:
+ intent =
+ RenderIntent::render_intent_absolute;
+ break;
+ }
+ return intent;
+}
+
+void KisSRGBSurfaceColorSpaceManager::slotConfigChanged() {
+ if (m_interface->isReady() && calculateConfigIntent() != m_interface->renderingIntent()) {
+ reinitializeSurfaceDescription();
+ }
+}
+
+void KisSRGBSurfaceColorSpaceManager::slotInterfaceReadyChanged(bool isReady) {
+ if (isReady) {
+ reinitializeSurfaceDescription();
+ }
+}
+
+void KisSRGBSurfaceColorSpaceManager::reinitializeSurfaceDescription() {
+ using KisSurfaceColorimetry::RenderIntent;
+ using KisSurfaceColorimetry::SurfaceDescription;
+ using KisSurfaceColorimetry::NamedPrimaries;
+ using KisSurfaceColorimetry::NamedTransferFunction;
+
+ RenderIntent preferredIntent = calculateConfigIntent();
+
+ if (!m_interface->supportsRenderIntent(preferredIntent)) {
+ qWarning() << "WARNING: failed to set user preferred rendering"
+ << "intent for the surface, intent \""
+ << preferredIntent << "\" is unsupported, falling back to \"perceptual\"";
+
+ preferredIntent = RenderIntent::render_intent_perceptual;
+
+ // perceptual intent is guaranteed to be supported by the compositor
+ KIS_SAFE_ASSERT_RECOVER_RETURN(m_interface->supportsRenderIntent(preferredIntent));
+ }
+
+ SurfaceDescription preferredDescription;
+ preferredDescription.colorSpace.primaries = NamedPrimaries::primaries_srgb;
+ preferredDescription.colorSpace.transferFunction = NamedTransferFunction::transfer_function_srgb;
+
+ if (m_interface->supportsSurfaceDescription(preferredDescription)) {
+ auto future = m_interface->setSurfaceDescription(preferredDescription, preferredIntent);
+ future.then([] (QFuture<bool> result) {
+ if (!result.isValid() || !result.result()) {
+ qWarning() << "WARNING: failed to set sRGB color space for the surface, setSurfaceDescription() returned false";
+ }
+ });
+ } else {
+ qWarning() << "WARNING: failed to set sRGB color space for the surface,"
+ << "the color space is unsupported by compositor";
+ }
+}
+
+#include <moc_KisSRGBSurfaceColorSpaceManager.cpp>
diff --git a/libs/ui/KisSRGBSurfaceColorSpaceManager.h b/libs/ui/KisSRGBSurfaceColorSpaceManager.h
new file mode 100644
index 0000000000..29c7ea30a3
--- /dev/null
+++ b/libs/ui/KisSRGBSurfaceColorSpaceManager.h
@@ -0,0 +1,34 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISSRGBSURFACECOLORSPACEMANAGER_H
+#define KISSRGBSURFACECOLORSPACEMANAGER_H
+
+#include <QObject>
+#include <QScopedPointer>
+
+#include <surfacecolormanagement/KisSurfaceColorimetry.h>
+
+class KisSurfaceColorManagerInterface;
+
+
+class KisSRGBSurfaceColorSpaceManager : public QObject
+{
+public:
+ KisSRGBSurfaceColorSpaceManager(KisSurfaceColorManagerInterface *interface, QObject *parent = nullptr);
+ ~KisSRGBSurfaceColorSpaceManager();
+
+protected:
+ static KisSurfaceColorimetry::RenderIntent calculateConfigIntent();
+
+ void slotConfigChanged();
+ void slotInterfaceReadyChanged(bool isReady);
+ void reinitializeSurfaceDescription();
+
+protected:
+ QScopedPointer<KisSurfaceColorManagerInterface> m_interface;
+};
+
+#endif /* KISSRGBSURFACECOLORSPACEMANAGER_H */
diff --git a/libs/ui/canvas/kis_canvas2.cpp b/libs/ui/canvas/kis_canvas2.cpp
index 2a58eb7d27..834ddab06f 100644
--- a/libs/ui/canvas/kis_canvas2.cpp
+++ b/libs/ui/canvas/kis_canvas2.cpp
@@ -94,6 +94,11 @@
#include "KisDisplayConfig.h"
#include "config-qt-patches-present.h"
+#include <KoPluginLoader.h>
+#include <kpluginfactory.h>
+#include <KisCanvasSurfaceColorSpaceManager.h>
+#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+
class Q_DECL_HIDDEN KisCanvas2::KisCanvas2Private
{
@@ -193,6 +198,8 @@ public:
QRect renderingLimit;
int isBatchUpdateActive = 0;
+ QScopedPointer<KisCanvasSurfaceColorSpaceManager> surfaceColorManager;
+
bool effectiveLodAllowedInImage() const {
return lodPreferredInImage && !bootstrapLodBlocked;
}
@@ -384,6 +391,43 @@ void KisCanvas2::setCanvasWidget(KisAbstractCanvasWidget *widget)
if (controller && controller->canvas() == this) {
controller->changeCanvasWidget(widget->widget());
}
+
+ /**
+ * Load platform plugin for surface color management and set
+ * the surface color space to sRGB exactly
+ */
+ {
+ m_d->surfaceColorManager.reset();
+
+ KPluginFactory *factory = KoPluginLoader::instance()->loadSinglePlugin(
+ std::make_pair("X-Krita-PlatformId", QGuiApplication::platformName()),
+ "Krita/PlatformPlugin");
+
+ if (factory) {
+ QWindow *mainWindowNativeWindow = m_d->view->mainWindow()->windowHandle();
+ QWindow *nativeWindow = widget->widget()->windowHandle();
+
+ if (nativeWindow && nativeWindow != mainWindowNativeWindow) {
+ QVariantList args = {QVariant::fromValue(nativeWindow)};
+
+ std::unique_ptr<KisSurfaceColorManagerInterface> iface(
+ factory->create<KisSurfaceColorManagerInterface>(nullptr, args));
+
+ if (iface) {
+ m_d->surfaceColorManager.reset(new KisCanvasSurfaceColorSpaceManager(iface.release(), this));
+
+ m_d->surfaceColorManager->setProofingConfiguration(m_d->proofingConfig);
+ setDisplayConfig(m_d->surfaceColorManager->displayConfig());
+
+ connect(m_d->surfaceColorManager.data(), &KisCanvasSurfaceColorSpaceManager::sigDisplayConfigChanged,
+ this, &KisCanvas2::setDisplayConfig);
+ }
+ } else {
+ qWarning() << "WARNING: created non-native Krita canvas on managed platform,"
+ << "its color space will be limited to sRGB";
+ }
+ }
+ }
}
bool KisCanvas2::canvasIsOpenGL() const
@@ -587,7 +631,7 @@ void KisCanvas2::createCanvas(bool useOpenGL)
}
m_d->displayColorConverter.notifyOpenGLCanvasIsActive(useOpenGL && KisOpenGL::hasOpenGL());
- m_d->displayColorConverter.setDisplayConfig(KisDisplayConfig(canvasScreenNumber, cfg));
+ m_d->displayColorConverter.setDisplayConfig(KisDisplayConfig(effectiveDisplayProfile(canvasScreenNumber, cfg), cfg));
if (useOpenGL && !KisOpenGL::hasOpenGL()) {
warnKrita << "Tried to create OpenGL widget when system doesn't have OpenGL\n";
@@ -784,8 +828,11 @@ void KisCanvas2::updateProofingState()
displayFlags.setFlag(KoColorConversionTransformation::GamutCheck, imageView()->gamutCheck());
}
m_d->proofingConfig->displayFlags = displayFlags;
-
m_d->proofingConfigUpdated = true;
+
+ if (m_d->surfaceColorManager) {
+ m_d->surfaceColorManager->setProofingConfiguration(m_d->proofingConfig);
+ }
}
void KisCanvas2::slotSoftProofing()
@@ -1264,21 +1311,44 @@ void KisCanvas2::slotConfigChanged()
initializeFpsDecoration();
}
+const KoColorProfile* KisCanvas2::effectiveDisplayProfile(int screenNumber, const KisConfig &config) const
+{
+ 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()) {
+ /// If surface color space is managed globally, just return the
+ /// globally managed profile
+ return managedProfile;
+ }
+
+ return config.displayProfile(screenNumber);
+}
+
void KisCanvas2::slotScreenChanged(QScreen *screen)
{
/**
- * We cannot use KisPortingUtils::getScreenNumberForWidget(mainWindow) here,
- * because this data is not yet ready when screenChanged signal is delivered.
+ * In managed surface colorspace mode, the display screen migrations
+ * are managed by the manager itself
*/
+ if (!m_d->surfaceColorManager) {
+ /**
+ * We cannot use KisPortingUtils::getScreenNumberForWidget(mainWindow) here,
+ * because this data is not yet ready when screenChanged signal is delivered.
+ */
- const int canvasScreenNumber = qApp->screens().indexOf(screen);
+ const int canvasScreenNumber = qApp->screens().indexOf(screen);
- if (canvasScreenNumber != -1) {
- // If profile is the same, then setDisplayProfile does nothing
- KisConfig cfg(true);
- setDisplayConfig(KisDisplayConfig(canvasScreenNumber, cfg));
- } else {
- warnUI << "Failed to get screenNumber for updating display profile.";
+ if (canvasScreenNumber != -1) {
+ // If profile is the same, then setDisplayProfile does nothing
+ KisConfig cfg(true);
+ setDisplayConfig(
+ KisDisplayConfig(effectiveDisplayProfile(canvasScreenNumber, cfg), cfg));
+ } else {
+ warnUI << "Failed to get screenNumber for updating display profile.";
+ }
}
}
diff --git a/libs/ui/canvas/kis_canvas2.h b/libs/ui/canvas/kis_canvas2.h
index d81a5550fa..c8472785c1 100644
--- a/libs/ui/canvas/kis_canvas2.h
+++ b/libs/ui/canvas/kis_canvas2.h
@@ -322,6 +322,8 @@ private:
void resetCanvas(bool useOpenGL);
void setDisplayConfig(const KisDisplayConfig &config);
+ const KoColorProfile* effectiveDisplayProfile(int screenNumber, const KisConfig &config) const;
+
void notifyLevelOfDetailChange();
// Completes construction of canvas.
diff --git a/plugins/platforms/wayland/CMakeLists.txt b/plugins/platforms/wayland/CMakeLists.txt
index 0c10db5e9c..721fdc66aa 100644
--- a/plugins/platforms/wayland/CMakeLists.txt
+++ b/plugins/platforms/wayland/CMakeLists.txt
@@ -38,6 +38,15 @@ set(kritaplatformpluginwayland_LIB_SRCS
KisWaylandKeyboardWatcher.cpp
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
)
kis_add_library(kritaplatformpluginwayland MODULE ${kritaplatformpluginwayland_LIB_SRCS})
@@ -45,6 +54,7 @@ kis_add_library(kritaplatformpluginwayland MODULE ${kritaplatformpluginwayland_L
qt6_generate_wayland_protocol_client_sources(kritaplatformpluginwayland
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/protocols/wayland.xml"
+ "${CMAKE_CURRENT_SOURCE_DIR}/protocols/color-management-v1.xml"
)
set_source_files_properties(
@@ -61,6 +71,7 @@ target_link_libraries(kritaplatformpluginwayland
Qt::WaylandClient
kritaglobal
kritaui
+ kritasurfacecolormanagementapi
)
install(TARGETS kritaplatformpluginwayland DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
diff --git a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
index bfc00670cb..0dbf168daa 100644
--- a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
+++ b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
@@ -6,8 +6,35 @@
#include <kpluginfactory.h>
+#include <kis_assert.h>
+
#include <KisExtendedModifiersMapperWayland.h>
+#include <waylandcolormanagement/KisWaylandSurfaceColorManager.h>
+#include <waylandcolormanagement/KisWaylandOutputColorInfo.h>
+
+#include <QWindow>
+
+namespace detail {
+
+// just a simple wrapper that unpacks arguments from a QVariantList into
+// a proper interface for KisWaylandSurfaceColorManager
+class KisWaylandSurfaceColorManagerWrapper: public KisWaylandSurfaceColorManager
+{
+public:
+ KisWaylandSurfaceColorManagerWrapper(QObject *parent, const QVariantList &args)
+ : KisWaylandSurfaceColorManager(args.first().value<QWindow*>(), parent)
+ {
+ KIS_SAFE_ASSERT_RECOVER_NOOP(args.size() == 1);
+ }
+};
+
+} // namespace detail
-K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayland.json", registerPlugin<KisExtendedModifiersMapperWayland>();)
+K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayland.json",
+ (
+ registerPlugin<KisExtendedModifiersMapperWayland>(),
+ registerPlugin<detail::KisWaylandSurfaceColorManagerWrapper>(),
+ registerPlugin<KisWaylandOutputColorInfo>()
+ );)
#include <KritaPlatformPluginWayland.moc>
diff --git a/plugins/platforms/wayland/protocols/color-management-v1.xml b/plugins/platforms/wayland/protocols/color-management-v1.xml
new file mode 100644
index 0000000000..7f8da78f12
--- /dev/null
+++ b/plugins/platforms/wayland/protocols/color-management-v1.xml
@@ -0,0 +1,1631 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="color_management_v1">
+ <copyright>
+ Copyright 2019 Sebastian Wick
+ Copyright 2019 Erwin Burema
+ Copyright 2020 AMD
+ Copyright 2020-2024 Collabora, Ltd.
+ Copyright 2024 Xaver Hugl
+ Copyright 2022-2025 Red Hat, Inc.
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ </copyright>
+
+ <description summary="color management protocol">
+ The aim of the color management extension is to allow clients to know
+ the color properties of outputs, and to tell the compositor about the color
+ properties of their content on surfaces. Doing this enables a compositor
+ to perform automatic color management of content for different outputs
+ according to how content is intended to look like.
+
+ The color properties are represented as an image description object which
+ is immutable after it has been created. A wl_output always has an
+ associated image description that clients can observe. A wl_surface
+ always has an associated preferred image description as a hint chosen by
+ the compositor that clients can also observe. Clients can set an image
+ description on a wl_surface to denote the color characteristics of the
+ surface contents.
+
+ An image description includes SDR and HDR colorimetry and encoding, HDR
+ metadata, and viewing environment parameters. An image description does
+ not include the properties set through color-representation extension.
+ It is expected that the color-representation extension is used in
+ conjunction with the color management extension when necessary,
+ particularly with the YUV family of pixel formats.
+
+ Recommendation ITU-T H.273
+ "Coding-independent code points for video signal type identification"
+ shall be referred to as simply H.273 here.
+
+ The color-and-hdr repository
+ (https://gitlab.freedesktop.org/pq/color-and-hdr) contains
+ background information on the protocol design and legacy color management.
+ It also contains a glossary, learning resources for digital color, tools,
+ samples and more.
+
+ The terminology used in this protocol is based on common color science and
+ color encoding terminology where possible. The glossary in the color-and-hdr
+ repository shall be the authority on the definition of terms in this
+ protocol.
+
+ Warning! The protocol described in this file is currently in the testing
+ phase. Backward compatible changes may be added together with the
+ corresponding interface version bump. Backward incompatible changes can
+ only be done by creating a new major version of the extension.
+ </description>
+
+ <interface name="wp_color_manager_v1" version="1">
+ <description summary="color manager singleton">
+ A singleton global interface used for getting color management extensions
+ for wl_surface and wl_output objects, and for creating client defined
+ image description objects. The extension interfaces allow
+ getting the image description of outputs and setting the image
+ description of surfaces.
+
+ Compositors should never remove this global.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the color manager">
+ Destroy the wp_color_manager_v1 object. This does not affect any other
+ objects in any way.
+ </description>
+ </request>
+
+ <enum name="error">
+ <entry name="unsupported_feature" value="0"
+ summary="request not supported"/>
+ <entry name="surface_exists" value="1"
+ summary="color management surface exists already"/>
+ </enum>
+
+ <enum name="render_intent">
+ <description summary="rendering intents">
+ See the ICC.1:2022 specification from the International Color Consortium
+ for more details about rendering intents.
+
+ The principles of ICC defined rendering intents apply with all types of
+ image descriptions, not only those with ICC file profiles.
+
+ Compositors must support the perceptual rendering intent. Other
+ rendering intents are optional.
+ </description>
+
+ <entry name="perceptual" value="0"
+ summary="perceptual"/>
+ <entry name="relative" value="1"
+ summary="media-relative colorimetric"/>
+ <entry name="saturation" value="2"
+ summary="saturation"/>
+ <entry name="absolute" value="3"
+ summary="ICC-absolute colorimetric"/>
+ <entry name="relative_bpc" value="4"
+ summary="media-relative colorimetric + black point compensation"/>
+ </enum>
+
+ <enum name="feature">
+ <description summary="compositor supported features"/>
+
+ <entry name="icc_v2_v4" value="0"
+ summary="create_icc_creator request"/>
+ <entry name="parametric" value="1"
+ summary="create_parametric_creator request"/>
+ <entry name="set_primaries" value="2"
+ summary="parametric set_primaries request"/>
+ <entry name="set_tf_power" value="3"
+ summary="parametric set_tf_power request"/>
+ <entry name="set_luminances" value="4"
+ summary="parametric set_luminances request"/>
+ <entry name="set_mastering_display_primaries" value="5">
+ <description summary="parametric set_mastering_display_primaries request">
+ The compositor supports set_mastering_display_primaries request with a
+ target color volume fully contained inside the primary color volume.
+ </description>
+ </entry>
+ <entry name="extended_target_volume" value="6">
+ <description summary="parametric target exceeds primary color volume">
+ The compositor additionally supports target color volumes that
+ extend outside of the primary color volume.
+
+ This can only be advertised if feature set_mastering_display_primaries
+ is supported as well.
+ </description>
+ </entry>
+ <entry name="windows_scrgb" value="7"
+ summary="get_windows_scrgb request"/>
+ </enum>
+
+ <enum name="primaries">
+ <description summary="named color primaries">
+ Named color primaries used to encode well-known sets of primaries. H.273
+ is the authority, when it comes to the exact values of primaries and
+ authoritative specifications, where an equivalent code point exists.
+
+ A value of 0 is invalid and will never be present in the list of enums.
+
+ Descriptions do list the specifications for convenience.
+ </description>
+
+ <entry name="srgb" value="1">
+ <description summary="Color primaries for the sRGB color space as defined by the BT.709 standard">
+ Color primaries as defined by
+ - Rec. ITU-R BT.709-6
+ - Rec. ITU-R BT.1361-0 conventional colour gamut system and extended
+ colour gamut system (historical)
+ - IEC 61966-2-1 sRGB or sYCC
+ - IEC 61966-2-4
+ - Society of Motion Picture and Television Engineers (SMPTE) RP 177
+ (1993) Annex B
+ Equivalent to H.273 ColourPrimaries code point 1.
+ </description>
+ </entry>
+ <entry name="pal_m" value="2">
+ <description summary="Color primaries for PAL-M as defined by the BT.470 standard">
+ Color primaries as defined by
+ - Rec. ITU-R BT.470-6 System M (historical)
+ - United States National Television System Committee 1953
+ Recommendation for transmission standards for color television
+ - United States Federal Communications Commission (2003) Title 47 Code
+ of Federal Regulations 73.682 (a)(20)
+ Equivalent to H.273 ColourPrimaries code point 4.
+ </description>
+ </entry>
+ <entry name="pal" value="3">
+ <description summary="Color primaries for PAL as defined by the BT.601 standard">
+ Color primaries as defined by
+ - Rec. ITU-R BT.470-6 System B, G (historical)
+ - Rec. ITU-R BT.601-7 625
+ - Rec. ITU-R BT.1358-0 625 (historical)
+ - Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM
+ Equivalent to H.273 ColourPrimaries code point 5.
+ </description>
+ </entry>
+ <entry name="ntsc" value="4">
+ <description summary="Color primaries for NTSC as defined by the BT.601 standard">
+ Color primaries as defined by
+ - Rec. ITU-R BT.601-7 525
+ - Rec. ITU-R BT.1358-1 525 or 625 (historical)
+ - Rec. ITU-R BT.1700-0 NTSC
+ - SMPTE 170M (2004)
+ - SMPTE 240M (1999) (historical)
+ Equivalent to H.273 ColourPrimaries code point 6 and 7.
+ </description>
+ </entry>
+ <entry name="generic_film" value="5">
+ <description summary="Generic film with colour filters using Illuminant C">
+ Color primaries as defined by H.273 for generic film.
+ Equivalent to H.273 ColourPrimaries code point 8.
+ </description>
+ </entry>
+ <entry name="bt2020" value="6">
+ <description summary="Color primaries as defined by the BT.2020 and BT.2100 standard">
+ Color primaries as defined by
+ - Rec. ITU-R BT.2020-2
+ - Rec. ITU-R BT.2100-0
+ Equivalent to H.273 ColourPrimaries code point 9.
+ </description>
+ </entry>
+ <entry name="cie1931_xyz" value="7">
+ <description summary="Color primaries of the full CIE 1931 XYZ color space">
+ Color primaries as defined as the maximum of the CIE 1931 XYZ color
+ space by
+ - SMPTE ST 428-1
+ - (CIE 1931 XYZ as in ISO 11664-1)
+ Equivalent to H.273 ColourPrimaries code point 10.
+ </description>
+ </entry>
+ <entry name="dci_p3" value="8">
+ <description summary="Color primaries of the DCI P3 color space as defined by the SMPTE RP 431 standard">
+ Color primaries as defined by Digital Cinema System and published in
+ SMPTE RP 431-2 (2011). Equivalent to H.273 ColourPrimaries code point
+ 11.
+ </description>
+ </entry>
+ <entry name="display_p3" value="9">
+ <description summary="Color primaries of Display P3 variant of the DCI-P3 color space as defined by the SMPTE EG 432 standard">
+ Color primaries as defined by Digital Cinema System and published in
+ SMPTE EG 432-1 (2010).
+ Equivalent to H.273 ColourPrimaries code point 12.
+ </description>
+ </entry>
+ <entry name="adobe_rgb" value="10">
+ <description summary="Color primaries of the Adobe RGB color space as defined by the ISO 12640 standard">
+ Color primaries as defined by Adobe as "Adobe RGB" and later published
+ by ISO 12640-4 (2011).
+ </description>
+ </entry>
+ </enum>
+
+ <enum name="transfer_function">
+ <description summary="named transfer functions">
+ Named transfer functions used to represent well-known transfer
+ characteristics. H.273 is the authority, when it comes to the exact
+ formulas and authoritative specifications, where an equivalent code
+ point exists.
+
+ A value of 0 is invalid and will never be present in the list of enums.
+
+ Descriptions do list the specifications for convenience.
+ </description>
+
+ <entry name="bt1886" value="1">
+ <description summary="BT.1886 display transfer characteristic">
+ Rec. ITU-R BT.1886 is the display transfer characteristic assumed by
+ - Rec. ITU-R BT.601-7 525 and 625
+ - Rec. ITU-R BT.709-6
+ - Rec. ITU-R BT.2020-2
+ These recommendations are referred to by H.273 TransferCharacteristics
+ code points 1, 6, 14, and 15, which are all equivalent.
+
+ This TF implies these default luminances from Rec. ITU-R BT.2035:
+ - primary color volume minimum: 0.01 cd/m²
+ - primary color volume maximum: 100 cd/m²
+ - reference white: 100 cd/m²
+ </description>
+ </entry>
+ <entry name="gamma22" value="2">
+ <description summary="Assumed display gamma 2.2 transfer function">
+ Transfer characteristics as defined by
+ - Rec. ITU-R BT.470-6 System M (historical)
+ - United States National Television System Committee 1953
+ Recommendation for transmission standards for color television
+ - United States Federal Communications Commission (2003) Title 47 Code
+ of Federal Regulations 73.682 (a) (20)
+ - Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM
+ Equivalent to H.273 TransferCharacteristics code point 4.
+ </description>
+ </entry>
+ <entry name="gamma28" value="3">
+ <description summary="Assumed display gamma 2.8 transfer function">
+ Transfer characteristics as defined by
+ - Rec. ITU-R BT.470-6 System B, G (historical)
+ Equivalent to H.273 TransferCharacteristics code point 5.
+ </description>
+ </entry>
+ <entry name="st240" value="4">
+ <description summary="SMPTE ST 240 transfer function">
+ Transfer characteristics as defined by
+ - SMPTE ST 240 (1999)
+ Equivalent to H.273 TransferCharacteristics code point 7.
+ </description>
+ </entry>
+ <entry name="ext_linear" value="5">
+ <description summary="extended linear transfer function">
+ Linear transfer function defined over all real numbers.
+ Normalised electrical values are equal the normalised optical values.
+
+ The differences to H.273 TransferCharacteristics code point 8 are
+ the definition over all real numbers.
+ </description>
+ </entry>
+ <entry name="log_100" value="6">
+ <description summary="logarithmic 100:1 transfer function">
+ Logarithmic transfer characteristic (100:1 range).
+ Equivalent to H.273 TransferCharacteristics code point 9.
+ </description>
+ </entry>
+ <entry name="log_316" value="7">
+ <description summary="logarithmic (100*Sqrt(10) : 1) transfer function">
+ Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range).
+ Equivalent to H.273 TransferCharacteristics code point 10.
+ </description>
+ </entry>
+ <entry name="xvycc" value="8">
+ <description summary="IEC 61966-2-4 transfer function">
+ Transfer characteristics as defined by
+ - IEC 61966-2-4
+ Equivalent to H.273 TransferCharacteristics code point 11.
+ </description>
+ </entry>
+ <entry name="srgb" value="9">
+ <description summary="sRGB piece-wise transfer function">
+ Transfer characteristics as defined by
+ - IEC 61966-2-1 sRGB
+ Equivalent to H.273 TransferCharacteristics code point 13 with
+ MatrixCoefficients set to 0.
+ </description>
+ </entry>
+ <entry name="ext_srgb" value="10">
+ <description summary="Extended sRGB piece-wise transfer function">
+ Transfer characteristics as defined by
+ - IEC 61966-2-1 sYCC
+ Equivalent to H.273 TransferCharacteristics code point 13 with
+ MatrixCoefficients set to anything but 0.
+ </description>
+ </entry>
+ <entry name="st2084_pq" value="11">
+ <description summary="perceptual quantizer transfer function">
+ Transfer characteristics as defined by
+ - SMPTE ST 2084 (2014) for 10-, 12-, 14- and 16-bit systems
+ - Rec. ITU-R BT.2100-2 perceptual quantization (PQ) system
+ Equivalent to H.273 TransferCharacteristics code point 16.
+
+ This TF implies these default luminances
+ - primary color volume minimum: 0.005 cd/m²
+ - primary color volume maximum: 10000 cd/m²
+ - reference white: 203 cd/m²
+
+ The difference between the primary color volume minimum and maximum
+ must be approximately 10000 cd/m² as that is the swing of the EOTF
+ defined by ST 2084 and BT.2100. The default value for the
+ reference white is a protocol addition: it is suggested by
+ Report ITU-R BT.2408-7 and is not part of ST 2084 or BT.2100.
+ </description>
+ </entry>
+ <entry name="st428" value="12">
+ <description summary="SMPTE ST 428 transfer function">
+ Transfer characteristics as defined by
+ - SMPTE ST 428-1 (2019)
+ Equivalent to H.273 TransferCharacteristics code point 17.
+ </description>
+ </entry>
+ <entry name="hlg" value="13">
+ <description summary="hybrid log-gamma transfer function">
+ Transfer characteristics as defined by
+ - ARIB STD-B67 (2015)
+ - Rec. ITU-R BT.2100-2 hybrid log-gamma (HLG) system
+ Equivalent to H.273 TransferCharacteristics code point 18.
+
+ This TF implies these default luminances
+ - primary color volume minimum: 0.005 cd/m²
+ - primary color volume maximum: 1000 cd/m²
+ - reference white: 203 cd/m²
+
+ HLG is a relative display-referred signal with a specified
+ non-linear mapping to the display peak luminance (the HLG OOTF).
+ All absolute luminance values used here for HLG assume a 1000 cd/m²
+ peak display.
+
+ The default value for the reference white is a protocol addition:
+ it is suggested by Report ITU-R BT.2408-7 and is not part of
+ ARIB STD-B67 or BT.2100.
+ </description>
+ </entry>
+ </enum>
+
+ <request name="get_output">
+ <description summary="create a color management interface for a wl_output">
+ This creates a new wp_color_management_output_v1 object for the
+ given wl_output.
+
+ See the wp_color_management_output_v1 interface for more details.
+ </description>
+
+ <arg name="id" type="new_id" interface="wp_color_management_output_v1"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ </request>
+
+ <request name="get_surface">
+ <description summary="create a color management interface for a wl_surface">
+ If a wp_color_management_surface_v1 object already exists for the given
+ wl_surface, the protocol error surface_exists is raised.
+
+ This creates a new color wp_color_management_surface_v1 object for the
+ given wl_surface.
+
+ See the wp_color_management_surface_v1 interface for more details.
+ </description>
+
+ <arg name="id" type="new_id" interface="wp_color_management_surface_v1"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ </request>
+
+ <request name="get_surface_feedback">
+ <description summary="create a color management feedback interface">
+ This creates a new color wp_color_management_surface_feedback_v1 object
+ for the given wl_surface.
+
+ See the wp_color_management_surface_feedback_v1 interface for more
+ details.
+ </description>
+
+ <arg name="id" type="new_id"
+ interface="wp_color_management_surface_feedback_v1"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ </request>
+
+ <request name="create_icc_creator">
+ <description summary="make a new ICC-based image description creator object">
+ Makes a new ICC-based image description creator object with all
+ properties initially unset. The client can then use the object's
+ interface to define all the required properties for an image description
+ and finally create a wp_image_description_v1 object.
+
+ This request can be used when the compositor advertises
+ wp_color_manager_v1.feature.icc_v2_v4.
+ Otherwise this request raises the protocol error unsupported_feature.
+ </description>
+
+ <arg name="obj"
+ type="new_id" interface="wp_image_description_creator_icc_v1"
+ summary="the new creator object"/>
+ </request>
+
+ <request name="create_parametric_creator">
+ <description summary="make a new parametric image description creator object">
+ Makes a new parametric image description creator object with all
+ properties initially unset. The client can then use the object's
+ interface to define all the required properties for an image description
+ and finally create a wp_image_description_v1 object.
+
+ This request can be used when the compositor advertises
+ wp_color_manager_v1.feature.parametric.
+ Otherwise this request raises the protocol error unsupported_feature.
+ </description>
+
+ <arg name="obj"
+ type="new_id" interface="wp_image_description_creator_params_v1"
+ summary="the new creator object"/>
+ </request>
+
+ <request name="create_windows_scrgb">
+ <description summary="create Windows-scRGB image description object">
+ This creates a pre-defined image description for the so-called
+ Windows-scRGB stimulus encoding. This comes from the Windows 10 handling
+ of its own definition of an scRGB color space for an HDR screen
+ driven in BT.2100/PQ signalling mode.
+
+ Windows-scRGB uses sRGB (BT.709) color primaries and white point.
+ The transfer characteristic is extended linear.
+
+ The nominal color channel value range is extended, meaning it includes
+ negative and greater than 1.0 values. Negative values are used to
+ escape the sRGB color gamut boundaries. To make use of the extended
+ range, the client needs to use a pixel format that can represent those
+ values, e.g. floating-point 16 bits per channel.
+
+ Nominal color value R=G=B=0.0 corresponds to BT.2100/PQ system
+ 0 cd/m², and R=G=B=1.0 corresponds to BT.2100/PQ system 80 cd/m².
+ The maximum is R=G=B=125.0 corresponding to 10k cd/m².
+
+ Windows-scRGB is displayed by Windows 10 by converting it to
+ BT.2100/PQ, maintaining the CIE 1931 chromaticity and mapping the
+ luminance as above. No adjustment is made to the signal to account
+ for the viewing conditions.
+
+ The reference white level of Windows-scRGB is unknown. If a
+ reference white level must be assumed for compositor processing, it
+ should be R=G=B=2.5375 corresponding to 203 cd/m² of Report ITU-R
+ BT.2408-7.
+
+ The target color volume of Windows-scRGB is unknown. The color gamut
+ may be anything between sRGB and BT.2100.
+
+ Note: EGL_EXT_gl_colorspace_scrgb_linear definition differs from
+ Windows-scRGB by using R=G=B=1.0 as the reference white level, while
+ Windows-scRGB reference white level is unknown or varies. However,
+ it seems probable that Windows implements both
+ EGL_EXT_gl_colorspace_scrgb_linear and Vulkan
+ VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT as Windows-scRGB.
+
+ This request can be used when the compositor advertises
+ wp_color_manager_v1.feature.windows_scrgb.
+ Otherwise this request raises the protocol error unsupported_feature.
+
+ The resulting image description object does not allow get_information
+ request. The wp_image_description_v1.ready event shall be sent.
+ </description>
+
+ <arg name="image_description"
+ type="new_id" interface="wp_image_description_v1"/>
+ </request>
+
+ <event name="supported_intent">
+ <description summary="supported rendering intent">
+ When this object is created, it shall immediately send this event once
+ for each rendering intent the compositor supports.
+ </description>
+
+ <arg name="render_intent" type="uint" enum="render_intent"
+ summary="rendering intent"/>
+ </event>
+
+ <event name="supported_feature">
+ <description summary="supported features">
+ When this object is created, it shall immediately send this event once
+ for each compositor supported feature listed in the enumeration.
+ </description>
+
+ <arg name="feature" type="uint" enum="feature"
+ summary="supported feature"/>
+ </event>
+
+ <event name="supported_tf_named">
+ <description summary="supported named transfer characteristic">
+ When this object is created, it shall immediately send this event once
+ for each named transfer function the compositor supports with the
+ parametric image description creator.
+ </description>
+
+ <arg name="tf" type="uint" enum="transfer_function"
+ summary="Named transfer function"/>
+ </event>
+
+ <event name="supported_primaries_named">
+ <description summary="supported named primaries">
+ When this object is created, it shall immediately send this event once
+ for each named set of primaries the compositor supports with the
+ parametric image description creator.
+ </description>
+
+ <arg name="primaries" type="uint" enum="primaries"
+ summary="Named color primaries"/>
+ </event>
+
+ <event name="done">
+ <description summary="all features have been sent">
+ This event is sent when all supported rendering intents, features,
+ transfer functions and named primaries have been sent.
+ </description>
+ </event>
+ </interface>
+
+ <interface name="wp_color_management_output_v1" version="1">
+ <description summary="output color properties">
+ A wp_color_management_output_v1 describes the color properties of an
+ output.
+
+ The wp_color_management_output_v1 is associated with the wl_output global
+ underlying the wl_output object. Therefore the client destroying the
+ wl_output object has no impact, but the compositor removing the output
+ global makes the wp_color_management_output_v1 object inert.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the color management output">
+ Destroy the color wp_color_management_output_v1 object. This does not
+ affect any remaining protocol objects.
+ </description>
+ </request>
+
+ <event name="image_description_changed">
+ <description summary="image description changed">
+ This event is sent whenever the image description of the output changed,
+ followed by one wl_output.done event common to output events across all
+ extensions.
+
+ If the client wants to use the updated image description, it needs to do
+ get_image_description again, because image description objects are
+ immutable.
+ </description>
+ </event>
+
+ <request name="get_image_description">
+ <description summary="get the image description of the output">
+ This creates a new wp_image_description_v1 object for the current image
+ description of the output. There always is exactly one image description
+ active for an output so the client should destroy the image description
+ created by earlier invocations of this request. This request is usually
+ sent as a reaction to the image_description_changed event or when
+ creating a wp_color_management_output_v1 object.
+
+ The image description of an output represents the color encoding the
+ output expects. There might be performance and power advantages, as well
+ as improved color reproduction, if a content update matches the image
+ description of the output it is being shown on. If a content update is
+ shown on any other output than the one it matches the image description
+ of, then the color reproduction on those outputs might be considerably
+ worse.
+
+ The created wp_image_description_v1 object preserves the image
+ description of the output from the time the object was created.
+
+ The resulting image description object allows get_information request.
+
+ If this protocol object is inert, the resulting image description object
+ shall immediately deliver the wp_image_description_v1.failed event with
+ the no_output cause.
+
+ If the interface version is inadequate for the output's image
+ description, meaning that the client does not support all the events
+ needed to deliver the crucial information, the resulting image
+ description object shall immediately deliver the
+ wp_image_description_v1.failed event with the low_version cause.
+
+ Otherwise the object shall immediately deliver the ready event.
+ </description>
+
+ <arg name="image_description"
+ type="new_id" interface="wp_image_description_v1"/>
+ </request>
+ </interface>
+
+ <interface name="wp_color_management_surface_v1" version="1">
+ <description summary="color management extension to a surface">
+ A wp_color_management_surface_v1 allows the client to set the color
+ space and HDR properties of a surface.
+
+ If the wl_surface associated with the wp_color_management_surface_v1 is
+ destroyed, the wp_color_management_surface_v1 object becomes inert.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the color management interface for a surface">
+ Destroy the wp_color_management_surface_v1 object and do the same as
+ unset_image_description.
+ </description>
+ </request>
+
+ <enum name="error">
+ <description summary="protocol errors"/>
+ <entry name="render_intent" value="0"
+ summary="unsupported rendering intent"/>
+ <entry name="image_description" value="1"
+ summary="invalid image description"/>
+ <entry name="inert" value="2"
+ summary="forbidden request on inert object"/>
+ </enum>
+
+ <request name="set_image_description">
+ <description summary="set the surface image description">
+ If this protocol object is inert, the protocol error inert is raised.
+
+ Set the image description of the underlying surface. The image
+ description and rendering intent are double-buffered state, see
+ wl_surface.commit.
+
+ It is the client's responsibility to understand the image description
+ it sets on a surface, and to provide content that matches that image
+ description. Compositors might convert images to match their own or any
+ other image descriptions.
+
+ Image descriptions which are not ready (see wp_image_description_v1)
+ are forbidden in this request, and in such case the protocol error
+ image_description is raised.
+
+ All image descriptions which are ready (see wp_image_description_v1)
+ are allowed and must always be accepted by the compositor.
+
+ A rendering intent provides the client's preference on how content
+ colors should be mapped to each output. The render_intent value must
+ be one advertised by the compositor with
+ wp_color_manager_v1.render_intent event, otherwise the protocol error
+ render_intent is raised.
+
+ When an image description is set on a surface, the Transfer
+ Characteristics of the image description defines the valid range of
+ the nominal (real-valued) color channel values. The processing of
+ out-of-range color channel values is undefined, but compositors are
+ recommended to clamp the values to the valid range when possible.
+
+ By default, a surface does not have an associated image description
+ nor a rendering intent. The handling of color on such surfaces is
+ compositor implementation defined. Compositors should handle such
+ surfaces as sRGB, but may handle them differently if they have specific
+ requirements.
+
+ Setting the image description has copy semantics; after this request,
+ the image description can be immediately destroyed without affecting
+ the pending state of the surface.
+ </description>
+
+ <arg name="image_description"
+ type="object" interface="wp_image_description_v1"/>
+ <arg name="render_intent"
+ type="uint" enum="wp_color_manager_v1.render_intent"
+ summary="rendering intent"/>
+ </request>
+
+ <request name="unset_image_description">
+ <description summary="remove the surface image description">
+ If this protocol object is inert, the protocol error inert is raised.
+
+ This request removes any image description from the surface. See
+ set_image_description for how a compositor handles a surface without
+ an image description. This is double-buffered state, see
+ wl_surface.commit.
+ </description>
+ </request>
+ </interface>
+
+ <interface name="wp_color_management_surface_feedback_v1" version="1">
+ <description summary="color management extension to a surface">
+ A wp_color_management_surface_feedback_v1 allows the client to get the
+ preferred image description of a surface.
+
+ If the wl_surface associated with this object is destroyed, the
+ wp_color_management_surface_feedback_v1 object becomes inert.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the color management interface for a surface">
+ Destroy the wp_color_management_surface_feedback_v1 object.
+ </description>
+ </request>
+
+ <enum name="error">
+ <description summary="protocol errors"/>
+ <entry name="inert" value="0"
+ summary="forbidden request on inert object"/>
+ <entry name="unsupported_feature" value="1"
+ summary="attempted to use an unsupported feature"/>
+ </enum>
+
+ <event name="preferred_changed">
+ <description summary="the preferred image description changed">
+ The preferred image description is the one which likely has the most
+ performance and/or quality benefits for the compositor if used by the
+ client for its wl_surface contents. This event is sent whenever the
+ compositor changes the wl_surface's preferred image description.
+
+ This event sends the identity of the new preferred state as the argument,
+ so clients who are aware of the image description already can reuse it.
+ Otherwise, if the client client wants to know what the preferred image
+ description is, it shall use the get_preferred request.
+
+ The preferred image description is not automatically used for anything.
+ It is only a hint, and clients may set any valid image description with
+ set_image_description, but there might be performance and color accuracy
+ improvements by providing the wl_surface contents in the preferred
+ image description. Therefore clients that can, should render according
+ to the preferred image description
+ </description>
+
+ <arg name="identity" type="uint" summary="image description id number"/>
+ </event>
+
+ <request name="get_preferred">
+ <description summary="get the preferred image description">
+ If this protocol object is inert, the protocol error inert is raised.
+
+ The preferred image description represents the compositor's preferred
+ color encoding for this wl_surface at the current time. There might be
+ performance and power advantages, as well as improved color
+ reproduction, if the image description of a content update matches the
+ preferred image description.
+
+ This creates a new wp_image_description_v1 object for the currently
+ preferred image description for the wl_surface. The client should
+ stop using and destroy the image descriptions created by earlier
+ invocations of this request for the associated wl_surface.
+ This request is usually sent as a reaction to the preferred_changed
+ event or when creating a wp_color_management_surface_feedback_v1 object
+ if the client is capable of adapting to image descriptions.
+
+ The created wp_image_description_v1 object preserves the preferred image
+ description of the wl_surface from the time the object was created.
+
+ The resulting image description object allows get_information request.
+
+ If the image description is parametric, the client should set it on its
+ wl_surface only if the image description is an exact match with the
+ client content. Particularly if everything else matches, but the target
+ color volume is greater than what the client needs, the client should
+ create its own parameric image description with its exact parameters.
+
+ If the interface version is inadequate for the preferred image
+ description, meaning that the client does not support all the
+ events needed to deliver the crucial information, the resulting image
+ description object shall immediately deliver the
+ wp_image_description_v1.failed event with the low_version cause,
+ otherwise the object shall immediately deliver the ready event.
+ </description>
+
+ <arg name="image_description"
+ type="new_id" interface="wp_image_description_v1"/>
+ </request>
+
+ <request name="get_preferred_parametric">
+ <description summary="get the preferred image description">
+ The same description as for get_preferred applies, except the returned
+ image description is guaranteed to be parametric. This is meant for
+ clients that can only deal with parametric image descriptions.
+
+ If the compositor doesn't support parametric image descriptions, the
+ unsupported_feature error is emitted.
+ </description>
+
+ <arg name="image_description"
+ type="new_id" interface="wp_image_description_v1"/>
+ </request>
+ </interface>
+
+ <interface name="wp_image_description_creator_icc_v1" version="1">
+ <description summary="holder of image description ICC information">
+ This type of object is used for collecting all the information required
+ to create a wp_image_description_v1 object from an ICC file. A complete
+ set of required parameters consists of these properties:
+ - ICC file
+
+ Each required property must be set exactly once if the client is to create
+ an image description. The set requests verify that a property was not
+ already set. The create request verifies that all required properties are
+ set. There may be several alternative requests for setting each property,
+ and in that case the client must choose one of them.
+
+ Once all properties have been set, the create request must be used to
+ create the image description object, destroying the creator in the
+ process.
+ </description>
+
+ <enum name="error">
+ <description summary="protocol errors"/>
+
+ <entry name="incomplete_set" value="0"
+ summary="incomplete parameter set"/>
+ <entry name="already_set" value="1"
+ summary="property already set"/>
+ <entry name="bad_fd" value="2"
+ summary="fd not seekable and readable"/>
+ <entry name="bad_size" value="3"
+ summary="no or too much data"/>
+ <entry name="out_of_file" value="4"
+ summary="offset + length exceeds file size"/>
+ </enum>
+
+ <request name="create" type="destructor">
+ <description summary="Create the image description object from ICC data">
+ Create an image description object based on the ICC information
+ previously set on this object. A compositor must parse the ICC data in
+ some undefined but finite amount of time.
+
+ The completeness of the parameter set is verified. If the set is not
+ complete, the protocol error incomplete_set is raised. For the
+ definition of a complete set, see the description of this interface.
+
+ If the particular combination of the information is not supported
+ by the compositor, the resulting image description object shall
+ immediately deliver the wp_image_description_v1.failed event with the
+ 'unsupported' cause. If a valid image description was created from the
+ information, the wp_image_description_v1.ready event will eventually
+ be sent instead.
+
+ This request destroys the wp_image_description_creator_icc_v1 object.
+
+ The resulting image description object does not allow get_information
+ request.
+ </description>
+
+ <arg name="image_description"
+ type="new_id" interface="wp_image_description_v1"/>
+ </request>
+
+ <request name="set_icc_file">
+ <description summary="set the ICC profile file">
+ Sets the ICC profile file to be used as the basis of the image
+ description.
+
+ The data shall be found through the given fd at the given offset, having
+ the given length. The fd must be seekable and readable. Violating these
+ requirements raises the bad_fd protocol error.
+
+ If reading the data fails due to an error independent of the client, the
+ compositor shall send the wp_image_description_v1.failed event on the
+ created wp_image_description_v1 with the 'operating_system' cause.
+
+ The maximum size of the ICC profile is 32 MB. If length is greater than
+ that or zero, the protocol error bad_size is raised. If offset + length
+ exceeds the file size, the protocol error out_of_file is raised.
+
+ A compositor may read the file at any time starting from this request
+ and only until whichever happens first:
+ - If create request was issued, the wp_image_description_v1 object
+ delivers either failed or ready event; or
+ - if create request was not issued, this
+ wp_image_description_creator_icc_v1 object is destroyed.
+
+ A compositor shall not modify the contents of the file, and the fd may
+ be sealed for writes and size changes. The client must ensure to its
+ best ability that the data does not change while the compositor is
+ reading it.
+
+ The data must represent a valid ICC profile. The ICC profile version
+ must be 2 or 4, it must be a 3 channel profile and the class must be
+ Display or ColorSpace. Violating these requirements will not result in a
+ protocol error, but will eventually send the
+ wp_image_description_v1.failed event on the created
+ wp_image_description_v1 with the 'unsupported' cause.
+
+ See the International Color Consortium specification ICC.1:2022 for more
+ details about ICC profiles.
+
+ If ICC file has already been set on this object, the protocol error
+ already_set is raised.
+ </description>
+
+ <arg name="icc_profile" type="fd"
+ summary="ICC profile"/>
+ <arg name="offset" type="uint"
+ summary="byte offset in fd to start of ICC data"/>
+ <arg name="length" type="uint"
+ summary="length of ICC data in bytes"/>
+ </request>
+ </interface>
+
+ <interface name="wp_image_description_creator_params_v1" version="1">
+ <description summary="holder of image description parameters">
+ This type of object is used for collecting all the parameters required
+ to create a wp_image_description_v1 object. A complete set of required
+ parameters consists of these properties:
+ - transfer characteristic function (tf)
+ - chromaticities of primaries and white point (primary color volume)
+
+ The following properties are optional and have a well-defined default
+ if not explicitly set:
+ - primary color volume luminance range
+ - reference white luminance level
+ - mastering display primaries and white point (target color volume)
+ - mastering luminance range
+
+ The following properties are optional and will be ignored
+ if not explicitly set:
+ - maximum content light level
+ - maximum frame-average light level
+
+ Each required property must be set exactly once if the client is to create
+ an image description. The set requests verify that a property was not
+ already set. The create request verifies that all required properties are
+ set. There may be several alternative requests for setting each property,
+ and in that case the client must choose one of them.
+
+ Once all properties have been set, the create request must be used to
+ create the image description object, destroying the creator in the
+ process.
+ </description>
+
+ <enum name="error">
+ <description summary="protocol errors"/>
+
+ <entry name="incomplete_set" value="0"
+ summary="incomplete parameter set"/>
+ <entry name="already_set" value="1"
+ summary="property already set"/>
+ <entry name="unsupported_feature" value="2"
+ summary="request not supported"/>
+ <entry name="invalid_tf" value="3"
+ summary="invalid transfer characteristic"/>
+ <entry name="invalid_primaries_named" value="4"
+ summary="invalid primaries named"/>
+ <entry name="invalid_luminance" value="5"
+ summary="invalid luminance value or range"/>
+ </enum>
+
+ <request name="create" type="destructor">
+ <description summary="Create the image description object using params">
+ Create an image description object based on the parameters previously
+ set on this object.
+
+ The completeness of the parameter set is verified. If the set is not
+ complete, the protocol error incomplete_set is raised. For the
+ definition of a complete set, see the description of this interface.
+
+ The protocol error invalid_luminance is raised if any of the following
+ requirements is not met:
+ - When max_cll is set, it must be greater than min L and less or equal
+ to max L of the mastering luminance range.
+ - When max_fall is set, it must be greater than min L and less or equal
+ to max L of the mastering luminance range.
+ - When both max_cll and max_fall are set, max_fall must be less or equal
+ to max_cll.
+
+ If the particular combination of the parameter set is not supported
+ by the compositor, the resulting image description object shall
+ immediately deliver the wp_image_description_v1.failed event with the
+ 'unsupported' cause. If a valid image description was created from the
+ parameter set, the wp_image_description_v1.ready event will eventually
+ be sent instead.
+
+ This request destroys the wp_image_description_creator_params_v1
+ object.
+
+ The resulting image description object does not allow get_information
+ request.
+ </description>
+
+ <arg name="image_description"
+ type="new_id" interface="wp_image_description_v1"/>
+ </request>
+
+ <request name="set_tf_named">
+ <description summary="named transfer characteristic">
+ Sets the transfer characteristic using explicitly enumerated named
+ functions.
+
+ When the resulting image description is attached to an image, the
+ content should be encoded and decoded according to the industry standard
+ practices for the transfer characteristic.
+
+ Only names advertised with wp_color_manager_v1 event supported_tf_named
+ are allowed. Other values shall raise the protocol error invalid_tf.
+
+ If transfer characteristic has already been set on this object, the
+ protocol error already_set is raised.
+ </description>
+
+ <arg name="tf" type="uint" enum="wp_color_manager_v1.transfer_function"
+ summary="named transfer function"/>
+ </request>
+
+ <request name="set_tf_power">
+ <description summary="transfer characteristic as a power curve">
+ Sets the color component transfer characteristic to a power curve with
+ the given exponent. Negative values are handled by mirroring the
+ positive half of the curve through the origin. The valid domain and
+ range of the curve are all finite real numbers. This curve represents
+ the conversion from electrical to optical color channel values.
+
+ When the resulting image description is attached to an image, the
+ content should be encoded with the inverse of the power curve.
+
+ The curve exponent shall be multiplied by 10000 to get the argument eexp
+ value to carry the precision of 4 decimals.
+
+ The curve exponent must be at least 1.0 and at most 10.0. Otherwise the
+ protocol error invalid_tf is raised.
+
+ If transfer characteristic has already been set on this object, the
+ protocol error already_set is raised.
+
+ This request can be used when the compositor advertises
+ wp_color_manager_v1.feature.set_tf_power. Otherwise this request raises
+ the protocol error unsupported_feature.
+ </description>
+
+ <arg name="eexp" type="uint" summary="the exponent * 10000"/>
+ </request>
+
+ <request name="set_primaries_named">
+ <description summary="named primaries">
+ Sets the color primaries and white point using explicitly named sets.
+ This describes the primary color volume which is the basis for color
+ value encoding.
+
+ Only names advertised with wp_color_manager_v1 event
+ supported_primaries_named are allowed. Other values shall raise the
+ protocol error invalid_primaries_named.
+
+ If primaries have already been set on this object, the protocol error
+ already_set is raised.
+ </description>
+
+ <arg name="primaries" type="uint" enum="wp_color_manager_v1.primaries"
+ summary="named primaries"/>
+ </request>
+
+ <request name="set_primaries">
+ <description summary="primaries as chromaticity coordinates">
+ Sets the color primaries and white point using CIE 1931 xy chromaticity
+ coordinates. This describes the primary color volume which is the basis
+ for color value encoding.
+
+ Each coordinate value is multiplied by 1 million to get the argument
+ value to carry precision of 6 decimals.
+
+ If primaries have already been set on this object, the protocol error
+ already_set is raised.
+
+ This request can be used if the compositor advertises
+ wp_color_manager_v1.feature.set_primaries. Otherwise this request raises
+ the protocol error unsupported_feature.
+ </description>
+
+ <arg name="r_x" type="int" summary="Red x * 1M"/>
+ <arg name="r_y" type="int" summary="Red y * 1M"/>
+ <arg name="g_x" type="int" summary="Green x * 1M"/>
+ <arg name="g_y" type="int" summary="Green y * 1M"/>
+ <arg name="b_x" type="int" summary="Blue x * 1M"/>
+ <arg name="b_y" type="int" summary="Blue y * 1M"/>
+ <arg name="w_x" type="int" summary="White x * 1M"/>
+ <arg name="w_y" type="int" summary="White y * 1M"/>
+ </request>
+
+ <request name="set_luminances">
+ <description summary="primary color volume luminance range and reference white">
+ Sets the primary color volume luminance range and the reference white
+ luminance level. These values include the minimum display emission
+ and ambient flare luminances, assumed to be optically additive and have
+ the chromaticity of the primary color volume white point.
+
+ The default luminances from
+ https://www.color.org/chardata/rgb/srgb.xalter are
+ - primary color volume minimum: 0.2 cd/m²
+ - primary color volume maximum: 80 cd/m²
+ - reference white: 80 cd/m²
+
+ Setting a named transfer characteristic can imply other default
+ luminances.
+
+ The default luminances get overwritten when this request is used.
+ With transfer_function.st2084_pq the given 'max_lum' value is ignored,
+ and 'max_lum' is taken as 'min_lum' + 10000 cd/m².
+
+ 'min_lum' and 'max_lum' specify the minimum and maximum luminances of
+ the primary color volume as reproduced by the targeted display.
+
+ 'reference_lum' specifies the luminance of the reference white as
+ reproduced by the targeted display, and reflects the targeted viewing
+ environment.
+
+ Compositors should make sure that all content is anchored, meaning that
+ an input signal level of 'reference_lum' on one image description and
+ another input signal level of 'reference_lum' on another image
+ description should produce the same output level, even though the
+ 'reference_lum' on both image representations can be different.
+
+ 'reference_lum' may be higher than 'max_lum'. In that case reaching
+ the reference white output level in image content requires the
+ 'extended_target_volume' feature support.
+
+ If 'max_lum' or 'reference_lum' are less than or equal to 'min_lum',
+ the protocol error invalid_luminance is raised.
+
+ The minimum luminance is multiplied by 10000 to get the argument
+ 'min_lum' value and carries precision of 4 decimals. The maximum
+ luminance and reference white luminance values are unscaled.
+
+ If the primary color volume luminance range and the reference white
+ luminance level have already been set on this object, the protocol error
+ already_set is raised.
+
+ This request can be used if the compositor advertises
+ wp_color_manager_v1.feature.set_luminances. Otherwise this request
+ raises the protocol error unsupported_feature.
+ </description>
+
+ <arg name="min_lum" type="uint"
+ summary="minimum luminance (cd/m²) * 10000"/>
+ <arg name="max_lum" type="uint"
+ summary="maximum luminance (cd/m²)"/>
+ <arg name="reference_lum" type="uint"
+ summary="reference white luminance (cd/m²)"/>
+ </request>
+
+ <request name="set_mastering_display_primaries">
+ <description summary="mastering display primaries as chromaticity coordinates">
+ Provides the color primaries and white point of the mastering display
+ using CIE 1931 xy chromaticity coordinates. This is compatible with the
+ SMPTE ST 2086 definition of HDR static metadata.
+
+ The mastering display primaries and mastering display luminances define
+ the target color volume.
+
+ If mastering display primaries are not explicitly set, the target color
+ volume is assumed to have the same primaries as the primary color volume.
+
+ The target color volume is defined by all tristimulus values between 0.0
+ and 1.0 (inclusive) of the color space defined by the given mastering
+ display primaries and white point. The colorimetry is identical between
+ the container color space and the mastering display color space,
+ including that no chromatic adaptation is applied even if the white
+ points differ.
+
+ The target color volume can exceed the primary color volume to allow for
+ a greater color volume with an existing color space definition (for
+ example scRGB). It can be smaller than the primary color volume to
+ minimize gamut and tone mapping distances for big color spaces (HDR
+ metadata).
+
+ To make use of the entire target color volume a suitable pixel format
+ has to be chosen (e.g. floating point to exceed the primary color
+ volume, or abusing limited quantization range as with xvYCC).
+
+ Each coordinate value is multiplied by 1 million to get the argument
+ value to carry precision of 6 decimals.
+
+ If mastering display primaries have already been set on this object, the
+ protocol error already_set is raised.
+
+ This request can be used if the compositor advertises
+ wp_color_manager_v1.feature.set_mastering_display_primaries. Otherwise
+ this request raises the protocol error unsupported_feature. The
+ advertisement implies support only for target color volumes fully
+ contained within the primary color volume.
+
+ If a compositor additionally supports target color volume exceeding the
+ primary color volume, it must advertise
+ wp_color_manager_v1.feature.extended_target_volume. If a client uses
+ target color volume exceeding the primary color volume and the
+ compositor does not support it, the result is implementation defined.
+ Compositors are recommended to detect this case and fail the image
+ description gracefully, but it may as well result in color artifacts.
+ </description>
+
+ <arg name="r_x" type="int" summary="Red x * 1M"/>
+ <arg name="r_y" type="int" summary="Red y * 1M"/>
+ <arg name="g_x" type="int" summary="Green x * 1M"/>
+ <arg name="g_y" type="int" summary="Green y * 1M"/>
+ <arg name="b_x" type="int" summary="Blue x * 1M"/>
+ <arg name="b_y" type="int" summary="Blue y * 1M"/>
+ <arg name="w_x" type="int" summary="White x * 1M"/>
+ <arg name="w_y" type="int" summary="White y * 1M"/>
+ </request>
+
+ <request name="set_mastering_luminance">
+ <description summary="display mastering luminance range">
+ Sets the luminance range that was used during the content mastering
+ process as the minimum and maximum absolute luminance L. These values
+ include the minimum display emission and ambient flare luminances,
+ assumed to be optically additive and have the chromaticity of the
+ primary color volume white point. This should be
+ compatible with the SMPTE ST 2086 definition of HDR static metadata.
+
+ The mastering display primaries and mastering display luminances define
+ the target color volume.
+
+ If mastering luminances are not explicitly set, the target color volume
+ is assumed to have the same min and max luminances as the primary color
+ volume.
+
+ If max L is less than or equal to min L, the protocol error
+ invalid_luminance is raised.
+
+ Min L value is multiplied by 10000 to get the argument min_lum value
+ and carry precision of 4 decimals. Max L value is unscaled for max_lum.
+
+ This request can be used if the compositor advertises
+ wp_color_manager_v1.feature.set_mastering_display_primaries. Otherwise
+ this request raises the protocol error unsupported_feature. The
+ advertisement implies support only for target color volumes fully
+ contained within the primary color volume.
+
+ If a compositor additionally supports target color volume exceeding the
+ primary color volume, it must advertise
+ wp_color_manager_v1.feature.extended_target_volume. If a client uses
+ target color volume exceeding the primary color volume and the
+ compositor does not support it, the result is implementation defined.
+ Compositors are recommended to detect this case and fail the image
+ description gracefully, but it may as well result in color artifacts.
+ </description>
+
+ <arg name="min_lum" type="uint" summary="min L (cd/m²) * 10000"/>
+ <arg name="max_lum" type="uint" summary="max L (cd/m²)"/>
+ </request>
+
+ <request name="set_max_cll">
+ <description summary="maximum content light level">
+ Sets the maximum content light level (max_cll) as defined by CTA-861-H.
+
+ max_cll is undefined by default.
+ </description>
+
+ <arg name="max_cll" type="uint" summary="Maximum content light level (cd/m²)"/>
+ </request>
+
+ <request name="set_max_fall">
+ <description summary="maximum frame-average light level">
+ Sets the maximum frame-average light level (max_fall) as defined by
+ CTA-861-H.
+
+ max_fall is undefined by default.
+ </description>
+
+ <arg name="max_fall" type="uint" summary="Maximum frame-average light level (cd/m²)"/>
+ </request>
+ </interface>
+
+ <interface name="wp_image_description_v1" version="1">
+ <description summary="Colorimetric image description">
+ An image description carries information about the color encoding used on
+ a surface when attached to a wl_surface via
+ wp_color_management_surface_v1.set_image_description. A compositor can use
+ this information to decode pixel values into colorimetrically meaningful
+ quantities.
+
+ Note, that the wp_image_description_v1 object is not ready to be used
+ immediately after creation. The object eventually delivers either the
+ 'ready' or the 'failed' event, specified in all requests creating it. The
+ object is deemed "ready" after receiving the 'ready' event.
+
+ An object which is not ready is illegal to use, it can only be destroyed.
+ Any other request in this interface shall result in the 'not_ready'
+ protocol error. Attempts to use an object which is not ready through other
+ interfaces shall raise protocol errors defined there.
+
+ Once created and regardless of how it was created, a
+ wp_image_description_v1 object always refers to one fixed image
+ description. It cannot change after creation.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the image description">
+ Destroy this object. It is safe to destroy an object which is not ready.
+
+ Destroying a wp_image_description_v1 object has no side-effects, not
+ even if a wp_color_management_surface_v1.set_image_description has not
+ yet been followed by a wl_surface.commit.
+ </description>
+ </request>
+
+ <enum name="error">
+ <description summary="protocol errors"/>
+
+ <entry name="not_ready" value="0"
+ summary="attempted to use an object which is not ready"/>
+ <entry name="no_information" value="1"
+ summary="get_information not allowed"/>
+ </enum>
+
+ <enum name="cause">
+ <description summary="generic reason for failure"/>
+
+ <entry name="low_version" value="0"
+ summary="interface version too low"/>
+ <entry name="unsupported" value="1"
+ summary="unsupported image description data"/>
+ <entry name="operating_system" value="2"
+ summary="error independent of the client"/>
+ <entry name="no_output" value="3"
+ summary="the relevant output no longer exists"/>
+ </enum>
+
+ <event name="failed">
+ <description summary="graceful error on creating the image description">
+ If creating a wp_image_description_v1 object fails for a reason that is
+ not defined as a protocol error, this event is sent.
+
+ The requests that create image description objects define whether and
+ when this can occur. Only such creation requests can trigger this event.
+ This event cannot be triggered after the image description was
+ successfully formed.
+
+ Once this event has been sent, the wp_image_description_v1 object will
+ never become ready and it can only be destroyed.
+ </description>
+
+ <arg name="cause" type="uint" enum="cause"
+ summary="generic reason"/>
+ <arg name="msg" type="string"
+ summary="ad hoc human-readable explanation"/>
+ </event>
+
+ <event name="ready">
+ <description summary="indication that the object is ready to be used">
+ Once this event has been sent, the wp_image_description_v1 object is
+ deemed "ready". Ready objects can be used to send requests and can be
+ used through other interfaces.
+
+ Every ready wp_image_description_v1 protocol object refers to an
+ underlying image description record in the compositor. Multiple protocol
+ objects may end up referring to the same record. Clients may identify
+ these "copies" by comparing their id numbers: if the numbers from two
+ protocol objects are identical, the protocol objects refer to the same
+ image description record. Two different image description records
+ cannot have the same id number simultaneously. The id number does not
+ change during the lifetime of the image description record.
+
+ The id number is valid only as long as the protocol object is alive. If
+ all protocol objects referring to the same image description record are
+ destroyed, the id number may be recycled for a different image
+ description record.
+
+ Image description id number is not a protocol object id. Zero is
+ reserved as an invalid id number. It shall not be possible for a client
+ to refer to an image description by its id number in protocol. The id
+ numbers might not be portable between Wayland connections. A compositor
+ shall not send an invalid id number.
+
+ This identity allows clients to de-duplicate image description records
+ and avoid get_information request if they already have the image
+ description information.
+ </description>
+
+ <arg name="identity" type="uint" summary="image description id number"/>
+ </event>
+
+ <request name="get_information">
+ <description summary="get information about the image description">
+ Creates a wp_image_description_info_v1 object which delivers the
+ information that makes up the image description.
+
+ Not all image description protocol objects allow get_information
+ request. Whether it is allowed or not is defined by the request that
+ created the object. If get_information is not allowed, the protocol
+ error no_information is raised.
+ </description>
+
+ <arg name="information"
+ type="new_id" interface="wp_image_description_info_v1"/>
+ </request>
+ </interface>
+
+ <interface name="wp_image_description_info_v1" version="1">
+ <description summary="Colorimetric image description information">
+ Sends all matching events describing an image description object exactly
+ once and finally sends the 'done' event.
+
+ This means
+ - if the image description is parametric, it must send
+ - primaries
+ - named_primaries, if applicable
+ - at least one of tf_power and tf_named, as applicable
+ - luminances
+ - target_primaries
+ - target_luminance
+ - if the image description is parametric, it may send, if applicable,
+ - target_max_cll
+ - target_max_fall
+ - if the image description contains an ICC profile, it must send the
+ icc_file event
+
+ Once a wp_image_description_info_v1 object has delivered a 'done' event it
+ is automatically destroyed.
+
+ Every wp_image_description_info_v1 created from the same
+ wp_image_description_v1 shall always return the exact same data.
+ </description>
+
+ <event name="done" type="destructor">
+ <description summary="end of information">
+ Signals the end of information events and destroys the object.
+ </description>
+ </event>
+
+ <event name="icc_file">
+ <description summary="ICC profile matching the image description">
+ The icc argument provides a file descriptor to the client which may be
+ memory-mapped to provide the ICC profile matching the image description.
+ The fd is read-only, and if mapped then it must be mapped with
+ MAP_PRIVATE by the client.
+
+ The ICC profile version and other details are determined by the
+ compositor. There is no provision for a client to ask for a specific
+ kind of a profile.
+ </description>
+
+ <arg name="icc" type="fd" summary="ICC profile file descriptor"/>
+ <arg name="icc_size" type="uint" summary="ICC profile size, in bytes"/>
+ <!-- Offset always 0, compositor must not expose unnecessary data. -->
+ </event>
+
+ <event name="primaries">
+ <description summary="primaries as chromaticity coordinates">
+ Delivers the primary color volume primaries and white point using CIE
+ 1931 xy chromaticity coordinates.
+
+ Each coordinate value is multiplied by 1 million to get the argument
+ value to carry precision of 6 decimals.
+ </description>
+
+ <arg name="r_x" type="int" summary="Red x * 1M"/>
+ <arg name="r_y" type="int" summary="Red y * 1M"/>
+ <arg name="g_x" type="int" summary="Green x * 1M"/>
+ <arg name="g_y" type="int" summary="Green y * 1M"/>
+ <arg name="b_x" type="int" summary="Blue x * 1M"/>
+ <arg name="b_y" type="int" summary="Blue y * 1M"/>
+ <arg name="w_x" type="int" summary="White x * 1M"/>
+ <arg name="w_y" type="int" summary="White y * 1M"/>
+ </event>
+
+ <event name="primaries_named">
+ <description summary="named primaries">
+ Delivers the primary color volume primaries and white point using an
+ explicitly enumerated named set.
+ </description>
+
+ <arg name="primaries" type="uint" enum="wp_color_manager_v1.primaries"
+ summary="named primaries"/>
+ </event>
+
+ <event name="tf_power">
+ <description summary="transfer characteristic as a power curve">
+ The color component transfer characteristic of this image description is
+ a pure power curve. This event provides the exponent of the power
+ function. This curve represents the conversion from electrical to
+ optical pixel or color values.
+
+ The curve exponent has been multiplied by 10000 to get the argument eexp
+ value to carry the precision of 4 decimals.
+ </description>
+
+ <arg name="eexp" type="uint" summary="the exponent * 10000"/>
+ </event>
+
+ <event name="tf_named">
+ <description summary="named transfer characteristic">
+ Delivers the transfer characteristic using an explicitly enumerated
+ named function.
+ </description>
+
+ <arg name="tf" type="uint" enum="wp_color_manager_v1.transfer_function"
+ summary="named transfer function"/>
+ </event>
+
+ <event name="luminances">
+ <description summary="primary color volume luminance range and reference white">
+ Delivers the primary color volume luminance range and the reference
+ white luminance level. These values include the minimum display emission
+ and ambient flare luminances, assumed to be optically additive and have
+ the chromaticity of the primary color volume white point.
+
+ The minimum luminance is multiplied by 10000 to get the argument
+ 'min_lum' value and carries precision of 4 decimals. The maximum
+ luminance and reference white luminance values are unscaled.
+ </description>
+
+ <arg name="min_lum" type="uint"
+ summary="minimum luminance (cd/m²) * 10000"/>
+ <arg name="max_lum" type="uint"
+ summary="maximum luminance (cd/m²)"/>
+ <arg name="reference_lum" type="uint"
+ summary="reference white luminance (cd/m²)"/>
+ </event>
+
+ <event name="target_primaries">
+ <description summary="target primaries as chromaticity coordinates">
+ Provides the color primaries and white point of the target color volume
+ using CIE 1931 xy chromaticity coordinates. This is compatible with the
+ SMPTE ST 2086 definition of HDR static metadata for mastering displays.
+
+ While primary color volume is about how color is encoded, the target
+ color volume is the actually displayable color volume. If target color
+ volume is equal to the primary color volume, then this event is not
+ sent.
+
+ Each coordinate value is multiplied by 1 million to get the argument
+ value to carry precision of 6 decimals.
+ </description>
+
+ <arg name="r_x" type="int" summary="Red x * 1M"/>
+ <arg name="r_y" type="int" summary="Red y * 1M"/>
+ <arg name="g_x" type="int" summary="Green x * 1M"/>
+ <arg name="g_y" type="int" summary="Green y * 1M"/>
+ <arg name="b_x" type="int" summary="Blue x * 1M"/>
+ <arg name="b_y" type="int" summary="Blue y * 1M"/>
+ <arg name="w_x" type="int" summary="White x * 1M"/>
+ <arg name="w_y" type="int" summary="White y * 1M"/>
+ </event>
+
+ <event name="target_luminance">
+ <description summary="target luminance range">
+ Provides the luminance range that the image description is targeting as
+ the minimum and maximum absolute luminance L. These values include the
+ minimum display emission and ambient flare luminances, assumed to be
+ optically additive and have the chromaticity of the primary color
+ volume white point. This should be compatible with the SMPTE ST 2086
+ definition of HDR static metadata.
+
+ This luminance range is only theoretical and may not correspond to the
+ luminance of light emitted on an actual display.
+
+ Min L value is multiplied by 10000 to get the argument min_lum value and
+ carry precision of 4 decimals. Max L value is unscaled for max_lum.
+ </description>
+
+ <arg name="min_lum" type="uint" summary="min L (cd/m²) * 10000"/>
+ <arg name="max_lum" type="uint" summary="max L (cd/m²)"/>
+ </event>
+
+ <event name="target_max_cll">
+ <description summary="target maximum content light level">
+ Provides the targeted max_cll of the image description. max_cll is
+ defined by CTA-861-H.
+
+ This luminance is only theoretical and may not correspond to the
+ luminance of light emitted on an actual display.
+ </description>
+
+ <arg name="max_cll" type="uint"
+ summary="Maximum content light-level (cd/m²)"/>
+ </event>
+
+ <event name="target_max_fall">
+ <description summary="target maximum frame-average light level">
+ Provides the targeted max_fall of the image description. max_fall is
+ defined by CTA-861-H.
+
+ This luminance is only theoretical and may not correspond to the
+ luminance of light emitted on an actual display.
+ </description>
+
+ <arg name="max_fall" type="uint"
+ summary="Maximum frame-average light level (cd/m²)"/>
+ </event>
+ </interface>
+</protocol>
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIColorManager.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIColorManager.cpp
new file mode 100644
index 0000000000..61fcf054fb
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIColorManager.cpp
@@ -0,0 +1,61 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandAPIColorManager.h"
+
+#include <QDebug>
+
+KisWaylandAPIColorManager::KisWaylandAPIColorManager()
+ : QWaylandClientExtensionTemplate(1)
+{
+ connect(this, &QWaylandClientExtensionTemplate::activeChanged, this, [this] {
+ if (!isActive()) {
+ m_supportedFeatures.clear();
+ m_supportedIntents.clear();
+ m_supportedPrimariesNamed.clear();
+ m_supportedTransferFunctionsNamed.clear();
+ if (m_isReady) {
+ m_isReady = false;
+ Q_EMIT sigReadyChanged(m_isReady);
+ }
+ }
+ });
+}
+
+KisWaylandAPIColorManager::~KisWaylandAPIColorManager()
+{
+ // the destruction of the member object is automatically handled
+ // be the extension template class (thanks to the second template
+ // parameter)
+}
+
+void KisWaylandAPIColorManager::wp_color_manager_v1_supported_intent(uint32_t _render_intent)
+{
+ m_supportedIntents.insert(static_cast<render_intent>(_render_intent));
+}
+void KisWaylandAPIColorManager::wp_color_manager_v1_supported_feature(uint32_t _feature)
+{
+ m_supportedFeatures.insert(static_cast<feature>(_feature));
+}
+void KisWaylandAPIColorManager::wp_color_manager_v1_supported_tf_named(uint32_t tf)
+{
+ m_supportedTransferFunctionsNamed.insert(static_cast<transfer_function>(tf));
+}
+void KisWaylandAPIColorManager::wp_color_manager_v1_supported_primaries_named(uint32_t _primaries)
+{
+ m_supportedPrimariesNamed.insert(static_cast<primaries>(_primaries));
+}
+void KisWaylandAPIColorManager::wp_color_manager_v1_done()
+{
+ if (m_isReady) {
+ qWarning() << "WARNING: KisWaylandAPIColorManager::wp_color_manager_v1_done(): done event arrived while ready is true";
+ }
+
+ m_isReady = true;
+ Q_EMIT sigReadyChanged(m_isReady);
+}
+
+#include "moc_KisWaylandAPIColorManager.cpp"
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIColorManager.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIColorManager.h
new file mode 100644
index 0000000000..c570c14c57
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIColorManager.h
@@ -0,0 +1,65 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISWAYLANDAPICOLORMANAGER_H
+#define KISWAYLANDAPICOLORMANAGER_H
+
+#include <QWaylandClientExtension>
+#include <qwayland-color-management-v1.h>
+
+#include <QSet>
+
+class KisWaylandAPIColorManager
+ : public QWaylandClientExtensionTemplate<KisWaylandAPIColorManager, &QtWayland::wp_color_manager_v1::destroy>
+ , public QtWayland::wp_color_manager_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPIColorManager();
+ ~KisWaylandAPIColorManager();
+
+ bool isReady() const {
+ return m_isReady;
+ }
+
+ bool isFeatureSupported(feature f) const
+ {
+ return m_supportedFeatures.contains(f);
+ }
+
+ bool isIntentSupported(render_intent ri) const
+ {
+ return m_supportedIntents.contains(ri);
+ }
+
+ bool isTransferFunctionNamedSupported(transfer_function tf) const
+ {
+ return m_supportedTransferFunctionsNamed.contains(tf);
+ }
+
+ bool isPrimariesNamedSupported(primaries p) const
+ {
+ return m_supportedPrimariesNamed.contains(p);
+ }
+
+Q_SIGNALS:
+ void sigReadyChanged(bool value);
+
+protected:
+ void wp_color_manager_v1_supported_intent(uint32_t _render_intent) override;
+ void wp_color_manager_v1_supported_feature(uint32_t _feature) override;
+ void wp_color_manager_v1_supported_tf_named(uint32_t tf) override;
+ void wp_color_manager_v1_supported_primaries_named(uint32_t _primaries) override;
+ void wp_color_manager_v1_done() override;
+
+private:
+ QSet<render_intent> m_supportedIntents;
+ QSet<feature> m_supportedFeatures;
+ QSet<transfer_function> m_supportedTransferFunctionsNamed;
+ QSet<primaries> m_supportedPrimariesNamed;
+ bool m_isReady {false};
+};
+
+#endif /* KISWAYLANDAPICOLORMANAGER_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescription.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescription.cpp
new file mode 100644
index 0000000000..84986f9c67
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescription.cpp
@@ -0,0 +1,161 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandAPIImageDescription.h"
+
+using namespace Qt::Literals::StringLiterals;
+
+
+KisWaylandAPIImageDescriptionInfo::KisWaylandAPIImageDescriptionInfo(::wp_image_description_info_v1 *info)
+ : QtWayland::wp_image_description_info_v1(info)
+{
+}
+KisWaylandAPIImageDescriptionInfo::~KisWaylandAPIImageDescriptionInfo()
+{
+ wp_image_description_info_v1_destroy(object());
+}
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_done()
+{
+ m_isReady = true;
+ Q_EMIT done();
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_primaries(int32_t r_x,
+ int32_t r_y,
+ int32_t g_x,
+ int32_t g_y,
+ int32_t b_x,
+ int32_t b_y,
+ int32_t w_x,
+ int32_t w_y)
+{
+ using KisSurfaceColorimetry::WaylandPrimaries;
+ using KisSurfaceColorimetry::xyFromWaylandXy;
+
+ WaylandPrimaries colorPrimaries;
+ colorPrimaries.red = xyFromWaylandXy(r_x, r_y);
+ colorPrimaries.green = xyFromWaylandXy(g_x, g_y);
+ colorPrimaries.blue = xyFromWaylandXy(b_x, b_y);
+ colorPrimaries.white = xyFromWaylandXy(w_x, w_y);
+ m_data.container = colorPrimaries;
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_primaries_named(uint32_t primaries)
+{
+ using KisSurfaceColorimetry::WaylandSurfaceDescription;
+
+ Q_ASSERT(!m_data.namedContainer);
+ m_data.namedContainer = WaylandSurfaceDescription::primaries(primaries);
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_tf_power(uint32_t eexp)
+{
+ Q_ASSERT(!m_data.tfGamma);
+ m_data.tfGamma = eexp;
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_tf_named(uint32_t tf)
+{
+ using KisSurfaceColorimetry::WaylandSurfaceDescription;
+
+ Q_ASSERT(!m_data.tfNamed);
+ m_data.tfNamed = WaylandSurfaceDescription::transfer_function(tf);
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_luminances(uint32_t min_lum, uint32_t max_lum, uint32_t reference_lum)
+{
+ m_data.luminances = {min_lum, max_lum, reference_lum};
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_primaries(int32_t r_x,
+ int32_t r_y,
+ int32_t g_x,
+ int32_t g_y,
+ int32_t b_x,
+ int32_t b_y,
+ int32_t w_x,
+ int32_t w_y)
+
+{
+ using KisSurfaceColorimetry::WaylandPrimaries;
+ using KisSurfaceColorimetry::xyFromWaylandXy;
+
+ WaylandPrimaries colorPrimaries;
+ colorPrimaries.red = xyFromWaylandXy(r_x, r_y);
+ colorPrimaries.green = xyFromWaylandXy(g_x, g_y);
+ colorPrimaries.blue = xyFromWaylandXy(b_x, b_y);
+ colorPrimaries.white = xyFromWaylandXy(w_x, w_y);
+ m_data.target = colorPrimaries;
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_luminance(uint32_t min_lum, uint32_t max_lum)
+{
+ m_data.masteringLuminance = {min_lum, max_lum};
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_max_cll(uint32_t max_cll)
+{
+ m_data.targetMaxCLL = max_cll;
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_max_fall(uint32_t max_fall)
+{
+ m_data.targetMaxFALL = max_fall;
+}
+
+void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_icc_file(int32_t icc, uint32_t icc_size)
+{
+ Q_UNUSED(icc)
+ Q_UNUSED(icc_size)
+ m_data.iccFileIsPresent = true;
+ qWarning() << "WARNING: wp_image_description_info_v1_icc_file was received, but we don't support ICC files for the surface description!";
+}
+
+KisWaylandAPIImageDescription::KisWaylandAPIImageDescription(::wp_image_description_v1 *descr)
+ : QtWayland::wp_image_description_v1(descr)
+ , info(get_information())
+{
+ connect(&info, &KisWaylandAPIImageDescriptionInfo::done, this, &KisWaylandAPIImageDescription::done);
+}
+
+KisWaylandAPIImageDescription::~KisWaylandAPIImageDescription()
+{
+ wp_image_description_v1_destroy(object());
+}
+
+void KisWaylandAPIImageDescription::wp_image_description_v1_failed(uint32_t cause, const QString &msg)
+{
+ using cause_type = QtWayland::wp_image_description_v1::cause;
+
+ cause_type realCause = static_cast<cause_type>(cause);
+ QLatin1String causeText;
+
+ switch (realCause) {
+ case cause_low_version:
+ causeText = "cause_low_version"_L1;
+ break;
+ case cause_unsupported:
+ causeText = "cause_unsupported"_L1;
+ break;
+ case cause_operating_system:
+ causeText = "cause_operating_system"_L1;
+ break;
+ case cause_no_output:
+ causeText = "cause_no_output"_L1;
+ break;
+ }
+
+ qWarning() << "KisWaylandImageDescription: Failed to create image description:" << causeText << ": " << msg;
+ Q_EMIT sigDescriptionConstructed(false);
+}
+
+void KisWaylandAPIImageDescription::wp_image_description_v1_ready(uint32_t identity)
+{
+ m_identity = identity;
+ Q_EMIT sigDescriptionConstructed(true);
+}
+
+#include "moc_KisWaylandAPIImageDescription.cpp"
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescription.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescription.h
new file mode 100644
index 0000000000..45b654fd17
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescription.h
@@ -0,0 +1,75 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISWAYLANDAPIIMAGEDESCRIPTION_H
+#define KISWAYLANDAPIIMAGEDESCRIPTION_H
+
+#include <QWaylandClientExtension>
+#include <qwayland-color-management-v1.h>
+
+#include <QString>
+#include <QPointF>
+
+#include "KisWaylandSurfaceColorimetry.h"
+
+class KisWaylandAPIImageDescriptionInfo : public QObject, public QtWayland::wp_image_description_info_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPIImageDescriptionInfo(::wp_image_description_info_v1 *info);
+
+ ~KisWaylandAPIImageDescriptionInfo();
+
+ bool isReady() const {
+ return m_isReady;
+ }
+
+ Q_SIGNAL void done();
+
+ void wp_image_description_info_v1_done() override;
+ void
+ wp_image_description_info_v1_primaries(int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y) override;
+ void wp_image_description_info_v1_primaries_named(uint32_t primaries) override;
+ void wp_image_description_info_v1_tf_power(uint32_t eexp) override;
+ void wp_image_description_info_v1_tf_named(uint32_t tf) override;
+ void wp_image_description_info_v1_luminances(uint32_t min_lum, uint32_t max_lum, uint32_t reference_lum) override;
+ void wp_image_description_info_v1_target_primaries(int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y)
+ override;
+ void wp_image_description_info_v1_target_luminance(uint32_t min_lum, uint32_t max_lum) override;
+ void wp_image_description_info_v1_target_max_cll(uint32_t max_cll) override;
+ void wp_image_description_info_v1_target_max_fall(uint32_t max_fall) override;
+ void wp_image_description_info_v1_icc_file(int32_t icc, uint32_t icc_size) override;
+
+ KisSurfaceColorimetry::WaylandSurfaceDescription m_data;
+ bool m_isReady {false};
+};
+
+class KisWaylandAPIImageDescription : public QObject, public QtWayland::wp_image_description_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPIImageDescription(::wp_image_description_v1 *descr);
+
+ ~KisWaylandAPIImageDescription();
+
+ Q_SIGNAL void done();
+ Q_SIGNAL void sigDescriptionConstructed(bool success);
+
+ KisWaylandAPIImageDescriptionInfo info;
+
+ uint32_t identity() const {
+ return m_identity;
+ }
+
+protected:
+ void wp_image_description_v1_failed(uint32_t cause, const QString &msg) override;
+ void wp_image_description_v1_ready(uint32_t identity) override;
+
+private:
+ uint32_t m_identity {0};
+};
+
+
+#endif /* KISWAYLANDAPIIMAGEDESCRIPTION_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.cpp
new file mode 100644
index 0000000000..4a1cad8c83
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.cpp
@@ -0,0 +1,99 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandAPIImageDescriptionCreatorParams.h"
+
+#include "KisWaylandAPIColorManager.h"
+#include "KisWaylandAPIImageDescription.h"
+#include "KisWaylandSurfaceColorimetry.h"
+
+KisWaylandAPIImageDescriptionCreatorParams::KisWaylandAPIImageDescriptionCreatorParams(KisWaylandAPIColorManager *colorManager)
+ : KisWaylandAPIImageDescriptionCreatorParams(colorManager->create_parametric_creator(), colorManager)
+{
+}
+
+KisWaylandAPIImageDescriptionCreatorParams::KisWaylandAPIImageDescriptionCreatorParams(::wp_image_description_creator_params_v1 *params,
+ KisWaylandAPIColorManager *colorManager)
+ : QtWayland::wp_image_description_creator_params_v1(params)
+ , m_colorManager(colorManager)
+{
+}
+KisWaylandAPIImageDescriptionCreatorParams::~KisWaylandAPIImageDescriptionCreatorParams()
+{
+ // object() is null if the information creation has succeeded
+ if (object()) {
+ wp_image_description_creator_params_v1_destroy(object());
+ }
+}
+
+std::unique_ptr<KisWaylandAPIImageDescription> KisWaylandAPIImageDescriptionCreatorParams::createImageDescription(const KisSurfaceColorimetry::WaylandSurfaceDescription &data)
+{
+ if (data.tfNamed) {
+ set_tf_named(static_cast<uint32_t>(*data.tfNamed));
+ } else if (data.tfGamma) {
+ Q_ASSERT(m_colorManager->isFeatureSupported(KisWaylandAPIColorManager::feature_set_tf_power));
+ set_tf_power(*data.tfGamma);
+ }
+
+ if (data.namedContainer) {
+ set_primaries_named(static_cast<uint32_t>(*data.namedContainer));
+ } else {
+ Q_ASSERT(m_colorManager->isFeatureSupported(KisWaylandAPIColorManager::feature_set_primaries));
+ set_primaries(std::rint(data.container->red.x * 1'000'000.00),
+ std::rint(data.container->red.y * 1'000'000.00),
+ std::rint(data.container->green.x * 1'000'000.00),
+ std::rint(data.container->green.y * 1'000'000.00),
+ std::rint(data.container->blue.x * 1'000'000.00),
+ std::rint(data.container->blue.y * 1'000'000.00),
+ std::rint(data.container->white.x * 1'000'000.00),
+ std::rint(data.container->white.y * 1'000'000.00));
+ }
+
+ if (data.target) {
+ Q_ASSERT(m_colorManager->isFeatureSupported(KisWaylandAPIColorManager::feature_set_mastering_display_primaries));
+ set_mastering_display_primaries(std::rint(data.target->red.x * 1'000'000.00),
+ std::rint(data.target->red.y * 1'000'000.00),
+ std::rint(data.target->green.x * 1'000'000.00),
+ std::rint(data.target->green.y * 1'000'000.00),
+ std::rint(data.target->blue.x * 1'000'000.00),
+ std::rint(data.target->blue.y * 1'000'000.00),
+ std::rint(data.target->white.x * 1'000'000.00),
+ std::rint(data.target->white.y * 1'000'000.00));
+ }
+
+ if (data.luminances) {
+ Q_ASSERT(m_colorManager->isFeatureSupported(KisWaylandAPIColorManager::feature_set_luminances));
+ set_luminances(data.luminances->minLuminance,
+ data.luminances->maxLuminance,
+ data.luminances->referenceLuminance);
+ }
+
+ if (data.masteringLuminance) {
+ Q_ASSERT(m_colorManager->isFeatureSupported(KisWaylandAPIColorManager::feature_extended_target_volume));
+ set_mastering_luminance(data.masteringLuminance->minLuminance, data.masteringLuminance->maxLuminance);
+ }
+
+ if (data.targetMaxCLL) {
+ set_max_cll(*data.targetMaxCLL);
+ }
+
+ if (data.targetMaxFALL) {
+ set_max_fall(*data.targetMaxFALL);
+ }
+
+ if (data.iccFileIsPresent) {
+ // We do not support ICC files yet
+ qWarning() << "ICC file is not supported yet.";
+ }
+
+ auto result = std::make_unique<KisWaylandAPIImageDescription>(create());
+
+ init(nullptr);
+
+ return result;
+}
+
+#include <moc_KisWaylandAPIImageDescriptionCreatorParams.cpp>
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.h
new file mode 100644
index 0000000000..b8d02a2c79
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIImageDescriptionCreatorParams.h
@@ -0,0 +1,34 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef KISWAYLANDAPIIMAGEDESCRIPTIONCREATORPARAMS_H
+#define KISWAYLANDAPIIMAGEDESCRIPTIONCREATORPARAMS_H
+
+#include <QObject>
+#include <qwayland-color-management-v1.h>
+
+class KisWaylandAPIColorManager;
+class KisWaylandAPIImageDescription;
+namespace KisSurfaceColorimetry {
+ class WaylandSurfaceDescription;
+}
+
+class KisWaylandAPIImageDescriptionCreatorParams : public QObject, public QtWayland::wp_image_description_creator_params_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPIImageDescriptionCreatorParams(KisWaylandAPIColorManager *colorManager);
+ explicit KisWaylandAPIImageDescriptionCreatorParams(::wp_image_description_creator_params_v1 *params, KisWaylandAPIColorManager *colorManager);
+
+ ~KisWaylandAPIImageDescriptionCreatorParams();
+
+ std::unique_ptr<KisWaylandAPIImageDescription> createImageDescription(const KisSurfaceColorimetry::WaylandSurfaceDescription &data);
+
+private:
+ KisWaylandAPIColorManager *m_colorManager;
+};
+
+#endif /* KISWAYLANDIMAGEDESCRIPTIONCREATORPARAMS_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIOutput.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIOutput.cpp
new file mode 100644
index 0000000000..22d5e4a9d3
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIOutput.cpp
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandAPIOutput.h"
+
+#include "KisWaylandAPIImageDescription.h"
+
+KisWaylandAPIOutput::KisWaylandAPIOutput(::wp_color_management_output_v1 *obj)
+ : QtWayland::wp_color_management_output_v1(obj)
+{
+ wp_color_management_output_v1_image_description_changed();
+}
+
+KisWaylandAPIOutput::~KisWaylandAPIOutput()
+{
+ wp_color_management_output_v1_destroy(object());
+}
+
+void KisWaylandAPIOutput::wp_color_management_output_v1_image_description_changed()
+{
+ m_imageDescription = std::make_unique<KisWaylandAPIImageDescription>(get_image_description());
+ connect(m_imageDescription.get(), &KisWaylandAPIImageDescription::done, this, &KisWaylandAPIOutput::outputImageDescriptionChanged);
+}
+
+#include "moc_KisWaylandAPIOutput.cpp"
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIOutput.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIOutput.h
new file mode 100644
index 0000000000..5e54b0be05
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPIOutput.h
@@ -0,0 +1,32 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef KISWAYLANDAPIOUTPUT_H
+#define KISWAYLANDAPIOUTPUT_H
+
+#include <QObject>
+#include <qwayland-color-management-v1.h>
+
+class KisWaylandAPIImageDescription;
+
+class KisWaylandAPIOutput : public QObject, public QtWayland::wp_color_management_output_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPIOutput(::wp_color_management_output_v1 *obj);
+ ~KisWaylandAPIOutput();
+
+ std::unique_ptr<KisWaylandAPIImageDescription> m_imageDescription;
+
+Q_SIGNALS:
+ void outputImageDescriptionChanged();
+
+protected:
+ void wp_color_management_output_v1_image_description_changed() override;
+
+};
+
+#endif /* KISWAYLANDAPIOUTPUT_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPISurface.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPISurface.cpp
new file mode 100644
index 0000000000..4c592bb845
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPISurface.cpp
@@ -0,0 +1,42 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandAPISurface.h"
+
+#include "KisWaylandAPIImageDescription.h"
+
+
+KisWaylandAPISurfaceFeedback::KisWaylandAPISurfaceFeedback(::wp_color_management_surface_feedback_v1 *obj)
+ : QtWayland::wp_color_management_surface_feedback_v1(obj)
+ , m_preferred(std::make_unique<KisWaylandAPIImageDescription>(get_preferred()))
+{
+ connect(m_preferred.get(), &KisWaylandAPIImageDescription::done, this, &KisWaylandAPISurfaceFeedback::preferredChanged);
+}
+
+KisWaylandAPISurfaceFeedback::~KisWaylandAPISurfaceFeedback()
+{
+ wp_color_management_surface_feedback_v1_destroy(object());
+}
+
+void KisWaylandAPISurfaceFeedback::wp_color_management_surface_feedback_v1_preferred_changed(uint32_t identity)
+{
+ Q_UNUSED(identity);
+ m_preferred = std::make_unique<KisWaylandAPIImageDescription>(get_preferred());
+ connect(m_preferred.get(), &KisWaylandAPIImageDescription::done, this, &KisWaylandAPISurfaceFeedback::preferredChanged);
+}
+
+KisWaylandAPISurface::KisWaylandAPISurface(::wp_color_management_surface_v1 *obj, std::unique_ptr<KisWaylandAPISurfaceFeedback> &&feedback)
+ : QtWayland::wp_color_management_surface_v1(obj)
+ , m_feedback(std::move(feedback))
+{
+}
+
+KisWaylandAPISurface::~KisWaylandAPISurface()
+{
+ wp_color_management_surface_v1_destroy(object());
+}
+
+#include "moc_KisWaylandAPISurface.cpp"
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPISurface.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPISurface.h
new file mode 100644
index 0000000000..38804eba1d
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandAPISurface.h
@@ -0,0 +1,38 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISWAYLANDAPISURFACE_H
+#define KISWAYLANDAPISURFACE_H
+
+#include <QObject>
+#include <qwayland-color-management-v1.h>
+
+class KisWaylandAPIImageDescription;
+
+class KisWaylandAPISurfaceFeedback : public QObject, public QtWayland::wp_color_management_surface_feedback_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPISurfaceFeedback(::wp_color_management_surface_feedback_v1 *obj);
+
+ ~KisWaylandAPISurfaceFeedback();
+
+ Q_SIGNAL void preferredChanged();
+ void wp_color_management_surface_feedback_v1_preferred_changed(uint32_t identity) override;
+
+ std::unique_ptr<KisWaylandAPIImageDescription> m_preferred;
+};
+
+class KisWaylandAPISurface : public QObject, public QtWayland::wp_color_management_surface_v1
+{
+ Q_OBJECT
+public:
+ explicit KisWaylandAPISurface(::wp_color_management_surface_v1 *obj, std::unique_ptr<KisWaylandAPISurfaceFeedback> &&feedback);
+ ~KisWaylandAPISurface();
+
+ std::unique_ptr<KisWaylandAPISurfaceFeedback> m_feedback;
+};
+
+#endif /* KISWAYLANDAPISURFACE_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandOutputColorInfo.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandOutputColorInfo.cpp
new file mode 100644
index 0000000000..65526b4298
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandOutputColorInfo.cpp
@@ -0,0 +1,139 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandOutputColorInfo.h"
+
+#include <QScreen>
+#include <QTimer>
+#include <QPointer>
+
+#include <qpa/qplatformnativeinterface.h>
+
+#include "KisWaylandAPIColorManager.h"
+#include "KisWaylandAPIImageDescription.h"
+#include "KisWaylandAPIOutput.h"
+
+#include "KisWaylandSurfaceColorManager.h"
+
+ #include <QtAssert>
+ #include <kis_debug.h>
+
+KisWaylandOutputColorInfo::KisWaylandOutputColorInfo(QObject *parent)
+ : KisOutputColorInfoInterface(parent)
+{
+ m_waylandManager = KisWaylandSurfaceColorManager::getOrCreateGlobalWaylandManager();
+ connect(m_waylandManager.get(), &KisWaylandAPIColorManager::sigReadyChanged,
+ this, &KisWaylandOutputColorInfo::reinitialize);
+ reinitialize();
+
+ connect(qApp, &QGuiApplication::screenAdded, this, &KisWaylandOutputColorInfo::slotScreenAdded);
+ connect(qApp, &QGuiApplication::screenRemoved, this, &KisWaylandOutputColorInfo::slotScreenRemoved);
+}
+
+KisWaylandOutputColorInfo::~KisWaylandOutputColorInfo()
+{
+}
+
+void KisWaylandOutputColorInfo::setReadyImpl(bool value)
+{
+ if (value == m_isReady) return;
+
+ m_isReady = value;
+ Q_EMIT sigReadyChanged(m_isReady);
+}
+
+bool KisWaylandOutputColorInfo::checkIfAllReady() const
+{
+ if (m_waylandOutputs.empty()) return false;
+
+ return std::find_if(m_waylandOutputs.begin(), m_waylandOutputs.end(),
+ [] (const auto &it) {
+ return !it.second->m_imageDescription->info.isReady();
+ }
+ ) == m_waylandOutputs.end();
+}
+
+void KisWaylandOutputColorInfo::reinitialize()
+{
+ m_waylandOutputs.clear();
+
+ if (!m_waylandManager->isReady()) {
+ setReadyImpl(false);
+ return;
+ }
+
+ for (QScreen *screen : qApp->screens()) {
+ initScreenConnection(screen);
+ }
+
+ setReadyImpl(checkIfAllReady());
+}
+
+void KisWaylandOutputColorInfo::initScreenConnection(QScreen *screen)
+{
+ auto waylandScreen = screen->nativeInterface<QNativeInterface::QWaylandScreen>();
+
+ // the sceen may have no wayland screen if it is a fake placeholder screen
+ // that was created by Qt while compositor restart
+ if (!waylandScreen) return;
+
+ ::wl_output *output = waylandScreen->output();
+ ::wp_color_management_output_v1 *cmoutput = m_waylandManager->get_output(output);
+ Q_ASSERT(cmoutput);
+
+ auto outputObject = std::make_unique<KisWaylandAPIOutput>(cmoutput);
+ connect(outputObject.get(), &KisWaylandAPIOutput::outputImageDescriptionChanged, outputObject.get(), [this, screen, outputPtr = outputObject.get()]() {
+ auto desc = outputPtr->m_imageDescription->info.m_data;
+ Q_EMIT sigOutputDescriptionChanged(screen, desc.toSurfaceDescription());
+
+ setReadyImpl(checkIfAllReady());
+ });
+
+ m_waylandOutputs.insert_or_assign(screen, std::move(outputObject));
+}
+
+void KisWaylandOutputColorInfo::slotScreenAdded(QScreen *screen)
+{
+ if (!m_waylandManager->isActive()) {
+ return;
+ }
+
+ initScreenConnection(screen);
+
+ setReadyImpl(checkIfAllReady());
+}
+
+void KisWaylandOutputColorInfo::slotScreenRemoved(QScreen *screen)
+{
+ if (!m_waylandManager->isActive()) {
+ return;
+ }
+
+ m_waylandOutputs.erase(screen);
+
+ setReadyImpl(checkIfAllReady());
+}
+
+bool KisWaylandOutputColorInfo::isReady() const
+{
+ return m_isReady;
+}
+
+std::optional<KisSurfaceColorimetry::SurfaceDescription> KisWaylandOutputColorInfo::outputDescription(const QScreen *screen) const
+{
+ auto it = m_waylandOutputs.find(screen);
+ if (it == m_waylandOutputs.end()) return std::nullopt;
+
+ const auto &info = it->second->m_imageDescription->info;
+
+ if (!info.isReady()) {
+ return std::nullopt;
+ }
+
+ return info.m_data.toSurfaceDescription();
+}
+
+#include <moc_KisWaylandOutputColorInfo.cpp>
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandOutputColorInfo.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandOutputColorInfo.h
new file mode 100644
index 0000000000..1e9f7c78d8
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandOutputColorInfo.h
@@ -0,0 +1,41 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISWAYLANDOUTPUTCOLORINFO_H
+#define KISWAYLANDOUTPUTCOLORINFO_H
+
+#include <surfacecolormanagement/KisOutputColorInfoInterface.h>
+
+#include <unordered_map>
+
+class KisWaylandAPIOutput;
+class KisWaylandAPIColorManager;
+
+class KisWaylandOutputColorInfo : public KisOutputColorInfoInterface
+{
+ Q_OBJECT
+public:
+ KisWaylandOutputColorInfo(QObject *parent = nullptr);
+ ~KisWaylandOutputColorInfo() override;
+
+ bool isReady() const override;
+ std::optional<KisSurfaceColorimetry::SurfaceDescription> outputDescription(const QScreen *screen) const override;
+
+private:
+ void reinitialize();
+ void initScreenConnection(QScreen *screen);
+ void slotScreenAdded(QScreen *screen);
+ void slotScreenRemoved(QScreen *screen);
+
+ void setReadyImpl(bool value);
+ bool checkIfAllReady() const;
+
+private:
+ std::shared_ptr<KisWaylandAPIColorManager> m_waylandManager;
+ std::unordered_map<const QScreen*, std::unique_ptr<KisWaylandAPIOutput>> m_waylandOutputs;
+ bool m_isReady {false};
+};
+
+#endif /* KISWAYLANDOUTPUTCOLORINFO_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorManager.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorManager.cpp
new file mode 100644
index 0000000000..e83844e83e
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorManager.cpp
@@ -0,0 +1,355 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandSurfaceColorManager.h"
+
+#include <QWindow>
+#include <QPromise>
+#include <QFuture>
+
+#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformwindow_p.h>
+
+#include "KisWaylandAPISurface.h"
+#include "KisWaylandAPIColorManager.h"
+#include "KisWaylandAPIImageDescription.h"
+#include "KisWaylandAPIImageDescriptionCreatorParams.h"
+
+#include <kis_debug.h>
+
+namespace {
+template <typename T>
+QFuture<std::decay_t<T>> makeReadyQFuture(T &&value) {
+ QPromise<std::decay_t<T>> promise;
+ promise.start();
+ promise.addResult(std::forward<T>(value));
+ promise.finish();
+ return promise.future();
+}
+}
+
+Q_GLOBAL_STATIC(std::weak_ptr<KisWaylandAPIColorManager>, s_waylandManager)
+
+std::shared_ptr<KisWaylandAPIColorManager> KisWaylandSurfaceColorManager::getOrCreateGlobalWaylandManager()
+{
+ std::shared_ptr<KisWaylandAPIColorManager> result;
+
+ if (s_waylandManager.exists()) {
+ result = s_waylandManager->lock();
+ } else {
+ result.reset(new KisWaylandAPIColorManager());
+ *s_waylandManager = result;
+ }
+
+ return result;
+}
+
+KisWaylandSurfaceColorManager::KisWaylandSurfaceColorManager(QWindow *window, QObject *parent)
+ : KisSurfaceColorManagerInterface(window, parent)
+{
+ m_waylandManager = getOrCreateGlobalWaylandManager();
+ connect(m_waylandManager.get(), &KisWaylandAPIColorManager::sigReadyChanged,
+ this, &KisWaylandSurfaceColorManager::reinitialize);
+
+ /**
+ * If we have reused an existing wayland manager, then it will be ready
+ */
+ if (m_waylandManager->isReady()) {
+ reinitialize();
+ }
+}
+
+KisWaylandSurfaceColorManager::~KisWaylandSurfaceColorManager()
+{
+}
+
+void KisWaylandSurfaceColorManager::setReadyImpl(bool value)
+{
+ if (value == m_isReady) return;
+
+ m_isReady = value;
+ Q_EMIT sigReadyChanged(m_isReady);
+}
+
+#include <QPlatformSurfaceEvent>
+
+class WindowIdEventFilter : public QObject
+{
+ Q_OBJECT
+public:
+ WindowIdEventFilter(QObject *watched, QObject *parent = nullptr)
+ : QObject(parent)
+ , m_watched(watched)
+ {
+ // TODO: autoinstall the filter
+ }
+
+Q_SIGNALS:
+ void sigWindowIdChanged();
+
+private:
+ bool eventFilter(QObject *watched, QEvent *event) override {
+ if (watched == m_watched) {
+ qDebug() << watched->objectName() << event->type();
+ }
+
+ if (watched == m_watched && event->type() == QEvent::PlatformSurface) {
+ QPlatformSurfaceEvent *pevent = static_cast<QPlatformSurfaceEvent*>(event);
+ if (pevent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
+ ENTER_FUNCTION() << "found the event";
+ Q_EMIT sigWindowIdChanged();
+
+ // we allow only one-shot
+ m_watched = nullptr;
+
+ // dispose of ourselves
+ this->deleteLater();
+ }
+ }
+
+ return false;
+ }
+
+ QObject *m_watched = nullptr;
+};
+
+
+void KisWaylandSurfaceColorManager::reinitialize()
+{
+ ENTER_FUNCTION() << ppVar(m_waylandManager->isReady()) << ppVar(m_window);
+
+ if (!m_waylandManager->isReady()) {
+ m_surface.reset();
+ m_preferredDescription = std::nullopt;
+ m_currentDescription = std::nullopt;
+ m_renderingIntent = std::nullopt;
+ setReadyImpl(false);
+ return;
+ }
+
+ auto waylandWindow = m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
+
+ ENTER_FUNCTION() << ppVar(m_window) << ppVar(m_window->handle()) << ppVar(waylandWindow);
+
+ if (!waylandWindow) {
+ // the window has not completed its creation yet, just wait a little bit
+ auto *filter = new WindowIdEventFilter(m_window, this);
+ connect(filter, &WindowIdEventFilter::sigWindowIdChanged, this, &KisWaylandSurfaceColorManager::reinitialize);
+ m_window->installEventFilter(filter);
+ return;
+ }
+
+ auto initializeWaylandSurface = [this, waylandWindow]() {
+ disconnect(m_windowConnection);
+ if (m_surface) {
+ qWarning() << "WARNING: KisWaylandSurfaceColorManager::reinitialize(): surfaceCreated signal got delivered twice!";
+ return;
+ }
+
+ auto feedback = std::make_unique<KisWaylandAPISurfaceFeedback>(m_waylandManager->get_surface_feedback(waylandWindow->surface()));
+ connect(feedback.get(), &KisWaylandAPISurfaceFeedback::preferredChanged, this, &KisWaylandSurfaceColorManager::slotPreferredChanged);
+ m_surface = std::make_unique<KisWaylandAPISurface>(m_waylandManager->get_surface(waylandWindow->surface()), std::move(feedback));
+ };
+
+ if (waylandWindow->surface()) {
+ initializeWaylandSurface();
+ } else {
+ /**
+ * In case the Wayland server got disconnected, wait until the Qt
+ * surface is actually created.
+ */
+ m_windowConnection =
+ connect(waylandWindow, &QNativeInterface::Private::QWaylandWindow::surfaceCreated, this, initializeWaylandSurface);
+ }
+}
+
+bool KisWaylandSurfaceColorManager::isReady() const
+{
+ return m_isReady;
+}
+
+bool KisWaylandSurfaceColorManager::supportsSurfaceDescription(const KisSurfaceColorimetry::SurfaceDescription &desc)
+{
+ using feature = QtWayland::wp_color_manager_v1::feature;
+ using namespace KisColorimetryUtils;
+
+ if (!m_waylandManager->isFeatureSupported(feature::feature_parametric)) {
+ qWarning() << "KisWaylandSurfaceColorManager: feature_parametric is not supported";
+ return false;
+ }
+
+ if (!m_waylandManager->isFeatureSupported(feature::feature_set_primaries) &&
+ std::holds_alternative<Colorimetry>(desc.colorSpace.primaries)) {
+
+ qWarning() << "KisWaylandSurfaceColorManager: feature_set_primaries is not supported, even though requested";
+ return false;
+ }
+
+ if (!m_waylandManager->isFeatureSupported(feature::feature_set_tf_power) &&
+ std::holds_alternative<uint32_t>(desc.colorSpace.transferFunction)) {
+
+ qWarning() << "KisWaylandSurfaceColorManager: feature_set_tf_power is not supported, even though requested";
+ return false;
+ }
+
+ if (!m_waylandManager->isFeatureSupported(feature::feature_set_luminances) &&
+ desc.colorSpace.luminance) {
+
+ qWarning() << "KisWaylandSurfaceColorManager: feature_set_luminances is not supported, even though requested";
+ return false;
+ }
+
+ if (!m_waylandManager->isFeatureSupported(feature::feature_set_mastering_display_primaries) &&
+ desc.masteringInfo) {
+
+ qWarning() << "KisWaylandSurfaceColorManager: feature_set_mastering_display_primaries is not supported, even though requested";
+ return false;
+ }
+
+ if (!m_waylandManager->isFeatureSupported(feature::feature_extended_target_volume) &&
+ desc.masteringInfo && desc.colorSpace.luminance) {
+ if (desc.masteringInfo->luminance.minLuminance < desc.colorSpace.luminance->minLuminance
+ || desc.masteringInfo->luminance.maxLuminance > desc.colorSpace.luminance->maxLuminance) {
+
+ qWarning() << "KisWaylandSurfaceColorManager: feature_set_mastering_display_primaries is not supported, even though requested";
+ return false;
+ }
+ }
+
+ if (std::holds_alternative<KisSurfaceColorimetry::NamedPrimaries>(desc.colorSpace.primaries)) {
+ auto waylandPrimaries = primariesKritaToWayland(std::get<KisSurfaceColorimetry::NamedPrimaries>(desc.colorSpace.primaries));
+
+ if (!m_waylandManager->isPrimariesNamedSupported(waylandPrimaries))
+ return false;
+ }
+
+ if (std::holds_alternative<KisSurfaceColorimetry::NamedTransferFunction>(desc.colorSpace.transferFunction)) {
+ auto waylandTransferFunction = transferFunctionKritaToWayland(std::get<KisSurfaceColorimetry::NamedTransferFunction>(desc.colorSpace.transferFunction));
+
+ if (!m_waylandManager->isTransferFunctionNamedSupported(waylandTransferFunction))
+ return false;
+ }
+
+ return true;
+}
+
+bool KisWaylandSurfaceColorManager::supportsRenderIntent(const KisSurfaceColorimetry::RenderIntent &intent)
+{
+ auto waylandIntent = renderIntentKritaToWayland(intent);
+ return m_waylandManager->isIntentSupported(waylandIntent);
+}
+
+#warning USE_KWIN_BUG_WORKAROUND should become optional switch depending on the version of KWin used
+#define USE_KWIN_BUG_WORKAROUND
+
+#ifdef USE_KWIN_BUG_WORKAROUND
+#include "wayland-wayland-client-protocol.h"
+#endif
+
+QFuture<bool> KisWaylandSurfaceColorManager::setSurfaceDescription(const KisSurfaceColorimetry::SurfaceDescription &desc, KisSurfaceColorimetry::RenderIntent intent)
+{
+ if (!m_isReady) {
+ qWarning() << "ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: the manager is not ready";
+ return makeReadyQFuture(false);
+ }
+
+ using KisSurfaceColorimetry::WaylandSurfaceDescription;
+
+ auto waylandDescription = WaylandSurfaceDescription::fromSurfaceDescription(desc);
+ auto waylandIntent = renderIntentKritaToWayland(intent);
+
+ if (!supportsSurfaceDescription(desc)) {
+ qWarning() << "ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: unsupported surface description";
+ return makeReadyQFuture(false);
+ }
+
+ if (!m_waylandManager->isIntentSupported(waylandIntent)) {
+ qWarning() << "ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: unsupported rendering intent";
+ return makeReadyQFuture(false);
+ }
+
+ KisWaylandAPIImageDescriptionCreatorParams creator(m_waylandManager.get());
+ std::shared_ptr<KisWaylandAPIImageDescription> descriptionObject =
+ creator.createImageDescription(waylandDescription);
+
+ QPromise<bool> imageDescriptionPromise;
+ auto future = imageDescriptionPromise.future();
+
+ connect(descriptionObject.get(), &KisWaylandAPIImageDescription::sigDescriptionConstructed,
+ this,
+ [promise = std::move(imageDescriptionPromise)] (bool success) mutable {
+ promise.start();
+ promise.addResult(success);
+ promise.finish();
+ });
+
+ QFuture<bool> result =
+ future.then([this, desc, descriptionObject, waylandIntent, intent] (QFuture<bool> future) {
+ if (!future.result()) return false;
+
+#ifdef USE_KWIN_BUG_WORKAROUND
+ // WARNING: KWin <= 6.4.4 doesn't handle intent changes properly
+ if (m_currentDescription && m_currentDescription == desc &&
+ m_renderingIntent && m_renderingIntent != intent) {
+
+ m_surface->unset_image_description();
+ auto waylandWindow = m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
+ ::wl_surface_commit(waylandWindow->surface());
+ }
+#endif
+
+ m_surface->set_image_description(descriptionObject->object(), waylandIntent);
+ m_window->requestUpdate();
+ m_currentDescription = desc;
+ m_renderingIntent = intent;
+ return true;
+ });
+
+ return result;
+}
+
+void KisWaylandSurfaceColorManager::unsetSurfaceDescription()
+{
+ if (!m_isReady) return;
+
+ m_surface->unset_image_description();
+ m_currentDescription = std::nullopt;
+ m_renderingIntent = std::nullopt;
+}
+
+std::optional<KisSurfaceColorimetry::SurfaceDescription> KisWaylandSurfaceColorManager::surfaceDescription() const
+{
+ return m_currentDescription;
+}
+
+std::optional<KisSurfaceColorimetry::RenderIntent> KisWaylandSurfaceColorManager::renderingIntent() const
+{
+ return m_renderingIntent;
+}
+
+std::optional<KisSurfaceColorimetry::SurfaceDescription> KisWaylandSurfaceColorManager::preferredSurfaceDescription() const
+{
+ return m_preferredDescription;
+}
+
+void KisWaylandSurfaceColorManager::slotPreferredChanged()
+{
+ auto waylandDesc = m_surface->m_feedback->m_preferred->info.m_data;
+ m_preferredDescription = waylandDesc.toSurfaceDescription();
+
+ ENTER_FUNCTION() << ppVar(m_window) << ppVar(m_preferredDescription);
+
+ if (!m_isReady) {
+ setReadyImpl(true);
+ } else {
+ Q_EMIT sigPreferredSurfaceDescriptionChanged(*m_preferredDescription);
+ }
+}
+
+#include <moc_KisWaylandSurfaceColorManager.cpp>
+
+// TODO: remove
+#include <KisWaylandSurfaceColorManager.moc>
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorManager.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorManager.h
new file mode 100644
index 0000000000..d690d78b29
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorManager.h
@@ -0,0 +1,52 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISWAYLANDSURFACECOLORMANAGER_H
+#define KISWAYLANDSURFACECOLORMANAGER_H
+
+#include <surfacecolormanagement/KisSurfaceColorManagerInterface.h>
+
+class KisWaylandAPIColorManager;
+class KisWaylandAPISurface;
+
+class KisWaylandSurfaceColorManager : public KisSurfaceColorManagerInterface
+{
+ Q_OBJECT
+public:
+ KisWaylandSurfaceColorManager(QWindow *window, QObject *parent = nullptr);
+ ~KisWaylandSurfaceColorManager() override;
+
+ bool isReady() const override;
+ bool supportsSurfaceDescription(const KisSurfaceColorimetry::SurfaceDescription &desc) override;
+ bool supportsRenderIntent(const KisSurfaceColorimetry::RenderIntent &intent) override;
+ QFuture<bool> setSurfaceDescription(const KisSurfaceColorimetry::SurfaceDescription &desc, KisSurfaceColorimetry::RenderIntent intent) override;
+ void unsetSurfaceDescription() override;
+ std::optional<KisSurfaceColorimetry::SurfaceDescription> surfaceDescription() const override;
+ std::optional<KisSurfaceColorimetry::RenderIntent> renderingIntent() const override;
+ std::optional<KisSurfaceColorimetry::SurfaceDescription> preferredSurfaceDescription() const override;
+
+ static std::shared_ptr<KisWaylandAPIColorManager> getOrCreateGlobalWaylandManager();
+
+private Q_SLOTS:
+ void slotPreferredChanged();
+
+private:
+ void reinitialize();
+ void setReadyImpl(bool value);
+
+private:
+ std::shared_ptr<KisWaylandAPIColorManager> m_waylandManager;
+ std::unique_ptr<KisWaylandAPISurface> m_surface;
+
+ std::optional<KisSurfaceColorimetry::SurfaceDescription> m_currentDescription;
+ std::optional<KisSurfaceColorimetry::RenderIntent> m_renderingIntent;
+ std::optional<KisSurfaceColorimetry::SurfaceDescription> m_preferredDescription;
+
+ bool m_isReady {false};
+
+ QMetaObject::Connection m_windowConnection;
+};
+
+#endif /* KISWAYLANDSURFACECOLORMANAGER_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorimetry.cpp b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorimetry.cpp
new file mode 100644
index 0000000000..7c13aa0518
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorimetry.cpp
@@ -0,0 +1,484 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisWaylandSurfaceColorimetry.h"
+
+#include <QDebug>
+
+namespace KisSurfaceColorimetry {
+
+SurfaceDescription WaylandSurfaceDescription::toSurfaceDescription() const
+{
+ KisSurfaceColorimetry::SurfaceDescription description;
+
+ // Map transfer function
+ if (this->tfNamed) {
+ switch (*this->tfNamed) {
+ case QtWayland::wp_color_manager_v1::transfer_function_bt1886:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_bt1886;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_gamma22:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_gamma22;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_gamma28:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_gamma28;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_st240:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_ext_linear:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_ext_linear;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_log_100:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_log_316:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_xvycc:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_srgb:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_srgb;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_ext_srgb:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_ext_srgb;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_st2084_pq:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_st2084_pq;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_st428:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_hlg:
+ description.colorSpace.transferFunction = KisSurfaceColorimetry::NamedTransferFunction::transfer_function_unknown;
+ break;
+ }
+ } else if (this->tfGamma) {
+ description.colorSpace.transferFunction = *this->tfGamma;
+ }
+
+ // Map primaries
+ if (this->namedContainer) {
+ switch (*this->namedContainer) {
+ case QtWayland::wp_color_manager_v1::primaries_srgb:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_srgb;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_pal_m:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_pal:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_ntsc:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_generic_film:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_bt2020:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_bt2020;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_cie1931_xyz:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_unknown;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_dci_p3:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_dci_p3;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_display_p3:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_display_p3;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_adobe_rgb:
+ description.colorSpace.primaries = KisSurfaceColorimetry::NamedPrimaries::primaries_adobe_rgb;
+ break;
+ }
+ } else if (this->container) {
+ description.colorSpace.primaries = this->container->toColorimetry();
+ }
+
+ // Map luminance
+ if (this->luminances) {
+ description.colorSpace.luminance = this->luminances;
+ }
+
+ // Map mastering info
+ if (this->target || this->masteringLuminance) {
+ KisSurfaceColorimetry::MasteringInfo masteringInfo;
+
+ if (this->target) {
+ masteringInfo.primaries = this->target->toColorimetry();
+ } else if (std::holds_alternative<KisSurfaceColorimetry::Colorimetry>(description.colorSpace.primaries)) {
+ masteringInfo.primaries = std::get<KisSurfaceColorimetry::Colorimetry>(description.colorSpace.primaries);
+ } else if (this->namedContainer) {
+ switch (*this->namedContainer) {
+ case QtWayland::wp_color_manager_v1::primaries_srgb:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::BT709;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_pal_m:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::PAL_M;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_pal:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::PAL;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_ntsc:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::NTSC;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_generic_film:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::GenericFilm;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_bt2020:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::BT2020;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_cie1931_xyz:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::CIEXYZ;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_dci_p3:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::DCIP3;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_display_p3:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::DisplayP3;
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_adobe_rgb:
+ masteringInfo.primaries = KisColorimetryUtils::Colorimetry::AdobeRGB;
+ break;
+ }
+ }
+
+ if (this->masteringLuminance) {
+ masteringInfo.luminance = *this->masteringLuminance;
+ } else {
+ if (description.colorSpace.luminance) {
+ masteringInfo.luminance.fromLuminance(*description.colorSpace.luminance);
+ } else {
+ masteringInfo.luminance = KisSurfaceColorimetry::MasteringLuminance();
+ }
+ }
+
+ if (this->targetMaxCLL) {
+ masteringInfo.maxCll = *this->targetMaxCLL;
+ }
+ if (this->targetMaxFALL) {
+ masteringInfo.maxFall = *this->targetMaxFALL;
+ }
+
+ description.masteringInfo = masteringInfo;
+ }
+
+ return description;
+}
+
+WaylandSurfaceDescription WaylandSurfaceDescription::fromSurfaceDescription(const SurfaceDescription &rhs)
+{
+ WaylandSurfaceDescription desc;
+
+ using namespace KisColorimetryUtils;
+ using namespace KisSurfaceColorimetry;
+
+ if (std::holds_alternative<NamedPrimaries>(rhs.colorSpace.primaries)) {
+ desc.namedContainer = primariesKritaToWayland(std::get<NamedPrimaries>(rhs.colorSpace.primaries));
+ } else {
+ desc.container = WaylandPrimaries::fromColorimetry(
+ std::get<Colorimetry>(rhs.colorSpace.primaries));
+ }
+
+ if (std::holds_alternative<NamedTransferFunction>(rhs.colorSpace.transferFunction)) {
+ desc.tfNamed = transferFunctionKritaToWayland(std::get<NamedTransferFunction>(rhs.colorSpace.transferFunction));
+ } else {
+ desc.tfGamma = std::get<uint32_t>(rhs.colorSpace.transferFunction);
+ }
+
+ if (rhs.colorSpace.luminance) {
+ desc.luminances = rhs.colorSpace.luminance;
+ }
+
+ if (rhs.masteringInfo) {
+ desc.target = WaylandPrimaries::fromColorimetry(rhs.masteringInfo->primaries);
+ desc.masteringLuminance = rhs.masteringInfo->luminance;
+
+ if (rhs.masteringInfo->maxCll) {
+ desc.targetMaxCLL = *rhs.masteringInfo->maxCll;
+ }
+
+ if (rhs.masteringInfo->maxFall) {
+ desc.targetMaxCLL = *rhs.masteringInfo->maxFall;
+ }
+ }
+
+ return desc;
+}
+
+QDebug operator<<(QDebug dbg, const WaylandPrimaries &points) {
+ dbg.nospace() << Qt::fixed << qSetRealNumberPrecision(5) << "KisColorPrimaries("
+ << "red: " << points.red << ", "
+ << "green: " << points.green << ", "
+ << "blue: " << points.blue << ", "
+ << "white: " << points.white
+ << ")";
+ dbg.resetFormat();
+ return dbg.space();
+}
+
+QDebug operator<<(QDebug dbg, const WaylandSurfaceDescription &data) {
+
+ dbg.nospace() << "WaylandSurfaceDescription(";
+
+ auto printOptionalTag = [&dbg](const char *tag, const auto &value) {
+ dbg.nospace() << tag << ": ";
+ if (value) {
+ dbg << *value << ", ";
+ } else {
+ dbg << "none" << ", ";
+ }
+ };
+
+ printOptionalTag("tfGamma", data.tfGamma);
+ printOptionalTag("tfNamed", data.tfNamed);
+ printOptionalTag("container", data.container);
+ printOptionalTag("namedContainer", data.namedContainer);
+ printOptionalTag("target", data.target);
+ printOptionalTag("luminances", data.luminances);
+ printOptionalTag("masteringLuminance", data.masteringLuminance);
+ printOptionalTag("targetMaxCLL", data.targetMaxCLL);
+ printOptionalTag("targetMaxFALL", data.targetMaxFALL);
+
+ dbg.nospace() << "iccFileIsPresent: " << data.iccFileIsPresent;
+
+ dbg.nospace() << ")";
+
+ return dbg.space();
+}
+
+QtWayland::wp_color_manager_v1::primaries primariesKritaToWayland(KisSurfaceColorimetry::NamedPrimaries primaries)
+{
+ using namespace KisSurfaceColorimetry;
+ using primaries_type = QtWayland::wp_color_manager_v1::primaries;
+
+ switch (primaries) {
+ case NamedPrimaries::primaries_srgb:
+ return primaries_type::primaries_srgb;
+ case NamedPrimaries::primaries_bt2020:
+ return primaries_type::primaries_bt2020;
+ case NamedPrimaries::primaries_dci_p3:
+ return primaries_type::primaries_dci_p3;
+ case NamedPrimaries::primaries_display_p3:
+ return primaries_type::primaries_display_p3;
+ case NamedPrimaries::primaries_adobe_rgb:
+ return primaries_type::primaries_adobe_rgb;
+ case NamedPrimaries::primaries_unknown:
+ Q_ASSERT(0 && "trying to set unknown named primary to the surface");
+ }
+ return primaries_type::primaries_srgb;
+}
+
+QtWayland::wp_color_manager_v1::transfer_function transferFunctionKritaToWayland(KisSurfaceColorimetry::NamedTransferFunction transferFunction)
+{
+ using namespace KisSurfaceColorimetry;
+ using transfer_function_type = QtWayland::wp_color_manager_v1::transfer_function;
+
+ switch (transferFunction) {
+ case NamedTransferFunction::transfer_function_bt1886:
+ return transfer_function_type::transfer_function_bt1886;
+ case NamedTransferFunction::transfer_function_gamma22:
+ return transfer_function_type::transfer_function_gamma22;
+ case NamedTransferFunction::transfer_function_gamma28:
+ return transfer_function_type::transfer_function_gamma28;
+ case NamedTransferFunction::transfer_function_ext_linear:
+ return transfer_function_type::transfer_function_ext_linear;
+ case NamedTransferFunction::transfer_function_srgb:
+ return transfer_function_type::transfer_function_srgb;
+ case NamedTransferFunction::transfer_function_ext_srgb:
+ return transfer_function_type::transfer_function_ext_srgb;
+ case NamedTransferFunction::transfer_function_st2084_pq:
+ return transfer_function_type::transfer_function_st2084_pq;
+ case NamedTransferFunction::transfer_function_st428:
+ return transfer_function_type::transfer_function_st428;
+ case NamedTransferFunction::transfer_function_unknown:
+ Q_ASSERT(0 && "trying to set unknown named transfer function to the surface");
+ }
+ return transfer_function_type::transfer_function_srgb;
+}
+
+QtWayland::wp_color_manager_v1::render_intent renderIntentKritaToWayland(KisSurfaceColorimetry::RenderIntent intent)
+{
+ using namespace KisSurfaceColorimetry;
+
+ switch (intent) {
+ case RenderIntent::render_intent_perceptual:
+ return QtWayland::wp_color_manager_v1::render_intent::render_intent_perceptual;
+ case RenderIntent::render_intent_relative:
+ return QtWayland::wp_color_manager_v1::render_intent::render_intent_relative;
+ case RenderIntent::render_intent_saturation:
+ return QtWayland::wp_color_manager_v1::render_intent::render_intent_saturation;
+ case RenderIntent::render_intent_absolute:
+ return QtWayland::wp_color_manager_v1::render_intent::render_intent_absolute;
+ case RenderIntent::render_intent_relative_bpc:
+ return QtWayland::wp_color_manager_v1::render_intent::render_intent_relative_bpc;
+ default:
+ Q_ASSERT(false && "Unknown RenderIntent value");
+ return QtWayland::wp_color_manager_v1::render_intent::render_intent_perceptual; // Default fallback
+ }
+}
+
+} // namespace KisSurfaceColorimetry
+
+/**
+ * The operators for the members of QtWayland::wp_color_manager_v1 are
+ * placed **outside** the KisSurfaceColorimetry namespace
+ */
+
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::primaries p)
+{
+ QDebugStateSaver saver(debug);
+ switch (p) {
+ case QtWayland::wp_color_manager_v1::primaries_srgb:
+ debug << "srgb";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_pal_m:
+ debug << "pal_m";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_pal:
+ debug << "pal";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_ntsc:
+ debug << "ntsc";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_generic_film:
+ debug << "generic_film";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_bt2020:
+ debug << "bt2020";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_cie1931_xyz:
+ debug << "cie1931_xyz";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_dci_p3:
+ debug << "dci_p3";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_display_p3:
+ debug << "display_p3";
+ break;
+ case QtWayland::wp_color_manager_v1::primaries_adobe_rgb:
+ debug << "adobe_rgb";
+ break;
+ default:
+ debug << "Unknown primaries:" << static_cast<int>(p);
+ break;
+ }
+ return debug;
+}
+
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::feature f)
+{
+ QDebugStateSaver saver(debug);
+ switch (f) {
+ case QtWayland::wp_color_manager_v1::feature_icc_v2_v4:
+ debug << "icc_v2_v4";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_parametric:
+ debug << "parametric";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_set_primaries:
+ debug << "set_primaries";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_set_tf_power:
+ debug << "set_tf_power";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_set_luminances:
+ debug << "set_luminances";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_set_mastering_display_primaries:
+ debug << "set_mastering_display_primaries";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_extended_target_volume:
+ debug << "extended_target_volume";
+ break;
+ case QtWayland::wp_color_manager_v1::feature_windows_scrgb:
+ debug << "windows_scrgb";
+ break;
+ default:
+ debug << "Unknown feature:" << static_cast<int>(f);
+ break;
+ }
+ return debug;
+}
+
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::render_intent ri)
+{
+ QDebugStateSaver saver(debug);
+ switch (ri) {
+ case QtWayland::wp_color_manager_v1::render_intent_perceptual:
+ debug << "perceptual";
+ break;
+ case QtWayland::wp_color_manager_v1::render_intent_relative:
+ debug << "relative";
+ break;
+ case QtWayland::wp_color_manager_v1::render_intent_saturation:
+ debug << "saturation";
+ break;
+ case QtWayland::wp_color_manager_v1::render_intent_absolute:
+ debug << "absolute";
+ break;
+ case QtWayland::wp_color_manager_v1::render_intent_relative_bpc:
+ debug << "relative_bpc";
+ break;
+ default:
+ debug << "Unknown render intent:" << static_cast<int>(ri);
+ break;
+ }
+ return debug;
+}
+
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::transfer_function tf)
+{
+ QDebugStateSaver saver(debug);
+ switch (tf) {
+ case QtWayland::wp_color_manager_v1::transfer_function_bt1886:
+ debug << "bt1886";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_gamma22:
+ debug << "gamma22";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_gamma28:
+ debug << "gamma28";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_st240:
+ debug << "st240";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_ext_linear:
+ debug << "ext_linear";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_log_100:
+ debug << "log_100";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_log_316:
+ debug << "log_316";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_xvycc:
+ debug << "xvycc";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_srgb:
+ debug << "srgb";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_ext_srgb:
+ debug << "ext_srgb";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_st2084_pq:
+ debug << "st2084_pq";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_st428:
+ debug << "st428";
+ break;
+ case QtWayland::wp_color_manager_v1::transfer_function_hlg:
+ debug << "hlg";
+ break;
+ default:
+ debug << "Unknown transfer function:" << static_cast<int>(tf);
+ break;
+ }
+ return debug;
+}
+
+/* KISSURFACECOLORIMETRY_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorimetry.h b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorimetry.h
new file mode 100644
index 0000000000..9425c43ba7
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/KisWaylandSurfaceColorimetry.h
@@ -0,0 +1,110 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISWAYLANDSURFACECOLORIMETRY_H
+#define KISWAYLANDSURFACECOLORIMETRY_H
+
+#include <surfacecolormanagement/KisSurfaceColorimetry.h>
+#include <qwayland-color-management-v1.h>
+
+namespace KisSurfaceColorimetry
+{
+
+struct WaylandPrimaries : boost::equality_comparable<WaylandPrimaries> {
+ using xy = KisColorimetryUtils::xy;
+ using Colorimetry = KisColorimetryUtils::Colorimetry;
+
+ xy red;
+ xy green;
+ xy blue;
+ xy white;
+
+ bool operator==(const WaylandPrimaries &other) const {
+ return red == other.red &&
+ green == other.green &&
+ blue == other.blue &&
+ white == other.white;
+ }
+
+ Colorimetry toColorimetry() const {
+ return Colorimetry(red, green, blue, white);
+ }
+
+ static WaylandPrimaries fromColorimetry(const Colorimetry &colorimetry) {
+ WaylandPrimaries result;
+
+ result.red = colorimetry.red().toxy();
+ result.green = colorimetry.green().toxy();
+ result.blue = colorimetry.blue().toxy();
+ result.white = colorimetry.white().toxy();
+
+ return result;
+ }
+};
+
+
+inline KisColorimetryUtils::xy xyFromWaylandXy(int32_t x, int32_t y) {
+ return {x / 1'000'000.0, y / 1'000'000.0};
+}
+
+inline std::pair<int32_t, int32_t> waylandXyFromXy(KisColorimetryUtils::xy value) {
+ return {std::rint(value.x * 1'000'000.0), std::rint(value.y * 1'000'000.0)};
+}
+
+
+struct WaylandSurfaceDescription : boost::equality_comparable<WaylandSurfaceDescription>
+{
+ using transfer_function = QtWayland::wp_color_manager_v1::transfer_function;
+ using primaries = QtWayland::wp_color_manager_v1::primaries;
+
+ std::optional<uint32_t> tfGamma;
+ std::optional<transfer_function> tfNamed;
+
+ std::optional<WaylandPrimaries> container;
+ std::optional<primaries> namedContainer;
+
+ std::optional<WaylandPrimaries> target;
+
+ std::optional<KisSurfaceColorimetry::Luminance> luminances;
+ std::optional<KisSurfaceColorimetry::MasteringLuminance> masteringLuminance;
+
+ std::optional<uint32_t> targetMaxCLL;
+ std::optional<uint32_t> targetMaxFALL;
+
+ bool iccFileIsPresent = false;
+
+ bool operator==(const WaylandSurfaceDescription &other) const {
+ return tfGamma == other.tfGamma &&
+ tfNamed == other.tfNamed &&
+ container == other.container &&
+ namedContainer == other.namedContainer &&
+ target == other.target &&
+ luminances == other.luminances &&
+ masteringLuminance == other.masteringLuminance &&
+ targetMaxCLL == other.targetMaxCLL &&
+ targetMaxFALL == other.targetMaxFALL &&
+ iccFileIsPresent == other.iccFileIsPresent;
+
+ }
+
+ SurfaceDescription toSurfaceDescription() const;
+ static WaylandSurfaceDescription fromSurfaceDescription(const SurfaceDescription &desc);
+};
+
+QDebug operator<<(QDebug dbg, const WaylandPrimaries &points);
+QDebug operator<<(QDebug dbg, const WaylandSurfaceDescription &data);
+
+QtWayland::wp_color_manager_v1::primaries primariesKritaToWayland(KisSurfaceColorimetry::NamedPrimaries primaries);
+QtWayland::wp_color_manager_v1::transfer_function transferFunctionKritaToWayland(KisSurfaceColorimetry::NamedTransferFunction transferFunction);
+QtWayland::wp_color_manager_v1::render_intent renderIntentKritaToWayland(KisSurfaceColorimetry::RenderIntent intent);
+
+}
+
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::primaries p);
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::feature f);
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::render_intent ri);
+QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::transfer_function tf);
+
+#endif /* KISWAYLANDSURFACECOLORIMETRY_H */
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md b/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md
new file mode 100644
index 0000000000..464e8c0527
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md
@@ -0,0 +1,85 @@
+# Rules of thumb when writing a Wayland plugin
+
+## Client extension object lifetime management
+
+When constructing a client extension with `QWaylandClientExtensionTemplate`,
+use automated deletion routines provided by the generated code:
+
+Pass the autogenerated `destroy()` method into the second argument of the
+template:
+
+```cpp
+class KisWaylandAPIColorManager
+ : public QWaylandClientExtensionTemplate<KisWaylandAPIColorManager,
+ // \|/ pass the destructor here!
+ &QtWayland::wp_color_manager_v1::destroy>
+ , public QtWayland::wp_color_manager_v1
+{
+};
+```
+
+This will generate a code that performs two things for you:
+
+1) Destruction of the Wayland's C-style object in the destructor of
+ the C++-object
+
+2) Destruction of the Wayland's C-style object when the extenstion
+ gets inactive, i.e. when the connection is lost.
+
+## Active and non-active states
+
+Wayland protocol is a "connection" to the compositor, which means that this
+connection may be lost sometimes (e.g. when the compositor crashes). Theoretically,
+we should expose this state on the API level, but we don't do that. Instead we
+expose ready and non-ready states (see below).
+
+## Ready and non-ready states
+
+The Wayland protocol is asyncronous. It means thet when we request some
+information from the compositor we do not get the reply immediately. Instead
+we should wait untit the compositor sends us an event with the reply.
+
+For this reason we added two states to the plugin API. The interface may be
+"ready" (i.e. all information is available right away) or "non-ready". The
+"non-ready" state also covers the case when the connection is lost and
+the API is in non-active state.
+
+## Handling of the disconnection signal
+
+When the connection to the compositor is lost (i.e. it crashed and got restarted),
+we should handle that and recreate all the objects related to our extension.
+
+Basically, you need to handle `QWaylandClientExtensionTemplate::activeChanged`
+signal, destroy all the object and turn the object into "non-ready" mode.
+
+See an example in `KisWaylandAPIColorManager`:
+
+```cpp
+KisWaylandAPIColorManager::KisWaylandAPIColorManager()
+ : QWaylandClientExtensionTemplate(1)
+{
+ connect(this, &QWaylandClientExtensionTemplate::activeChanged, this, [this] {
+ if (!isActive()) {
+ m_supportedFeatures.clear();
+ m_supportedIntents.clear();
+ m_supportedPrimariesNamed.clear();
+ m_supportedTransferFunctionsNamed.clear();
+ if (m_isReady) {
+ m_isReady = false;
+ Q_EMIT sigReadyChanged(m_isReady);
+ }
+ }
+ });
+}
+```
+
+To test if your app handles the disconnection signal correctly just run:
+
+```bash
+kwin_wayland --replace
+```
+
+Your app should not die :)
+
+**WARNING:** it will kill all your XWayland apps (and wayland-native apps
+that handle this case incorrectly).
\ No newline at end of file
diff --git a/plugins/platforms/wayland/waylandcolormanagement/on-color-proofing-under-wayland.md b/plugins/platforms/wayland/waylandcolormanagement/on-color-proofing-under-wayland.md
new file mode 100644
index 0000000000..663c8e4d96
--- /dev/null
+++ b/plugins/platforms/wayland/waylandcolormanagement/on-color-proofing-under-wayland.md
@@ -0,0 +1,119 @@
+# On color proofing under Wayland
+
+ICCv4 specification is really weird in area that is related to the white point
+of the profile's color space. ICC defines two different white points:
+
+* `cmsSigChromaticAdaptationTag` defines the color adaptation of the viewer
+ in which the resulting image is viewed. For Display class profiles
+ ICCv4 explicitly specifies that the user is assumed to be fully adapted
+ to the display. In layman terms it means that the user does not look
+ anywhere outside the of the display, hence display's white looks as
+ "perfect white" for him/her.
+
+* `cmsSigMediaWhitePointTag` defines the color tint of the paper used
+ for printing. This tint will be visible to the user even **after**
+ he/she is fully adapted to the environment light (as defined by
+ `cmsSigChromaticAdaptationTag`). For Display class profiles
+ ICCv4 explicitly specifies that `cmsSigMediaWhitePointTag` must
+ be set to `D50`, which means that the user is fully adapted to
+ the display.
+
+The weird thing is that ICC's "absolute colorimetric" is not really
+"absolute". It still adjusts `cmsSigChromaticAdaptationTag` between
+the source and destination profiles, ignoring `cmsSigMediaWhitePointTag`
+difference.
+
+From the user perspective we have three usecases:
+
+## Gamut preview in the display space
+
+We basically show the image to the user as if the he/she was
+fully adapted to the **paper white** of the output. I.e.
+both `cmsSigMediaWhitePointTag` and `cmsSigChromaticAdaptationTag`
+values are taken into account (well, internally they are **not**
+taken into account since their values are encoded into AToB1 and
+BToA1 pipelines).
+
+When using Wayland we set up proofing pipelines in the following way:
+
+1) Image -> Proofing Space [0]
+ * intent: chosen by the user
+ * bpc: chosen by the user
+
+2) Proofing Space -> Monitor Space
+ * intent: `IntentPerceptual`
+ * adaptation state: _unused_
+ * bpc: `true`
+
+3) Wayland surface
+ * intent: `render_intent_relative_bpc`
+
+## Simulate paper white in the display space **with full adaptation**
+
+The user might want to preview the paper white in the current
+display space, while keeping the eye adapted to the display's
+white. It means that the color will be adpted using
+`cmsSigChromaticAdaptationTag` of the profiles, but **not**
+for `cmsSigMediaWhitePointTag`.
+
+The the image's white will look as different to the diffuse
+white of the display, as different the real paper white when
+looked on in the environment defined by
+`cmsSigChromaticAdaptationTag`.
+
+When using Wayland we set up proofing pipelines in the following way:
+
+1) Image -> Proofing Space [0]
+ * intent: chosen by the user
+ * bpc: chosen by the user
+
+2) Proofing Space -> Monitor Space
+ * intent: `IntentAbsoluteColorimetric`
+ * adaptation state: `1.0`
+ * bpc: _unused_
+
+3) Wayland surface
+ * intent: `render_intent_absolute` [1]
+
+## Simulate paper white in the display space **without adaptation**
+
+Sometimes the user may want to look into the image without full adaptation
+to the display's white point. It may be useful in the case when the user
+stretches the source image to full-screen, puts the printed version on
+the table in front of the display and tries to compare them.
+
+If the Output profile for the media encodes the adaptation state of
+the viewing environment, and and Display profile encodes the white
+point of the display, then the resulting image on the screen will have
+skewed white point, equal to the one on the printed media [2]
+
+When using Wayland we set up proofing pipelines in the following way:
+
+1) Image -> Proofing Space [0]
+ * intent: chosen by the user
+ * bpc: chosen by the user
+
+2) Proofing Space -> Monitor Space
+ * intent: `IntentAbsoluteColorimetric`
+ * adaptation state: `0.0`
+ * bpc: _unused_
+
+3) Wayland surface
+ * intent: `render_intent_absolute_no_adaptation`
+
+## Footnotes
+
+[0] - "Image -> Proofing Space" leg of the conversion is chosen by the user.
+It means that the user is responsible to convert the image into the
+"Proofing Space" using the selected intent right before sending to
+the printing device. This step is mandatory to get correct colors in the end.
+
+[1] - In early versions of Wayland protocol `render_intent_absolute` was implemented
+to work as `render_intent_absolute_no_adaptation`. For such buggy versions of
+the compositor one should use `render_intent_relative` instead. The change happened in
+this patch in [kwin](https://invent.kde.org/plasma/kwin/-/merge_requests/8032)
+and [wayland](https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/439/).
+
+[2] - It is usually recommended to calibrate the display to the same white
+point as the viewing environment around it. But that might be not easy to guarantee
+their equality, especially in case of laptops.
\ No newline at end of file