From c881616cfbbd8c20d67f469d363254b2c56a12b7 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 27 Apr 2022 13:46:04 -0700 Subject: til_fb: til_fb_fragment_t.{pitch,stride} uint32_t units Originally it seemed sensible to make these units of bytes, for flexibility reasons. But it's advantageous for everything to be able to assume pixels are always 4-byte/32-bit aligned. Having the stride/pitch be in bytes of units made it theoretically possible to produce unaligned rows of pixels, which would break that assumption. I don't think anything was ever actually producing such things, and I've added some asserts to the {sdl,drm}_fb.c page acquisition code to go fatal on such pages. This change required going through all the modules and get rid of their uint32_t vs. void* dances and other such 1-byte vs. 4-byte scaling arithmetic. Code is simpler now, and probably faster in some cases. And now allows future work to just assume things cna always occur 4-bytes at a time without concern for unaligned accesses. --- src/til_fb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/til_fb.c') diff --git a/src/til_fb.c b/src/til_fb.c index 5a6a956..eb14e27 100644 --- a/src/til_fb.c +++ b/src/til_fb.c @@ -395,12 +395,11 @@ int til_fb_fragment_slice_single(const til_fb_fragment_t *fragment, unsigned n_f { unsigned slice = fragment->height / n_fragments; unsigned yoff = slice * number; - unsigned pitch; if (yoff >= fragment->height) return 0; - res_fragment->buf = ((void *)fragment->buf) + yoff * fragment->pitch; + res_fragment->buf = fragment->buf + yoff * fragment->pitch; res_fragment->x = fragment->x; res_fragment->y = yoff; res_fragment->width = fragment->width; @@ -436,14 +435,14 @@ int til_fb_fragment_tile_single(const til_fb_fragment_t *fragment, unsigned tile xoff = x * tile_size; yoff = y * tile_size; - res_fragment->buf = (void *)fragment->buf + (yoff * fragment->pitch) + (xoff * 4); + res_fragment->buf = fragment->buf + (yoff * fragment->pitch) + (xoff); res_fragment->x = fragment->x + xoff; res_fragment->y = fragment->y + yoff; res_fragment->width = MIN(fragment->width - xoff, tile_size); res_fragment->height = MIN(fragment->height - yoff, tile_size); res_fragment->frame_width = fragment->frame_width; res_fragment->frame_height = fragment->frame_height; - res_fragment->stride = fragment->stride + ((fragment->width - res_fragment->width) * 4); + res_fragment->stride = fragment->stride + (fragment->width - res_fragment->width); res_fragment->pitch = fragment->pitch; res_fragment->number = number; res_fragment->cleared = fragment->cleared; -- cgit v1.2.1