Commit 5aabb22
committed
task_screenshot: skip redundant BGR24 copy on viewport screenshot path
take_screenshot_viewport allocates a BGR24 buffer, has the video
driver's read_viewport fill it bottom-up, and hands it to
screenshot_dump. screenshot_dump then allocates a second full-frame
BGR24 buffer (state->out_buffer), and screenshot_dump_direct runs
the generic scaler to convert the first buffer into the second --
which for this case (input and output both BGR24 at the same
dimensions) amounts to a flip-and-copy.
rpng_save_image_stream already walks source rows via `data += pitch`
with a signed pitch, and take_screenshot_raw already exploits this
to feed the encoder a bottom-up buffer via a pointer to the last
row plus a negative pitch. Apply the same trick to the viewport
path: when the source is already BGR24 and no rescaling is needed,
hand the source buffer directly to rpng_save_image_bgr24 and skip
the out_buffer allocation entirely.
For a PNG viewport screenshot this saves one full-frame BGR24
allocation plus one full-frame memcpy. At 4K that is ~48 MiB of
heap pressure and copy work avoided per screenshot.
The savestate thumbnail path (where out_width/out_height differ
from width/height because thumbnails render at native core
geometry) is unaffected: the fast path is gated on dimensions
matching, and smaller-than-screen thumbnail dimensions fall
through to the existing scaler. The XRGB8888 and RGB565 raw
paths are also unaffected; they still go through the scaler for
real format conversion.
Also tightens the retained-case allocation to
out_width*out_height*3 instead of width*height*3. The old size
was always >= the needed size and never under-allocated, but the
extra bytes were only ever used for savestate thumbnails smaller
than screen dimensions.
Tested: PNG viewport screenshots are byte-identical before and
after the patch (verified with cmp).1 parent 36fe5ab commit 5aabb22
1 file changed
Lines changed: 42 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
102 | 129 | | |
103 | 130 | | |
104 | 131 | | |
| |||
109 | 136 | | |
110 | 137 | | |
111 | 138 | | |
112 | | - | |
113 | | - | |
| 139 | + | |
114 | 140 | | |
115 | 141 | | |
116 | 142 | | |
| |||
431 | 457 | | |
432 | 458 | | |
433 | 459 | | |
434 | | - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
435 | 468 | | |
436 | | - | |
437 | | - | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
438 | 475 | | |
439 | | - | |
440 | 476 | | |
441 | 477 | | |
442 | 478 | | |
| |||
0 commit comments