Skip to content

Commit 5a4856e

Browse files
author
Thomas Zimmermann
committed
drm/tests: Do not use drm_fb_blit() in format-helper tests
Export additional helpers from the format-helper library and open-code drm_fb_blit() in tests. Prepares for the removal of drm_fb_blit(). Only sysfb drivers use drm_fb_blit(). The function will soon be removed from format helpers and be refactored within sysfb helpers. Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: José Expósito <[email protected]> Acked-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7872997 commit 5a4856e

File tree

4 files changed

+131
-102
lines changed

4 files changed

+131
-102
lines changed

drivers/gpu/drm/drm_format_helper.c

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -858,11 +858,33 @@ static void drm_fb_xrgb8888_to_abgr8888_line(void *dbuf, const void *sbuf, unsig
858858
drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_abgr8888);
859859
}
860860

861-
static void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
862-
const struct iosys_map *src,
863-
const struct drm_framebuffer *fb,
864-
const struct drm_rect *clip,
865-
struct drm_format_conv_state *state)
861+
/**
862+
* drm_fb_xrgb8888_to_abgr8888 - Convert XRGB8888 to ABGR8888 clip buffer
863+
* @dst: Array of ABGR8888 destination buffers
864+
* @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
865+
* within @dst; can be NULL if scanlines are stored next to each other.
866+
* @src: Array of XRGB8888 source buffer
867+
* @fb: DRM framebuffer
868+
* @clip: Clip rectangle area to copy
869+
* @state: Transform and conversion state
870+
*
871+
* This function copies parts of a framebuffer to display memory and converts the
872+
* color format during the process. The parameters @dst, @dst_pitch and @src refer
873+
* to arrays. Each array must have at least as many entries as there are planes in
874+
* @fb's format. Each entry stores the value for the format's respective color plane
875+
* at the same index.
876+
*
877+
* This function does not apply clipping on @dst (i.e. the destination is at the
878+
* top-left corner).
879+
*
880+
* Drivers can use this function for ABGR8888 devices that don't support XRGB8888
881+
* natively. It sets an opaque alpha channel as part of the conversion.
882+
*/
883+
void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
884+
const struct iosys_map *src,
885+
const struct drm_framebuffer *fb,
886+
const struct drm_rect *clip,
887+
struct drm_format_conv_state *state)
866888
{
867889
static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
868890
4,
@@ -871,17 +893,40 @@ static void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned in
871893
drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
872894
drm_fb_xrgb8888_to_abgr8888_line);
873895
}
896+
EXPORT_SYMBOL(drm_fb_xrgb8888_to_abgr8888);
874897

875898
static void drm_fb_xrgb8888_to_xbgr8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
876899
{
877900
drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_xbgr8888);
878901
}
879902

