mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-12-01 16:56:34 +01:00
The previous bitmap cache was a three-level rbtree keyed by (wchar_t, font_id, size), which had two problems: 1. The wchar_t key collapses Unicode codepoints that map to the same glyph in a given face into separate cache slots, missing real reuse opportunities and bloating memory under text-heavy workloads. 2. There was no upper bound; long-running apps would grow the cache without limit until pd_font_library_destroy. Replace it with a flat hash table keyed by a packed 64-bit (face_id, glyph_index, size) tuple, plus a doubly-linked LRU list for O(1) eviction. - pd_font_engine gets a new get_glyph_index hook; FreeType maps via FT_Get_Char_Index, the in-core engine treats codepoints as identity (no cmap). - pd_font_cache_add_bitmap / pd_font_cache_get_bitmap now resolve the glyph index via the engine before keying the cache, so the same glyph reused across composed sequences hits the same entry. - pd_font_cache_set_capacity / pd_font_cache_count expose the LRU bound (default 8192 entries, 0 = unlimited) for runtime tuning and tests. Shrinking the capacity evicts immediately. - list_t is used with append at tail / evict from head so the yutil tail.prev pointer stays consistent (list_link does not update it). Adds lib/pandagl/tests/test_font_cache.c covering hit identity, size differentiation, unknown-codepoint fallback, and LRU eviction.
30 lines
902 B
C
30 lines
902 B
C
/*
|
|
* lib/pandagl/tests/main.c
|
|
*
|
|
* Copyright (c) 2026, Liu Chao <i@lc-soft.io> All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* This file is part of LCUI, distributed under the MIT License found in the
|
|
* LICENSE.TXT file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <ctest.h>
|
|
|
|
extern void test_pandagl_canvas_mix(void);
|
|
extern void test_pandagl_image_reader(void);
|
|
extern void test_pandagl_font_load(void);
|
|
extern void test_pandagl_text_edit(void);
|
|
extern void test_pandagl_font_cache(void);
|
|
|
|
static const ctest_suite_t suites[] = {
|
|
{ "pandagl/canvas mix", test_pandagl_canvas_mix },
|
|
{ "pandagl/image reader", test_pandagl_image_reader },
|
|
{ "pandagl/font load", test_pandagl_font_load },
|
|
{ "pandagl/text edit", test_pandagl_text_edit },
|
|
{ "pandagl/font cache", test_pandagl_font_cache },
|
|
{ NULL, NULL }
|
|
};
|
|
|
|
CTEST_MAIN(suites)
|