瀏覽代碼

change: lv_font_glyph_dsc_t 添加data属性,支持一次性取出bitmap数据

1. 因为存储空间是调用者提供的, 所以点阵数据不再需要是静态数据
2. 不需要查2次, 也就不需要考虑缓存查询结果, 提高效率

以上修改需要font对应的get_glyph_dsc函数进行配合, 否则依然走老的逻辑, 正常运行
Wendal Chen 3 年之前
父節點
當前提交
aa75d375a7
共有 2 個文件被更改,包括 22 次插入5 次删除
  1. 17 2
      components/lvgl/src/lv_draw/lv_draw_label.c
  2. 5 3
      components/lvgl/src/lv_font/lv_font.h

+ 17 - 2
components/lvgl/src/lv_draw/lv_draw_label.c

@@ -400,6 +400,11 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_letter(const lv_point_t * pos_p, const
                                                  uint32_t letter,
                                                  lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode)
 {
+    //printf("CALL lv_draw_letter\n");
+    // 足以存放64字号的bitmap数据
+    uint8_t bitmap_buff[512] = {0};
+    const uint8_t * map_p;
+    lv_font_glyph_dsc_t g = {0};
     if(opa < LV_OPA_MIN) return;
     if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
 
@@ -408,7 +413,12 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_letter(const lv_point_t * pos_p, const
         return;
     }
 
-    lv_font_glyph_dsc_t g;
+    g.data_ready = 0;
+    if (font_p->line_height <= 64)
+        g.data = bitmap_buff;
+    else
+        g.data = NULL;
+    //printf("g %p g.data %p\n", &g, g.data);
     bool g_ret = lv_font_get_glyph_dsc(font_p, &g, letter, '\0');
     if(g_ret == false)  {
         /* Add warning if the dsc is not found
@@ -433,7 +443,12 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_letter(const lv_point_t * pos_p, const
         return;
     }
 
-    const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter);
+    // add by wendal, 2022-08-04
+    // 若字体支持直接去数据,就不用查2次, 也不会加缓存了
+    if (g.data_ready == 0)
+        map_p = lv_font_get_glyph_bitmap(font_p, letter);
+    else
+        map_p = bitmap_buff;
     if(map_p == NULL) {
         LV_LOG_WARN("lv_draw_letter: character's bitmap not found");
         return;

+ 5 - 3
components/lvgl/src/lv_font/lv_font.h

@@ -41,6 +41,8 @@ typedef struct {
     int16_t ofs_x;   /**< x offset of the bounding box*/
     int16_t ofs_y;  /**< y offset of the bounding box*/
     uint8_t bpp;   /**< Bit-per-pixel: 1, 2, 4, 8*/
+    uint8_t data_ready;
+    uint8_t *data;
 } lv_font_glyph_dsc_t;
 
 /** The bitmaps might be upscaled by 3 to achieve subpixel rendering. */
@@ -70,9 +72,9 @@ typedef struct _lv_font_struct {
     int8_t underline_thickness;     /**< Thickness of the underline*/
 
     void * dsc;                     /**< Store implementation specific or run_time data or caching here*/
-#if LV_USE_USER_DATA
-    lv_font_user_data_t user_data;  /**< Custom user data for font. */
-#endif
+// #if LV_USE_USER_DATA
+//     lv_font_user_data_t user_data;  /**< Custom user data for font. */
+// #endif
 
 } lv_font_t;