880-
static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
881-
const struct iosys_map *src,
882-
const struct drm_framebuffer *fb,
883-
const struct drm_rect *clip,
884-
struct drm_format_conv_state *state)
903+
/**
904+
* drm_fb_xrgb8888_to_xbgr8888 - Convert XRGB8888 to XBGR8888 clip buffer
905+
* @dst: Array of XBGR8888 destination buffers
906+
* @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
907+
* within @dst; can be NULL if scanlines are stored next to each other.
908+
* @src: Array of XRGB8888 source buffer
909+
* @fb: DRM framebuffer
910+
* @clip: Clip rectangle area to copy
911+
* @state: Transform and conversion state
912+
*
913+
* This function copies parts of a framebuffer to display memory and converts the
914+
* color format during the process. The parameters @dst, @dst_pitch and @src refer
915+
* to arrays. Each array must have at least as many entries as there are planes in
916+
* @fb's format. Each entry stores the value for the format's respective color plane
917+
* at the same index.
918+
*
919+
* This function does not apply clipping on @dst (i.e. the destination is at the
920+
* top-left corner).
921+
*
922+
* Drivers can use this function for XBGR8888 devices that don't support XRGB8888
923+
* natively.
924+
*/
925+
void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
926+
const struct iosys_map *src,
927+
const struct drm_framebuffer *fb,
928+
const struct drm_rect *clip,
929+
struct drm_format_conv_state *state)
885930
{
886931
static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
887932
4,
@@ -890,6 +935,49 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
890935
drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
891936
drm_fb_xrgb8888_to_xbgr8888_line);
892937
}
938+
EXPORT_SYMBOL(drm_fb_xrgb8888_to_xbgr8888);
939+
940+
static void drm_fb_xrgb8888_to_bgrx8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
941+
{
942+
drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_bgrx8888);
943+
}
944+
945+
/**
946+
* drm_fb_xrgb8888_to_bgrx8888 - Convert XRGB8888 to BGRX8888 clip buffer
947+
* @dst: Array of BGRX8888 destination buffers
948+
* @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
949+
* within @dst; can be NULL if scanlines are stored next to each other.
950+
* @src: Array of XRGB8888 source buffer
951+
* @fb: DRM framebuffer
952+
* @clip: Clip rectangle area to copy
953+
* @state: Transform and conversion state
954+
*
955+
* This function copies parts of a framebuffer to display memory and converts the
956+
* color format during the process. The parameters @dst, @dst_pitch and @src refer
957+
* to arrays. Each array must have at least as many entries as there are planes in
958+
* @fb's format. Each entry stores the value for the format's respective color plane
959+
* at the same index.
960+
*
961+
* This function does not apply clipping on @dst (i.e. the destination is at the
962+
* top-left corner).
963+
*
964+
* Drivers can use this function for BGRX8888 devices that don't support XRGB8888
965+
* natively.
966+
*/
967+
void drm_fb_xrgb8888_to_bgrx8888(struct iosys_map *dst, const unsigned int *dst_pitch,
968+
const struct iosys_map *src,
969+
const struct drm_framebuffer *fb,
970+
const struct drm_rect *clip,
971+
struct drm_format_conv_state *state)
972+
{
973+
static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
974+
4,
975+
};
976+
977+
drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
978+
drm_fb_xrgb8888_to_bgrx8888_line);
979+
}
980+
EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgrx8888);
893981

894982
static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
895983
{

drivers/gpu/drm/drm_format_internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ static inline u32 drm_pixel_xrgb8888_to_xbgr8888(u32 pix)
111111
((pix & 0x000000ff) << 16);
112112
}
113113

114+
static inline u32 drm_pixel_xrgb8888_to_bgrx8888(u32 pix)
115+
{
116+
return ((pix & 0xff000000) >> 24) | /* also copy filler bits */
117+
((pix & 0x00ff0000) >> 8) |
118+
((pix & 0x0000ff00) << 8) |
119+
((pix & 0x000000ff) << 24);
120+
}
121+
114122
static inline u32 drm_pixel_xrgb8888_to_abgr8888(u32 pix)
115123
{
116124
return GENMASK(31, 24) | /* fill alpha bits */

drivers/gpu/drm/tests/drm_format_helper_test.c

Lines changed: 16 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,9 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
748748
buf = dst.vaddr;
749749
memset(buf, 0, dst_size);
750750

751-
int blit_result = 0;
752-
753-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGB565, &src, &fb, &params->clip,
754-
&fmtcnv_state);
755-
751+
drm_fb_xrgb8888_to_rgb565(&dst, dst_pitch, &src, &fb, &params->clip,
752+
&fmtcnv_state, false);
756753
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
757-
758-
KUNIT_EXPECT_FALSE(test, blit_result);
759754
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
760755
}
761756

@@ -795,14 +790,8 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)
795790
buf = dst.vaddr; /* restore original value of buf */
796791
memset(buf, 0, dst_size);
797792

798-
int blit_result = 0;
799-
800-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB1555, &src, &fb, &params->clip,
801-
&fmtcnv_state);
802-
793+
drm_fb_xrgb8888_to_xrgb1555(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
803794
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
804-
805-
KUNIT_EXPECT_FALSE(test, blit_result);
806795
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
807796
}
808797

