mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
fix(freetype): fix potential multi-threaded data conflicts (#6252)
This commit is contained in:
parent
0f5cda602b
commit
903e2754c8
@ -368,12 +368,14 @@ static bool cache_node_cache_create_cb(lv_freetype_cache_node_t * node, void * u
|
||||
}
|
||||
|
||||
node->face = face;
|
||||
lv_mutex_init(&node->face_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
static void cache_node_cache_free_cb(lv_freetype_cache_node_t * node, void * user_data)
|
||||
{
|
||||
FT_Done_Face(node->face);
|
||||
lv_mutex_delete(&node->face_lock);
|
||||
|
||||
if(node->glyph_cache) {
|
||||
lv_cache_destroy(node->glyph_cache, user_data);
|
||||
|
@ -132,6 +132,7 @@ static bool freetype_glyph_create_cb(lv_freetype_glyph_cache_data_t * data, void
|
||||
|
||||
lv_font_glyph_dsc_t * dsc_out = &data->glyph_dsc;
|
||||
|
||||
lv_mutex_lock(&dsc->cache_node->face_lock);
|
||||
FT_Face face = dsc->cache_node->face;
|
||||
FT_UInt glyph_index = FT_Get_Char_Index(face, data->unicode);
|
||||
|
||||
@ -139,6 +140,7 @@ static bool freetype_glyph_create_cb(lv_freetype_glyph_cache_data_t * data, void
|
||||
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_COMPUTE_METRICS | FT_LOAD_NO_BITMAP);
|
||||
if(error) {
|
||||
FT_ERROR_MSG("FT_Load_Glyph", error);
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -175,6 +177,8 @@ static bool freetype_glyph_create_cb(lv_freetype_glyph_cache_data_t * data, void
|
||||
dsc_out->is_placeholder = glyph_index == 0;
|
||||
dsc_out->gid.index = (uint32_t)glyph_index;
|
||||
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
static void freetype_glyph_free_cb(lv_freetype_glyph_cache_data_t * data, void * user_data)
|
||||
|
@ -124,16 +124,20 @@ static bool freetype_image_create_cb(lv_freetype_image_cache_data_t * data, void
|
||||
|
||||
FT_Error error;
|
||||
|
||||
lv_mutex_lock(&dsc->cache_node->face_lock);
|
||||
|
||||
FT_Face face = dsc->cache_node->face;
|
||||
FT_Set_Pixel_Sizes(face, 0, dsc->size);
|
||||
error = FT_Load_Glyph(face, data->glyph_index, FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL);
|
||||
if(error) {
|
||||
FT_ERROR_MSG("FT_Load_Glyph", error);
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
return false;
|
||||
}
|
||||
error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
|
||||
if(error) {
|
||||
FT_ERROR_MSG("FT_Render_Glyph", error);
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -141,6 +145,7 @@ static bool freetype_image_create_cb(lv_freetype_image_cache_data_t * data, void
|
||||
error = FT_Get_Glyph(face->glyph, &glyph);
|
||||
if(error) {
|
||||
FT_ERROR_MSG("FT_Get_Glyph", error);
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -159,6 +164,8 @@ static bool freetype_image_create_cb(lv_freetype_image_cache_data_t * data, void
|
||||
|
||||
FT_Done_Glyph(glyph);
|
||||
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
static void freetype_image_free_cb(lv_freetype_image_cache_data_t * data, void * user_data)
|
||||
|
@ -120,11 +120,14 @@ bool lv_freetype_is_outline_font(const lv_font_t * font)
|
||||
static bool freetype_glyph_outline_create_cb(lv_freetype_outline_node_t * node, lv_freetype_font_dsc_t * dsc)
|
||||
{
|
||||
lv_freetype_outline_t outline;
|
||||
|
||||
lv_mutex_lock(&dsc->cache_node->face_lock);
|
||||
outline = outline_create(dsc->context,
|
||||
dsc->cache_node->face,
|
||||
node->glyph_index,
|
||||
dsc->cache_node->ref_size,
|
||||
dsc->style & LV_FREETYPE_FONT_STYLE_BOLD ? 1 : 0);
|
||||
lv_mutex_unlock(&dsc->cache_node->face_lock);
|
||||
|
||||
if(!outline) {
|
||||
return false;
|
||||
|
@ -67,6 +67,7 @@ struct _lv_freetype_cache_node_t {
|
||||
uint32_t ref_size; /**< Reference size for calculating outline glyph's real size.*/
|
||||
|
||||
FT_Face face;
|
||||
lv_mutex_t face_lock;
|
||||
|
||||
/*glyph cache*/
|
||||
lv_cache_t * glyph_cache;
|
||||
|
Loading…
x
Reference in New Issue
Block a user