VEFontCache: Initial hookup to sectr module & runtime bugfixes
This commit is contained in:
parent
38be79d7a9
commit
71e8fadcab
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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),
|
||||
|
@ -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" )
|
||||
|
Loading…
Reference in New Issue
Block a user