Removed usage of procedure using statements from vefontcache

This commit is contained in:
Edward R. Gonzalez 2025-01-06 11:23:30 -05:00
parent 840e6053ff
commit f1f98ffafb
4 changed files with 110 additions and 134 deletions

View File

@ -39,18 +39,17 @@ pool_list_init :: proc( pool : ^Pool_List, capacity : i32, dbg_name : string = "
pool.capacity = capacity
pool.dbg_name = dbg_name
using pool
for id in 0 ..< capacity {
free_list[id] = i32(id)
items[id] = {
for id in 0 ..< pool.capacity {
pool.free_list[id] = i32(id)
pool.items[id] = {
prev = -1,
next = -1,
}
}
front = -1
back = -1
pool.front = -1
pool.back = -1
}
pool_list_free :: proc( pool : ^Pool_List ) {
@ -65,96 +64,91 @@ pool_list_reload :: proc( pool : ^Pool_List, allocator : Allocator ) {
pool_list_clear :: proc( pool: ^Pool_List )
{
using pool
clear(& items)
clear(& free_list)
clear(& pool.items)
clear(& pool.free_list)
resize( & pool.items, cap(pool.items) )
resize( & pool.free_list, cap(pool.free_list) )
for id in 0 ..< capacity {
free_list[id] = i32(id)
items[id] = {
for id in 0 ..< pool.capacity {
pool.free_list[id] = i32(id)
pool.items[id] = {
prev = -1,
next = -1,
}
}
front = -1
back = -1
size = 0
pool.front = -1
pool.back = -1
pool.size = 0
}
pool_list_push_front :: proc( pool : ^Pool_List, value : Pool_ListValue )
{
using pool
if size >= capacity do return
if pool.size >= pool.capacity do return
length := len(free_list)
length := len(pool.free_list)
assert( length > 0 )
assert( length == int(capacity - size) )
assert( length == int(pool.capacity - pool.size) )
id := free_list[ len(free_list) - 1 ]
id := pool.free_list[ len(pool.free_list) - 1 ]
if pool.dbg_name != "" {
logf("pool_list: back %v", id)
}
pop( & free_list )
items[ id ].prev = -1
items[ id ].next = front
items[ id ].value = value
pop( & pool.free_list )
pool.items[ id ].prev = -1
pool.items[ id ].next = pool.front
pool.items[ id ].value = value
if pool.dbg_name != "" {
logf("pool_list: pushed %v into id %v", value, id)
}
if front != -1 do items[ front ].prev = id
if back == -1 do back = id
front = id
size += 1
if pool.front != -1 do pool.items[ pool.front ].prev = id
if pool.back == -1 do pool.back = id
pool.front = id
pool.size += 1
}
pool_list_erase :: proc( pool : ^Pool_List, iter : Pool_ListIter )
{
using pool
if size <= 0 do return
assert( iter >= 0 && iter < i32(capacity) )
assert( len(free_list) == int(capacity - size) )
if pool.size <= 0 do return
assert( iter >= 0 && iter < i32(pool.capacity) )
assert( len(pool.free_list) == int(pool.capacity - pool.size) )
iter_node := & items[ iter ]
iter_node := & pool.items[ iter ]
prev := iter_node.prev
next := iter_node.next
if iter_node.prev != -1 do items[ prev ].next = iter_node.next
if iter_node.next != -1 do items[ next ].prev = iter_node.prev
if iter_node.prev != -1 do pool.items[ prev ].next = iter_node.next
if iter_node.next != -1 do pool.items[ next ].prev = iter_node.prev
if front == iter do front = iter_node.next
if back == iter do back = iter_node.prev
if pool.front == iter do pool.front = iter_node.next
if pool.back == iter do pool.back = iter_node.prev
iter_node.prev = -1
iter_node.next = -1
iter_node.value = 0
append( & free_list, iter )
append( & pool.free_list, iter )
size -= 1
if size == 0 {
back = -1
front = -1
pool.size -= 1
if pool.size == 0 {
pool.back = -1
pool.front = -1
}
}
pool_list_move_to_front :: proc "contextless" ( pool : ^Pool_List, iter : Pool_ListIter )
{
using pool
if pool.front == iter do return
if front == iter do return
item := & pool.items[iter]
if item.prev != -1 do pool.items[ item.prev ].next = item.next
if item.next != -1 do pool.items[ item.next ].prev = item.prev
if pool.back == iter do pool.back = item.prev
item := & items[iter]
if item.prev != -1 do items[ item.prev ].next = item.next
if item.next != -1 do items[ item.next ].prev = item.prev
if back == iter do back = item.prev
item.prev = -1
item.next = front
items[ front ].prev = iter
front = iter
item.prev = -1
item.next = pool.front
pool.items[ pool.front ].prev = iter
pool.front = iter
}
pool_list_peek_back :: #force_inline proc ( pool : Pool_List ) -> Pool_ListValue #no_bounds_check {

View File

@ -615,19 +615,14 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
to_glyph_buffer_space( & dst_region_pos, & dst_region_size, atlas_size )
clear_target_region : Draw_Call
{
using clear_target_region
pass = .Atlas
region = .Ignore
start_index = cast(u32) len(glyph_buffer.clear_draw_list.indices)
blit_quad( & glyph_buffer.clear_draw_list,
dst_region_pos, dst_region_pos + dst_region_size,
{ 1.0, 1.0 }, { 1.0, 1.0 }
)
end_index = cast(u32) len(glyph_buffer.clear_draw_list.indices)
}
clear_target_region.pass = .Atlas
clear_target_region.region = .Ignore
clear_target_region.start_index = cast(u32) len(glyph_buffer.clear_draw_list.indices)
blit_quad( & glyph_buffer.clear_draw_list,
dst_region_pos, dst_region_pos + dst_region_size,
{ 1.0, 1.0 }, { 1.0, 1.0 }
)
clear_target_region.end_index = cast(u32) len(glyph_buffer.clear_draw_list.indices)
dst_glyph_pos := glyph.region_pos
dst_glyph_size := glyph.bounds_size_scaled + atlas.glyph_padding
@ -638,21 +633,15 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
src_size := (glyph.bounds_size_scaled + atlas.glyph_padding) * glyph_buffer.over_sample
// src_size.y = ceil(src_size.y) // Note(Ed): Seems to improve hinting
to_target_space( & src_position, & src_size, glyph_buffer_size )
blit_to_atlas : Draw_Call
{
using blit_to_atlas
pass = .Atlas
region = .None
start_index = cast(u32) len(glyph_buffer.draw_list.indices)
blit_quad( & glyph_buffer.draw_list,
dst_glyph_pos, dst_glyph_pos + dst_glyph_size,
src_position, src_position + src_size )
end_index = cast(u32) len(glyph_buffer.draw_list.indices)
}
blit_to_atlas.pass = .Atlas
blit_to_atlas.region = .None
blit_to_atlas.start_index = cast(u32) len(glyph_buffer.draw_list.indices)
blit_quad( & glyph_buffer.draw_list,
dst_glyph_pos, dst_glyph_pos + dst_glyph_size,
src_position, src_position + src_size )
blit_to_atlas.end_index = cast(u32) len(glyph_buffer.draw_list.indices)
append( & glyph_buffer.clear_draw_list.calls, clear_target_region )
append( & glyph_buffer.draw_list.calls, blit_to_atlas )

View File

@ -58,19 +58,17 @@ shaper_shutdown :: proc( ctx : ^Shaper_Context )
shaper_load_font :: #force_inline proc( ctx : ^Shaper_Context, label : string, data : []byte, user_data : rawptr = nil ) -> (info : Shaper_Info)
{
using info
blob = harfbuzz.blob_create( raw_data(data), cast(c.uint) len(data), harfbuzz.Memory_Mode.READONLY, user_data, nil )
face = harfbuzz.face_create( blob, 0 )
font = harfbuzz.font_create( face )
info.blob = harfbuzz.blob_create( raw_data(data), cast(c.uint) len(data), harfbuzz.Memory_Mode.READONLY, user_data, nil )
info.face = harfbuzz.face_create( info.blob, 0 )
info.font = harfbuzz.font_create( info.face )
return
}
shaper_unload_font :: #force_inline proc( ctx : ^Shaper_Info )
shaper_unload_font :: #force_inline proc( info : ^Shaper_Info )
{
using ctx
if blob != nil do harfbuzz.font_destroy( font )
if face != nil do harfbuzz.face_destroy( face )
if blob != nil do harfbuzz.blob_destroy( blob )
if info.blob != nil do harfbuzz.font_destroy( info.font )
if info.face != nil do harfbuzz.face_destroy( info.face )
if info.blob != nil do harfbuzz.blob_destroy( info.blob )
}
shaper_shape_harfbuzz :: #force_inline proc( ctx : ^Shaper_Context, text_utf8 : string, entry : Entry, font_px_Size, font_scale : f32, output :^Shaped_Text )

View File

@ -273,8 +273,6 @@ startup :: proc( ctx : ^Context, parser_kind : Parser_Kind = .STB_TrueType,
Glyph_Buffer_Setup:
{
glyph_buffer := & ctx.glyph_buffer
// using glyph_buffer
glyph_buffer.over_sample = glyph_draw_params.over_sample
glyph_buffer.width = atlas.region_d.width * i32(glyph_buffer.over_sample.x) * i32(glyph_draw_params.buffer_glyph_limit)
glyph_buffer.height = atlas.region_d.height * i32(glyph_buffer.over_sample.y)
@ -325,10 +323,13 @@ hot_reload :: proc( ctx : ^Context, allocator : Allocator )
assert( ctx != nil )
ctx.backing = allocator
context.allocator = ctx.backing
using ctx
// using ctx.atlas
reload_array( & entries, allocator )
atlas := & ctx.atlas
glyph_buffer := & ctx.glyph_buffer
shape_cache := & ctx.shape_cache
draw_list := & ctx.draw_list
reload_array( & ctx.entries, allocator )
reload_array( & glyph_buffer.draw_list.calls, allocator )
reload_array( & glyph_buffer.draw_list.indices, allocator )
@ -353,10 +354,9 @@ hot_reload :: proc( ctx : ^Context, allocator : Allocator )
lru_reload( & shape_cache.state, allocator )
for idx : i32 = 0; idx < i32(len(shape_cache.storage)); idx += 1 {
stroage_entry := & shape_cache.storage[idx]
using stroage_entry
reload_array( & glyphs, allocator )
reload_array( & positions, allocator )
storage_entry := & shape_cache.storage[idx]
reload_array( & storage_entry.glyphs, allocator )
reload_array( & storage_entry.positions, allocator )
}
reload_array( & shape_cache.storage, allocator )
@ -369,12 +369,16 @@ shutdown :: proc( ctx : ^Context )
{
assert( ctx != nil )
context.allocator = ctx.backing
using ctx
for & entry in entries {
atlas := & ctx.atlas
glyph_buffer := & ctx.glyph_buffer
shape_cache := & ctx.shape_cache
draw_list := & ctx.draw_list
for & entry in ctx.entries {
unload_font( ctx, entry.id )
}
delete( entries )
delete( ctx.entries )
delete( glyph_buffer.draw_list.vertices )
delete( glyph_buffer.draw_list.indices )
@ -398,11 +402,9 @@ shutdown :: proc( ctx : ^Context )
lru_free( & atlas.region_d.state )
for idx : i32 = 0; idx < i32(len(shape_cache.storage)); idx += 1 {
stroage_entry := & shape_cache.storage[idx]
using stroage_entry
delete( glyphs )
delete( positions )
storage_entry := & shape_cache.storage[idx]
delete( storage_entry.glyphs )
delete( storage_entry.positions )
}
lru_free( & shape_cache.state )
@ -410,8 +412,8 @@ shutdown :: proc( ctx : ^Context )
delete( draw_list.indices )
delete( draw_list.calls )
shaper_shutdown( & shaper_ctx )
parser_shutdown( & parser_ctx )
shaper_shutdown( & ctx.shaper_ctx )
parser_shutdown( & ctx.parser_ctx )
}
load_font :: proc( ctx : ^Context, label : string, data : []byte, glyph_curve_quality : u32 = 0 ) -> (font_id : Font_ID, error : Load_Font_Error)
@ -419,8 +421,9 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, glyph_curve_qu
profile(#procedure)
assert( ctx != nil )
assert( len(data) > 0 )
using ctx
context.allocator = backing
context.allocator = ctx.backing
entries := & ctx.entries
id : i32 = -1
@ -430,7 +433,7 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, glyph_curve_qu
break
}
if id == -1 {
append_elem( & entries, Entry {})
append_elem( entries, Entry {})
id = cast(i32) len(entries) - 1
}
assert( id >= 0 && id < i32(len(entries)) )
@ -441,12 +444,12 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, glyph_curve_qu
profile_begin("calling loaders")
parser_error : b32
entry.parser_info, parser_error = parser_load_font( & parser_ctx, label, data )
entry.parser_info, parser_error = parser_load_font( & ctx.parser_ctx, label, data )
if parser_error {
error = .Parser_Failed
return
}
entry.shaper_info = shaper_load_font( & shaper_ctx, label, data )
entry.shaper_info = shaper_load_font( & ctx.shaper_ctx, label, data )
profile_end()
ascent, descent, line_gap := parser_get_font_vertical_metrics(entry.parser_info)
@ -628,19 +631,17 @@ get_draw_list_layer :: #force_inline proc( ctx : ^Context, optimize_before_retur
flush_draw_list :: #force_inline proc( ctx : ^Context ) {
assert( ctx != nil )
using ctx
clear_draw_list( & draw_list )
draw_layer.vertices_offset = 0
draw_layer.indices_offset = 0
draw_layer.calls_offset = 0
clear_draw_list( & ctx.draw_list )
ctx.draw_layer.vertices_offset = 0
ctx.draw_layer.indices_offset = 0
ctx.draw_layer.calls_offset = 0
}
flush_draw_list_layer :: #force_inline proc( ctx : ^Context ) {
assert( ctx != nil )
using ctx
draw_layer.vertices_offset = len(draw_list.vertices)
draw_layer.indices_offset = len(draw_list.indices)
draw_layer.calls_offset = len(draw_list.calls)
ctx.draw_layer.vertices_offset = len(ctx.draw_list.vertices)
ctx.draw_layer.indices_offset = len(ctx.draw_list.indices)
ctx.draw_layer.calls_offset = len(ctx.draw_list.calls)
}
//#endregion("drawing")
@ -759,19 +760,13 @@ clear_atlas_region_caches :: proc(ctx : ^Context)
// Can be used with hot-reload
clear_shape_cache :: proc (ctx : ^Context)
{
using ctx
lru_clear(& shape_cache.state)
for idx : i32 = 0; idx < cast(i32) cap(shape_cache.storage); idx += 1
{
stroage_entry := & shape_cache.storage[idx]
using stroage_entry
end_cursor_pos = {}
size = {}
clear(& glyphs)
clear(& positions)
clear(& draw_list.calls)
clear(& draw_list.indices)
clear(& draw_list.vertices)
lru_clear(& ctx.shape_cache.state)
for idx : i32 = 0; idx < cast(i32) cap(ctx.shape_cache.storage); idx += 1 {
stroage_entry := & ctx.shape_cache.storage[idx]
stroage_entry.end_cursor_pos = {}
stroage_entry.size = {}
clear(& stroage_entry.glyphs)
clear(& stroage_entry.positions)
}
ctx.shape_cache.next_cache_id = 0
}