From a4eb2cff46a9b07582873f26d97ddab9abc7fd92 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 17 Jul 2025 10:55:11 +0100 Subject: [PATCH] color-representation-v1: Add wlr enums + converters Add wlr-internal enums for the properties specified in color-representation-v1 (encoding, range, chroma siting, alpha mode) so that other parts of wlroots can use these without depending on the protocol specifics and without needing to include the protocol headers. Also add conversion functions to convert the protocol enum values into the wlroots enum values. --- include/wlr/render/color.h | 51 ++++++++++++++ .../wlr/types/wlr_color_representation_v1.h | 9 +++ types/wlr_color_representation_v1.c | 66 +++++++++++++++++++ 3 files changed, 126 insertions(+) diff --git a/include/wlr/render/color.h b/include/wlr/render/color.h index 3341668a8..e2397b75a 100644 --- a/include/wlr/render/color.h +++ b/include/wlr/render/color.h @@ -30,6 +30,57 @@ enum wlr_color_transfer_function { WLR_COLOR_TRANSFER_FUNCTION_EXT_LINEAR = 1 << 2, }; +/** + * Specifies alpha blending modes. Note that premultiplied_electrical + * is the default, so there is no "none" or "unset" value. + */ +enum wlr_alpha_mode { + WLR_COLOR_ALPHA_MODE_PREMULTIPLIED_ELECTRICAL, + WLR_COLOR_ALPHA_MODE_PREMULTIPLIED_OPTICAL, + WLR_COLOR_ALPHA_MODE_STRAIGHT, +}; + +/** + * Well-known color encodings, each representing a set of matrix coefficients + * used to convert that particular YCbCr encoding to RGB. NONE means the + * value is unset or unknown. + */ +enum wlr_color_encoding { + WLR_COLOR_ENCODING_NONE, + WLR_COLOR_ENCODING_IDENTITY, + WLR_COLOR_ENCODING_BT709, + WLR_COLOR_ENCODING_FCC, + WLR_COLOR_ENCODING_BT601, + WLR_COLOR_ENCODING_SMPTE240, + WLR_COLOR_ENCODING_BT2020, + WLR_COLOR_ENCODING_BT2020_CL, + WLR_COLOR_ENCODING_ICTCP, +}; + +/** + * Specifies whether a particular color-encoding uses full- or limited-range + * values. NONE means the value is unset or unknown. + */ +enum wlr_color_range { + WLR_COLOR_RANGE_NONE, + WLR_COLOR_RANGE_LIMITED, + WLR_COLOR_RANGE_FULL, +}; + +/** + * Chroma sample locations, corresponding to Chroma420SampleLocType code + * points in H.273. NONE means the value is unset or unknown. + */ +enum wlr_color_chroma_location { + WLR_COLOR_CHROMA_LOCATION_NONE, + WLR_COLOR_CHROMA_LOCATION_TYPE0, + WLR_COLOR_CHROMA_LOCATION_TYPE1, + WLR_COLOR_CHROMA_LOCATION_TYPE2, + WLR_COLOR_CHROMA_LOCATION_TYPE3, + WLR_COLOR_CHROMA_LOCATION_TYPE4, + WLR_COLOR_CHROMA_LOCATION_TYPE5, +}; + /** * CIE 1931 xy chromaticity coordinates. */ diff --git a/include/wlr/types/wlr_color_representation_v1.h b/include/wlr/types/wlr_color_representation_v1.h index 251f4e6f9..d575eedf5 100644 --- a/include/wlr/types/wlr_color_representation_v1.h +++ b/include/wlr/types/wlr_color_representation_v1.h @@ -82,4 +82,13 @@ struct wlr_color_representation_v1_surface_state { const struct wlr_color_representation_v1_surface_state *wlr_color_representation_v1_get_surface_state( struct wlr_surface *surface); +enum wlr_alpha_mode wlr_color_representation_v1_alpha_mode_to_wlr( + enum wp_color_representation_surface_v1_alpha_mode wp_val); +enum wlr_color_encoding wlr_color_representation_v1_color_encoding_to_wlr( + enum wp_color_representation_surface_v1_coefficients wp_val); +enum wlr_color_range wlr_color_representation_v1_color_range_to_wlr( + enum wp_color_representation_surface_v1_range wp_val); +enum wlr_color_chroma_location wlr_color_representation_v1_chroma_location_to_wlr( + enum wp_color_representation_surface_v1_chroma_location wp_val); + #endif // WLR_TYPES_WLR_COLOR_REPRESENTATION_V1_H diff --git a/types/wlr_color_representation_v1.c b/types/wlr_color_representation_v1.c index 294f946a0..0bf33d156 100644 --- a/types/wlr_color_representation_v1.c +++ b/types/wlr_color_representation_v1.c @@ -11,6 +11,72 @@ #define WP_COLOR_REPRESENTATION_VERSION 1 +enum wlr_alpha_mode wlr_color_representation_v1_alpha_mode_to_wlr( + enum wp_color_representation_surface_v1_alpha_mode wp_val) { + switch (wp_val) { + case WP_COLOR_REPRESENTATION_SURFACE_V1_ALPHA_MODE_PREMULTIPLIED_ELECTRICAL: + return WLR_COLOR_ALPHA_MODE_PREMULTIPLIED_ELECTRICAL; + case WP_COLOR_REPRESENTATION_SURFACE_V1_ALPHA_MODE_PREMULTIPLIED_OPTICAL: + return WLR_COLOR_ALPHA_MODE_PREMULTIPLIED_OPTICAL; + case WP_COLOR_REPRESENTATION_SURFACE_V1_ALPHA_MODE_STRAIGHT: + return WLR_COLOR_ALPHA_MODE_STRAIGHT; + } + abort(); // unreachable +} + +enum wlr_color_encoding wlr_color_representation_v1_color_encoding_to_wlr( + enum wp_color_representation_surface_v1_coefficients wp_val) { + switch (wp_val) { + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_IDENTITY: + return WLR_COLOR_ENCODING_IDENTITY; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_BT709: + return WLR_COLOR_ENCODING_BT709; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_FCC: + return WLR_COLOR_ENCODING_FCC; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_BT601: + return WLR_COLOR_ENCODING_BT601; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_SMPTE240: + return WLR_COLOR_ENCODING_SMPTE240; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_BT2020: + return WLR_COLOR_ENCODING_BT2020; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_BT2020_CL: + return WLR_COLOR_ENCODING_BT2020_CL; + case WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_ICTCP: + return WLR_COLOR_ENCODING_ICTCP; + } + abort(); // unreachable +} + +enum wlr_color_range wlr_color_representation_v1_color_range_to_wlr( + enum wp_color_representation_surface_v1_range wp_val) { + switch (wp_val) { + case WP_COLOR_REPRESENTATION_SURFACE_V1_RANGE_LIMITED: + return WLR_COLOR_RANGE_LIMITED; + case WP_COLOR_REPRESENTATION_SURFACE_V1_RANGE_FULL: + return WLR_COLOR_RANGE_FULL; + } + abort(); // unreachable +} + +enum wlr_color_chroma_location wlr_color_representation_v1_chroma_location_to_wlr( + enum wp_color_representation_surface_v1_chroma_location wp_val) { + switch (wp_val) { + case WP_COLOR_REPRESENTATION_SURFACE_V1_CHROMA_LOCATION_TYPE_0: + return WLR_COLOR_CHROMA_LOCATION_TYPE0; + case WP_COLOR_REPRESENTATION_SURFACE_V1_CHROMA_LOCATION_TYPE_1: + return WLR_COLOR_CHROMA_LOCATION_TYPE1; + case WP_COLOR_REPRESENTATION_SURFACE_V1_CHROMA_LOCATION_TYPE_2: + return WLR_COLOR_CHROMA_LOCATION_TYPE2; + case WP_COLOR_REPRESENTATION_SURFACE_V1_CHROMA_LOCATION_TYPE_3: + return WLR_COLOR_CHROMA_LOCATION_TYPE3; + case WP_COLOR_REPRESENTATION_SURFACE_V1_CHROMA_LOCATION_TYPE_4: + return WLR_COLOR_CHROMA_LOCATION_TYPE4; + case WP_COLOR_REPRESENTATION_SURFACE_V1_CHROMA_LOCATION_TYPE_5: + return WLR_COLOR_CHROMA_LOCATION_TYPE5; + } + abort(); // unreachable +} + struct wlr_color_representation_v1 { struct wl_resource *resource; struct wlr_surface *surface;