From 85ee1df12bb2843392931aa31435b839f40e0ef9 Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Mon, 20 Apr 2026 14:52:14 -0300 Subject: [PATCH] backend-drm: do not init color encoding and range props with __COUNT Let's follow the code design of the other properties: init them with _DEFAULT. In the setter function we ensure they are >= 0 and < COUNT, just like we do with other properties. Signed-off-by: Leandro Ribeiro --- libweston/backend-drm/kms.c | 17 +++++++++++------ libweston/backend-drm/state-helpers.c | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c index 073f797d8..3161d8982 100644 --- a/libweston/backend-drm/kms.c +++ b/libweston/backend-drm/kms.c @@ -37,6 +37,7 @@ #include #include #include "shared/helpers.h" +#include "shared/weston-assert.h" #include "shared/weston-drm-fourcc.h" #include "drm-internal.h" #include "pixel-formats.h" @@ -1258,8 +1259,10 @@ drm_plane_set_color_encoding(struct drm_plane *plane, enum wdrm_plane_color_encoding color_encoding, drmModeAtomicReq *req) { - if (color_encoding == WDRM_PLANE_COLOR_ENCODING__COUNT) - return 0; + struct weston_compositor *wc = plane->base.compositor; + + weston_assert_s32_ge(wc, color_encoding, 0); + weston_assert_s32_lt(wc, color_encoding, WDRM_PLANE_COLOR_ENCODING__COUNT); if (plane->props[WDRM_PLANE_COLOR_ENCODING].prop_id == 0) { if (color_encoding == WDRM_PLANE_COLOR_ENCODING_DEFAULT) @@ -1268,7 +1271,7 @@ drm_plane_set_color_encoding(struct drm_plane *plane, return -1; } - assert(drm_plane_supports_color_encoding(plane, color_encoding)); + weston_assert_true(wc, drm_plane_supports_color_encoding(plane, color_encoding)); return plane_add_prop(req, plane, WDRM_PLANE_COLOR_ENCODING, color_encoding); @@ -1279,8 +1282,10 @@ drm_plane_set_color_range(struct drm_plane *plane, enum wdrm_plane_color_range color_range, drmModeAtomicReq *req) { - if (color_range == WDRM_PLANE_COLOR_RANGE__COUNT) - return 0; + struct weston_compositor *wc = plane->base.compositor; + + weston_assert_s32_ge(wc, color_range, 0); + weston_assert_s32_lt(wc, color_range, WDRM_PLANE_COLOR_RANGE__COUNT); if (plane->props[WDRM_PLANE_COLOR_RANGE].prop_id == 0) { if (color_range == WDRM_PLANE_COLOR_RANGE_DEFAULT) @@ -1289,7 +1294,7 @@ drm_plane_set_color_range(struct drm_plane *plane, return -1; } - assert(drm_plane_supports_color_range(plane, color_range)); + weston_assert_true(wc, drm_plane_supports_color_range(plane, color_range)); return plane_add_prop(req, plane, WDRM_PLANE_COLOR_RANGE, color_range); } diff --git a/libweston/backend-drm/state-helpers.c b/libweston/backend-drm/state-helpers.c index dbcef7696..e34d03b04 100644 --- a/libweston/backend-drm/state-helpers.c +++ b/libweston/backend-drm/state-helpers.c @@ -58,8 +58,8 @@ drm_plane_state_alloc(struct drm_output_state *state_output, state->alpha = (plane->alpha_max < DRM_PLANE_ALPHA_OPAQUE) ? plane->alpha_max : DRM_PLANE_ALPHA_OPAQUE; - state->color_encoding = WDRM_PLANE_COLOR_ENCODING__COUNT; - state->color_range = WDRM_PLANE_COLOR_RANGE__COUNT; + state->color_encoding = WDRM_PLANE_COLOR_ENCODING_DEFAULT; + state->color_range = WDRM_PLANE_COLOR_RANGE_DEFAULT; /* Here we only add the plane state to the desired link, and not * set the member. Having an output pointer set means that the