17 #include <freerdp/config.h>
18 #include <winpr/crypto.h>
20 #include <winpr/sysinfo.h>
21 #include "prim_test.h"
23 #define COPY_TESTSIZE (256 * 2 + 16 * 2 + 15 + 15)
26 static BOOL test_copy8u_func(
void)
29 BYTE ALIGN(data[COPY_TESTSIZE + 15]) = { 0 };
30 winpr_RAND(data,
sizeof(data));
32 for (
int soff = 0; soff < 16; ++soff)
34 for (
int doff = 0; doff < 16; ++doff)
36 for (
int length = 1; length <= COPY_TESTSIZE - doff; ++length)
38 BYTE ALIGN(dest[COPY_TESTSIZE + 15]) = { 0 };
40 if (prims->copy_8u(data + soff, dest + doff, length) != PRIMITIVES_SUCCESS)
43 for (
int i = 0; i < length; ++i)
45 if (dest[i + doff] != data[i + soff])
47 printf(
"COPY8U FAIL: off=%d len=%d, dest[%d]=0x%02" PRIx8
""
48 "data[%d]=0x%02" PRIx8
"\n",
49 doff, length, i + doff, dest[i + doff], i + soff, data[i + soff]);
61 static BOOL test_copy8u_speed(
void)
63 BYTE ALIGN(src[MAX_TEST_SIZE + 4]);
64 BYTE ALIGN(dst[MAX_TEST_SIZE + 4]);
66 if (!speed_test(
"copy_8u",
"aligned", g_Iterations, (speed_test_fkt)generic->copy_8u,
67 (speed_test_fkt)optimized->copy_8u, src, dst, MAX_TEST_SIZE))
70 if (!speed_test(
"copy_8u",
"unaligned", g_Iterations, (speed_test_fkt)generic->copy_8u,
71 (speed_test_fkt)optimized->copy_8u, src + 1, dst + 1, MAX_TEST_SIZE))
77 static BYTE* rand_alloc(
size_t w,
size_t h,
size_t bpp,
size_t pad, BYTE** copy)
79 const size_t s = w * bpp + pad;
80 BYTE* ptr = calloc(s, h);
84 winpr_RAND(ptr, s * h);
88 BYTE* ptr2 = calloc(s, h);
94 memcpy(ptr2, ptr, s * h);
100 static size_t runcount = 0;
102 static BOOL test_copy_no_overlap_off(BOOL verbose, UINT32 srcFormat, UINT32 dstFormat, UINT32 flags,
103 UINT32 pad, UINT32 w, UINT32 h, UINT32 dxoff, UINT32 dyoff,
104 UINT32 sxoff, UINT32 syoff)
114 WINPR_ASSERT(dxoff < w);
115 WINPR_ASSERT(sxoff < w);
116 WINPR_ASSERT(dyoff < h);
117 WINPR_ASSERT(syoff < h);
119 const UINT32 sbpp = FreeRDPGetBytesPerPixel(srcFormat);
120 const UINT32 dbpp = FreeRDPGetBytesPerPixel(dstFormat);
124 (void)fprintf(stderr,
125 "run src: %s, dst: %s [flags 0x%08" PRIx32
"] %" PRIu32
"x%" PRIu32
126 ", soff=%" PRIu32
"x%" PRIu32
", doff=%" PRIu32
"x%" PRIu32
", pad=%" PRIu32
128 FreeRDPGetColorFormatName(srcFormat), FreeRDPGetColorFormatName(dstFormat),
129 flags, w, h, sxoff, syoff, dxoff, dyoff, pad);
132 const UINT32 sstride = (w + sxoff) * sbpp + pad;
133 const UINT32 dstride = (w + dxoff) * dbpp + pad;
136 BYTE* dst1 = rand_alloc(w + dxoff, h + dyoff, dbpp, pad, &dst2);
137 BYTE* src1 = rand_alloc(w + sxoff, h + syoff, sbpp, pad, &src2);
138 if (!dst1 || !dst2 || !src1 || !src2)
141 if (gen->
copy_no_overlap(dst1, dstFormat, dstride, dxoff, dyoff, w, h, src1, srcFormat, sstride,
142 sxoff, syoff, NULL, flags) != PRIMITIVES_SUCCESS)
145 if (memcmp(src1, src2, 1ULL * sstride * h) != 0)
148 if (prims->
copy_no_overlap(dst2, dstFormat, dstride, dxoff, dyoff, w, h, src1, srcFormat,
149 sstride, sxoff, syoff, NULL, flags) != PRIMITIVES_SUCCESS)
152 if (memcmp(src1, src2, 1ULL * sstride * h) != 0)
155 if (memcmp(dst1, dst2, 1ULL * dstride * h) != 0)
158 if (flags == FREERDP_KEEP_DST_ALPHA)
160 for (
size_t y = 0; y < h; y++)
162 const BYTE* d1 = &dst1[(y + dyoff) * dstride];
163 const BYTE* d2 = &dst2[(y + dyoff) * dstride];
164 for (
size_t x = 0; x < w; x++)
166 const UINT32 c1 = FreeRDPReadColor(&d1[(x + dxoff) * dbpp], dstFormat);
167 const UINT32 c2 = FreeRDPReadColor(&d2[(x + dxoff) * dbpp], dstFormat);
170 FreeRDPSplitColor(c1, dstFormat, NULL, NULL, NULL, &a1, NULL);
171 FreeRDPSplitColor(c2, dstFormat, NULL, NULL, NULL, &a2, NULL);
182 (void)fprintf(stderr,
"failed to compare copy_no_overlap(%s -> %s [0x%08" PRIx32
"])\n",
183 FreeRDPGetColorFormatName(srcFormat), FreeRDPGetColorFormatName(dstFormat),
193 static BOOL test_copy_no_overlap(BOOL verbose, UINT32 srcFormat, UINT32 dstFormat, UINT32 flags,
194 UINT32 width, UINT32 height)
199 for (UINT32 dxoff = 0; dxoff < mw; dxoff++)
201 for (UINT32 dyoff = 0; dyoff <= mh; dyoff++)
203 for (UINT32 sxoff = 0; sxoff <= mw; sxoff++)
205 for (UINT32 syoff = 0; syoff <= mh; syoff++)
211 for (UINT32 pad = 8; pad <= 12; pad++)
213 if (!test_copy_no_overlap_off(verbose, srcFormat, dstFormat, flags, pad,
214 width, height, dxoff, dyoff, sxoff, syoff))
225 int TestPrimitivesCopy(
int argc,
char* argv[])
230 const BOOL verbose = argc > 1;
232 prim_test_setup(FALSE);
234 if (!test_copy8u_func())
237 if (g_TestPrimitivesPerformance)
239 if (!test_copy8u_speed())
243 const UINT32 flags[] = {
245 FREERDP_KEEP_DST_ALPHA,
246 FREERDP_FLIP_HORIZONTAL,
247 FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_HORIZONTAL,
249 FREERDP_FLIP_VERTICAL,
250 FREERDP_FLIP_VERTICAL | FREERDP_FLIP_HORIZONTAL,
251 FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_VERTICAL,
252 FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_VERTICAL | FREERDP_FLIP_HORIZONTAL
255 const UINT32 formats[] = {
260 , PIXEL_FORMAT_RGB24,
261 PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XBGR32,
262 PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32
267 for (
size_t z = 0; z < ARRAYSIZE(flags); z++)
269 const UINT32 flag = flags[z];
270 for (
size_t x = 0; x < ARRAYSIZE(formats); x++)
272 const UINT32 sformat = formats[x];
273 for (
size_t y = 0; y < ARRAYSIZE(formats); y++)
275 const UINT32 dformat = formats[y];
277 if (!test_copy_no_overlap(verbose, sformat, dformat, flag, 21, 17))
284 (void)fprintf(stderr,
"runcount=%" PRIuz
"\n", runcount);
__copy_no_overlap_t copy_no_overlap