Test Fix for TTF caching issue

This commit is contained in:
fvanroie 2022-04-18 17:29:42 +02:00
parent 53af0b0210
commit 7ea6de2ee2

View File

@ -36,7 +36,8 @@ QueueHandle_t FTResponseQueue;
TaskHandle_t FTTaskHandle;
void FT_loop_task(void* pvParameters);
typedef struct FT_glyph_dsc_request {
typedef struct FT_glyph_dsc_request
{
const lv_font_t* font;
lv_font_glyph_dsc_t* dsc_out;
uint32_t unicode_letter;
@ -45,7 +46,6 @@ typedef struct FT_glyph_dsc_request {
typedef bool FT_glyph_dsc_response;
/*********************
* DEFINES
*********************/
@ -62,13 +62,12 @@ static void face_add_to_list(FT_Face face);
static void face_remove_from_list(FT_Face face);
static void face_generic_finalizer(void* object);
static bool get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out,
uint32_t unicode_letter, uint32_t unicode_letter_next);
static bool get_glyph_dsc_cb(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out, uint32_t unicode_letter,
uint32_t unicode_letter_next);
static const uint8_t* get_glyph_bitmap_cb(const lv_font_t* font, uint32_t unicode_letter);
#if LV_USE_FT_CACHE_MANAGER
static FT_Error font_face_requester(FTC_FaceID face_id,
FT_Library library_is,FT_Pointer req_data,FT_Face* aface);
static FT_Error font_face_requester(FTC_FaceID face_id, FT_Library library_is, FT_Pointer req_data, FT_Face* aface);
#endif
/**********************
@ -105,8 +104,7 @@ bool lv_freetype_init(FT_UInt max_faces, FT_UInt max_sizes, FT_ULong max_bytes)
}
#if LV_USE_FT_CACHE_MANAGER
error = FTC_Manager_New(library, max_faces, max_sizes,
max_bytes, font_face_requester, NULL, &cache_manager);
error = FTC_Manager_New(library, max_faces, max_sizes, max_bytes, font_face_requester, NULL, &cache_manager);
if(error) {
FT_Done_FreeType(library);
LV_LOG_ERROR("Failed to open cache manager");
@ -129,7 +127,8 @@ bool lv_freetype_init(FT_UInt max_faces, FT_UInt max_sizes, FT_ULong max_bytes)
FTRequestQueue = xQueueCreate(1, sizeof(FT_glyph_dsc_request));
FTResponseQueue = xQueueCreate(1, sizeof(FT_glyph_dsc_response));
xTaskCreatePinnedToCore(FT_loop_task, "FreeType_task", LV_USE_FT_STACK_SIZE, NULL, 1, &FTTaskHandle, ARDUINO_RUNNING_CORE);
xTaskCreatePinnedToCore(FT_loop_task, "FreeType_task", LV_USE_FT_STACK_SIZE, NULL, 1, &FTTaskHandle,
ARDUINO_RUNNING_CORE);
if(FTRequestQueue && FTResponseQueue) {
return true;
@ -166,7 +165,7 @@ bool lv_ft_font_init(lv_ft_info_t *info)
lv_face_info_t* face_info = NULL;
FT_Face face = face_find_in_list(info);
if (face == NULL) {
if(1 || face == NULL) {
if(face_control.cnt == face_control.num - 1) {
LV_LOG_WARN("face full");
goto Fail;
@ -188,8 +187,7 @@ bool lv_ft_font_init(lv_ft_info_t *info)
face->generic.data = face_info;
face->generic.finalizer = face_generic_finalizer;
face_add_to_list(face);
}
else {
} else {
#if LV_USE_FT_CACHE_MANAGER == 0
FT_Size size;
FT_Error error = FT_New_Size(face, &size);
@ -304,8 +302,7 @@ static void face_remove_from_list(FT_Face face)
#if LV_USE_FT_CACHE_MANAGER
static FT_Error font_face_requester(FTC_FaceID face_id,
FT_Library library_is,FT_Pointer req_data,FT_Face* aface)
static FT_Error font_face_requester(FTC_FaceID face_id, FT_Library library_is, FT_Pointer req_data, FT_Face* aface)
{
LV_UNUSED(library_is);
LV_UNUSED(req_data);
@ -313,8 +310,8 @@ static FT_Error font_face_requester(FTC_FaceID face_id,
return FT_Err_Ok;
}
static bool get_glyph_dsc_cb_cache(const lv_font_t * font,
lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next)
static bool get_glyph_dsc_cb_cache(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out, uint32_t unicode_letter,
uint32_t unicode_letter_next)
{
LV_UNUSED(unicode_letter_next);
if(unicode_letter < 0x20) {
@ -359,8 +356,8 @@ static const uint8_t * get_glyph_bitmap_cb_cache(const lv_font_t * font, uint32_
#else /* LV_USE_FT_CACHE_MANAGER */
// extern void berry_log_C(const char * berry_buf, ...);
static bool get_glyph_dsc_cb_nocache(const lv_font_t * font,
lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next)
static bool get_glyph_dsc_cb_nocache(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out, uint32_t unicode_letter,
uint32_t unicode_letter_next)
{
// berry_log_C(">> get_glyph_dsc_cb_nocache %i %i", unicode_letter, unicode_letter_next);
LV_UNUSED(unicode_letter_next);
@ -402,10 +399,12 @@ static bool get_glyph_dsc_cb_nocache(const lv_font_t * font,
dsc_out->box_h = face->glyph->bitmap.rows; /*Height of the bitmap in [px]*/
dsc_out->box_w = face->glyph->bitmap.width; /*Width of the bitmap in [px]*/
dsc_out->ofs_x = face->glyph->bitmap_left; /*X offset of the bitmap in [pf]*/
dsc_out->ofs_y = face->glyph->bitmap_top - face->glyph->bitmap.rows; /*Y offset of the bitmap measured from the as line*/
dsc_out->ofs_y =
face->glyph->bitmap_top - face->glyph->bitmap.rows; /*Y offset of the bitmap measured from the as line*/
dsc_out->bpp = 8; /*Bit per pixel: 1/2/4/8*/
// berry_log_C("+++ adv_w %i, h %i, w %i, x %i, y %i", dsc_out->adv_w, dsc_out->box_h, dsc_out->box_w, dsc_out->ofs_x, dsc_out->ofs_y);
// berry_log_C("+++ adv_w %i, h %i, w %i, x %i, y %i", dsc_out->adv_w, dsc_out->box_h, dsc_out->box_w,
// dsc_out->ofs_x, dsc_out->ofs_y);
return true;
}
@ -420,8 +419,8 @@ static const uint8_t * get_glyph_bitmap_cb_nocache(const lv_font_t * font, uint3
#endif /* LV_USE_FT_CACHE_MANAGER */
static bool get_glyph_dsc_cb(const lv_font_t * font,
lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next)
static bool get_glyph_dsc_cb(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out, uint32_t unicode_letter,
uint32_t unicode_letter_next)
{
// #if LV_USE_FT_CACHE_MANAGER
// return get_glyph_dsc_cb_cache(font, dsc_out, unicode_letter, unicode_letter_next);
@ -452,7 +451,8 @@ static const uint8_t * get_glyph_bitmap_cb(const lv_font_t * font, uint32_t unic
#endif
}
void FT_loop_task(void *pvParameters) {
void FT_loop_task(void* pvParameters)
{
(void)pvParameters;
while(1) {
@ -461,9 +461,11 @@ void FT_loop_task(void *pvParameters) {
if(xQueueReceive(FTRequestQueue, &request, portMAX_DELAY)) {
#if LV_USE_FT_CACHE_MANAGER
response = get_glyph_dsc_cb_cache(request.font, request.dsc_out, request.unicode_letter, request.unicode_letter_next);
response = get_glyph_dsc_cb_cache(request.font, request.dsc_out, request.unicode_letter,
request.unicode_letter_next);
#else
response = get_glyph_dsc_cb_nocache(request.font, request.dsc_out, request.unicode_letter, request.unicode_letter_next);
response = get_glyph_dsc_cb_nocache(request.font, request.dsc_out, request.unicode_letter,
request.unicode_letter_next);
#endif
xQueueSendToBack(FTResponseQueue, &response, portMAX_DELAY); // send back response
}