From 71e8fadcabd3d6389825aac67c0837377c1b4fb0 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 6 Jun 2024 01:07:23 -0400 Subject: [PATCH] VEFontCache: Initial hookup to sectr module & runtime bugfixes --- code/font/VEFontCache/VEFontCache.odin | 2 +- code/font/VEFontCache/mappings.odin | 14 ++++++++------ code/font/VEFontCache/parser.odin | 5 +++++ code/font/VEFontCache/shaper.odin | 7 +++++++ code/grime/hashmap_chained.odin | 7 ++++--- code/sectr/font/provider_VEFontCache.odin | 7 ++++--- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/code/font/VEFontCache/VEFontCache.odin b/code/font/VEFontCache/VEFontCache.odin index 9b763cd..5de6c6e 100644 --- a/code/font/VEFontCache/VEFontCache.odin +++ b/code/font/VEFontCache/VEFontCache.odin @@ -226,7 +226,7 @@ InitShapeCacheParams_Default :: InitShapeCacheParams { } // ve_fontcache_init -init :: proc( ctx : ^Context, +init :: proc( ctx : ^Context, parser_kind : ParserKind, allocator := context.allocator, atlas_params := InitAtlasParams_Default, glyph_draw_params := InitGlyphDrawParams_Default, diff --git a/code/font/VEFontCache/mappings.odin b/code/font/VEFontCache/mappings.odin index 8210b9b..5d10453 100644 --- a/code/font/VEFontCache/mappings.odin +++ b/code/font/VEFontCache/mappings.odin @@ -40,12 +40,13 @@ array_underlying_slice :: grime.array_underlying_slice HMapChained :: grime.HMapChained -hmap_chained_clear :: grime.hmap_chained_clear -hmap_chained_init :: grime.hmap_chained_init -hmap_chained_get :: grime.hmap_chained_get -hmap_chained_remove :: grime.hmap_chained_remove -hmap_chained_set :: grime.hmap_chained_set -hmap_closest_prime :: grime.hmap_closest_prime +hmap_chained_clear :: grime.hmap_chained_clear +hmap_chained_destroy :: grime.hmap_chained_destroy +hmap_chained_init :: grime.hmap_chained_init +hmap_chained_get :: grime.hmap_chained_get +hmap_chained_remove :: grime.hmap_chained_remove +hmap_chained_set :: grime.hmap_chained_set +hmap_closest_prime :: grime.hmap_closest_prime // Pool :: grime.Pool @@ -82,6 +83,7 @@ clear :: proc { delete :: proc { array_free, + hmap_chained_destroy, } get :: proc { diff --git a/code/font/VEFontCache/parser.odin b/code/font/VEFontCache/parser.odin index 661911f..83de99c 100644 --- a/code/font/VEFontCache/parser.odin +++ b/code/font/VEFontCache/parser.odin @@ -70,6 +70,11 @@ parser_init :: proc( ctx : ^ParserContext ) assert( error == .None, "VEFontCache.parser_init: Failed to allocate fonts array" ) } +parser_shutdown :: proc( ctx : ^ParserContext ) +{ + // TODO(Ed): Implement +} + parser_load_font :: proc( ctx : ParserContext, label : string, data : []byte ) -> (font : ^ParserFontInfo) { key := font_key_from_label(label) diff --git a/code/font/VEFontCache/shaper.odin b/code/font/VEFontCache/shaper.odin index dfa9107..619e19d 100644 --- a/code/font/VEFontCache/shaper.odin +++ b/code/font/VEFontCache/shaper.odin @@ -27,6 +27,11 @@ ShaperInfo :: struct { shaper_init :: proc( ctx : ^ShaperContext ) { ctx.hb_buffer = harfbuzz.buffer_create() + assert( ctx.hb_buffer != nil, "VEFontCache.shaper_init: Failed to create harfbuzz buffer") + + error : AllocatorError + ctx.infos, error = make( HMapChained(ShaperInfo), 256 ) + assert( error == .None, "VEFontCache.shaper_init: Failed to create shaper infos map" ) } shaper_shutdown :: proc( ctx : ^ShaperContext ) @@ -34,6 +39,8 @@ shaper_shutdown :: proc( ctx : ^ShaperContext ) if ctx.hb_buffer != nil { harfbuzz.buffer_destory( ctx.hb_buffer ) } + + delete(& ctx.infos) } shaper_load_font :: proc( ctx : ^ShaperContext, label : string, data : []byte, user_data : rawptr ) -> (info : ^ShaperInfo) diff --git a/code/grime/hashmap_chained.odin b/code/grime/hashmap_chained.odin index feb426d..ffcba73 100644 --- a/code/grime/hashmap_chained.odin +++ b/code/grime/hashmap_chained.odin @@ -98,8 +98,8 @@ hmap_chained_clear :: proc( using self : HMapChained($Type)) hmap_chained_destroy :: proc( using self : ^HMapChained($Type)) { pool_destroy( pool ) - free( self.header, backing) - self = nil + free( self.header, self.pool.backing) + self.header = nil } hmap_chained_lookup_id :: #force_inline proc( using self : HMapChained($Type), key : u64 ) -> u64 @@ -163,9 +163,10 @@ hmap_chained_remove :: proc( self : HMapChained($Type), key : u64 ) -> b32 // Sets the value to a vacant slot // Will preemptively allocate the next slot in the hashtable if its null for the slot. -hmap_chained_set :: proc( using self : HMapChained($Type), key : u64, value : Type ) -> (^ Type, AllocatorError) +hmap_chained_set :: proc( self : HMapChained($Type), key : u64, value : Type ) -> (^ Type, AllocatorError) { // profile(#procedure) + using self hash_index := hmap_chained_lookup_id(self, key) surface_slot := lookup[hash_index] set_slot :: #force_inline proc( using self : HMapChained(Type), diff --git a/code/sectr/font/provider_VEFontCache.odin b/code/sectr/font/provider_VEFontCache.odin index 856d0ff..f6ba42a 100644 --- a/code/sectr/font/provider_VEFontCache.odin +++ b/code/sectr/font/provider_VEFontCache.odin @@ -42,13 +42,13 @@ font_provider_startup :: proc() profile(#procedure) state := get_state() - provider_data := state.font_provider_data; using provider_data + provider_data := & state.font_provider_data; using provider_data error : AllocatorError font_cache, error = make( HMapChained(FontDef), hmap_closest_prime(1 * Kilo), persistent_allocator() /*dbg_name = "font_cache"*/ ) verify( error == AllocatorError.None, "Failed to allocate font_cache" ) - ve.init( & provider_data.ve_font_cache, allocator = persistent_slab_allocator() ) + ve.init( & provider_data.ve_font_cache, .STB_TrueType, allocator = persistent_slab_allocator() ) log("VEFontCached initialized") // TODO(Ed): Setup sokol hookup for VEFontCache @@ -62,7 +62,6 @@ font_provider_shutdown :: proc() ve.shutdown( & provider_data.ve_font_cache ) } - font_load :: proc(path_file : string, default_size : f32 = Font_Load_Use_Default_Size, desired_id : string = Font_Load_Gen_ID @@ -86,6 +85,8 @@ font_load :: proc(path_file : string, desired_id = file_name_from_path(path_file) } + font_cache_watch := provider_data.font_cache + key := cast(u64) crc32( transmute([]byte) desired_id ) def, set_error := hmap_chained_set(font_cache, key, FontDef{}) verify( set_error == AllocatorError.None, "Failed to add new font entry to cache" )