@@ -842,14 +831,8 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)
842831
buf = dst.vaddr; /* restore original value of buf */
843832
memset(buf, 0, dst_size);
844833

845-
int blit_result = 0;
846-
847-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB1555, &src, &fb, &params->clip,
848-
&fmtcnv_state);
849-
834+
drm_fb_xrgb8888_to_argb1555(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
850835
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
851-
852-
KUNIT_EXPECT_FALSE(test, blit_result);
853836
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
854837
}
855838

@@ -889,14 +872,8 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)
889872
buf = dst.vaddr; /* restore original value of buf */
890873
memset(buf, 0, dst_size);
891874

892-
int blit_result = 0;
893-
894-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGBA5551, &src, &fb, &params->clip,
895-
&fmtcnv_state);
896-
875+
drm_fb_xrgb8888_to_rgba5551(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
897876
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
898-
899-
KUNIT_EXPECT_FALSE(test, blit_result);
900877
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
901878
}
902879

@@ -939,12 +916,7 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
939916
buf = dst.vaddr; /* restore original value of buf */
940917
memset(buf, 0, dst_size);
941918

942-
int blit_result = 0;
943-
944-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGB888, &src, &fb, &params->clip,
945-
&fmtcnv_state);
946-
947-
KUNIT_EXPECT_FALSE(test, blit_result);
919+
drm_fb_xrgb8888_to_rgb888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
948920
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
949921
}
950922

@@ -985,12 +957,8 @@ static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test)
985957
buf = dst.vaddr; /* restore original value of buf */
986958
memset(buf, 0, dst_size);
987959

988-
int blit_result = 0;
989-
990-
blit_result = drm_fb_blit(&dst, &result->dst_pitch, DRM_FORMAT_BGR888, &src, &fb, &params->clip,
960+
drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, &params->clip,
991961
&fmtcnv_state);
992-
993-
KUNIT_EXPECT_FALSE(test, blit_result);
994962
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
995963
}
996964

@@ -1030,14 +998,8 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
1030998
buf = dst.vaddr; /* restore original value of buf */
1031999
memset(buf, 0, dst_size);
10321000

1033-
int blit_result = 0;
1034-
1035-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB8888, &src, &fb, &params->clip,
1036-
&fmtcnv_state);
1037-
1001+
drm_fb_xrgb8888_to_argb8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
10381002
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1039-
1040-
KUNIT_EXPECT_FALSE(test, blit_result);
10411003
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
10421004
}
10431005

@@ -1077,12 +1039,7 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)
10771039
buf = dst.vaddr; /* restore original value of buf */
10781040
memset(buf, 0, dst_size);
10791041

1080-
int blit_result = 0;
1081-
1082-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB2101010, &src, &fb,
1083-
&params->clip, &fmtcnv_state);
1084-
1085-
KUNIT_EXPECT_FALSE(test, blit_result);
1042+
drm_fb_xrgb8888_to_xrgb2101010(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
10861043
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
10871044
}
10881045

@@ -1122,14 +1079,8 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
11221079
buf = dst.vaddr; /* restore original value of buf */
11231080
memset(buf, 0, dst_size);
11241081

1125-
int blit_result = 0;
1126-
1127-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB2101010, &src, &fb,
1128-
&params->clip, &fmtcnv_state);
1129-
1082+
drm_fb_xrgb8888_to_argb2101010(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
11301083
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1131-
1132-
KUNIT_EXPECT_FALSE(test, blit_result);
11331084
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
11341085
}
11351086

@@ -1202,23 +1153,15 @@ static void drm_test_fb_swab(struct kunit *test)
12021153
buf = dst.vaddr; /* restore original value of buf */
12031154
memset(buf, 0, dst_size);
12041155

1205-
int blit_result;
1206-
1207-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB8888 | DRM_FORMAT_BIG_ENDIAN,
1208-
&src, &fb, &params->clip, &fmtcnv_state);
1156+
drm_fb_swab(&dst, dst_pitch, &src, &fb, &params->clip, false, &fmtcnv_state);
12091157
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1210-
1211-
KUNIT_EXPECT_FALSE(test, blit_result);
12121158
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
12131159

