summaryrefslogtreecommitdiff
path: root/src/fb.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-24 01:19:06 -0800
committerVito Caputo <vcaputo@pengaru.com>2019-11-24 01:19:06 -0800
commit53cc747fd2bdd774bc6f27f8aca5749c664b5cc7 (patch)
treeb786391e503379d539919657f01ea9eafd28292b /src/fb.h
parent6bfd66051632fdb8eca4103df2c3c67492d28af7 (diff)
fb: add pitch to fb_fragment_t
The put_pixel helpers really needed reworking to properly handle subframe fragments modules like montage will utilize. I had the stride present as it's convenient for a number of modules that maintain a buf pointer as they progress down a row, but the pitch is more applicable to put_pixel for scaling the y coordinate. Now there's both pitch and stride so everyone's happy with what's most convenient for their needs.
Diffstat (limited to 'src/fb.h')
-rw-r--r--src/fb.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/fb.h b/src/fb.h
index f9d0b77..dfd4550 100644
--- a/src/fb.h
+++ b/src/fb.h
@@ -17,6 +17,7 @@ typedef struct fb_fragment_t {
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 */
} fb_fragment_t;
/* This is a page handle object for page flip submission/life-cycle.
@@ -67,10 +68,9 @@ static inline int fb_fragment_contains(fb_fragment_t *fragment, int x, int y)
/* puts a pixel into the fragment, no bounds checking is performed. */
static inline void fb_fragment_put_pixel_unchecked(fb_fragment_t *fragment, int x, int y, uint32_t pixel)
{
- uint32_t *pixels = fragment->buf;
+ uint32_t *pixels = ((void *)fragment->buf) + (y - fragment->y) * fragment->pitch;
- /* FIXME this assumes stride is aligned to 4 */
- pixels[((y - fragment->y) * (fragment->width + (fragment->stride >> 2))) + (x - fragment->x)] = pixel;
+ pixels[x - fragment->x] = pixel;
}
@@ -89,7 +89,11 @@ static inline int fb_fragment_put_pixel_checked(fb_fragment_t *fragment, int x,
/* zero a fragment */
static inline void fb_fragment_zero(fb_fragment_t *fragment)
{
- memset(fragment->buf, 0, ((fragment->width << 2) + fragment->stride) * fragment->height);
+ void *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)
+ memset(buf, 0, fragment->pitch - fragment->stride);
}
#endif
© All Rights Reserved