xref: /aosp_15_r20/external/libkmsxx/kms++util/inc/kms++util/kms++util.h (revision f0687c8a10b3e371dbe09214db6664e37c283cca)
1 #pragma once
2 
3 #include <kms++/kms++.h>
4 
5 #include <kms++util/color.h>
6 #include <kms++util/strhelpers.h>
7 #include <kms++util/cpuframebuffer.h>
8 #include <kms++util/extcpuframebuffer.h>
9 #include <kms++util/stopwatch.h>
10 #include <kms++util/opts.h>
11 #include <kms++util/resourcemanager.h>
12 
13 #include <cstdio>
14 #include <cstdlib>
15 
16 namespace kms
17 {
18 class IFramebuffer;
19 
20 void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color);
21 void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv);
22 void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2);
23 void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
24 			    YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4);
25 void draw_rect(IFramebuffer& fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color);
26 void draw_circle(IFramebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color);
27 void draw_text(IFramebuffer& buf, uint32_t x, uint32_t y, const std::string& str, RGB color);
28 
29 void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width);
30 
31 void draw_test_pattern(IFramebuffer& fb, YUVType yuvt = YUVType::BT601_Lim);
32 } // namespace kms
33 
34 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
35 
36 #define unlikely(x) __builtin_expect(!!(x), 0)
37 
38 /* __STRING(x) is a glibcism (i.e. not standard), which happens to also
39  * be available in uClibc. However, musl does not define it. Do it here.
40  */
41 #ifndef __STRING
42 #define __STRING(x) #x
43 #endif
44 
45 #define ASSERT(x)                                                                                                        \
46 	if (unlikely(!(x))) {                                                                                            \
47 		fprintf(stderr, "%s:%d: %s: ASSERT(%s) failed\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(x)); \
48 		abort();                                                                                                 \
49 	}
50 
51 #define FAIL(fmt, ...)                                                                                            \
52 	do {                                                                                                      \
53 		fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \
54 		abort();                                                                                          \
55 	} while (0)
56 
57 #define FAIL_IF(x, fmt, ...)                                                                                      \
58 	if (unlikely(x)) {                                                                                        \
59 		fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \
60 		abort();                                                                                          \
61 	}
62 
63 #define EXIT(fmt, ...)                                    \
64 	do {                                              \
65 		fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
66 		exit(-1);                                 \
67 	} while (0)
68 
69 #define EXIT_IF(x, fmt, ...)                              \
70 	if (unlikely(x)) {                                \
71 		fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
72 		exit(-1);                                 \
73 	}
74