12141160
buf = dst.vaddr;
12151161
memset(buf, 0, dst_size);
12161162

1217-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_BGRX8888, &src, &fb, &params->clip,
1218-
&fmtcnv_state);
1163+
drm_fb_xrgb8888_to_bgrx8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
12191164
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1220-
1221-
KUNIT_EXPECT_FALSE(test, blit_result);
12221165
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
12231166

12241167
buf = dst.vaddr;
@@ -1229,11 +1172,8 @@ static void drm_test_fb_swab(struct kunit *test)
12291172
mock_format.format |= DRM_FORMAT_BIG_ENDIAN;
12301173
fb.format = &mock_format;
12311174

1232-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB8888, &src, &fb, &params->clip,
1233-
&fmtcnv_state);
1175+
drm_fb_swab(&dst, dst_pitch, &src, &fb, &params->clip, false, &fmtcnv_state);
12341176
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1235-
1236-
KUNIT_EXPECT_FALSE(test, blit_result);
12371177
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
12381178
}
12391179

@@ -1266,14 +1206,8 @@ static void drm_test_fb_xrgb8888_to_abgr8888(struct kunit *test)
12661206
const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
12671207
NULL : &result->dst_pitch;
12681208

1269-
int blit_result = 0;
1270-
1271-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ABGR8888, &src, &fb, &params->clip,
1272-
&fmtcnv_state);
1273-
1209+
drm_fb_xrgb8888_to_abgr8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
12741210
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1275-
1276-
KUNIT_EXPECT_FALSE(test, blit_result);
12771211
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
12781212
}
12791213

@@ -1306,14 +1240,8 @@ static void drm_test_fb_xrgb8888_to_xbgr8888(struct kunit *test)
13061240
const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
13071241
NULL : &result->dst_pitch;
13081242

1309-
int blit_result = 0;
1310-
1311-
blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XBGR8888, &src, &fb, &params->clip,
1312-
&fmtcnv_state);
1313-
1243+
drm_fb_xrgb8888_to_xbgr8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
13141244
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
1315-
1316-
KUNIT_EXPECT_FALSE(test, blit_result);
13171245
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
13181246
}
13191247

@@ -1910,12 +1838,8 @@ static void drm_test_fb_memcpy(struct kunit *test)
19101838
memset(buf[i], 0, dst_size[i]);
19111839
}
19121840

1913-
int blit_result;
1914-
1915-
blit_result = drm_fb_blit(dst, dst_pitches, params->format, src, &fb, &params->clip,
1916-
&fmtcnv_state);
1841+
drm_fb_memcpy(dst, dst_pitches, src, &fb, &params->clip);
19171842

1918-
KUNIT_EXPECT_FALSE(test, blit_result);
19191843
for (size_t i = 0; i < fb.format->num_planes; i++) {
19201844
expected[i] = cpubuf_to_le32(test, params->expected[i], TEST_BUF_SIZE);
19211845
KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i],

include/drm/drm_format_helper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pi
102102
void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
103103
const struct iosys_map *src, const struct drm_framebuffer *fb,
104104
const struct drm_rect *clip, struct drm_format_conv_state *state);
105+
void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
106+
const struct iosys_map *src, const struct drm_framebuffer *fb,
107+
const struct drm_rect *clip, struct drm_format_conv_state *state);
108+
void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
109+
const struct iosys_map *src, const struct drm_framebuffer *fb,
110+
const struct drm_rect *clip, struct drm_format_conv_state *state);
111+
void drm_fb_xrgb8888_to_bgrx8888(struct iosys_map *dst, const unsigned int *dst_pitch,
112+
const struct iosys_map *src, const struct drm_framebuffer *fb,
113+
const struct drm_rect *clip, struct drm_format_conv_state *state);
105114
void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
106115
const struct iosys_map *src, const struct drm_framebuffer *fb,
107116
const struct drm_rect *clip,

0 commit comments

Comments
 (0)