From nobody Sun Nov 24 08:41:51 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE10018452E for ; Fri, 22 Nov 2024 16:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292119; cv=none; b=Ud3uZcVFAjn9paNwsv15Dt6q3ezzIdozoYhzn2Nf9rvC+JyCQytr4A3hNlzwwUgvC5T8g6r9Pu7YDNqM/L7FlE9+ffE7B8UnOU8NtK7Mfh68/MJK+vePFUR9cjDLn7MfmIPQU44uONhcGxhhixC4vAgxir0vDCVjHfRgDTncp9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292119; c=relaxed/simple; bh=xXvj+crpyp9sfQgjGWcgkb4EGOJwO9WuwNz2TVJhiqc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YUgZj7az1Vdf7oVAzWHWfwmbcKK1gYX/dihcL9fs1FjOPyFcHZQElrKz4ZCtTrJTZnp67o9PaEV8MJc5X8vDT6Sdma2AfVQekT0LFFM/L5Vv+ORehAqyE3K7gaBVaOIpaPdkJd/aa/6lZcQusAOp07zEPajYV15IvVJEegVP1PM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ph6Mgh4D; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ph6Mgh4D" Received: by mail.gandi.net (Postfix) with ESMTPSA id 2030E1C0004; Fri, 22 Nov 2024 16:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wp31ywIXD1K5mMtQQFNYiTSeygR6X7Jueg+AoYzX29o=; b=ph6Mgh4DJuwbNNOy+oIAOpVsF70MwZkiKAfUnmRv/lz9EA6cKE1BIl9l8zepBAir/3mcZa n/KeNpX2tP44WkN2TVVo50UxqB9vHhK6FWg80OHLN0CqzpbKAGFqGHTu9QVUvtMZpeQ0P7 I9YyL+LXAbFoR171Cw0GjmcBNmmuExSaV9mZhEl6v7IKxo4imDuU2nAlwV7irvVkWUMFw2 XhHe85caD//CVSdVruJESKHIUWLmeKFiJ8ChaGDbh1BWfs2iLudbPmt69KNl7646gi7wE3 8fO6kSZRno0Tv0pWCPcV4fiiaGxs1EG23EDIeWAt/4EFEw2eu2mpeAiOIbj4mQ== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:01 +0100 Subject: [PATCH v14 1/7] drm/vkms: Add YUV support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241122-yuv-v14-1-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=18934; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=x+PpGq/NazLPIBNQiPNlHKbW2GeWAhOXfFOTKwe+f0c=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4GuLC9DthePmhqpuVan4yx1shRhQ49dKTtN opkx1yBf++JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuBgAKCRAgrS7GWxAs 4kQaD/474quXcVmtE5I5CgOM1NO2Jvy4pvauna+IzKfvdrFmh12q+aagbM9RucWp8tIp9B8SOri qb4Di8AsLfWA7cCeSKFH3pVMUzTlz7tWskX+qyxMdB5fvL3seJQzSOXLDt+Y3qUnQRs+zgJrwW/ Dad7kM1fhi0jPOzbZHGPfq89JEjS/i2VGum1RzCXb0B7YffLE5W0y9Rk4nPDqR9wVod7hN//nt4 ctpRy1lUlFY9+4hYb9O2G7d0RuZQJMvMkHwsmzDxfyfS2jsDBi6vhdXJujY8q/o2s8qcrzYlI9B SKwedKfa2jiHRjAErvKsBPeoI9ZGLuhSDmvgtiI/RP1h2yTtOOl+kCoiSbLrvg5dyukkfuBAA2z vpZQJMHb1J4vjflQoTGAlkBBf1UqKOrMrEz85VIZoUuKYS4a5jrspUv2NwioL2ZBQs4RTzMyEgZ l22l1ANc7iL3QxIETMBEWMgdz+gSth9+GDXV0dWdoJBSQGR34zjNlLN0rlDLpqikt6811ajNLez EHSkp3YjG8n5KNEln4Nusk6ttAAy8gNChEl4wCF97GeW9kCC6Bnim77B75CW0OmTAXIyBKh7lLO QGJ4zn43IuwQ8Maaz7YNymGKxNi+XZLAtXnfvkmFbzKgKfVJa75/uH5ONdVVES9LaHTEhC1lULs 48mybN1hLw14yJw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Add support to the YUV formats bellow: - NV12/NV16/NV24 - NV21/NV61/NV42 - YUV420/YUV422/YUV444 - YVU420/YVU422/YVU444 The conversion from yuv to rgb is done with fixed-point arithmetic, using 32.32 fixed-point numbers and the drm_fixed helpers. To do the conversion, a specific matrix must be used for each color range (DRM_COLOR_*_RANGE) and encoding (DRM_COLOR_*). This matrix is stored in the `conversion_matrix` struct, along with the specific y_offset needed. This matrix is queried only once, in `vkms_plane_atomic_update` and stored in a `vkms_plane_state`. Those conversion matrices of each encoding and range were obtained by rounding the values of the original conversion matrices multiplied by 2^32. This is done to avoid the use of floating point operations. The same reading function is used for YUV and YVU formats. As the only difference between those two category of formats is the order of field, a simple swap in conversion matrix columns allows using the same function. Signed-off-by: Arthur Grillo [Louis Chauvet: - Adapted Arthur's work - Implemented the read_line_t callbacks for yuv - add struct conversion_matrix - store the whole conversion_matrix in the plane state - remove struct pixel_yuv_u8 - update the commit message - Merge the modifications from Arthur] Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 18 ++ drivers/gpu/drm/vkms/vkms_formats.c | 354 ++++++++++++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_formats.h | 4 + drivers/gpu/drm/vkms/vkms_plane.c | 16 +- 4 files changed, 391 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index 00541eff3d1b0aa4b374fb94c8fe34932df31509..ae721d998c7d381b9e4105c41de= c90b7b0ce2dc0 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -100,17 +100,35 @@ typedef void (*pixel_read_line_t)(const struct vkms_p= lane_state *plane, int x_st int y_start, enum pixel_read_direction direction, int count, struct pixel_argb_u16 out_pixel[]); =20 +/** + * struct conversion_matrix - Matrix to use for a specific encoding and ra= nge + * + * @matrix: Conversion matrix from yuv to rgb. The matrix is stored in a r= ow-major manner and is + * used to compute rgb values from yuv values: + * [[r],[g],[b]] =3D @matrix * [[y],[u],[v]] + * OR for yvu formats: + * [[r],[g],[b]] =3D @matrix * [[y],[v],[u]] + * The values of the matrix are signed fixed-point values with 32 bits fr= actional part. + * @y_offset: Offset to apply on the y value. + */ +struct conversion_matrix { + s64 matrix[3][3]; + int y_offset; +}; + /** * struct vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation * @pixel_read_line: function to read a pixel line in this plane. The crea= tor of a * struct vkms_plane_state must ensure that this pointer is valid + * @conversion_matrix: matrix used for yuv formats to convert to rgb */ struct vkms_plane_state { struct drm_shadow_plane_state base; struct vkms_frame_info *frame_info; pixel_read_line_t pixel_read_line; + struct conversion_matrix conversion_matrix; }; =20 struct vkms_plane { diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 39b1d7c97d454dfa1420990d35e455ed47e57c0c..1f3ce4f334be9560e62c9a7fd93= 3fa0ed6640e8f 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -140,6 +140,51 @@ static void packed_pixels_addr_1x1(const struct vkms_f= rame_info *frame_info, *addr =3D (u8 *)frame_info->map[0].vaddr + offset; } =20 +/** + * get_subsampling() - Get the subsampling divisor value on a specific dir= ection + * + * @format: format to extarct the subsampling from + * @direction: direction of the subsampling requested + */ +static int get_subsampling(const struct drm_format_info *format, + enum pixel_read_direction direction) +{ + switch (direction) { + case READ_BOTTOM_TO_TOP: + case READ_TOP_TO_BOTTOM: + return format->vsub; + case READ_RIGHT_TO_LEFT: + case READ_LEFT_TO_RIGHT: + return format->hsub; + } + WARN_ONCE(true, "Invalid direction for pixel reading: %d\n", direction); + return 1; +} + +/** + * get_subsampling_offset() - An offset for keeping the chroma siting cons= istent regardless of + * x_start and y_start values + * + * @direction: direction of the reading to properly compute this offset + * @x_start: x coordinate of the starting point of the readed line + * @y_start: y coordinate of the starting point of the readed line + */ +static int get_subsampling_offset(enum pixel_read_direction direction, int= x_start, int y_start) +{ + switch (direction) { + case READ_BOTTOM_TO_TOP: + return -y_start - 1; + case READ_TOP_TO_BOTTOM: + return y_start; + case READ_RIGHT_TO_LEFT: + return -x_start - 1; + case READ_LEFT_TO_RIGHT: + return x_start; + } + WARN_ONCE(true, "Invalid direction for pixel reading: %d\n", direction); + return 0; +} + /* * The following functions take pixel data (a, r, g, b, pixel, ...) and co= nvert them to * &struct pixel_argb_u16 @@ -202,6 +247,38 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(cons= t __le16 *pixel) return out_pixel; } =20 +static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 c= hannel_2, + const struct conversion_matrix *matrix) +{ + u16 r, g, b; + s64 fp_y, fp_channel_1, fp_channel_2; + s64 fp_r, fp_g, fp_b; + + fp_y =3D drm_int2fixp(((int)y - matrix->y_offset) * 257); + fp_channel_1 =3D drm_int2fixp(((int)channel_1 - 128) * 257); + fp_channel_2 =3D drm_int2fixp(((int)channel_2 - 128) * 257); + + fp_r =3D drm_fixp_mul(matrix->matrix[0][0], fp_y) + + drm_fixp_mul(matrix->matrix[0][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[0][2], fp_channel_2); + fp_g =3D drm_fixp_mul(matrix->matrix[1][0], fp_y) + + drm_fixp_mul(matrix->matrix[1][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[1][2], fp_channel_2); + fp_b =3D drm_fixp_mul(matrix->matrix[2][0], fp_y) + + drm_fixp_mul(matrix->matrix[2][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[2][2], fp_channel_2); + + fp_r =3D drm_fixp2int_round(fp_r); + fp_g =3D drm_fixp2int_round(fp_g); + fp_b =3D drm_fixp2int_round(fp_b); + + r =3D clamp(fp_r, 0, 0xffff); + g =3D clamp(fp_g, 0, 0xffff); + b =3D clamp(fp_b, 0, 0xffff); + + return argb_u16_from_u16161616(0xffff, r, g, b); +} + /* * The following functions are read_line function for each pixel format su= pported by VKMS. * @@ -311,6 +388,92 @@ static void RGB565_read_line(const struct vkms_plane_s= tate *plane, int x_start, } } =20 +/* + * This callback can be used for YUV formats where U and V values are + * stored in the same plane (often called semi-planar formats). It will + * correctly handle subsampling as described in the drm_format_info of the= plane. + * + * The conversion matrix stored in the @plane is used to: + * - Apply the correct color range and encoding + * - Convert YUV and YVU with the same function (a column swap is needed w= hen setting up + * plane->conversion_matrix) + */ +static void semi_planar_yuv_read_line(const struct vkms_plane_state *plane= , int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + u8 *y_plane; + u8 *uv_plane; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, + &y_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 1, + &uv_plane); + int step_y =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int step_uv =3D get_block_step_bytes(plane->frame_info->fb, direction, 1); + int subsampling =3D get_subsampling(plane->frame_info->fb->format, direct= ion); + int subsampling_offset =3D get_subsampling_offset(direction, x_start, y_s= tart); + const struct conversion_matrix *conversion_matrix =3D &plane->conversion_= matrix; + + for (int i =3D 0; i < count; i++) { + *out_pixel =3D argb_u16_from_yuv888(y_plane[0], uv_plane[0], uv_plane[1], + conversion_matrix); + out_pixel +=3D 1; + y_plane +=3D step_y; + if ((i + subsampling_offset + 1) % subsampling =3D=3D 0) + uv_plane +=3D step_uv; + } +} + +/* + * This callback can be used for YUV format where each color component is + * stored in a different plane (often called planar formats). It will + * correctly handle subsampling as described in the drm_format_info of the= plane. + * + * The conversion matrix stored in the @plane is used to: + * - Apply the correct color range and encoding + * - Convert YUV and YVU with the same function (a column swap is needed w= hen setting up + * plane->conversion_matrix) + */ +static void planar_yuv_read_line(const struct vkms_plane_state *plane, int= x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + u8 *y_plane; + u8 *channel_1_plane; + u8 *channel_2_plane; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, + &y_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 1, + &channel_1_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 2, + &channel_2_plane); + int step_y =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int step_channel_1 =3D get_block_step_bytes(plane->frame_info->fb, direct= ion, 1); + int step_channel_2 =3D get_block_step_bytes(plane->frame_info->fb, direct= ion, 2); + int subsampling =3D get_subsampling(plane->frame_info->fb->format, direct= ion); + int subsampling_offset =3D get_subsampling_offset(direction, x_start, y_s= tart); + const struct conversion_matrix *conversion_matrix =3D &plane->conversion_= matrix; + + for (int i =3D 0; i < count; i++) { + *out_pixel =3D argb_u16_from_yuv888(*y_plane, *channel_1_plane, *channel= _2_plane, + conversion_matrix); + out_pixel +=3D 1; + y_plane +=3D step_y; + if ((i + subsampling_offset + 1) % subsampling =3D=3D 0) { + channel_1_plane +=3D step_channel_1; + channel_2_plane +=3D step_channel_2; + } + } +} + /* * The following functions take one &struct pixel_argb_u16 and convert it = to a specific format. * The result is stored in @out_pixel. @@ -426,6 +589,20 @@ pixel_read_line_t get_pixel_read_line_function(u32 for= mat) return &XRGB16161616_read_line; case DRM_FORMAT_RGB565: return &RGB565_read_line; + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV24: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV42: + return &semi_planar_yuv_read_line; + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YVU444: + return &planar_yuv_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported @@ -439,6 +616,183 @@ pixel_read_line_t get_pixel_read_line_function(u32 fo= rmat) } } =20 +/* + * Those matrices were generated using the colour python framework + * + * Below are the function calls used to generate each matrix, go to + * https://colour.readthedocs.io/en/develop/generated/colour.matrix_YCbCr.= html + * for more info: + * + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601= "], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix no_operation =3D { + .matrix =3D { + { 4294967296, 0, 0, }, + { 0, 4294967296, 0, }, + { 0, 0, 4294967296, }, + }, + .y_offset =3D 0, +}; + +static const struct conversion_matrix yuv_bt601_full =3D { + .matrix =3D { + { 4294967296, 0, 6021544149 }, + { 4294967296, -1478054095, -3067191994 }, + { 4294967296, 7610682049, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601= "], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt601_limited =3D { + .matrix =3D { + { 5020601039, 0, 6881764740 }, + { 5020601039, -1689204679, -3505362278 }, + { 5020601039, 8697922339, 0 }, + }, + .y_offset =3D 16, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709= "], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt709_full =3D { + .matrix =3D { + { 4294967296, 0, 6763714498 }, + { 4294967296, -804551626, -2010578443 }, + { 4294967296, 7969741314, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709= "], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt709_limited =3D { + .matrix =3D { + { 5020601039, 0, 7729959424 }, + { 5020601039, -919487572, -2297803934 }, + { 5020601039, 9108275786, 0 }, + }, + .y_offset =3D 16, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.202= 0"], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt2020_full =3D { + .matrix =3D { + { 4294967296, 0, 6333358775 }, + { 4294967296, -706750298, -2453942994 }, + { 4294967296, 8080551471, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.202= 0"], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt2020_limited =3D { + .matrix =3D { + { 5020601039, 0, 7238124312 }, + { 5020601039, -807714626, -2804506279 }, + { 5020601039, 9234915964, 0 }, + }, + .y_offset =3D 16, +}; + +/** + * swap_uv_columns() - Swap u and v column of a given matrix + * + * @matrix: Matrix in which column are swapped + */ +static void swap_uv_columns(struct conversion_matrix *matrix) +{ + swap(matrix->matrix[0][2], matrix->matrix[0][1]); + swap(matrix->matrix[1][2], matrix->matrix[1][1]); + swap(matrix->matrix[2][2], matrix->matrix[2][1]); +} + +/** + * get_conversion_matrix_to_argb_u16() - Retrieve the correct yuv to rgb c= onversion matrix for a + * given encoding and range. + * + * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) + * @encoding: DRM_COLOR_* value for which to obtain a conversion matrix + * @range: DRM_COLOR_*_RANGE value for which to obtain a conversion matrix + * @matrix: Pointer to store the value into + */ +void get_conversion_matrix_to_argb_u16(u32 format, + enum drm_color_encoding encoding, + enum drm_color_range range, + struct conversion_matrix *matrix) +{ + const struct conversion_matrix *matrix_to_copy; + bool limited_range; + + switch (range) { + case DRM_COLOR_YCBCR_LIMITED_RANGE: + limited_range =3D true; + break; + case DRM_COLOR_YCBCR_FULL_RANGE: + limited_range =3D false; + break; + case DRM_COLOR_RANGE_MAX: + limited_range =3D false; + WARN_ONCE(true, "The requested range is not supported."); + break; + } + + switch (encoding) { + case DRM_COLOR_YCBCR_BT601: + matrix_to_copy =3D limited_range ? &yuv_bt601_limited : + &yuv_bt601_full; + break; + case DRM_COLOR_YCBCR_BT709: + matrix_to_copy =3D limited_range ? &yuv_bt709_limited : + &yuv_bt709_full; + break; + case DRM_COLOR_YCBCR_BT2020: + matrix_to_copy =3D limited_range ? &yuv_bt2020_limited : + &yuv_bt2020_full; + break; + case DRM_COLOR_ENCODING_MAX: + matrix_to_copy =3D &no_operation; + WARN_ONCE(true, "The requested encoding is not supported."); + break; + } + + memcpy(matrix, matrix_to_copy, sizeof(*matrix_to_copy)); + + switch (format) { + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YVU444: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV42: + swap_uv_columns(matrix); + break; + default: + break; + } +} +EXPORT_SYMBOL(get_conversion_matrix_to_argb_u16); + /** * get_pixel_write_function() - Retrieve the correct write_pixel function = for a specific format. * The returned pointer is NULL for unsupported pixel formats. The caller = must ensure that the diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index 8d2bef95ff7974a5c852dbaf3bf3f45c3ac32047..d583855cb32027d16b73d2a5b5a= 0644b13191d08 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -9,4 +9,8 @@ pixel_read_line_t get_pixel_read_line_function(u32 format); =20 pixel_write_t get_pixel_write_function(u32 format); =20 +void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding= encoding, + enum drm_color_range range, + struct conversion_matrix *matrix); + #endif /* _VKMS_FORMATS_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index e2fce471870f1899f2ccb66b339ce8c4332cc287..10e032e146f093d0fd99a82c7b5= 8d62a0d987fd7 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -17,7 +17,19 @@ static const u32 vkms_formats[] =3D { DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB16161616, DRM_FORMAT_ARGB16161616, - DRM_FORMAT_RGB565 + DRM_FORMAT_RGB565, + DRM_FORMAT_NV12, + DRM_FORMAT_NV16, + DRM_FORMAT_NV24, + DRM_FORMAT_NV21, + DRM_FORMAT_NV61, + DRM_FORMAT_NV42, + DRM_FORMAT_YUV420, + DRM_FORMAT_YUV422, + DRM_FORMAT_YUV444, + DRM_FORMAT_YVU420, + DRM_FORMAT_YVU422, + DRM_FORMAT_YVU444, }; =20 static struct drm_plane_state * @@ -118,6 +130,8 @@ static void vkms_plane_atomic_update(struct drm_plane *= plane, frame_info->rotation =3D new_state->rotation; =20 vkms_plane_state->pixel_read_line =3D get_pixel_read_line_function(fmt); + get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, new_sta= te->color_range, + &vkms_plane_state->conversion_matrix); } =20 static int vkms_plane_atomic_check(struct drm_plane *plane, --=20 2.47.0