mirror of
https://github.com/lvgl/lvgl.git
synced 2026-09-27 18:34:13 +08:00
feat(draw_buf): user can separate font draw buf from default draw buff now (#5982)
This commit is contained in:
@@ -100,6 +100,7 @@ typedef struct _lv_global_t {
|
|||||||
lv_tick_state_t tick_state;
|
lv_tick_state_t tick_state;
|
||||||
|
|
||||||
lv_draw_buf_handlers_t draw_buf_handlers;
|
lv_draw_buf_handlers_t draw_buf_handlers;
|
||||||
|
lv_draw_buf_handlers_t font_draw_buf_handlers;
|
||||||
|
|
||||||
lv_ll_t img_decoder_ll;
|
lv_ll_t img_decoder_ll;
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
#define default_handlers LV_GLOBAL_DEFAULT()->draw_buf_handlers
|
#define default_handlers LV_GLOBAL_DEFAULT()->draw_buf_handlers
|
||||||
|
#define font_draw_buf_handlers LV_GLOBAL_DEFAULT()->font_draw_buf_handlers
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
@@ -47,6 +48,7 @@ static uint32_t _calculate_draw_buf_size(uint32_t w, uint32_t h, lv_color_format
|
|||||||
void _lv_draw_buf_init_handlers(void)
|
void _lv_draw_buf_init_handlers(void)
|
||||||
{
|
{
|
||||||
lv_draw_buf_init_with_default_handlers(&default_handlers);
|
lv_draw_buf_init_with_default_handlers(&default_handlers);
|
||||||
|
lv_draw_buf_init_with_default_handlers(&font_draw_buf_handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_draw_buf_init_with_default_handlers(lv_draw_buf_handlers_t * handlers)
|
void lv_draw_buf_init_with_default_handlers(lv_draw_buf_handlers_t * handlers)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "../misc/lv_assert.h"
|
#include "../misc/lv_assert.h"
|
||||||
#include "../stdlib/lv_mem.h"
|
#include "../stdlib/lv_mem.h"
|
||||||
#include "../stdlib/lv_string.h"
|
#include "../stdlib/lv_string.h"
|
||||||
|
#include "../core/lv_global.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -21,6 +22,8 @@
|
|||||||
#define LABEL_RECOLOR_PAR_LENGTH 6
|
#define LABEL_RECOLOR_PAR_LENGTH 6
|
||||||
#define LV_LABEL_HINT_UPDATE_TH 1024 /*Update the "hint" if the label's y coordinates have changed more then this*/
|
#define LV_LABEL_HINT_UPDATE_TH 1024 /*Update the "hint" if the label's y coordinates have changed more then this*/
|
||||||
|
|
||||||
|
#define font_draw_buf_handlers &(LV_GLOBAL_DEFAULT()->font_draw_buf_handlers)
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
@@ -361,7 +364,7 @@ void lv_draw_label_iterate_characters(lv_draw_unit_t * draw_unit, const lv_draw_
|
|||||||
if(pos.y > draw_unit->clip_area->y2) break;
|
if(pos.y > draw_unit->clip_area->y2) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(draw_letter_dsc._draw_buf) lv_draw_buf_destroy(draw_letter_dsc._draw_buf);
|
if(draw_letter_dsc._draw_buf) lv_draw_buf_destroy_user(font_draw_buf_handlers, draw_letter_dsc._draw_buf);
|
||||||
|
|
||||||
LV_ASSERT_MEM_INTEGRITY();
|
LV_ASSERT_MEM_INTEGRITY();
|
||||||
}
|
}
|
||||||
@@ -410,11 +413,11 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc,
|
|||||||
/*Only check draw buf for bitmap glyph*/
|
/*Only check draw buf for bitmap glyph*/
|
||||||
draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, LV_STRIDE_AUTO);
|
draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, LV_STRIDE_AUTO);
|
||||||
if(draw_buf == NULL) {
|
if(draw_buf == NULL) {
|
||||||
if(dsc->_draw_buf) lv_draw_buf_destroy(dsc->_draw_buf);
|
if(dsc->_draw_buf) lv_draw_buf_destroy_user(font_draw_buf_handlers, dsc->_draw_buf);
|
||||||
|
|
||||||
uint32_t h = g.box_h;
|
uint32_t h = g.box_h;
|
||||||
if(h * g.box_w < 64) h *= 2; /*Alloc a slightly larger buffer*/
|
if(h * g.box_w < 64) h *= 2; /*Alloc a slightly larger buffer*/
|
||||||
draw_buf = lv_draw_buf_create(g.box_w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
|
draw_buf = lv_draw_buf_create_user(font_draw_buf_handlers, g.box_w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
|
||||||
LV_ASSERT_MALLOC(draw_buf);
|
LV_ASSERT_MALLOC(draw_buf);
|
||||||
draw_buf->header.h = g.box_h;
|
draw_buf->header.h = g.box_h;
|
||||||
dsc->_draw_buf = draw_buf;
|
dsc->_draw_buf = draw_buf;
|
||||||
|
|||||||
@@ -12,6 +12,10 @@
|
|||||||
|
|
||||||
#if LV_USE_FREETYPE
|
#if LV_USE_FREETYPE
|
||||||
|
|
||||||
|
#include "../../core/lv_global.h"
|
||||||
|
|
||||||
|
#define font_draw_buf_handlers &(LV_GLOBAL_DEFAULT()->font_draw_buf_handlers)
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
@@ -143,7 +147,7 @@ static bool freetype_image_create_cb(lv_freetype_image_cache_data_t * data, void
|
|||||||
uint16_t box_w = glyph_bitmap->bitmap.width; /*Width of the bitmap in [px]*/
|
uint16_t box_w = glyph_bitmap->bitmap.width; /*Width of the bitmap in [px]*/
|
||||||
|
|
||||||
uint32_t stride = lv_draw_buf_width_to_stride(box_w, LV_COLOR_FORMAT_A8);
|
uint32_t stride = lv_draw_buf_width_to_stride(box_w, LV_COLOR_FORMAT_A8);
|
||||||
data->draw_buf = lv_draw_buf_create(box_w, box_h, LV_COLOR_FORMAT_A8, stride);
|
data->draw_buf = lv_draw_buf_create_user(font_draw_buf_handlers, box_w, box_h, LV_COLOR_FORMAT_A8, stride);
|
||||||
|
|
||||||
for(int y = 0; y < box_h; ++y) {
|
for(int y = 0; y < box_h; ++y) {
|
||||||
lv_memcpy((uint8_t *)(data->draw_buf->data) + y * stride, glyph_bitmap->bitmap.buffer + y * box_w,
|
lv_memcpy((uint8_t *)(data->draw_buf->data) + y * stride, glyph_bitmap->bitmap.buffer + y * box_w,
|
||||||
@@ -157,7 +161,7 @@ static bool freetype_image_create_cb(lv_freetype_image_cache_data_t * data, void
|
|||||||
static void freetype_image_free_cb(lv_freetype_image_cache_data_t * data, void * user_data)
|
static void freetype_image_free_cb(lv_freetype_image_cache_data_t * data, void * user_data)
|
||||||
{
|
{
|
||||||
LV_UNUSED(user_data);
|
LV_UNUSED(user_data);
|
||||||
lv_draw_buf_destroy(data->draw_buf);
|
lv_draw_buf_destroy_user(font_draw_buf_handlers, data->draw_buf);
|
||||||
}
|
}
|
||||||
static lv_cache_compare_res_t freetype_image_compare_cb(const lv_freetype_image_cache_data_t * lhs,
|
static lv_cache_compare_res_t freetype_image_compare_cb(const lv_freetype_image_cache_data_t * lhs,
|
||||||
const lv_freetype_image_cache_data_t * rhs)
|
const lv_freetype_image_cache_data_t * rhs)
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
#if LV_USE_TINY_TTF
|
#if LV_USE_TINY_TTF
|
||||||
|
|
||||||
|
#include "../../core/lv_global.h"
|
||||||
|
|
||||||
|
#define font_draw_buf_handlers &(LV_GLOBAL_DEFAULT()->font_draw_buf_handlers)
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
@@ -352,7 +356,7 @@ static bool tiny_ttf_cache_create_cb(tiny_ttf_cache_data_t * node, void * user_d
|
|||||||
int w, h;
|
int w, h;
|
||||||
w = x2 - x1 + 1;
|
w = x2 - x1 + 1;
|
||||||
h = y2 - y1 + 1;
|
h = y2 - y1 + 1;
|
||||||
lv_draw_buf_t * draw_buf = lv_draw_buf_create(w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
|
lv_draw_buf_t * draw_buf = lv_draw_buf_create_user(font_draw_buf_handlers, w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
|
||||||
if(NULL == draw_buf) {
|
if(NULL == draw_buf) {
|
||||||
LV_LOG_ERROR("tiny_ttf: out of memory\n");
|
LV_LOG_ERROR("tiny_ttf: out of memory\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -371,7 +375,7 @@ static void tiny_ttf_cache_free_cb(tiny_ttf_cache_data_t * node, void * user_dat
|
|||||||
{
|
{
|
||||||
LV_UNUSED(user_data);
|
LV_UNUSED(user_data);
|
||||||
|
|
||||||
lv_draw_buf_destroy(node->draw_buf);
|
lv_draw_buf_destroy_user(font_draw_buf_handlers, node->draw_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_cache_compare_res_t tiny_ttf_cache_compare_cb(const tiny_ttf_cache_data_t * lhs,
|
static lv_cache_compare_res_t tiny_ttf_cache_compare_cb(const tiny_ttf_cache_data_t * lhs,
|
||||||
|
|||||||
Reference in New Issue
Block a user