From 187fffd0f5104352bdfdb8c968572830589fad78 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Thu, 26 Sep 2024 17:28:35 -0500 Subject: [PATCH] wayland: add support for xx-color-management-v4 for vo_dmabuf_wayland Although this protocol isn't official yet, several compositors are known to support it to some extent and this lets users actually view HDR with less hacks/workarounds. The actual protocol here is simply copy and pasted from the upstream fork* where these are developed. There is also icc profile support in the protocol, but this is omitted for now in favor of setting colorspaces and signalling hdr metadata. However for mpv, this only actually has any practical use with vo_dmabuf_wayland so this is the only VO that will make use of the protocol. When using vulkan, this is already handled via vulkan extensions by compositors and vo_gpu_next. So actually we don't want to use the wayland protocol in that case since it will just get in the way. The only known limitation on that front is driver support for hdr vulkan surfaces but as soon as that is available it should just work with no code changes. For opengl, hdr support there is a whole other mess with a lot of unknowns but simply using this protocol isn't good enough and would require changes elsewhere. vo_wlshm is currently too stupid to pick any format besides bgr0 or 0rgb, so any color management there is meaningless at this stage. So this means that only vo_dmabuf_wayland can actually use this protocol. But that's perfectly fine. Without this, vo_dmabuf_wayland has a very bad limitation in that it cannot communicate colorspaces at all and compositors have to guess. Using xx-color-management-v4 fixes this. For the other VOs, merely having the common protocol setup stuff in the common code does no harm and later if they get smarter, it's easy for them to use the stuff since it is written generically anyway. *: https://gitlab.freedesktop.org/swick/wayland-protocols/-/tree/color-xx/staging/color-management --- video/out/meson.build | 3 +- .../out/protocols/xx-color-management-v4.xml | 1453 +++++++++++++++++ video/out/vo_dmabuf_wayland.c | 20 + video/out/wayland_common.c | 266 ++- video/out/wayland_common.h | 19 + 5 files changed, 1758 insertions(+), 3 deletions(-) create mode 100644 video/out/protocols/xx-color-management-v4.xml diff --git a/video/out/meson.build b/video/out/meson.build index de93508217..95ebd4a8cd 100644 --- a/video/out/meson.build +++ b/video/out/meson.build @@ -6,8 +6,9 @@ protocols = [[wl_protocol_dir, 'stable/presentation-time/presentation-time.xml'] [wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml'], [wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'], [wl_protocol_dir, 'staging/content-type/content-type-v1.xml'], + [wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml'], [wl_protocol_dir, 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml'], - [wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml']] + ['protocols', 'xx-color-management-v4.xml']] wl_protocols_source = [] wl_protocols_headers = [] diff --git a/video/out/protocols/xx-color-management-v4.xml b/video/out/protocols/xx-color-management-v4.xml new file mode 100644 index 0000000000..17f217cee6 --- /dev/null +++ b/video/out/protocols/xx-color-management-v4.xml @@ -0,0 +1,1453 @@ + + + + Copyright 2019 Sebastian Wick + Copyright 2019 Erwin Burema + Copyright 2020 AMD + Copyright 2020-2024 Collabora, Ltd. + Copyright 2024 Xaver Hugl + + 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. + + + + 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. + + + + + A 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. + + + + + Destroy the xx_color_manager_v4 object. This does not affect any other + objects in any way. + + + + + + + + + + + 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. + + + + + + + + + + + + + + + + + + + + The compositor supports set_mastering_display_primaries request with a + target color volume fully contained inside the 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. + + + + + + + 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. + + Descriptions do list the specifications for convenience. + + + + + 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. + + + + + 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. + + + + + 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. + + + + + 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. + + + + + Color primaries as defined by H.273 for generic film. + Equivalent to H.273 ColourPrimaries code point 8. + + + + + 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. + + + + + 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. + + + + + Color primaries as defined by Digital Cinema System and published in + SMPTE RP 431-2 (2011). Equivalent to H.273 ColourPrimaries code point + 11. + + + + + Color primaries as defined by Digital Cinema System and published in + SMPTE EG 432-1 (2010). + Equivalent to H.273 ColourPrimaries code point 12. + + + + + Color primaries as defined by Adobe as "Adobe RGB" and later published + by ISO 12640-4 (2011). + + + + + + + Named transfer functions used to encode 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. + + Descriptions do list the specifications for convenience. + + + + + Transfer characteristics as defined by + - Rec. ITU-R BT.709-6 + - Rec. ITU-R BT.1361-0 conventional colour gamut system (historical) + Equivalent to H.273 TransferCharacteristics code point 1, 6, 14, 15. + + + + + 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. + + + + + Transfer characteristics as defined by + - Rec. ITU-R BT.470-6 System B, G (historical) + Equivalent to H.273 TransferCharacteristics code point 5. + + + + + Transfer characteristics as defined by + - SMPTE ST 240 (1999) + Equivalent to H.273 TransferCharacteristics code point 7. + + + + + Linear transfer characteristics. + Equivalent to H.273 TransferCharacteristics code point 8. + + + + + Logarithmic transfer characteristic (100:1 range). + Equivalent to H.273 TransferCharacteristics code point 9. + + + + + Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range). + Equivalent to H.273 TransferCharacteristics code point 10. + + + + + Transfer characteristics as defined by + - IEC 61966-2-4 + Equivalent to H.273 TransferCharacteristics code point 11. + + + + + Transfer characteristics as defined by + - Rec. ITU-R BT.1361-0 extended colour gamut system (historical) + Equivalent to H.273 TransferCharacteristics code point 12. + + + + + Transfer characteristics as defined by + - IEC 61966-2-1 sRGB + Equivalent to H.273 TransferCharacteristics code point 13 with + MatrixCoefficients set to 0. + + + + + 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. + + + + + 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² + + + + + Transfer characteristics as defined by + - SMPTE ST 428-1 (2019) + Equivalent to H.273 TransferCharacteristics code point 17. + + + + + 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² + Note: HLG is a scene referred signal. All absolute luminance values + used here for HLG assume a 1000 cd/m² display. + + + + + + + This creates a new xx_color_management_output_v4 object for the + given wl_output. + + See the xx_color_management_output_v4 interface for more details. + + + + + + + + + If a xx_color_management_surface_v4 object already exists for the given + wl_surface, the protocol error surface_exists is raised. + + This creates a new color xx_color_management_surface_v4 object for the + given wl_surface. + + See the xx_color_management_surface_v4 interface for more details. + + + + + + + + + This creates a new color xx_color_management_feedback_surface_v4 object + for the given wl_surface. + + See the xx_color_management_feedback_surface_v4 interface for more + details. + + + + + + + + + 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 xx_image_description_v4 object. + + This request can be used when the compositor advertises + xx_color_manager_v4.feature.icc_v2_v4. + Otherwise this request raises the protocol error unsupported_feature. + + + + + + + + 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 xx_image_description_v4 object. + + This request can be used when the compositor advertises + xx_color_manager_v4.feature.parametric. + Otherwise this request raises the protocol error unsupported_feature. + + + + + + + + When this object is created, it shall immediately send this event once + for each rendering intent the compositor supports. + + + + + + + + When this object is created, it shall immediately send this event once + for each compositor supported feature listed in the enumeration. + + + + + + + + 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. + + + + + + + + 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. + + + + + + + + + A xx_color_management_output_v4 describes the color properties of an + output. + + The xx_color_management_output_v4 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 xx_color_management_output_v4 object inert. + + + + + Destroy the color xx_color_management_output_v4 object. This does not + affect any remaining protocol objects. + + + + + + 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. + + + + + + This creates a new xx_image_description_v4 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 xx_color_management_output_v4 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 xx_image_description_v4 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 xx_image_description_v4.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 + xx_image_description_v4.failed event with the low_version cause. + + Otherwise the object shall immediately deliver the ready event. + + + + + + + + + A xx_color_management_surface_v4 allows the client to set the color + space and HDR properties of a surface. + + If the wl_surface associated with the xx_color_management_surface_v4 is + destroyed, the xx_color_management_surface_v4 object becomes inert. + + + + + Destroy the xx_color_management_surface_v4 object and do the same as + unset_image_description. + + + + + + + + + + + + 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 description whose creation gracefully failed (received + xx_image_description_v4.failed) are forbidden in this request, and in + such case the protocol error image_description is raised. + + All image descriptions whose creation succeeded (received + xx_image_description_v4.ready) 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 + xx_color_manager_v4.render_intent event, otherwise the protocol error + render_intent is raised. + + 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. + + + + + + + + + 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. + + + + + + + A xx_color_management_feedback_surface_v4 allows the client to get the + preferred color description of a surface. + + If the wl_surface associated with this object is destroyed, the + xx_color_management_feedback_surface_v4 object becomes inert. + + + + + Destroy the xx_color_management_feedback_surface_v4 object. + + + + + + + + + + + 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 is merely a notification. When the 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 + + + + + + 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 xx_image_description_v4 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 xx_color_management_feedback_surface_v4 object + if the client is capable of adapting to image descriptions. + + The created xx_image_description_v4 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 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 + xx_image_description_v4.failed event with the low_version cause, + otherwise the object shall immediately deliver the ready event. + + + + + + + + + This type of object is used for collecting all the information required + to create a xx_image_description_v4 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. + + + + + + + + + + + + + + + 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 xx_image_description_v4.failed event with the + 'unsupported' cause. If a valid image description was created from the + information, the xx_image_description_v4.ready event will eventually + be sent instead. + + This request destroys the xx_image_description_creator_icc_v4 object. + + The resulting image description object does not allow get_information + request. + + + + + + + + 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 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 xx_image_description_v4.failed event on the + created xx_image_description_v4 with the 'operating_system' cause. + + The maximum size of the ICC profile is 4 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 xx_image_description_v4 object + delivers either failed or ready event; or + - if create request was not issued, this + xx_image_description_creator_icc_v4 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 + xx_image_description_v4.failed event on the created + xx_image_description_v4 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. + + + + + + + + + + + This type of object is used for collecting all the parameters required + to create a xx_image_description_v4 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 + - 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. + + + + + + + + + + + + + + + + + + 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. + + Also, the combination of the parameter set is verified. If the set is + not consistent, the protocol error inconsistent_set is raised. + + If the particular combination of the parameter set is not supported + by the compositor, the resulting image description object shall + immediately deliver the xx_image_description_v4.failed event with the + 'unsupported' cause. If a valid image description was created from the + parameter set, the xx_image_description_v4.ready event will eventually + be sent instead. + + This request destroys the xx_image_description_creator_params_v4 + object. + + The resulting image description object does not allow get_information + request. + + + + + + + + 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 xx_color_manager_v4 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. + + + + + + + + Sets the color component transfer characteristic to a power curve with + the given exponent. This curve represents the conversion from electrical + to optical pixel or color 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 + xx_color_manager_v4.feature.set_tf_power. Otherwise this request raises + the protocol error unsupported_feature. + + + + + + + + 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 xx_color_manager_v4 event + supported_primaries_named are allowed. Other values shall raise the + protocol error invalid_primaries. + + If primaries have already been set on this object, the protocol error + already_set is raised. + + + + + + + + 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 10000 to get the argument value + to carry precision of 4 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 + xx_color_manager_v4.feature.set_primaries. Otherwise this request raises + the protocol error unsupported_feature. + + + + + + + + + + + + + + + Sets the primary color volume luminance range and the reference white + luminance level. + + The default luminances 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. + + '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. + + If 'max_lum' is less than the 'reference_lum', or 'reference_lum' is + 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 + xx_color_manager_v4.feature.set_luminances. Otherwise this request + raises the protocol error unsupported_feature. + + + + + + + + + + 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 define the target color volume. + + If mastering display primaries are not explicitly set, the target color + volume is assumed to be equal to 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 10000 to get the argument value + to carry precision of 4 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 + xx_color_manager_v4.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 + xx_color_manager_v4.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. + + + + + + + + + + + + + + + Sets the luminance range that was used during the content mastering + process as the minimum and maximum absolute luminance L. This is + compatible with the SMPTE ST 2086 definition of HDR static metadata. + + The mastering luminance range is undefined by default. + + 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. + + + + + + + + + Sets the maximum content light level (max_cll) as defined by CTA-861-H. + + This can only be set when set_tf_cicp is used to set the transfer + characteristic to Rec. ITU-R BT.2100-2 perceptual quantization system. + Otherwise, 'create' request shall raise inconsistent_set protocol + error. + + max_cll is undefined by default. + + + + + + + + Sets the maximum frame-average light level (max_fall) as defined by + CTA-861-H. + + This can only be set when set_tf_cicp is used to set the transfer + characteristic to Rec. ITU-R BT.2100-2 perceptual quantization system. + Otherwise, 'create' request shall raise inconsistent_set protocol error. + + max_fall is undefined by default. + + + + + + + + + An image description carries information about the color encoding used on + a surface when attached to a wl_surface via + xx_color_management_surface_v4.set_image_description. A compositor can use + this information to decode pixel values into colorimetrically meaningful + quantities. + + Note, that the xx_image_description_v4 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 + xx_image_description_v4 object always refers to one fixed image + description. It cannot change after creation. + + + + + Destroy this object. It is safe to destroy an object which is not ready. + + Destroying a xx_image_description_v4 object has no side-effects, not + even if a xx_color_management_surface_v4.set_image_description has not + yet been followed by a wl_surface.commit. + + + + + + + + + + + + + + + + + + + + + + If creating a xx_image_description_v4 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 xx_image_description_v4 object will + never become ready and it can only be destroyed. + + + + + + + + + Once this event has been sent, the xx_image_description_v4 object is + deemed "ready". Ready objects can be used to send requests and can be + used through other interfaces. + + Every ready xx_image_description_v4 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. + + This identity allows clients to de-duplicate image description records + and avoid get_information request if they already have the image + description information. + + + + + + + + Creates a xx_image_description_info_v4 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. + + + + + + + + + Sends all matching events describing an image description object exactly + once and finally sends the 'done' event. + + Once a xx_image_description_info_v4 object has delivered a 'done' event it + is automatically destroyed. + + Every xx_image_description_info_v4 created from the same + xx_image_description_v4 shall always return the exact same data. + + + + + Signals the end of information events and destroys the object. + + + + + + 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. + + + + + + + + + + Delivers the primary color volume primaries and white point using CIE + 1931 xy chromaticity coordinates. + + Each coordinate value is multiplied by 10000 to get the argument value + to carry precision of 4 decimals. + + + + + + + + + + + + + + + Delivers the primary color volume primaries and white point using an + explicitly enumerated named set. + + + + + + + + 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. + + + + + + + + Delivers the transfer characteristic using an explicitly enumerated + named function. + + + + + + + + Delivers the primary color volume luminance range and the reference + white luminance level. + + 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. + + + + + + + + + + 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 10000 to get the argument value + to carry precision of 4 decimals. + + + + + + + + + + + + + + + Provides the luminance range that the image description is targeting as + the minimum and maximum absolute luminance L. This is 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. + + + + + + + + + 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. + + + + + + + + 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. + + + + + + diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c index 9a79eb947c..733a011cd9 100644 --- a/video/out/vo_dmabuf_wayland.c +++ b/video/out/vo_dmabuf_wayland.c @@ -100,6 +100,8 @@ struct priv { bool destroy_buffers; bool force_window; enum hwdec_type hwdec_type; + + struct mp_image_params target_params; uint32_t drm_format; uint64_t drm_modifier; }; @@ -538,6 +540,12 @@ static void resize(struct vo *vo) lround(vo->dheight / wl->scaling_factor)); wl_subsurface_set_position(wl->osd_subsurface, lround((0 - dst.x0) / wl->scaling_factor), lround((0 - dst.y0) / wl->scaling_factor)); set_viewport_source(vo, src); + + mp_mutex_lock(&vo->params_mutex); + vo->target_params->w = mp_rect_w(dst); + vo->target_params->h = mp_rect_h(dst); + vo->target_params->rotate = (vo->params->rotate % 90) * 90; + mp_mutex_unlock(&vo->params_mutex); } static bool draw_osd(struct vo *vo, struct mp_image *cur, double pts) @@ -612,6 +620,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame) buf = buffer_get(vo, frame); if (buf && buf->frame) { + vo_wayland_handle_color(wl); struct mp_image *image = buf->frame->current; wl_surface_attach(wl->video_surface, buf->buffer, 0, 0); wl_surface_damage_buffer(wl->video_surface, 0, 0, image->w, @@ -691,6 +700,17 @@ done: if (!vo_wayland_reconfig(vo)) return VO_ERROR; + mp_mutex_lock(&vo->params_mutex); + p->target_params = img->params; + // Restore fallback layer parameters if available. + mp_image_params_restore_dovi_mapping(&p->target_params); + // Strip metadata that is not understood anyway. + struct pl_hdr_metadata *hdr = &p->target_params.color.hdr; + hdr->scene_max[0] = hdr->scene_max[1] = hdr->scene_max[2] = 0; + hdr->scene_avg = hdr->max_pq_y = hdr->avg_pq_y = 0; + vo->target_params = &p->target_params; + mp_mutex_unlock(&vo->params_mutex); + wl_surface_set_buffer_transform(vo->wl->video_surface, img->params.rotate / 90); // Immediately destroy all buffers if params change. diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 0c93577ee3..998fc9ea26 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -46,6 +46,9 @@ #include "single-pixel-buffer-v1.h" #include "fractional-scale-v1.h" +// Vendored protocols +#include "xx-color-management-v4.h" + #if HAVE_DRM #include #include @@ -71,6 +74,9 @@ // From the fractional scale protocol #define WAYLAND_SCALE_FACTOR 120.0 +// From the xx color management protocol +#define WAYLAND_COLOR_FACTOR 10000 + enum resizing_constraint { MP_WIDTH_CONSTRAINT = 1, @@ -232,6 +238,7 @@ static void get_planar_drm_formats(struct vo_wayland_state *wl); static void get_shape_device(struct vo_wayland_state *wl, struct vo_wayland_seat *s); static void guess_focus(struct vo_wayland_state *wl); static void handle_key_input(struct vo_wayland_seat *s, uint32_t key, uint32_t state, bool no_emit); +static void initialize_color_maps(struct vo_wayland_state *wl); static void prepare_resize(struct vo_wayland_state *wl); static void remove_feedback(struct vo_wayland_feedback_pool *fback_pool, struct wp_presentation_feedback *fback); @@ -1241,6 +1248,136 @@ static const struct wp_fractional_scale_v1_listener fractional_scale_listener = preferred_scale, }; +static void supported_intent(void *data, struct xx_color_manager_v4 *color_manager, + uint32_t render_intent) +{ +} + +static void supported_feature(void *data, struct xx_color_manager_v4 *color_manager, + uint32_t feature) +{ + struct vo_wayland_state *wl = data; + + switch (feature) { + case XX_COLOR_MANAGER_V4_FEATURE_ICC_V2_V4: + MP_VERBOSE(wl, "Compositor supports ICC creator requests.\n"); + wl->supports_icc = true; // TODO: actually implement + break; + case XX_COLOR_MANAGER_V4_FEATURE_PARAMETRIC: + MP_VERBOSE(wl, "Compositor supports parametric image description creator.\n"); + wl->supports_parametric = true; + break; + case XX_COLOR_MANAGER_V4_FEATURE_SET_PRIMARIES: + MP_VERBOSE(wl, "Compositor supports setting primaries.\n"); + wl->supports_primaries = true; + break; + case XX_COLOR_MANAGER_V4_FEATURE_SET_TF_POWER: + MP_VERBOSE(wl, "Compositor supports setting transfer functions.\n"); + wl->supports_tf_power = true; + break; + case XX_COLOR_MANAGER_V4_FEATURE_SET_LUMINANCES: + MP_VERBOSE(wl, "Compositor supports setting luminances.\n"); + wl->supports_luminances = true; + break; + case XX_COLOR_MANAGER_V4_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES: + MP_VERBOSE(wl, "Compositor supports setting mastering display primaries.\n"); + wl->supports_display_primaries = true; + break; + } +} + +static void supported_tf_named(void *data, struct xx_color_manager_v4 *color_manager, + uint32_t tf) +{ + struct vo_wayland_state *wl = data; + + switch (tf) { + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB: + wl->transfer_map[PL_COLOR_TRC_SRGB] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB; + break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR: + wl->transfer_map[PL_COLOR_TRC_LINEAR] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR; + break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA22: + wl->transfer_map[PL_COLOR_TRC_GAMMA22] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA22; + break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA28: + wl->transfer_map[PL_COLOR_TRC_GAMMA28] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA28; + break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST428: + wl->transfer_map[PL_COLOR_TRC_ST428] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST428; + break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ: + wl->transfer_map[PL_COLOR_TRC_PQ] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ; + break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_HLG: + wl->transfer_map[PL_COLOR_TRC_HLG] = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_HLG; + break; + } +} + +static void supported_primaries_named(void *data, struct xx_color_manager_v4 *color_manager, + uint32_t primaries) +{ + struct vo_wayland_state *wl = data; + + switch (primaries) { + case XX_COLOR_MANAGER_V4_PRIMARIES_PAL: + wl->primaries_map[PL_COLOR_PRIM_BT_601_525] = XX_COLOR_MANAGER_V4_PRIMARIES_PAL; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_NTSC: + wl->primaries_map[PL_COLOR_PRIM_BT_601_625] = XX_COLOR_MANAGER_V4_PRIMARIES_NTSC; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_SRGB: + wl->primaries_map[PL_COLOR_PRIM_BT_709] = XX_COLOR_MANAGER_V4_PRIMARIES_SRGB; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_PAL_M: + wl->primaries_map[PL_COLOR_PRIM_BT_470M] = XX_COLOR_MANAGER_V4_PRIMARIES_PAL_M; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_BT2020: + wl->primaries_map[PL_COLOR_PRIM_BT_2020] = XX_COLOR_MANAGER_V4_PRIMARIES_BT2020; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_ADOBE_RGB: + wl->primaries_map[PL_COLOR_PRIM_ADOBE] = XX_COLOR_MANAGER_V4_PRIMARIES_ADOBE_RGB; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_DCI_P3: + wl->primaries_map[PL_COLOR_PRIM_DCI_P3] = XX_COLOR_MANAGER_V4_PRIMARIES_DCI_P3; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_DISPLAY_P3: + wl->primaries_map[PL_COLOR_PRIM_DISPLAY_P3] = XX_COLOR_MANAGER_V4_PRIMARIES_DISPLAY_P3; + break; + case XX_COLOR_MANAGER_V4_PRIMARIES_GENERIC_FILM: + wl->primaries_map[PL_COLOR_PRIM_FILM_C] = XX_COLOR_MANAGER_V4_PRIMARIES_GENERIC_FILM; + break; + } +} + +static const struct xx_color_manager_v4_listener color_manager_listener = { + supported_intent, + supported_feature, + supported_tf_named, + supported_primaries_named, +}; + +static void image_description_failed(void *data, struct xx_image_description_v4 *image_description, + uint32_t cause, const char *msg) +{ + struct vo_wayland_state *wl = data; + MP_VERBOSE(wl, "Image description failed: %d, %s\n", cause, msg); +} + +static void image_description_ready(void *data, struct xx_image_description_v4 *image_description, + uint32_t identity) +{ + struct vo_wayland_state *wl = data; + xx_color_management_surface_v4_set_image_description(wl->color_surface, wl->image_description, 0); +} + +static const struct xx_image_description_v4_listener image_description_listener = { + image_description_failed, + image_description_ready, +}; + static const char *zxdg_decoration_mode_to_str(const uint32_t mode) { switch (mode) { @@ -1503,6 +1640,8 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id wl->surface = wl_compositor_create_surface(wl->compositor); wl->video_surface = wl_compositor_create_surface(wl->compositor); wl->osd_surface = wl_compositor_create_surface(wl->compositor); + wl->callback_surface = !strcmp(wl->vo->driver->name, "dmabuf-wayland") ? + wl->video_surface : wl->surface; /* never accept input events on anything besides the main surface */ struct wl_region *region = wl_compositor_create_region(wl->compositor); @@ -1602,6 +1741,13 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id xdg_wm_base_add_listener(wl->wm_base, &xdg_wm_base_listener, wl); } + if (!strcmp(interface, xx_color_manager_v4_interface.name) && found++) { + ver = 1; + initialize_color_maps(wl); + wl->color_manager = wl_registry_bind(reg, id, &xx_color_manager_v4_interface, ver); + xx_color_manager_v4_add_listener(wl->color_manager, &color_manager_listener, wl); + } + if (!strcmp(interface, zxdg_decoration_manager_v1_interface.name) && found++) { ver = 1; wl->xdg_decoration_manager = wl_registry_bind(reg, id, &zxdg_decoration_manager_v1_interface, ver); @@ -2149,6 +2295,15 @@ static int handle_round(int scale, int n) return (scale * n + WAYLAND_SCALE_FACTOR / 2) / WAYLAND_SCALE_FACTOR; } +static void initialize_color_maps(struct vo_wayland_state *wl) +{ + // -1 indicates unsupported + for (int i = 0; i < PL_COLOR_PRIM_COUNT; i++) + wl->primaries_map[i] = -1; + for (int i = 0; i < PL_COLOR_TRC_COUNT; i++) + wl->transfer_map[i] = -1; +} + static void prepare_resize(struct vo_wayland_state *wl) { int32_t width = mp_rect_w(wl->geometry) / wl->scaling_factor; @@ -2243,6 +2398,75 @@ static void remove_seat(struct vo_wayland_seat *seat) return; } +static void reset_color_management(struct vo_wayland_state *wl) +{ + if (!wl->color_surface) + return; + + if (wl->image_creator_params) + xx_image_description_creator_params_v4_destroy(wl->image_creator_params); + + if (wl->image_description) { + xx_color_management_surface_v4_unset_image_description(wl->color_surface); + xx_image_description_v4_destroy(wl->image_description); + wl->image_description = NULL; + } + + wl->image_creator_params = xx_color_manager_v4_new_parametric_creator(wl->color_manager); + wl->unsupported_colorspace = false; +} + +static int set_colorspace(struct vo_wayland_state *wl) +{ + struct pl_color_space color = wl->vo->target_params->color; + int xx_primaries = wl->primaries_map[color.primaries]; + int xx_transfer = wl->transfer_map[color.transfer]; + + if (xx_primaries == -1) + MP_VERBOSE(wl, "Compositor does not support color primary: %s\n", pl_color_primaries_name(color.primaries)); + + if (xx_transfer == -1) + MP_VERBOSE(wl, "Compositor does not support transfer function: %s\n", pl_color_transfer_name(color.transfer)); + + if (xx_primaries == -1 || xx_transfer == -1) { + wl->unsupported_colorspace = true; + return -1; + } + + xx_image_description_creator_params_v4_set_primaries_named(wl->image_creator_params, xx_primaries); + xx_image_description_creator_params_v4_set_tf_named(wl->image_creator_params, xx_transfer); + return 0; +} + +static void set_color_management(struct vo_wayland_state *wl) +{ + struct pl_color_space color = wl->vo->target_params->color; + if (!wl->color_surface || wl->unsupported_colorspace || pl_color_space_equal(&color, &wl->target_params.color)) + return; + + wl->target_params = *wl->vo->target_params; + reset_color_management(wl); + if (set_colorspace(wl)) + return; + struct pl_hdr_metadata hdr = wl->vo->target_params->color.hdr; + if (wl->supports_display_primaries) { + xx_image_description_creator_params_v4_set_mastering_display_primaries(wl->image_creator_params, + hdr.prim.red.x * WAYLAND_COLOR_FACTOR, hdr.prim.red.y * WAYLAND_COLOR_FACTOR, hdr.prim.green.x * WAYLAND_COLOR_FACTOR, + hdr.prim.green.y * WAYLAND_COLOR_FACTOR, hdr.prim.blue.x * WAYLAND_COLOR_FACTOR, hdr.prim.blue.y * WAYLAND_COLOR_FACTOR, + hdr.prim.white.x * WAYLAND_COLOR_FACTOR, hdr.prim.white.y * WAYLAND_COLOR_FACTOR); + + // No clear enum in the protocol to indicate if these are supposed + // to work or not so just hope they do if setting display + // primaries is supported. + xx_image_description_creator_params_v4_set_mastering_luminance(wl->image_creator_params, hdr.min_luma * WAYLAND_COLOR_FACTOR, hdr.max_luma); + xx_image_description_creator_params_v4_set_max_cll(wl->image_creator_params, hdr.max_cll); + xx_image_description_creator_params_v4_set_max_fall(wl->image_creator_params, hdr.max_fall); + } + wl->image_description = xx_image_description_creator_params_v4_create(wl->image_creator_params); + wl->image_creator_params = NULL; + xx_image_description_v4_add_listener(wl->image_description, &image_description_listener, wl); +} + static void set_content_type(struct vo_wayland_state *wl) { if (!wl->content_type_manager) @@ -2767,6 +2991,15 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) return VO_NOTIMPL; } +void vo_wayland_handle_color(struct vo_wayland_state *wl) +{ + if (!wl->vo->target_params) + return; + + set_color_management(wl); +} + + void vo_wayland_handle_scale(struct vo_wayland_state *wl) { wp_viewport_set_destination(wl->viewport, lround(mp_rect_w(wl->geometry) / wl->scaling_factor), @@ -2825,7 +3058,6 @@ bool vo_wayland_init(struct vo *vo) .opts_cache = m_config_cache_alloc(wl, vo->global, &vo_sub_opts), }; wl->opts = wl->opts_cache->opts; - bool using_dmabuf_wayland = !strcmp(wl->vo->driver->name, "dmabuf-wayland"); wl_list_init(&wl->output_list); wl_list_init(&wl->seat_list); @@ -2879,6 +3111,14 @@ bool vo_wayland_init(struct vo *vo) wl->video_subsurface = wl_subcompositor_get_subsurface(wl->subcompositor, wl->video_surface, wl->surface); } + // Only bind to vo_dmabuf_wayland for now to avoid conflicting with VK_hdr_layer + if (wl->color_manager && !strcmp(wl->vo->driver->name, "dmabuf-wayland")) { + wl->color_surface = xx_color_manager_v4_get_surface(wl->color_manager, wl->callback_surface); + } else { + MP_VERBOSE(wl, "Compositor doesn't support the %s protocol!\n", + xx_color_manager_v4_interface.name); + } + if (wl->content_type_manager) { wl->content_type = wp_content_type_manager_v1_get_surface_content_type(wl->content_type_manager, wl->surface); } else { @@ -2954,7 +3194,6 @@ bool vo_wayland_init(struct vo *vo) update_app_id(wl); mp_make_wakeup_pipe(wl->wakeup_pipe); - wl->callback_surface = using_dmabuf_wayland ? wl->video_surface : wl->surface; wl->frame_callback = wl_surface_frame(wl->callback_surface); wl_callback_add_listener(wl->frame_callback, &frame_listener, wl); wl_surface_commit(wl->surface); @@ -2963,6 +3202,15 @@ bool vo_wayland_init(struct vo *vo) * before mpv does anything else. */ wl_display_roundtrip(wl->display); + // The compositor needs to at least support parametric otherwise + // the protocol is useless for us. + // TODO: Use the icc stuff. + if (wl->color_manager && !wl->supports_parametric) { + MP_VERBOSE(wl, "Compositor does not support parametic image descriptions!\n"); + xx_color_management_surface_v4_destroy(wl->color_surface); + wl->color_surface = NULL; + } + return true; err: @@ -2976,6 +3224,8 @@ bool vo_wayland_reconfig(struct vo *vo) MP_VERBOSE(wl, "Reconfiguring!\n"); + reset_color_management(wl); + if (!wl->current_output) { wl->current_output = find_output(wl); if (!wl->current_output) @@ -3060,6 +3310,18 @@ void vo_wayland_uninit(struct vo *vo) if (wl->cursor_theme) wl_cursor_theme_destroy(wl->cursor_theme); + if (wl->color_manager) + xx_color_manager_v4_destroy(wl->color_manager); + + if (wl->color_surface) + xx_color_management_surface_v4_destroy(wl->color_surface); + + if (wl->image_creator_params) + xx_image_description_creator_params_v4_destroy(wl->image_creator_params); + + if (wl->image_description) + xx_image_description_v4_destroy(wl->image_description); + if (wl->content_type) wp_content_type_v1_destroy(wl->content_type); diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index 23cca5b8e9..abce364cd5 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -19,7 +19,9 @@ #define MPLAYER_WAYLAND_COMMON_H #include + #include "input/event.h" +#include "video/mp_image.h" #include "vo.h" struct compositor_format; @@ -85,6 +87,22 @@ struct vo_wayland_state { int timeout_count; int wakeup_pipe[2]; + /* color-management */ + struct xx_color_manager_v4 *color_manager; + struct xx_color_management_surface_v4 *color_surface; + struct xx_image_description_v4 *image_description; + struct xx_image_description_creator_params_v4 *image_creator_params; + struct mp_image_params target_params; + bool supports_icc; + bool supports_parametric; + bool supports_primaries; + bool supports_tf_power; + bool supports_luminances; + bool supports_display_primaries; + bool unsupported_colorspace; + int primaries_map[PL_COLOR_PRIM_COUNT]; + int transfer_map[PL_COLOR_TRC_COUNT]; + /* content-type */ struct wp_content_type_manager_v1 *content_type_manager; struct wp_content_type_v1 *content_type; @@ -167,6 +185,7 @@ bool vo_wayland_reconfig(struct vo *vo); int vo_wayland_allocate_memfd(struct vo *vo, size_t size); int vo_wayland_control(struct vo *vo, int *events, int request, void *arg); +void vo_wayland_handle_color(struct vo_wayland_state *wl); void vo_wayland_handle_scale(struct vo_wayland_state *wl); void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha); void vo_wayland_sync_swap(struct vo_wayland_state *wl);