| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWAYLANDCOLORMANAGEMENT_H |
| 5 | #define QWAYLANDCOLORMANAGEMENT_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QObject> |
| 19 | #include <QPointF> |
| 20 | #include <QColorSpace> |
| 21 | #include <QList> |
| 22 | |
| 23 | #include "qwayland-xx-color-management-v4.h" |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | namespace QtWaylandClient { |
| 28 | |
| 29 | class ImageDescription; |
| 30 | |
| 31 | class ColorManager : public QObject, public QtWayland::xx_color_manager_v4 |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | public: |
| 35 | enum class Feature { |
| 36 | ICC = 1 << 0, |
| 37 | Parametric = 1 << 1, |
| 38 | SetPrimaries = 1 << 2, |
| 39 | PowerTransferFunction = 1 << 3, |
| 40 | SetLuminances = 1 << 4, |
| 41 | SetMasteringDisplayPrimaries = 1 << 5, |
| 42 | ExtendedTargetVolume = 1 << 6, |
| 43 | }; |
| 44 | Q_ENUM(Feature); |
| 45 | Q_DECLARE_FLAGS(Features, Feature); |
| 46 | |
| 47 | explicit ColorManager(struct ::wl_registry *registry, uint32_t id, int version); |
| 48 | ~ColorManager() override; |
| 49 | |
| 50 | Features supportedFeatures() const; |
| 51 | bool supportsNamedPrimary(QtWayland::xx_color_manager_v4::primaries primaries) const; |
| 52 | bool supportsTransferFunction(QtWayland::xx_color_manager_v4::transfer_function transferFunction) const; |
| 53 | |
| 54 | std::unique_ptr<ImageDescription> createImageDescription(const QColorSpace &colorspace); |
| 55 | |
| 56 | private: |
| 57 | void xx_color_manager_v4_supported_feature(uint32_t feature) override; |
| 58 | void xx_color_manager_v4_supported_primaries_named(uint32_t primaries) override; |
| 59 | void xx_color_manager_v4_supported_tf_named(uint32_t transferFunction) override; |
| 60 | |
| 61 | Features mFeatures; |
| 62 | QList<QtWayland::xx_color_manager_v4::primaries> mPrimaries; |
| 63 | QList<QtWayland::xx_color_manager_v4::transfer_function> mTransferFunctions; |
| 64 | }; |
| 65 | |
| 66 | class ImageDescriptionInfo : public QObject, public QtWayland::xx_image_description_info_v4 |
| 67 | { |
| 68 | Q_OBJECT |
| 69 | public: |
| 70 | explicit ImageDescriptionInfo(ImageDescription *descr); |
| 71 | ~ImageDescriptionInfo(); |
| 72 | |
| 73 | Q_SIGNAL void done(); |
| 74 | |
| 75 | uint32_t mTransferFunction = 0; |
| 76 | QPointF mContainerRed; |
| 77 | QPointF mContainerGreen; |
| 78 | QPointF mContainerBlue; |
| 79 | QPointF mContainerWhite; |
| 80 | QPointF mTargetRed; |
| 81 | QPointF mTargetGreen; |
| 82 | QPointF mTargetBlue; |
| 83 | QPointF mTargetWhite; |
| 84 | double mMinLuminance; |
| 85 | double mMaxLuminance; |
| 86 | double mReferenceLuminance; |
| 87 | double mTargetMinLuminance; |
| 88 | double mTargetMaxLuminance; |
| 89 | |
| 90 | private: |
| 91 | void xx_image_description_info_v4_done() override; |
| 92 | void xx_image_description_info_v4_icc_file(int32_t icc, uint32_t icc_size) override; |
| 93 | void xx_image_description_info_v4_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; |
| 94 | void xx_image_description_info_v4_tf_named(uint32_t transferFunction) override; |
| 95 | void xx_image_description_info_v4_luminances(uint32_t min_lum, uint32_t max_lum, uint32_t reference_lum) override; |
| 96 | void xx_image_description_info_v4_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; |
| 97 | void xx_image_description_info_v4_target_luminance(uint32_t min_lum, uint32_t max_lum) override; |
| 98 | }; |
| 99 | |
| 100 | class ImageDescription : public QObject, public QtWayland::xx_image_description_v4 |
| 101 | { |
| 102 | Q_OBJECT |
| 103 | public: |
| 104 | explicit ImageDescription(::xx_image_description_v4 *descr); |
| 105 | ~ImageDescription(); |
| 106 | |
| 107 | Q_SIGNAL void ready(); |
| 108 | |
| 109 | private: |
| 110 | void xx_image_description_v4_failed(uint32_t cause, const QString &msg) override; |
| 111 | void xx_image_description_v4_ready(uint32_t identity) override; |
| 112 | }; |
| 113 | |
| 114 | class ColorManagementFeedback : public QObject, public QtWayland::xx_color_management_feedback_surface_v4 |
| 115 | { |
| 116 | Q_OBJECT |
| 117 | public: |
| 118 | explicit ColorManagementFeedback(::xx_color_management_feedback_surface_v4 *obj); |
| 119 | ~ColorManagementFeedback(); |
| 120 | |
| 121 | Q_SIGNAL void preferredChanged(); |
| 122 | |
| 123 | std::unique_ptr<ImageDescriptionInfo> mPreferredInfo; |
| 124 | |
| 125 | private: |
| 126 | void xx_color_management_feedback_surface_v4_preferred_changed() override; |
| 127 | void handlePreferredDone(); |
| 128 | |
| 129 | std::unique_ptr<ImageDescription> mPreferred; |
| 130 | std::unique_ptr<ImageDescriptionInfo> mPendingPreferredInfo; |
| 131 | |
| 132 | }; |
| 133 | |
| 134 | class ColorManagementSurface : public QObject, public QtWayland::xx_color_management_surface_v4 |
| 135 | { |
| 136 | Q_OBJECT |
| 137 | public: |
| 138 | explicit ColorManagementSurface(::xx_color_management_surface_v4 *obj); |
| 139 | ~ColorManagementSurface(); |
| 140 | |
| 141 | void setImageDescription(ImageDescription *descr); |
| 142 | }; |
| 143 | |
| 144 | } |
| 145 | |
| 146 | QT_END_NAMESPACE |
| 147 | |
| 148 | #endif |
| 149 | |