Commit e7bb95f
committed
gfx/gdi,vga: reuse menu frame buffer across set_texture_frame calls
Both drivers unconditionally free'd menu_frame and set it to NULL
before a subsequent size-comparison check, making the "only reallocate
if size changed" branch dead. Every menu frame triggered a full
free+malloc+memcpy round-trip on a buffer whose size rarely or never
changes.
gdi: replace with a cached-capacity realloc pattern matching the
earlier caca/fpga/sixel/network fix — allocate or grow only when the
required size exceeds the current capacity; otherwise reuse. The
menu_frame_cap field is added to gdi_t in gdi_defines.h. Since gdi_t
is heap-allocated via calloc and freed entire, no explicit cap-reset
is needed in the free path (re-init gets fresh zeros).
vga: the menu buffer is *always* VGA_WIDTH*VGA_HEIGHT (64000 bytes)
regardless of the source frame dimensions — the incoming frame is
downscaled into this fixed-size buffer. No capacity tracking is
needed; allocate once on first call and reuse forever. The original
size-comparison check was doubly meaningless (against a buffer of
constant size).
Note on vga: an unrelated pre-existing bug — the rgb32 branch of the
downscaling loop does not populate vga_menu_frame at all, leaving
stale/uninitialized content — is flagged with a FIXME comment but not
fixed here. It deserves its own commit with testing on a real DOS
target.
Thread-safety for both: set_texture_frame and the frame read-site both
run on the video thread (threaded video) or main thread (non-threaded),
sequentially within the same loop iteration. No synchronization
required, none added. The Win32 WM_PAINT handler reads other fields
of gdi_t from the UI thread; menu_frame is not among them and this
patch does not alter the pre-existing concurrency surface. The
realloc/once-alloc patterns additionally close a transient NULL window
that existed between free and malloc in the original code.1 parent 05de9cb commit e7bb95f
3 files changed
Lines changed: 36 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
875 | | - | |
876 | | - | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
877 | 878 | | |
878 | | - | |
879 | | - | |
| 879 | + | |
| 880 | + | |
880 | 881 | | |
881 | | - | |
882 | | - | |
883 | | - | |
| 882 | + | |
884 | 883 | | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
| 884 | + | |
889 | 885 | | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
897 | 891 | | |
898 | 892 | | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
907 | 898 | | |
908 | 899 | | |
909 | 900 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
| 408 | + | |
409 | 409 | | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| 410 | + | |
| 411 | + | |
416 | 412 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
423 | 425 | | |
424 | | - | |
425 | 426 | | |
426 | 427 | | |
427 | 428 | | |
| |||
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
447 | 451 | | |
448 | 452 | | |
449 | 453 | | |
| |||
0 commit comments