Skip to content

Commit 824c8ec

Browse files
remove hot-path branches
1 parent d415b6c commit 824c8ec

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/basic/graphics.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,9 @@ static bool plot_sprite_quad_axis_aligned_int(struct basic_ctx* ctx, int64_t spr
943943
vi = CLAMP(vi, 0, h - 1);
944944

945945
uint32_t src = s->pixels[vi * w + ui];
946-
if ((src & 0xff000000) == 0xff000000) {
947-
*(volatile uint32_t*)(framebuffer + pixel_address(px, py)) = src;
948-
}
946+
uint32_t m = s->mask[vi * w + ui];
947+
volatile uint32_t* dst = (volatile uint32_t*)(framebuffer + pixel_address(px, py));
948+
*dst = (*dst & ~m) | (src & m);
949949

950950
u_fp += dx_u;
951951
v_fp += dx_v;
@@ -1071,6 +1071,7 @@ inline static void draw_strip_projective(dpoint_t L0, dpoint_t L1, dpoint_t S0,
10711071

10721072
/* hoist sprite fields */
10731073
const uint32_t* spx = s->pixels;
1074+
const uint32_t* mask = s->mask;
10741075
const uint64_t sw = s->width;
10751076
const uint64_t sh = s->height;
10761077
const double umin = -0.5, vmin = -0.5, umax = (double)sw + 0.5, vmax = (double)sh + 0.5;
@@ -1149,9 +1150,10 @@ inline static void draw_strip_projective(dpoint_t L0, dpoint_t L1, dpoint_t S0,
11491150

11501151
if (ui < sw && vi < sh) {
11511152
uint32_t src = spx[vi * sw + ui];
1152-
if ((src & 0xff000000) == 0xff000000) {
1153-
*(volatile uint32_t*)(framebuffer + pixel_address(x, y)) = src;
1154-
}
1153+
uint32_t m = mask[vi * sw + ui];
1154+
1155+
volatile uint32_t* dst = (volatile uint32_t*)(framebuffer + pixel_address(x, y));
1156+
*dst = (*dst & ~m) | (src & m);
11551157
}
11561158
}
11571159

0 commit comments

Comments
 (0)