vft_debug.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. /** Include Files */
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include "vg_lite_text.h"
  33. #include "vft_draw.h"
  34. #include "vft_debug.h"
  35. #ifdef ENABLE_DEBUG_TRACE
  36. /** Macros */
  37. /** Data structures */
  38. typedef enum path_type {
  39. PATH_DONE,
  40. PATH_CLOSE,
  41. MOVE_TO,
  42. MOVE_TO_REL,
  43. LINE_TO,
  44. LINE_TO_REL,
  45. QUAD_TO,
  46. QUAD_TO_REL,
  47. CUBI_TO,
  48. CUBI_TO_REL,
  49. NUM_PATH_CMD
  50. } path_type_t;
  51. /** Internal or external API prototypes */
  52. /** Globals */
  53. static const int data_count[] =
  54. {
  55. 0,
  56. 0,
  57. 2,
  58. 2,
  59. 2,
  60. 2,
  61. 4,
  62. 4,
  63. 6,
  64. 6
  65. };
  66. static char s_cmd_name[][16] =
  67. {
  68. {"PATH_DONE" },
  69. {"PATH_CLOSE" },
  70. {"MOVE_TO" },
  71. {"MOVE_TO_REL" },
  72. {"LINE_TO" },
  73. {"LINE_TO_REL" },
  74. {"QUAD_TO" },
  75. {"QUAD_TO_REL" },
  76. {"CUBI_TO" },
  77. {"CUBI_TO_REL" },
  78. {"NUM_PATH_CMD"},
  79. };
  80. /** Externs if any */
  81. /** Code section */
  82. void vfg_dbg_path_data(path_desc_t* path_data_desc, int offset)
  83. {
  84. float* draw_cmds;
  85. draw_cmds = &path_data_desc->draw_cmds[0];
  86. for (int i = 0; i < path_data_desc->num_draw_cmds; i++) {
  87. uint32_t cmd, j;
  88. cmd = *((uint32_t*)(&draw_cmds[i]));
  89. if (cmd < NUM_PATH_CMD) {
  90. TRACE_BIN(("BIN: %08x: %s(%d) [",
  91. offset + i * 4,
  92. s_cmd_name[cmd], cmd));
  93. for (j = 0; j < data_count[cmd]; j++) {
  94. TRACE_BIN((" %.2f", draw_cmds[i + j + 1]));
  95. }
  96. i += j;
  97. TRACE_BIN(("]\n"));
  98. }
  99. }
  100. }
  101. void vft_dbg_path(char *prefix, void *draw_cmds_args, int num_draw_cmds)
  102. {
  103. float* draw_cmds;
  104. draw_cmds = draw_cmds_args;
  105. int offset = 0;
  106. for (int i = 0; i < num_draw_cmds; i++) {
  107. uint32_t cmd, j;
  108. cmd = *((uint32_t*)(&draw_cmds[i]));
  109. if (cmd < NUM_PATH_CMD) {
  110. printf("BIN: %08x: %s(%d) [",
  111. offset + i * 4,
  112. s_cmd_name[cmd], cmd);
  113. for (j = 0; j < data_count[cmd]; j++) {
  114. printf(" %.2f", draw_cmds[i + j + 1]);
  115. }
  116. i += j;
  117. printf("]\n");
  118. }
  119. }
  120. }
  121. void vft_dbg_path_bounds(char *name, float *ary, int num_elements)
  122. {
  123. float* array_data;
  124. array_data = ary;
  125. printf("%s [",name);
  126. for (int i = 0; i < num_elements; i++) {
  127. printf(" %.2f", array_data[i]);
  128. }
  129. printf("]\n");
  130. }
  131. void vft_dbg_kern_desc(kern_desc_t* kern_desc, int num_kern_entries, int offset)
  132. {
  133. for (int i = 0; i < num_kern_entries; i++) {
  134. TRACE_BIN(("BIN: %08x: [%d] (u,k)=(%hu, %hu)\n",
  135. (int)(offset + i * sizeof(kern_desc_t)),
  136. i,
  137. kern_desc[i].unicode,
  138. kern_desc[i].kern));
  139. }
  140. }
  141. void vft_dbg_glyph_desc(glyph_desc_t* g, int offset)
  142. {
  143. glyph_desc_t _desc = *g; /* Temporary copy descriptor*/
  144. TRACE_BIN_FIELD_UINT16(unicode);
  145. TRACE_BIN_FIELD_UINT16(horiz_adv_x);
  146. TRACE_BIN_FIELD_UINT32(kern_num_entries);
  147. TRACE_BIN_FIELD_UINT32(kern_table_offset);
  148. TRACE_BIN_FIELD_FLOAT(path.bounds[0]);
  149. TRACE_BIN_FIELD_FLOAT(path.bounds[1]);
  150. TRACE_BIN_FIELD_FLOAT(path.bounds[2]);
  151. TRACE_BIN_FIELD_FLOAT(path.bounds[3]);
  152. TRACE_BIN_FIELD_UINT32(path.num_draw_cmds);
  153. TRACE_BIN_FIELD_UINT32(path.draw_cmds_offset);
  154. }
  155. /* TRACE values for debugging purpose */
  156. void vft_dbg_font_face_desc(font_face_desc_t* font_face, int offset)
  157. {
  158. font_face_desc_t _desc = *font_face; /* Temporary copy descriptor*/
  159. TRACE_INFO(("font-face-block\n"));
  160. TRACE_BIN_FIELD_STR(font_family_name); offset += sizeof(_desc.font_family_name);
  161. TRACE_BIN_FIELD_UINT16(units_per_em);
  162. TRACE_BIN_FIELD_UINT16(ascent);
  163. TRACE_BIN_FIELD_UINT16(descent);
  164. TRACE_BIN_FIELD_UINT16(vg_font);
  165. TRACE_BIN_FIELD_UINT32(num_glyphs);
  166. }
  167. void vft_dbg_matrix(char *name, vg_lite_matrix_t *mat)
  168. {
  169. printf("%s\n",name);
  170. printf(" %0.3f %0.3f %0.3f\n",
  171. mat->m[0][0],mat->m[0][1],mat->m[0][2]);
  172. printf(" %0.3f %0.3f %0.3f\n",
  173. mat->m[1][0],mat->m[1][1],mat->m[1][2]);
  174. printf(" %0.3f %0.3f %0.3f\n",
  175. mat->m[2][0],mat->m[1][1],mat->m[2][2]);
  176. }
  177. void vft_dbg_path_table(font_face_desc_t* font_face, int offset)
  178. {
  179. TRACE_INFO(("path-block\n"));
  180. for (uint32_t i = 0; i < font_face->num_glyphs; i++) {
  181. glyph_desc_t* g = &font_face->glyphs[i];
  182. TRACE_BIN(("Glyph - path: '%c' unicode = %d\n", g->unicode, g->unicode));
  183. offset = g->path.draw_cmds_offset;
  184. vfg_dbg_path_data(&g->path, offset);
  185. }
  186. }
  187. void vft_dbg_kern_table(font_face_desc_t* font_face, int offset)
  188. {
  189. TRACE_INFO(("kern-block\n"));
  190. for (uint32_t i = 0; i < font_face->num_glyphs; i++) {
  191. glyph_desc_t* g = &font_face->glyphs[i];
  192. TRACE_INFO(("Kern: '%c' unicode=%hu\n", g->unicode, g->unicode));
  193. vft_dbg_kern_desc(&g->kern_table[0],
  194. g->kern_num_entries,
  195. offset);
  196. offset += (g->kern_num_entries * sizeof(kern_desc_t));
  197. }
  198. }
  199. void vft_dbg_glyph_table(font_face_desc_t* font_face, int offset)
  200. {
  201. TRACE_INFO(("glyph-block\n"));
  202. for (uint32_t i = 0; i < font_face->num_glyphs; i++) {
  203. glyph_desc_t* g = &font_face->glyphs[i];
  204. TRACE_INFO(("Glyph: '%c'\n", g->unicode));
  205. vft_dbg_glyph_desc(g, offset);
  206. offset += sizeof(glyph_desc_t);
  207. }
  208. }
  209. int g_offset = 0;
  210. void dbg_float_ary(char *name, float *ary, int count, int *disk_offset)
  211. {
  212. int i;
  213. int offset = *disk_offset;
  214. for (i=0; i<count; i++) {
  215. DBG_TRACE(("DBG: %s[%d]=%f offset=%d\n", \
  216. name, \
  217. i, \
  218. ary[i], offset));
  219. offset+= 4;
  220. }
  221. *disk_offset = offset;
  222. }
  223. void dbg_int_ary(char *name, uint32_t *ary, int count, int *disk_offset)
  224. {
  225. int i;
  226. int offset = *disk_offset;
  227. for (i=0; i<count; i++) {
  228. DBG_TRACE(("DBG: %s[%d]=%d offset=%d\n", \
  229. name, \
  230. i, \
  231. ary[i], offset));
  232. offset+= 4;
  233. }
  234. *disk_offset = offset;
  235. }
  236. void dbg_int_param(char *name, uint32_t value, int *disk_offset)
  237. {
  238. int offset = *disk_offset;
  239. DBG_TRACE(("DBG: %s=%d offset=%d\n", \
  240. name, \
  241. value, offset));
  242. offset+= 4;
  243. *disk_offset = offset;
  244. }
  245. void dbg_float_ary_no_offset_update(char *name, float *ary,
  246. int count, int disk_offset)
  247. {
  248. int i;
  249. int offset = disk_offset;
  250. for (i=0; i<count; i++) {
  251. DBG_TRACE(("DBG: %s[%d]=%f offset=%d\n", \
  252. name, \
  253. i, \
  254. ary[i], offset));
  255. offset+= 4;
  256. }
  257. }
  258. void dbg_int_ary_no_offset_update(char *name, uint32_t *ary,
  259. int count, int disk_offset)
  260. {
  261. int i;
  262. int offset = disk_offset;
  263. for (i=0; i<count; i++) {
  264. DBG_TRACE(("DBG: %s[%d]=%d offset=%d\n", \
  265. name, \
  266. i, \
  267. ary[i], offset));
  268. offset+= 4;
  269. }
  270. }
  271. void dbg_int_param_no_offset_update(char *name, uint32_t value, int disk_offset)
  272. {
  273. int offset = disk_offset;
  274. DBG_TRACE(("DBG: %s=%d offset=%d\n", \
  275. name, \
  276. value, offset));
  277. offset+= 4;
  278. }
  279. #endif