utils: Add a dump_framebuffer() method
[renesas/kmsxx.git] / kms++util / inc / kms++util / kms++util.h
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 void dump_framebuffer(IFramebuffer& fb, int fd);
33 } // namespace kms
34
35 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
36
37 #define unlikely(x) __builtin_expect(!!(x), 0)
38
39 /* __STRING(x) is a glibcism (i.e. not standard), which happens to also
40  * be available in uClibc. However, musl does not define it. Do it here.
41  */
42 #ifndef __STRING
43 #define __STRING(x) #x
44 #endif
45
46 #define ASSERT(x)                                                                                                        \
47         if (unlikely(!(x))) {                                                                                            \
48                 fprintf(stderr, "%s:%d: %s: ASSERT(%s) failed\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(x)); \
49                 abort();                                                                                                 \
50         }
51
52 #define FAIL(fmt, ...)                                                                                            \
53         do {                                                                                                      \
54                 fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \
55                 abort();                                                                                          \
56         } while (0)
57
58 #define FAIL_IF(x, fmt, ...)                                                                                      \
59         if (unlikely(x)) {                                                                                        \
60                 fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \
61                 abort();                                                                                          \
62         }
63
64 #define EXIT(fmt, ...)                                    \
65         do {                                              \
66                 fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
67                 exit(-1);                                 \
68         } while (0)
69
70 #define EXIT_IF(x, fmt, ...)                              \
71         if (unlikely(x)) {                                \
72                 fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
73                 exit(-1);                                 \
74         }