Commit 7a488b8
committed
gfx/caca,fpga: 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 that
typically never changes size after the first call.
Replace with a cached-capacity realloc pattern: allocate or grow only
when the required size exceeds the current capacity; otherwise reuse
the existing buffer. On realloc failure the previous frame is kept
intact (the original free+malloc sequence would have lost it).
fpga_gfx.c also had a separate latent bug: the pitch calculation used
fpga->rgb32 (the video/core pixel format) instead of the rgb32 parameter
(the menu pixel format), producing wrong bytes-per-pixel when core and
menu formats differed. The menu_bits assignment had the same bug. Both
fixed to use the incoming parameter.
Thread-safety: 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 realloc pattern additionally closes a
transient NULL window that existed between the free and malloc in
the original code.1 parent c0551a8 commit 7a488b8
2 files changed
Lines changed: 38 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
371 | 372 | | |
372 | 373 | | |
373 | 374 | | |
374 | | - | |
375 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
376 | 378 | | |
377 | | - | |
378 | | - | |
| 379 | + | |
| 380 | + | |
379 | 381 | | |
380 | | - | |
381 | | - | |
382 | | - | |
| 382 | + | |
383 | 383 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
| 384 | + | |
388 | 385 | | |
389 | | - | |
390 | | - | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
391 | 392 | | |
392 | 393 | | |
393 | | - | |
394 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
395 | 398 | | |
396 | 399 | | |
397 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
307 | 308 | | |
308 | 309 | | |
309 | 310 | | |
310 | | - | |
311 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
312 | 314 | | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 315 | + | |
| 316 | + | |
319 | 317 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
| 318 | + | |
326 | 319 | | |
327 | | - | |
| 320 | + | |
328 | 321 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
334 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| |||
0 commit comments