Commit d197d89
committed
gl1/gl2/gl3: fix screenshot corruption in video_frame_convert_rgba_to_bgr
The RGBA-to-BGR24 helper used by the GL drivers' read-viewport /
screenshot path had two bugs:
1. The helper signature took only a single `width` parameter and
walked a tightly-packed source. Three of the four call sites
passed `vp.width * vp.height` (total pixel count) as that
`width`, which caused the inner loop to read past the end of the
region glReadPixels actually wrote.
2. The fourth site (gl2 GLES3 async path) iterated `vp.height`
times in an outer loop but always re-converted the same first
row of the source, dropping rows 1..N-1 entirely.
The underlying mismatch is that the readback buffer is allocated at
`vp.width * vp.height` but glReadPixels in each driver clamps its
read to `min(vp.{w,h}, video_{width,height})` (see
gl1_readback at gl1.c:1508-1509, gl2_renderchain_readback, and
gl3's sync readback). When the viewport is larger than the
current video output size -- common during resize, fullscreen
toggles, or when the frontend viewport exceeds the backing store --
the trailing bytes of the allocation are uninitialized and there
are fewer written bytes per row than `vp.width * 4`.
Fix:
- Change `video_frame_convert_rgba_to_bgr` to take explicit
`src_pitch`, `dst_pitch`, `width`, and `height`, looping both
axes. The function remains pure and `static INLINE`.
- At each of the four call sites compute
`rb_w = min(vp.w, video_w)` and `rb_h = min(vp.h, video_h)`,
then pass `rb_w * 4`, `rb_w * 3`, `rb_w`, `rb_h` to the helper.
For gl2 and gl3 the clamp uses `gl->video_width` / `video_height`,
which are cached copies of `video_driver_get_size()` set at init
and on context reset. For gl1 the same-named struct fields hold
the *core's* emulated frame size (assigned from `frame_width` at
gl1.c:1581-1582), not the window size, so the gl1 site calls
`video_driver_get_size()` directly to reconstruct the same value
glReadPixels saw. This mirrors the pattern already used in
`gl1_viewport_info` (gl1.c:1950). Screenshots are not a hot path,
so the extra mutex acquisition is negligible.
No external in-tree callers of the helper remain; verified by
grep across the source tree.1 parent 39c4f24 commit d197d89
4 files changed
Lines changed: 79 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1976 | 1976 | | |
1977 | 1977 | | |
1978 | 1978 | | |
1979 | | - | |
1980 | | - | |
1981 | | - | |
1982 | | - | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
1983 | 2001 | | |
1984 | 2002 | | |
1985 | 2003 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2331 | 2331 | | |
2332 | 2332 | | |
2333 | 2333 | | |
2334 | | - | |
2335 | | - | |
2336 | | - | |
2337 | | - | |
2338 | | - | |
2339 | | - | |
2340 | | - | |
2341 | | - | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
2342 | 2347 | | |
2343 | 2348 | | |
2344 | 2349 | | |
| |||
2381 | 2386 | | |
2382 | 2387 | | |
2383 | 2388 | | |
2384 | | - | |
2385 | | - | |
2386 | | - | |
2387 | | - | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
2388 | 2404 | | |
2389 | 2405 | | |
2390 | 2406 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3651 | 3651 | | |
3652 | 3652 | | |
3653 | 3653 | | |
3654 | | - | |
3655 | | - | |
3656 | | - | |
3657 | | - | |
| 3654 | + | |
| 3655 | + | |
| 3656 | + | |
| 3657 | + | |
| 3658 | + | |
| 3659 | + | |
| 3660 | + | |
| 3661 | + | |
| 3662 | + | |
| 3663 | + | |
| 3664 | + | |
| 3665 | + | |
| 3666 | + | |
| 3667 | + | |
3658 | 3668 | | |
3659 | 3669 | | |
3660 | 3670 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
189 | 192 | | |
190 | | - | |
191 | | - | |
| 193 | + | |
| 194 | + | |
192 | 195 | | |
193 | 196 | | |
194 | | - | |
| 197 | + | |
195 | 198 | | |
196 | | - | |
197 | | - | |
198 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
199 | 207 | | |
200 | 208 | | |
201 | 209 | | |
| |||
0 commit comments