@@ -60,6 +60,11 @@ struct convert_to_rgb888_result {
6060 const u8 expected [TEST_BUF_SIZE ];
6161};
6262
63+ struct convert_to_bgr888_result {
64+ unsigned int dst_pitch ;
65+ const u8 expected [TEST_BUF_SIZE ];
66+ };
67+
6368struct convert_to_argb8888_result {
6469 unsigned int dst_pitch ;
6570 const u32 expected [TEST_BUF_SIZE ];
@@ -107,6 +112,7 @@ struct convert_xrgb8888_case {
107112 struct convert_to_argb1555_result argb1555_result ;
108113 struct convert_to_rgba5551_result rgba5551_result ;
109114 struct convert_to_rgb888_result rgb888_result ;
115+ struct convert_to_bgr888_result bgr888_result ;
110116 struct convert_to_argb8888_result argb8888_result ;
111117 struct convert_to_xrgb2101010_result xrgb2101010_result ;
112118 struct convert_to_argb2101010_result argb2101010_result ;
@@ -151,6 +157,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
151157 .dst_pitch = TEST_USE_DEFAULT_PITCH ,
152158 .expected = { 0x00 , 0x00 , 0xFF },
153159 },
160+ .bgr888_result = {
161+ .dst_pitch = TEST_USE_DEFAULT_PITCH ,
162+ .expected = { 0xFF , 0x00 , 0x00 },
163+ },
154164 .argb8888_result = {
155165 .dst_pitch = TEST_USE_DEFAULT_PITCH ,
156166 .expected = { 0xFFFF0000 },
@@ -217,6 +227,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
217227 .dst_pitch = TEST_USE_DEFAULT_PITCH ,
218228 .expected = { 0x00 , 0x00 , 0xFF },
219229 },
230+ .bgr888_result = {
231+ .dst_pitch = TEST_USE_DEFAULT_PITCH ,
232+ .expected = { 0xFF , 0x00 , 0x00 },
233+ },
220234 .argb8888_result = {
221235 .dst_pitch = TEST_USE_DEFAULT_PITCH ,
222236 .expected = { 0xFFFF0000 },
@@ -330,6 +344,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
330344 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0x00 ,
331345 },
332346 },
347+ .bgr888_result = {
348+ .dst_pitch = TEST_USE_DEFAULT_PITCH ,
349+ .expected = {
350+ 0xFF , 0xFF , 0xFF , 0x00 , 0x00 , 0x00 ,
351+ 0xFF , 0x00 , 0x00 , 0x00 , 0xFF , 0x00 ,
352+ 0x00 , 0x00 , 0xFF , 0xFF , 0x00 , 0xFF ,
353+ 0xFF , 0xFF , 0x00 , 0x00 , 0xFF , 0xFF ,
354+ },
355+ },
333356 .argb8888_result = {
334357 .dst_pitch = TEST_USE_DEFAULT_PITCH ,
335358 .expected = {
@@ -468,6 +491,17 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
468491 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
469492 },
470493 },
494+ .bgr888_result = {
495+ .dst_pitch = 15 ,
496+ .expected = {
497+ 0x0E , 0x44 , 0x9C , 0x11 , 0x4D , 0x05 , 0xA8 , 0xF3 , 0x03 ,
498+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
499+ 0x6C , 0xF0 , 0x73 , 0x0E , 0x44 , 0x9C , 0x11 , 0x4D , 0x05 ,
500+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
501+ 0xA8 , 0x03 , 0x03 , 0x6C , 0xF0 , 0x73 , 0x0E , 0x44 , 0x9C ,
502+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
503+ },
504+ },
471505 .argb8888_result = {
472506 .dst_pitch = 20 ,
473507 .expected = {
@@ -914,6 +948,52 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
914948 KUNIT_EXPECT_MEMEQ (test , buf , result -> expected , dst_size );
915949}
916950
951+ static void drm_test_fb_xrgb8888_to_bgr888 (struct kunit * test )
952+ {
953+ const struct convert_xrgb8888_case * params = test -> param_value ;
954+ const struct convert_to_bgr888_result * result = & params -> bgr888_result ;
955+ size_t dst_size ;
956+ u8 * buf = NULL ;
957+ __le32 * xrgb8888 = NULL ;
958+ struct iosys_map dst , src ;
959+
960+ struct drm_framebuffer fb = {
961+ .format = drm_format_info (DRM_FORMAT_XRGB8888 ),
962+ .pitches = { params -> pitch , 0 , 0 },
963+ };
964+
965+ dst_size = conversion_buf_size (DRM_FORMAT_BGR888 , result -> dst_pitch ,
966+ & params -> clip , 0 );
967+ KUNIT_ASSERT_GT (test , dst_size , 0 );
968+
969+ buf = kunit_kzalloc (test , dst_size , GFP_KERNEL );
970+ KUNIT_ASSERT_NOT_ERR_OR_NULL (test , buf );
971+ iosys_map_set_vaddr (& dst , buf );
972+
973+ xrgb8888 = cpubuf_to_le32 (test , params -> xrgb8888 , TEST_BUF_SIZE );
974+ KUNIT_ASSERT_NOT_ERR_OR_NULL (test , xrgb8888 );
975+ iosys_map_set_vaddr (& src , xrgb8888 );
976+
977+ /*
978+ * BGR888 expected results are already in little-endian
979+ * order, so there's no need to convert the test output.
980+ */
981+ drm_fb_xrgb8888_to_bgr888 (& dst , & result -> dst_pitch , & src , & fb , & params -> clip ,
982+ & fmtcnv_state );
983+ KUNIT_EXPECT_MEMEQ (test , buf , result -> expected , dst_size );
984+
985+ buf = dst .vaddr ; /* restore original value of buf */
986+ memset (buf , 0 , dst_size );
987+
988+ int blit_result = 0 ;
989+
990+ blit_result = drm_fb_blit (& dst , & result -> dst_pitch , DRM_FORMAT_BGR888 , & src , & fb , & params -> clip ,
991+ & fmtcnv_state );
992+
993+ KUNIT_EXPECT_FALSE (test , blit_result );
994+ KUNIT_EXPECT_MEMEQ (test , buf , result -> expected , dst_size );
995+ }
996+
917997static void drm_test_fb_xrgb8888_to_argb8888 (struct kunit * test )
918998{
919999 const struct convert_xrgb8888_case * params = test -> param_value ;
@@ -1851,6 +1931,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {
18511931 KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb1555 , convert_xrgb8888_gen_params ),
18521932 KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_rgba5551 , convert_xrgb8888_gen_params ),
18531933 KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_rgb888 , convert_xrgb8888_gen_params ),
1934+ KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_bgr888 , convert_xrgb8888_gen_params ),
18541935 KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb8888 , convert_xrgb8888_gen_params ),
18551936 KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_xrgb2101010 , convert_xrgb8888_gen_params ),
18561937 KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb2101010 , convert_xrgb8888_gen_params ),
0 commit comments