summaryrefslogtreecommitdiff
path: root/src/drm_fb.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-04-27 13:46:04 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-04-27 13:46:04 -0700
commitc881616cfbbd8c20d67f469d363254b2c56a12b7 (patch)
treee3366155b36d06bf49441746d98912988f6ad9c6 /src/drm_fb.c
parent0f16aad8e0f51b8259b9a8c0a5bac26fcf8b3ef5 (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/drm_fb.c')
-rw-r--r--src/drm_fb.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/drm_fb.c b/src/drm_fb.c
index 328c92c..927f46c 100644
--- a/src/drm_fb.c
+++ b/src/drm_fb.c
@@ -476,6 +476,12 @@ static void * drm_fb_page_alloc(til_fb_t *fb, void *context, til_fb_page_t *res_
pexit_if(drmModeAddFB(c->drm_fd, c->mode->hdisplay, c->mode->vdisplay, 24, 32, create_dumb.pitch, create_dumb.handle, &fb_id) < 0,
"unable to add dumb buffer");
+ /* prevent unaligned pitches, we're just simplifying everything in rototiller that wants
+ * to do word-at-a-time operations without concern for arches that get angry when that happens
+ * on unaligned addresses.
+ */
+ assert(!(create_dumb.pitch & 0x3));
+
p->mmap = map;
p->mmap_size = create_dumb.size;
p->drm_dumb_handle = map_dumb.handle;
@@ -486,8 +492,8 @@ static void * drm_fb_page_alloc(til_fb_t *fb, void *context, til_fb_page_t *res_
res_page->fragment.frame_width = c->mode->hdisplay;
res_page->fragment.height = c->mode->vdisplay;
res_page->fragment.frame_height = c->mode->vdisplay;
- res_page->fragment.stride = create_dumb.pitch - (c->mode->hdisplay * 4);
- res_page->fragment.pitch = create_dumb.pitch;
+ res_page->fragment.pitch = create_dumb.pitch >> 2;
+ res_page->fragment.stride = res_page->fragment.pitch - (c->mode->hdisplay);
return p;
}
© All Rights Reserved