diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-07-03 10:43:54 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-07-03 10:43:54 +1000 |
| commit | 88ac96242f0d36e53876ece9f90baf776616f0bc (patch) | |
| tree | 4a937dd3f5f0178e91d5b797a276187a0fa7b64b /lib | |
| parent | cbcf1bea617a8f57fe80264e4b96da9274d133f0 (diff) | |
| download | tangara-fw-88ac96242f0d36e53876ece9f90baf776616f0bc.tar.gz | |
Load fonts asynchronously on a bg task
This saves a second or two from bootup; AFAICT this *mostly* reclaims
the dynamic fonts boot time regression.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/luavgl/src/font.c | 44 | ||||
| -rw-r--r-- | lib/luavgl/src/fs.c | 11 | ||||
| -rw-r--r-- | lib/luavgl/src/luavgl.h | 2 |
3 files changed, 21 insertions, 36 deletions
diff --git a/lib/luavgl/src/font.c b/lib/luavgl/src/font.c index 87e0bbef..7751e0c7 100644 --- a/lib/luavgl/src/font.c +++ b/lib/luavgl/src/font.c @@ -1,49 +1,23 @@ #include "luavgl.h" #include "private.h" -static char *to_lower(char *str) -{ - for (char *s = str; *s; ++s) - *s = *s >= 'A' && *s <= 'Z' ? *s | 0x60 : *s; - return str; -} - -static char *luavgl_strchr(const char *s, char c) -{ - while (*s) { - if (c == *s) { - return (char *)s; - } - s++; - } - return NULL; -} - -/** - * Dynamic font family fallback is not supported. - * The fallback only happen when font creation fails and continue to try next - * one. Fallback logic in lvgl is supposed to be system wide. - * - * lvgl.Font("MiSansW medium, montserrat", 24, "normal") - */ static int luavgl_font_create(lua_State *L) { - if (!lua_isstring(L, 1)) { return luaL_argerror(L, 1, "expect string"); } - const char *name = lua_tostring(L, 1); - const lv_font_t *font = NULL; + if (!lua_isfunction(L, 2)) { + return luaL_argerror(L, 1, "expect function"); + } luavgl_ctx_t *ctx = luavgl_context(L); - if (ctx->make_font) { - font = ctx->make_font(name); + if (!ctx->make_font) { + return luaL_error(L, "cannot create font"); } - if (font) { - lua_pushlightuserdata(L, (void *)font); - return 1; - } + const char *name = lua_tostring(L, 1); + int cb_ref = luaL_ref(L, LUA_REGISTRYINDEX); + ctx->make_font(L, name, cb_ref); - return luaL_error(L, "cannot create font"); + return 0; } diff --git a/lib/luavgl/src/fs.c b/lib/luavgl/src/fs.c index 4deec5e5..4918dcb6 100644 --- a/lib/luavgl/src/fs.c +++ b/lib/luavgl/src/fs.c @@ -1,6 +1,17 @@ #include "luavgl.h" #include "private.h" +static char *luavgl_strchr(const char *s, char c) +{ + while (*s) { + if (c == *s) { + return (char *)s; + } + s++; + } + return NULL; +} + typedef struct luavgl_fs_s { lv_fs_file_t file; bool closed; /* userdata exists but lv_fs has been closed */ diff --git a/lib/luavgl/src/luavgl.h b/lib/luavgl/src/luavgl.h index 6c5f8e98..8b7b92aa 100644 --- a/lib/luavgl/src/luavgl.h +++ b/lib/luavgl/src/luavgl.h @@ -12,7 +12,7 @@ extern "C" { #endif -typedef const lv_font_t *(*make_font_cb)(const char *); +typedef void (*make_font_cb)(lua_State *L, const char *, int cb); typedef void (*delete_font_cb)(const lv_font_t *); typedef int (*luavgl_pcall_t)(lua_State *L, int nargs, int nresults); |
