From nobody Mon Nov 25 01:49:05 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 4183419F13B; Thu, 31 Oct 2024 18:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397982; cv=none; b=uzlztOxoudAFqCtPzoBC1pofetVUfAWEK8Ss0h8KgbR2OIfbsI/jHVoUrHFpTtiPdW87uTZER8Mqtug7wSaOno3YaIlF6f0/OepEDOflvynFuRGER1tbOdFPtjNfIqBYE6e6cfyQGeUzdDI97ZguATNSD6cff8WOGPWzQYf84Y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397982; c=relaxed/simple; bh=/CnKcRoy2zzniLdXoudcf5h1SXIo8EK5hX/PNiu16Is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j2dgbr2ZlRq4Q9TCztHQSnPQyLbpjezKFiZthc+zvC5sjzROYcfVYg7rmyQ4aPxhjeGShzYmDLNLxK9LYefoDAG6D5VbLXxdVnrZYiFa2gmoiD4ft+qXXm85m9ysBamcqWqsFw4E0ZTcb3vTzB+ZVVDyECpchtnK4b4/aB+ptEQ= 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=NdJqkCjs; arc=none smtp.client-ip=217.70.183.200 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="NdJqkCjs" Received: by mail.gandi.net (Postfix) with ESMTPSA id D0A652000C; Thu, 31 Oct 2024 18:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397971; 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=bqUdHNzvsNs0NM53sXaQxXz2E0n3SnQyNT/O9oJLiLs=; b=NdJqkCjsGcVsB5JdfjHQbd8iJm1RgsbmQkVswRQxMYBrjQrcWfsoAZIW49+NqDR4yvtBFW F83cVgrVfNgPk9OdhdV1JEjqjltKIZxYmYfubCLMOwtAUdVjrTck1nUc5NlcT3gicCETE7 mbjqn4uJbczRuYXblYrYs84AELMl6DJWOWF9/6H2ts0a7LDrMcF9nEP7hkt/KKOMrbN8bn 8hn7P57051eLPDoRZ7iq4S1JmEig5MEX3JRzAnOrtOIg6n2e4p8FFEzmGOPZd4cpbp8Xas GB5oyNdsm2L/BXUM/U+GET+Sihr7dHhSXp+iN01P4XBVjM1wjjX9cfmVeSgCUQ== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:01 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-1-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=18710; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=gMgum11zQDjELLviyW4+/LCQ02/qwVenadipsHpvrMY=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cNNktcgt3RtGsEyPZTIh1y6vtK4WX78ofK6 PAVHuV/xZiJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDQAKCRAgrS7GWxAs 4q0MD/42Z4PlTZ0Gi6985dkZ6pIl/qE2095T6HRSYVqPrqvJPbkYCpcrnBytI6lzaN+Ux+nv7SJ M3RWBkXdfHX4mtl6c9zVoUlc5DrDsY8qBM+ec45biPDZKLqDuu6npR4J7auy+eD9lGc8oKdhzs4 GA+pLrGRlX1CvwJaw8Elo0DZYATMrW3HHQ8lZwwQ8BwnCcYkZZPNNTWYSFPm/yTw2Xy56/oIqJQ 82mNhM7WYhg9ublVEt9LdJ+3Xm7XXKrL0GkZjVoUNi7RBGtE9LiMAZ+AOHxasxhqfvM/AlkSi9N 07vWfJ1/lHv3Nyj+0qSHOs681ljG+ldICYjN8790s5P9B41WBaj3yU8RAdpSh65aD+UJqv9dzYV /v67YpnqXSHg+YK0XpsbRlII3aWq36DlOgJywgzjrPxskbkxrSYDi6W5SOsCaJjm5u5A/qxY1mF BhzP0k2JyV9XLNu3qVlmy7n/b1lNRVgj1FOUJltNgenke4b4uhU4qJNgkrf4L2wKP5NI6xV1z3M g7QianlHLN1P64ToitLJaPT3VR+r+TTniSw7dIf6rBWO/nsQk477IxkWb3s76/ThOIqRrLeHISu fhXtXRQAi6P8Fndrfr+8QQT3oQdtgzGL/BFhvMO2TcEUCS9LpiZRyVsh31rdSilB6g9/x2up6FP ickb26DrnIIGPpw== 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 067a4797f7a0..337ca3f39cd2 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 0f6678420a11..27865261f384 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 8d2bef95ff79..d583855cb320 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 5a028ee96c91..d4e375913122 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.46.2