| 1 | /* |
| 2 | * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #include "KisWaylandAPIImageDescription.h" |
| 8 | |
| 9 | using namespace Qt::Literals::StringLiterals; |
| 10 | |
| 11 | |
| 12 | KisWaylandAPIImageDescriptionInfo::KisWaylandAPIImageDescriptionInfo(::wp_image_description_info_v1 *info) |
| 13 | : QtWayland::wp_image_description_info_v1(info) |
| 14 | { |
| 15 | } |
| 16 | KisWaylandAPIImageDescriptionInfo::~KisWaylandAPIImageDescriptionInfo() |
| 17 | { |
| 18 | wp_image_description_info_v1_destroy(object()); |
| 19 | } |
| 20 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_done() |
| 21 | { |
| 22 | m_isReady = true; |
| 23 | Q_EMIT done(); |
| 24 | } |
| 25 | |
| 26 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_primaries(int32_t r_x, |
| 27 | int32_t r_y, |
| 28 | int32_t g_x, |
| 29 | int32_t g_y, |
| 30 | int32_t b_x, |
| 31 | int32_t b_y, |
| 32 | int32_t w_x, |
| 33 | int32_t w_y) |
| 34 | { |
| 35 | using KisSurfaceColorimetry::WaylandPrimaries; |
| 36 | using KisSurfaceColorimetry::xyFromWaylandXy; |
| 37 | |
| 38 | WaylandPrimaries colorPrimaries; |
| 39 | colorPrimaries.red = xyFromWaylandXy(r_x, r_y); |
| 40 | colorPrimaries.green = xyFromWaylandXy(g_x, g_y); |
| 41 | colorPrimaries.blue = xyFromWaylandXy(b_x, b_y); |
| 42 | colorPrimaries.white = xyFromWaylandXy(w_x, w_y); |
| 43 | m_data.container = colorPrimaries; |
| 44 | } |
| 45 | |
| 46 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_primaries_named(uint32_t primaries) |
| 47 | { |
| 48 | using KisSurfaceColorimetry::WaylandSurfaceDescription; |
| 49 | |
| 50 | Q_ASSERT(!m_data.namedContainer); |
| 51 | m_data.namedContainer = WaylandSurfaceDescription::primaries(primaries); |
| 52 | } |
| 53 | |
| 54 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_tf_power(uint32_t eexp) |
| 55 | { |
| 56 | Q_ASSERT(!m_data.tfGamma); |
| 57 | m_data.tfGamma = eexp; |
| 58 | } |
| 59 | |
| 60 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_tf_named(uint32_t tf) |
| 61 | { |
| 62 | using KisSurfaceColorimetry::WaylandSurfaceDescription; |
| 63 | |
| 64 | Q_ASSERT(!m_data.tfNamed); |
| 65 | m_data.tfNamed = WaylandSurfaceDescription::transfer_function(tf); |
| 66 | } |
| 67 | |
| 68 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_luminances(uint32_t min_lum, uint32_t max_lum, uint32_t reference_lum) |
| 69 | { |
| 70 | m_data.luminances = {min_lum, max_lum, reference_lum}; |
| 71 | } |
| 72 | |
| 73 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_primaries(int32_t r_x, |
| 74 | int32_t r_y, |
| 75 | int32_t g_x, |
| 76 | int32_t g_y, |
| 77 | int32_t b_x, |
| 78 | int32_t b_y, |
| 79 | int32_t w_x, |
| 80 | int32_t w_y) |
| 81 | |
| 82 | { |
| 83 | using KisSurfaceColorimetry::WaylandPrimaries; |
| 84 | using KisSurfaceColorimetry::xyFromWaylandXy; |
| 85 | |
| 86 | WaylandPrimaries colorPrimaries; |
| 87 | colorPrimaries.red = xyFromWaylandXy(r_x, r_y); |
| 88 | colorPrimaries.green = xyFromWaylandXy(g_x, g_y); |
| 89 | colorPrimaries.blue = xyFromWaylandXy(b_x, b_y); |
| 90 | colorPrimaries.white = xyFromWaylandXy(w_x, w_y); |
| 91 | m_data.target = colorPrimaries; |
| 92 | } |
| 93 | |
| 94 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_luminance(uint32_t min_lum, uint32_t max_lum) |
| 95 | { |
| 96 | m_data.masteringLuminance = {min_lum, max_lum}; |
| 97 | } |
| 98 | |
| 99 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_max_cll(uint32_t max_cll) |
| 100 | { |
| 101 | m_data.targetMaxCLL = max_cll; |
| 102 | } |
| 103 | |
| 104 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_target_max_fall(uint32_t max_fall) |
| 105 | { |
| 106 | m_data.targetMaxFALL = max_fall; |
| 107 | } |
| 108 | |
| 109 | void KisWaylandAPIImageDescriptionInfo::wp_image_description_info_v1_icc_file(int32_t icc, uint32_t icc_size) |
| 110 | { |
| 111 | Q_UNUSED(icc) |
| 112 | Q_UNUSED(icc_size) |
| 113 | m_data.iccFileIsPresent = true; |
| 114 | qWarning() << "WARNING: wp_image_description_info_v1_icc_file was received, but we don't support ICC files for the surface description!"; |
| 115 | } |
| 116 | |
| 117 | KisWaylandAPIImageDescriptionNoInfo::KisWaylandAPIImageDescriptionNoInfo(::wp_image_description_v1 *descr) |
| 118 | : QtWayland::wp_image_description_v1(descr) |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | KisWaylandAPIImageDescriptionNoInfo::~KisWaylandAPIImageDescriptionNoInfo() |
| 123 | { |
| 124 | wp_image_description_v1_destroy(object()); |
| 125 | } |
| 126 | |
| 127 | void KisWaylandAPIImageDescriptionNoInfo::wp_image_description_v1_failed(uint32_t cause, const QString &msg) |
| 128 | { |
| 129 | using cause_type = QtWayland::wp_image_description_v1::cause; |
| 130 | |
| 131 | cause_type realCause = static_cast<cause_type>(cause); |
| 132 | QLatin1String causeText; |
| 133 | |
| 134 | switch (realCause) { |
| 135 | case cause_low_version: |
| 136 | causeText = "cause_low_version"_L1; |
| 137 | break; |
| 138 | case cause_unsupported: |
| 139 | causeText = "cause_unsupported"_L1; |
| 140 | break; |
| 141 | case cause_operating_system: |
| 142 | causeText = "cause_operating_system"_L1; |
| 143 | break; |
| 144 | case cause_no_output: |
| 145 | causeText = "cause_no_output"_L1; |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | qWarning() << "KisWaylandImageDescription: Failed to create image description:" << causeText << ": " << msg; |
| 150 | m_error = realCause; |
| 151 | Q_EMIT sigDescriptionConstructed(false); |
| 152 | } |
| 153 | |
| 154 | void KisWaylandAPIImageDescriptionNoInfo::wp_image_description_v1_ready(uint32_t identity) |
| 155 | { |
| 156 | m_identity = identity; |
| 157 | Q_EMIT sigDescriptionConstructed(true); |
| 158 | } |
| 159 | |
| 160 | KisWaylandAPIImageDescription::KisWaylandAPIImageDescription(::wp_image_description_v1 *descr) |
| 161 | : KisWaylandAPIImageDescriptionNoInfo(descr) |
| 162 | , info(get_information()) |
| 163 | { |
| 164 | connect(&info, &KisWaylandAPIImageDescriptionInfo::done, this, &KisWaylandAPIImageDescription::done); |
| 165 | } |
| 166 | |
| 167 | #include "moc_KisWaylandAPIImageDescription.cpp" |