1 /****************************************************************************
2 *
3 * The MIT License (MIT)
4 *
5 * Copyright 2020 NXP
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * 'Software'), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject
14 * to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial
18 * portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 *****************************************************************************/
29
30 /** Include Files */
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "vg_lite_text.h"
34 #include "vft_draw.h"
35 #include "vft_debug.h"
36
37 #ifdef ENABLE_DEBUG_TRACE
38
39 /** Macros */
40
41 /** Data structures */
42 typedef enum path_type {
43 PATH_DONE,
44 PATH_CLOSE,
45 MOVE_TO,
46 MOVE_TO_REL,
47 LINE_TO,
48 LINE_TO_REL,
49 QUAD_TO,
50 QUAD_TO_REL,
51 CUBI_TO,
52 CUBI_TO_REL,
53 NUM_PATH_CMD
54 } path_type_t;
55
56 /** Internal or external API prototypes */
57
58 /** Globals */
59 static const int data_count[] =
60 {
61 0,
62 0,
63 2,
64 2,
65 2,
66 2,
67 4,
68 4,
69 6,
70 6
71 };
72
73 static char s_cmd_name[][16] =
74 {
75 {"PATH_DONE" },
76 {"PATH_CLOSE" },
77 {"MOVE_TO" },
78 {"MOVE_TO_REL" },
79 {"LINE_TO" },
80 {"LINE_TO_REL" },
81 {"QUAD_TO" },
82 {"QUAD_TO_REL" },
83 {"CUBI_TO" },
84 {"CUBI_TO_REL" },
85 {"NUM_PATH_CMD"},
86 };
87
88
89 /** Externs if any */
90
91 /** Code section */
vfg_dbg_path_data(path_desc_t * path_data_desc,int offset)92 void vfg_dbg_path_data(path_desc_t* path_data_desc, int offset)
93 {
94 float* draw_cmds;
95
96 draw_cmds = &path_data_desc->draw_cmds[0];
97
98 for (int i = 0; i < path_data_desc->num_draw_cmds; i++) {
99 uint32_t cmd, j;
100
101 cmd = *((uint32_t*)(&draw_cmds[i]));
102 if (cmd < NUM_PATH_CMD) {
103 TRACE_BIN(("BIN: %08x: %s(%d) [",
104 offset + i * 4,
105 s_cmd_name[cmd], cmd));
106 for (j = 0; j < data_count[cmd]; j++) {
107 TRACE_BIN((" %.2f", draw_cmds[i + j + 1]));
108 }
109 i += j;
110 TRACE_BIN(("]\n"));
111 }
112 }
113 }
114
vft_dbg_path(char * prefix,void * draw_cmds_args,int num_draw_cmds)115 void vft_dbg_path(char *prefix, void *draw_cmds_args, int num_draw_cmds)
116 {
117 float* draw_cmds;
118
119 draw_cmds = draw_cmds_args;
120 int offset = 0;
121 for (int i = 0; i < num_draw_cmds; i++) {
122 uint32_t cmd, j;
123
124 cmd = *((uint32_t*)(&draw_cmds[i]));
125 if (cmd < NUM_PATH_CMD) {
126 printf("BIN: %08x: %s(%d) [",
127 offset + i * 4,
128 s_cmd_name[cmd], cmd);
129 for (j = 0; j < data_count[cmd]; j++) {
130 printf(" %.2f", draw_cmds[i + j + 1]);
131 }
132 i += j;
133 printf("]\n");
134 }
135 }
136 }
137
vft_dbg_path_bounds(char * name,float * ary,int num_elements)138 void vft_dbg_path_bounds(char *name, float *ary, int num_elements)
139 {
140 float* array_data;
141
142 array_data = ary;
143 printf("%s [",name);
144 for (int i = 0; i < num_elements; i++) {
145 printf(" %.2f", array_data[i]);
146 }
147 printf("]\n");
148 }
149
vft_dbg_kern_desc(kern_desc_t * kern_desc,int num_kern_entries,int offset)150 void vft_dbg_kern_desc(kern_desc_t* kern_desc, int num_kern_entries, int offset)
151 {
152 for (int i = 0; i < num_kern_entries; i++) {
153 TRACE_BIN(("BIN: %08x: [%d] (u,k)=(%hu, %hu)\n",
154 (int)(offset + i * sizeof(kern_desc_t)),
155 i,
156 kern_desc[i].unicode,
157 kern_desc[i].kern));
158 }
159 }
vft_dbg_glyph_desc(glyph_desc_t * g,int offset)160 void vft_dbg_glyph_desc(glyph_desc_t* g, int offset)
161 {
162 glyph_desc_t _desc = *g; /* Temporary copy descriptor*/
163
164 TRACE_BIN_FIELD_UINT16(unicode);
165 TRACE_BIN_FIELD_UINT16(horiz_adv_x);
166 TRACE_BIN_FIELD_UINT32(kern_num_entries);
167 TRACE_BIN_FIELD_UINT32(kern_table_offset);
168 TRACE_BIN_FIELD_FLOAT(path.bounds[0]);
169 TRACE_BIN_FIELD_FLOAT(path.bounds[1]);
170 TRACE_BIN_FIELD_FLOAT(path.bounds[2]);
171 TRACE_BIN_FIELD_FLOAT(path.bounds[3]);
172 TRACE_BIN_FIELD_UINT32(path.num_draw_cmds);
173 TRACE_BIN_FIELD_UINT32(path.draw_cmds_offset);
174
175 }
176
177 /* TRACE values for debugging purpose */
vft_dbg_font_face_desc(font_face_desc_t * font_face,int offset)178 void vft_dbg_font_face_desc(font_face_desc_t* font_face, int offset)
179 {
180 font_face_desc_t _desc = *font_face; /* Temporary copy descriptor*/
181
182 TRACE_INFO(("font-face-block\n"));
183
184 TRACE_BIN_FIELD_STR(font_family_name); offset += sizeof(_desc.font_family_name);
185 TRACE_BIN_FIELD_UINT16(units_per_em);
186 TRACE_BIN_FIELD_UINT16(ascent);
187 TRACE_BIN_FIELD_UINT16(descent);
188 TRACE_BIN_FIELD_UINT16(vg_font);
189 TRACE_BIN_FIELD_UINT32(num_glyphs);
190 }
191
vft_dbg_matrix(char * name,vg_lite_matrix_t * mat)192 void vft_dbg_matrix(char *name, vg_lite_matrix_t *mat)
193 {
194 printf("%s\n",name);
195 printf(" %0.3f %0.3f %0.3f\n",
196 mat->m[0][0],mat->m[0][1],mat->m[0][2]);
197 printf(" %0.3f %0.3f %0.3f\n",
198 mat->m[1][0],mat->m[1][1],mat->m[1][2]);
199 printf(" %0.3f %0.3f %0.3f\n",
200 mat->m[2][0],mat->m[1][1],mat->m[2][2]);
201 }
202
vft_dbg_path_table(font_face_desc_t * font_face,int offset)203 void vft_dbg_path_table(font_face_desc_t* font_face, int offset)
204 {
205 TRACE_INFO(("path-block\n"));
206 for (uint32_t i = 0; i < font_face->num_glyphs; i++) {
207 glyph_desc_t* g = &font_face->glyphs[i];
208 TRACE_BIN(("Glyph - path: '%c' unicode = %d\n", g->unicode, g->unicode));
209 offset = g->path.draw_cmds_offset;
210 vfg_dbg_path_data(&g->path, offset);
211 }
212 }
213
vft_dbg_kern_table(font_face_desc_t * font_face,int offset)214 void vft_dbg_kern_table(font_face_desc_t* font_face, int offset)
215 {
216 TRACE_INFO(("kern-block\n"));
217 for (uint32_t i = 0; i < font_face->num_glyphs; i++) {
218 glyph_desc_t* g = &font_face->glyphs[i];
219
220 TRACE_INFO(("Kern: '%c' unicode=%hu\n", g->unicode, g->unicode));
221
222 vft_dbg_kern_desc(&g->kern_table[0],
223 g->kern_num_entries,
224 offset);
225 offset += (g->kern_num_entries * sizeof(kern_desc_t));
226 }
227 }
228
vft_dbg_glyph_table(font_face_desc_t * font_face,int offset)229 void vft_dbg_glyph_table(font_face_desc_t* font_face, int offset)
230 {
231 TRACE_INFO(("glyph-block\n"));
232 for (uint32_t i = 0; i < font_face->num_glyphs; i++) {
233 glyph_desc_t* g = &font_face->glyphs[i];
234 TRACE_INFO(("Glyph: '%c'\n", g->unicode));
235 vft_dbg_glyph_desc(g, offset);
236 offset += sizeof(glyph_desc_t);
237 }
238 }
239
240 int g_offset = 0;
241
dbg_float_ary(char * name,float * ary,int count,int * disk_offset)242 void dbg_float_ary(char *name, float *ary, int count, int *disk_offset)
243 {
244 int i;
245 int offset = *disk_offset;
246 for (i=0; i<count; i++) {
247 DBG_TRACE(("DBG: %s[%d]=%f offset=%d\n", \
248 name, \
249 i, \
250 ary[i], offset));
251 offset+= 4;
252 }
253 *disk_offset = offset;
254 }
255
dbg_int_ary(char * name,uint32_t * ary,int count,int * disk_offset)256 void dbg_int_ary(char *name, uint32_t *ary, int count, int *disk_offset)
257 {
258 int i;
259 int offset = *disk_offset;
260 for (i=0; i<count; i++) {
261 DBG_TRACE(("DBG: %s[%d]=%d offset=%d\n", \
262 name, \
263 i, \
264 ary[i], offset));
265 offset+= 4;
266 }
267 *disk_offset = offset;
268 }
269
dbg_int_param(char * name,uint32_t value,int * disk_offset)270 void dbg_int_param(char *name, uint32_t value, int *disk_offset)
271 {
272 int offset = *disk_offset;
273 DBG_TRACE(("DBG: %s=%d offset=%d\n", \
274 name, \
275 value, offset));
276 offset+= 4;
277 *disk_offset = offset;
278 }
279
dbg_float_ary_no_offset_update(char * name,float * ary,int count,int disk_offset)280 void dbg_float_ary_no_offset_update(char *name, float *ary,
281 int count, int disk_offset)
282 {
283 int i;
284 int offset = disk_offset;
285 for (i=0; i<count; i++) {
286 DBG_TRACE(("DBG: %s[%d]=%f offset=%d\n", \
287 name, \
288 i, \
289 ary[i], offset));
290 offset+= 4;
291 }
292 }
293
dbg_int_ary_no_offset_update(char * name,uint32_t * ary,int count,int disk_offset)294 void dbg_int_ary_no_offset_update(char *name, uint32_t *ary,
295 int count, int disk_offset)
296 {
297 int i;
298 int offset = disk_offset;
299 for (i=0; i<count; i++) {
300 DBG_TRACE(("DBG: %s[%d]=%d offset=%d\n", \
301 name, \
302 i, \
303 ary[i], offset));
304 offset+= 4;
305 }
306 }
307
dbg_int_param_no_offset_update(char * name,uint32_t value,int disk_offset)308 void dbg_int_param_no_offset_update(char *name, uint32_t value, int disk_offset)
309 {
310 int offset = disk_offset;
311 DBG_TRACE(("DBG: %s=%d offset=%d\n", \
312 name, \
313 value, offset));
314 offset+= 4;
315 }
316
317 #endif
318