Commit e976983
committed
gfx/vita2d: fix broken size-change check and replace per-pixel copy with per-row memcpy
vita2d_set_texture_frame had two separate bugs in its menu-texture
update path:
1. Broken size-change check. The recreate condition was
if ((width != vita->menu.width)
&& (height != vita->menu.height)
&& vita->menu.texture)
with && between the dimension comparisons. That only recreates the
texture when BOTH dimensions change. If a resize flips only one
dimension (e.g. 480x272 -> 480x544 on a portrait-mode menu toggle,
or a width-only change on menu-size setting updates), the old
texture stays in place but the per-pixel writes below run with the
new dimensions - indexing past the old allocation when the new
size is larger, or leaving stale border pixels when it is smaller.
Change the operator to || so either dimension change triggers a
recreate. Also hoist the 'vita->menu.texture' truthiness check to
the front of the expression so the short-circuit is: 'no texture
to free anyway -> skip the whole branch', which reads more
naturally than the old ordering.
2. Per-pixel copy. Both the rgb32 and rgb16 branches wrote the frame
into the texture one pixel at a time inside a double loop:
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
tex32[j + i*stride] = frame32[j + i*width];
The destination texture's stride can legitimately differ from the
source pitch (width * bpp) for alignment reasons, so a single
memcpy of the whole buffer is not correct, but a per-row memcpy
handles that case and is straightforwardly faster than the
per-pixel nested-loop form the compiler has to try hard to
vectorise. Replace with
for (i = 0; i < height; i++)
memcpy(tex + i * stride, frame + i * width, rowlen);
in both branches.
Also clean up the loop-counter type: the original declared 'int i, j'
but compared against 'unsigned height' / 'unsigned width'. Now just
'unsigned i'; j is no longer needed.
Pre-existing not-addressed-here: if rgb32 flips between calls while
the texture dimensions happen to stay the same, the new check (same
as the old one in this respect) does not recreate the texture, so
the texture format and the caller's data format diverge. In current
practice the menu drivers that drive set_texture_frame always pass a
consistent rgb32 for the duration of a session (rgui always passes
false), so this is latent rather than live, and fixing it cleanly
needs a stored 'was_rgb32' flag on vita_menu_t. Deferred.
Thread-safety: unchanged. set_texture_frame and vita2d_frame both
run on the video thread (threaded video) or main thread (non-threaded),
sequentially within the same loop iteration. No synchronisation
introduced or needed. The transient 'NULL texture between free and
recreate' window is present in both the old and new code and is
correctly guarded by the 'if (vita->menu.texture)' check at the
reader in vita2d_frame.1 parent d37d161 commit e976983
1 file changed
Lines changed: 28 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1041 | 1041 | | |
1042 | 1042 | | |
1043 | 1043 | | |
1044 | | - | |
| 1044 | + | |
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1052 | 1060 | | |
1053 | 1061 | | |
1054 | 1062 | | |
| |||
1073 | 1081 | | |
1074 | 1082 | | |
1075 | 1083 | | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
1076 | 1090 | | |
1077 | 1091 | | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1082 | 1095 | | |
| 1096 | + | |
1083 | 1097 | | |
1084 | | - | |
1085 | | - | |
| 1098 | + | |
1086 | 1099 | | |
1087 | 1100 | | |
1088 | 1101 | | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
1093 | 1105 | | |
| 1106 | + | |
1094 | 1107 | | |
1095 | | - | |
1096 | | - | |
| 1108 | + | |
1097 | 1109 | | |
1098 | 1110 | | |
1099 | 1111 | | |
| |||
0 commit comments