Hi,
On 23.06.26 18:48, Harry Wentland wrote:
In vkms_plane_atomic_check(), validate that when a color pipeline
is active and the framebuffer format is YUV:
- The first colorop must be DRM_COLOROP_FIXED_MATRIX
- The fixed matrix colorop must not be bypassed
In vkms_plane_atomic_update(), when a color pipeline is active,
read the fixed_matrix_type from the first colorop state and map
it to the appropriate (color_encoding, color_range) pair for the
existing get_conversion_matrix_to_argb_u16() function.
In apply_colorop(), add a no-op case for DRM_COLOROP_FIXED_MATRIX
since the actual YUV-to-RGB conversion is already performed at
format read time via the conversion matrix.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Harry Wentland <[email protected]>
Reviewed-by: Alex Hung <[email protected]>
---
drivers/gpu/drm/vkms/vkms_composer.c | 6 +++
drivers/gpu/drm/vkms/vkms_plane.c | 68 +++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c
b/drivers/gpu/drm/vkms/vkms_composer.c
index 83d217085ad0..899120cd07ac 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -187,6 +187,12 @@ static void apply_colorop(struct pixel_argb_s32 *pixel,
struct drm_colorop *colo
if (colorop_state->data)
apply_3x4_matrix(pixel,
(struct drm_color_ctm_3x4
*)colorop_state->data->data);
+ } else if (colorop->type == DRM_COLOROP_FIXED_MATRIX) {
+ /*
+ * Fixed Matrix is a no-op here. YUV-to-RGB conversion
+ * is handled at format read time via the
+ * conversion_matrix set in vkms_plane_atomic_update().
+ */
}
}
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index 68cb2a3335e6..4ef4cebe718b 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -6,6 +6,7 @@
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_blend.h>
+#include <drm/drm_colorop.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
@@ -148,8 +149,56 @@ static void vkms_plane_atomic_update(struct drm_plane
*plane,
frame_info->rotation = new_state->rotation;
vkms_plane_state->pixel_read_line = get_pixel_read_line_function(fmt);
- get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding,
new_state->color_range,
- &vkms_plane_state->conversion_matrix);
+
+ if (new_state->color_pipeline) {
+ struct drm_colorop *colorop = new_state->color_pipeline;
+ struct drm_colorop_state *colorop_state;
+
+ colorop_state = drm_atomic_get_new_colorop_state(state,
colorop);
+
+ if (colorop_state && !colorop_state->bypass) {
+ enum drm_color_encoding encoding;
+ enum drm_color_range range;
+
+ switch (colorop_state->fixed_matrix_type) {
+ case DRM_COLOROP_FM_YCBCR601_FULL_RGB:
+ encoding = DRM_COLOR_YCBCR_BT601;
+ range = DRM_COLOR_YCBCR_FULL_RANGE;
+ break;
+ case DRM_COLOROP_FM_YCBCR601_LIMITED_RGB:
+ encoding = DRM_COLOR_YCBCR_BT601;
+ range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+ break;
+ case DRM_COLOROP_FM_YCBCR709_FULL_RGB:
+ encoding = DRM_COLOR_YCBCR_BT709;
+ range = DRM_COLOR_YCBCR_FULL_RANGE;
+ break;
+ case DRM_COLOROP_FM_YCBCR709_LIMITED_RGB:
+ encoding = DRM_COLOR_YCBCR_BT709;
+ range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+ break;
+ case DRM_COLOROP_FM_YCBCR2020_NC_FULL_RGB:
+ encoding = DRM_COLOR_YCBCR_BT2020;
+ range = DRM_COLOR_YCBCR_FULL_RANGE;
+ break;
+ case DRM_COLOROP_FM_YCBCR2020_NC_LIMITED_RGB:
+ encoding = DRM_COLOR_YCBCR_BT2020;
+ range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+ break;
+ default:
+ encoding = DRM_COLOR_YCBCR_BT709;
+ range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+ break;
+ }
+
+ get_conversion_matrix_to_argb_u16(fmt, encoding, range,
+
&vkms_plane_state->conversion_matrix);
+ }
+ } else {
+ get_conversion_matrix_to_argb_u16(fmt,
new_state->color_encoding,
+ new_state->color_range,
+
&vkms_plane_state->conversion_matrix);
+ }
}
static int vkms_plane_atomic_check(struct drm_plane *plane,
@@ -175,6 +224,21 @@ static int vkms_plane_atomic_check(struct drm_plane *plane,
if (ret != 0)
return ret;
+ if (new_plane_state->color_pipeline && new_plane_state->fb->format->is_yuv) {
+ struct drm_colorop *colorop = new_plane_state->color_pipeline;
+ struct drm_colorop_state *colorop_state;
+ if (colorop->type != DRM_COLOROP_FIXED_MATRIX)
+
+ return -EINVAL;
+
+ colorop_state = drm_atomic_get_new_colorop_state(state,
colorop);
+ if (!colorop_state)
+ return -EINVAL;
+
+ if (colorop_state->bypass)
+ return -EINVAL;
+ }
+
return 0;
}
This simple implementation makes sense to me and looks correct.
Reviewed-by: Robert Mader <[email protected]>
--
Robert Mader
Consultant Software Developer
Collabora Ltd.
Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
Registered in England & Wales, no. 5513718