microui  14.5.2
microui
ui_trace.h
1 /*
2  * Copyright 2024-2025 MicroEJ Corp. All rights reserved.
3  * MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */
5 
6 #if !defined UI_TRACE_H
7 #define UI_TRACE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*
14  * @brief Provides elements that allow to trace some external events in the MicroUI trace
15  * group.
16  *
17  * The MicroUI trace group is identified by the global LLUI_TRACE_group.
18  *
19  * Notes:
20  * - The first event index is the event 40 (events [0,39] are reserved for MicroUI).
21  * - The number of events is 100 (fixed by MicroUI): [40,139].
22  * - The events [50,59] are reserved to trace the buffer refresh strategies (BRS) events.
23  *
24  * Example:
25  *
26  * #include "ui_trace.h"
27  * LLTRACE_record_event_u32(LLUI_TRACE_group, MY_EVENT_OFFSET, my_event_data);
28  *
29  * @author MicroEJ Developer Team
30  * @version 14.5.2
31  */
32 
33 // --------------------------------------------------------------------------------
34 // Includes
35 // --------------------------------------------------------------------------------
36 
37 /*
38  * @brief Includes right header file according the Architecture.
39  * - Architecture 7: include "trace.h"
40  * - Architecture 8: include "LLTRACE.h"
41  */
42 #if !defined UI_LLTRACE
43 #if !defined __has_include
44 #error "Set manually UI_LLTRACE: 0 for MicroEJ Architecture 7.x or 1 for MicroEJ Architecture 8.x"
45 #else
46 #define UI_LLTRACE __has_include("LLTRACE.h")
47 #endif // #if !defined __has_include
48 #endif // #if !defined UI_LLTRACE
49 #if UI_LLTRACE == (0u)
50 #include <trace.h>
51 #else
52 #include <LLTRACE.h>
53 #endif
54 
55 // --------------------------------------------------------------------------------
56 // Defines
57 // --------------------------------------------------------------------------------
58 
59 /*
60  * @brief Useful macros to concatenate easily some strings and defines.
61  */
62 #ifndef CONCAT
63 #define CONCAT0(p, s) p ## s
64 #define CONCAT(p, s) CONCAT0(p, s)
65 #endif
66 
67 /*
68  * @brief Macros to count the number of arguments of a trace (maximum 10)
69  */
70 #define UI_TRACE_COUNT_ARGS0(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, Pn, ...) Pn
71 #define UI_TRACE_COUNT_ARGS(...) UI_TRACE_COUNT_ARGS0(-1, ## __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
72 
73 /*
74  * @brief Identifies the traces for the Buffer Refresh Strategies (BRS).
75  */
76 #define UI_TRACE_BRS_FlushSingle 51
77 #define UI_TRACE_BRS_FlushMulti 52
78 #define UI_TRACE_BRS_RestoreRegion 57
79 
80 /*
81  * @brief Identifies the traces related to the clip and drawings
82  */
83 #define UI_TRACE_OutOfClip 67
84 #define UI_TRACE_DrawnRegion 68
85 
86 /*
87  * @brief Identifies the traces used by LLUI_PAINTER_impl.c
88  */
89 #define UI_TRACE_stringWidth 62
90 #define UI_TRACE_writePixel 80
91 #define UI_TRACE_drawLine 81
92 #define UI_TRACE_drawHorizontalLine 82
93 #define UI_TRACE_drawVerticalLine 83
94 #define UI_TRACE_drawRectangle 84
95 #define UI_TRACE_fillRectangle 85
96 #define UI_TRACE_drawRoundedRectangle 86
97 #define UI_TRACE_fillRoundedRectangle 87
98 #define UI_TRACE_drawCircleArc 88
99 #define UI_TRACE_fillCircleArc 89
100 #define UI_TRACE_drawEllipseArc 90
101 #define UI_TRACE_fillEllipseArc 91
102 #define UI_TRACE_drawEllipse 92
103 #define UI_TRACE_fillEllipse 93
104 #define UI_TRACE_drawCircle 94
105 #define UI_TRACE_fillCircle 95
106 #define UI_TRACE_drawImage 96
107 #define UI_TRACE_drawString 97
108 #define UI_TRACE_drawRenderableString 98
109 
110 /*
111  * @brief Identifies the traces used by LLDW_PAINTER_impl.c
112  */
113 #define UI_TRACE_Bilinear 0
114 #define UI_TRACE_NearestNeighbor 1
115 #define UI_TRACE_drawThickFadedPoint 110
116 #define UI_TRACE_drawThickFadedLine 111
117 #define UI_TRACE_drawThickFadedCircle 112
118 #define UI_TRACE_drawThickFadedCircleArc 113
119 #define UI_TRACE_drawThickFadedEllipse 114
120 #define UI_TRACE_drawThickLine 115
121 #define UI_TRACE_drawThickCircle 116
122 #define UI_TRACE_drawThickEllipse 117
123 #define UI_TRACE_drawThickCircleArc 118
124 #define UI_TRACE_drawFlippedImage 130
125 #define UI_TRACE_drawRotatedImage 131
126 #define UI_TRACE_drawScaledImage 132
127 #define UI_TRACE_drawScaledString 133
128 #define UI_TRACE_drawScaledRenderableString 134
129 #define UI_TRACE_drawRotatedCharacter 135
130 
131 /*
132  * @brief Compatibility of Architecture 7 with Architecture 8: use the prototypes
133  * of LLTRACE.h (Architecture 8).
134  */
135 #if UI_LLTRACE == (0u)
136 #define LLTRACE_record_event_void TRACE_record_event_void
137 #define LLTRACE_record_event_u32 TRACE_record_event_u32
138 #define LLTRACE_record_event_u32x2 TRACE_record_event_u32x2
139 #define LLTRACE_record_event_u32x3 TRACE_record_event_u32x3
140 #define LLTRACE_record_event_u32x4 TRACE_record_event_u32x4
141 #define LLTRACE_record_event_u32x5 TRACE_record_event_u32x5
142 #define LLTRACE_record_event_u32x6 TRACE_record_event_u32x6
143 #define LLTRACE_record_event_u32x7 TRACE_record_event_u32x7
144 #define LLTRACE_record_event_u32x8 TRACE_record_event_u32x8
145 #define LLTRACE_record_event_u32x9 TRACE_record_event_u32x9
146 #define LLTRACE_record_event_u32x10 TRACE_record_event_u32x10
147 #define LLTRACE_record_event_end TRACE_record_event_end
148 #define LLTRACE_record_event_end_u32 TRACE_record_event_end_u32
149 #endif // if UI_LLTRACE == (0u)
150 
151 /*
152  * @brief Macros to call the trace functions
153  */
154 #define LLTRACE_record_event_u32x1 LLTRACE_record_event_u32
155 #define UI_TRACE_FUNCTION(...) CONCAT(LLTRACE_record_event_u32x, UI_TRACE_COUNT_ARGS(__VA_ARGS__))
156 #define UI_TRACE_OFFSET(fn) CONCAT(UI_TRACE_, fn)
157 #define UI_TRACE_PARAMS(fn, ...) LLUI_TRACE_group, UI_TRACE_OFFSET(fn), __VA_ARGS__
158 
159 /*
160  * @brief Add the image's address as a trace
161  */
162 #define UI_TRACE_IMAGE(img) (uint32_t)LLUI_DISPLAY_getAddress(img)
163 
164 /*
165  * @brief Add the image's buffer address as a trace
166  */
167 #define UI_TRACE_BUFFER(img) (uint32_t)LLUI_DISPLAY_getBufferAddress(img)
168 
169 /*
170  * @brief Starts a UI trace (at least one parameter is required)
171  */
172 #define UI_TRACE_START(fn, ...) UI_TRACE_FUNCTION(__VA_ARGS__)(UI_TRACE_PARAMS(fn, __VA_ARGS__))
173 
174 /*
175  * @brief Ends a UI trace (one parameter is required)
176  */
177 #define UI_TRACE_END(fn, v) LLTRACE_record_event_end_u32(UI_TRACE_PARAMS(fn, v))
178 
179 /*
180  * @brief Starts a UI trace that denotes a drawing (destination "gc" is required)
181  */
182 #define UI_TRACE_DRAW_START(fn, gc, ...) UI_TRACE_START(fn, UI_TRACE_IMAGE(&gc->image), __VA_ARGS__)
183 
184 /*
185  * @brief Ends a UI trace that denotes a drawing
186  */
187 #define UI_TRACE_DRAW_END UI_TRACE_END
188 
189 // --------------------------------------------------------------------------------
190 // Fields
191 // --------------------------------------------------------------------------------
192 
193 /*
194  * @brief Identifies the MicroUI group to trace an event.
195  */
196 extern int32_t LLUI_TRACE_group;
197 
198 // --------------------------------------------------------------------------------
199 // EOF
200 // --------------------------------------------------------------------------------
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #endif // UI_TRACE_H