diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-04-27 13:46:04 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-04-27 13:46:04 -0700 |
commit | c881616cfbbd8c20d67f469d363254b2c56a12b7 (patch) | |
tree | e3366155b36d06bf49441746d98912988f6ad9c6 /src/til_fb.h | |
parent | 0f16aad8e0f51b8259b9a8c0a5bac26fcf8b3ef5 (diff) |
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.
Diffstat (limited to 'src/til_fb.h')
-rw-r--r-- | src/til_fb.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/til_fb.h b/src/til_fb.h index 6dd0975..55e9b6c 100644 --- a/src/til_fb.h +++ b/src/til_fb.h @@ -17,8 +17,8 @@ typedef struct til_fb_fragment_t { unsigned width, height; /* width and height of this fragment */ unsigned frame_width; /* width of the frame this fragment is part of */ unsigned frame_height; /* height of the frame this fragment is part of */ - unsigned stride; /* number of bytes from the end of one row to the start of the next */ - unsigned pitch; /* number of bytes separating y from y + 1, including any padding */ + unsigned stride; /* number of 32-bit words from the end of one row to the start of the next */ + unsigned pitch; /* number of 32-bit words separating y from y + 1, including any padding */ unsigned number; /* this fragment's number as produced by fragmenting */ unsigned cleared:1; /* if this fragment has been cleared since last flip */ } til_fb_fragment_t; @@ -73,7 +73,7 @@ static inline int til_fb_fragment_contains(til_fb_fragment_t *fragment, int x, i /* puts a pixel into the fragment, no bounds checking is performed. */ static inline void til_fb_fragment_put_pixel_unchecked(til_fb_fragment_t *fragment, int x, int y, uint32_t pixel) { - uint32_t *pixels = ((void *)fragment->buf) + (y - fragment->y) * fragment->pitch; + uint32_t *pixels = fragment->buf + (y - fragment->y) * fragment->pitch; pixels[x - fragment->x] = pixel; } @@ -94,13 +94,13 @@ static inline int til_fb_fragment_put_pixel_checked(til_fb_fragment_t *fragment, /* fill a fragment with an arbitrary pixel */ static inline void til_fb_fragment_fill(til_fb_fragment_t *fragment, uint32_t pixel) { - void *buf = fragment->buf; + uint32_t *buf = fragment->buf; /* TODO: there should be a fast-path for non-divided fragments where there's no stride to skip */ for (int y = 0; y < fragment->height; y++, buf += fragment->pitch) { /* TODO: this should use something memset-like for perf */ for (int x = 0; x < fragment->width; x++) - ((uint32_t *)buf)[x] = pixel; + buf[x] = pixel; } } |