KWin
Loading...
Searching...
No Matches
frog_colormanagement_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
7#include "display.h"
8#include "surface.h"
9#include "surface_p.h"
10
11namespace KWin
12{
13
14static constexpr uint32_t s_version = 1;
15
17 : QObject(parent)
18 , QtWaylandServer::frog_color_management_factory_v1(*display, s_version)
19{
20}
21
25
26void FrogColorManagementV1::frog_color_management_factory_v1_get_color_managed_surface(Resource *resource, wl_resource *surface, uint32_t callback)
27{
29 SurfaceInterfacePrivate::get(surf)->frogColorManagement = new FrogColorManagementSurfaceV1(surf, resource->client(), callback);
30}
31
32void FrogColorManagementV1::frog_color_management_factory_v1_destroy(Resource *resource)
33{
34 wl_resource_destroy(resource->handle);
35}
36
38 : QtWaylandServer::frog_color_managed_surface(client, id, s_version)
39 , m_surface(surface)
40{
41}
42
44{
45 if (m_surface) {
46 const auto priv = SurfaceInterfacePrivate::get(m_surface);
47 priv->pending->colorDescription = ColorDescription::sRGB;
48 priv->pending->colorDescriptionIsSet = true;
49 priv->frogColorManagement = nullptr;
50 }
51}
52
53static QtWaylandServer::frog_color_managed_surface::transfer_function kwinToFrogTransferFunction(NamedTransferFunction tf)
54{
55 switch (tf) {
57 return QtWaylandServer::frog_color_managed_surface::transfer_function_srgb;
59 return QtWaylandServer::frog_color_managed_surface::transfer_function_gamma_22;
61 return QtWaylandServer::frog_color_managed_surface::transfer_function_st2084_pq;
63 return QtWaylandServer::frog_color_managed_surface::transfer_function_scrgb_linear;
65 return QtWaylandServer::frog_color_managed_surface::transfer_function_scrgb_linear;
66 }
67 return QtWaylandServer::frog_color_managed_surface::transfer_function_undefined;
68}
69
70uint16_t encodePrimary(float primary)
71{
72 return uint16_t(std::clamp<float>(std::round(primary / 0.00002), 0, 0xC350));
73}
74
76{
77 const auto &color = colorDescription.colorimetry();
78 send_preferred_metadata(kwinToFrogTransferFunction(colorDescription.transferFunction()),
79 encodePrimary(color.red().x()), encodePrimary(color.red().y()),
80 encodePrimary(color.green().x()), encodePrimary(color.green().y()),
81 encodePrimary(color.blue().x()), encodePrimary(color.blue().y()),
82 encodePrimary(color.white().x()), encodePrimary(color.white().y()),
83 std::round(colorDescription.maxHdrHighlightBrightness()),
84 std::round(colorDescription.minHdrBrightness() / 0.0001),
85 std::round(colorDescription.maxFrameAverageBrightness()));
86}
87
88void FrogColorManagementSurfaceV1::frog_color_managed_surface_set_known_transfer_function(Resource *resource, uint32_t transfer_function)
89{
90 switch (transfer_function) {
91 case transfer_function_undefined:
92 case transfer_function_srgb:
93 case transfer_function_gamma_22:
94 m_transferFunction = NamedTransferFunction::gamma22;
95 break;
96 case transfer_function_st2084_pq:
98 break;
99 case transfer_function_scrgb_linear:
100 m_transferFunction = NamedTransferFunction::scRGB;
101 break;
102 }
103 updateColorDescription();
104}
105
106void FrogColorManagementSurfaceV1::frog_color_managed_surface_set_known_container_color_volume(Resource *resource, uint32_t primaries)
107{
108 switch (primaries) {
109 case primaries_undefined:
110 case primaries_rec709:
111 m_colorimetry = NamedColorimetry::BT709;
112 break;
113 case primaries_rec2020:
114 m_colorimetry = NamedColorimetry::BT2020;
115 break;
116 }
117 updateColorDescription();
118}
119
120void FrogColorManagementSurfaceV1::frog_color_managed_surface_set_render_intent(Resource *resource, uint32_t render_intent)
121{
122 // there's only perceptual right now, so this can be ignored
123}
124
125void FrogColorManagementSurfaceV1::frog_color_managed_surface_set_hdr_metadata(Resource *resource,
126 uint32_t mastering_display_primary_red_x, uint32_t mastering_display_primary_red_y,
127 uint32_t mastering_display_primary_green_x, uint32_t mastering_display_primary_green_y,
128 uint32_t mastering_display_primary_blue_x, uint32_t mastering_display_primary_blue_y,
129 uint32_t mastering_white_point_x, uint32_t mastering_white_point_y,
130 uint32_t max_display_mastering_luminance, uint32_t min_display_mastering_luminance,
131 uint32_t max_cll, uint32_t max_fall)
132{
133 m_maxPeakBrightness = max_cll;
134 m_maxFrameAverageBrightness = max_fall;
135 updateColorDescription();
136}
137
138void FrogColorManagementSurfaceV1::frog_color_managed_surface_destroy(Resource *resource)
139{
140 wl_resource_destroy(resource->handle);
141}
142
143void FrogColorManagementSurfaceV1::frog_color_managed_surface_destroy_resource(Resource *resource)
144{
145 delete this;
146}
147
148void FrogColorManagementSurfaceV1::updateColorDescription()
149{
150 if (m_surface) {
151 // TODO make brightness values optional in ColorDescription
152 SurfaceInterfacePrivate *priv = SurfaceInterfacePrivate::get(m_surface);
153 priv->pending->colorDescription = ColorDescription(m_colorimetry, m_transferFunction, 0, 0, m_maxFrameAverageBrightness, m_maxPeakBrightness);
154 priv->pending->colorDescriptionIsSet = true;
155 }
156}
157
158}
159
160#include "moc_frog_colormanagement_v1.cpp"
NamedTransferFunction transferFunction() const
double minHdrBrightness() const
static const ColorDescription sRGB
Definition colorspace.h:132
double maxHdrHighlightBrightness() const
const Colorimetry & colorimetry() const
double maxFrameAverageBrightness() const
Class holding the Wayland server display loop.
Definition display.h:34
void setPreferredColorDescription(const ColorDescription &colorDescription)
FrogColorManagementSurfaceV1(SurfaceInterface *surface, wl_client *client, uint32_t id)
FrogColorManagementV1(Display *display, QObject *parent)
Resource representing a wl_surface.
Definition surface.h:80
static SurfaceInterface * get(wl_resource *native)
Definition surface.cpp:819
FrogColorManagementSurfaceV1 * frogColorManagement
Definition surface_p.h:171
static SurfaceInterfacePrivate * get(SurfaceInterface *surface)
Definition surface_p.h:99
uint16_t encodePrimary(float primary)
NamedTransferFunction
Definition colorspace.h:90