Krita Source Code Documentation
Loading...
Searching...
No Matches
KritaPlatformPluginWayland.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include "qwayland-color-management-v1.h"
9#include <kpluginfactory.h>
10
11#include <kis_assert.h>
12
14
15#include <config-use-surface-color-management-api.h>
16
17#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
18
23
24#include <QWindow>
25
26namespace detail {
27
28// just a simple wrapper that unpacks arguments from a QVariantList into
29// a proper interface for KisWaylandSurfaceColorManager
30class KisWaylandSurfaceColorManagerWrapper: public KisWaylandSurfaceColorManager
31{
32public:
33 KisWaylandSurfaceColorManagerWrapper(QObject *parent, const QVariantList &args)
34 : KisWaylandSurfaceColorManager(args.first().value<QWindow*>(), parent)
35 {
36 KIS_SAFE_ASSERT_RECOVER_NOOP(args.size() == 1);
37 }
38};
39
40} // namespace detail
41
42class KisWaylandSurfaceColorManagementInfo : public KisSurfaceColorManagementInfo
43{
44 Q_OBJECT
45public:
47 bool surfaceColorManagedByOS() override {
49 return registry->globalExists(QtWayland::wp_color_manager_v1::interface()->name);
50 }
51
52 QFuture<QString> debugReport() override {
53 QPromise<QString> promise;
54 promise.start();
55
56 std::shared_ptr<KisWaylandDebugInfoFetcher> infoFetcher(new KisWaylandDebugInfoFetcher());
57
58 if (infoFetcher->isReady()) {
59 promise.addResult(infoFetcher->report());
60 promise.finish();
61
62 return promise.future();
63 } else {
64 // wrap the info fetcher into the resulting lambda
65 QFuture<QString> result = promise.future().then(
66 [infoFetcher] (const QString &report) {
67 // a simple wrapping class that holds the fetcher until the
68 // result is reported or the future is destroyed
69 return report;
70 });
71
72 // move the promise into the handler of its completion signal
73 connect(infoFetcher.get(), &KisWaylandDebugInfoFetcher::sigDebugInfoReady,
74 infoFetcher.get(), [promise = std::move(promise)] (const QString &report) mutable {
75 promise.addResult(report);
76 promise.finish();
77 });
78
79 return result;
80 }
81 }
82};
83
84#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
85
86K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayland.json",
87 (
88 registerPlugin<KisExtendedModifiersMapperWayland>()
89#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
90 , registerPlugin<detail::KisWaylandSurfaceColorManagerWrapper>()
91 , registerPlugin<KisWaylandOutputColorInfo>()
92 , registerPlugin<KisWaylandSurfaceColorManagementInfo>()
93#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
94 );)
95
96#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
97// for detail::KisWaylandSurfaceColorManagerWrapper
98#include <KritaPlatformPluginWayland.moc>
99#endif /* KRITA_USE_SURFACE_COLOR_MANAGEMENT_API */
float value(const T *src, size_t ch)
KisSurfaceColorManagementInfo(QObject *parent=nullptr)
virtual QFuture< QString > debugReport()=0
virtual bool surfaceColorManagedByOS()=0
void sigDebugInfoReady(const QString &report)
Wayland registry for tracking wayland globals.
static KisWaylandRegistry * getOrCreate()
bool globalExists(const QString &interface)
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327