From c2e4a7977349f5b4b69cc39829c50512a9503f15 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 3 Feb 2017 13:01:00 -0800 Subject: fb: add fragment bounds checking helper Simple x,y coordinate check --- src/fb.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/fb.h') diff --git a/src/fb.h b/src/fb.h index 13f6bcd..64f657b 100644 --- a/src/fb.h +++ b/src/fb.h @@ -34,4 +34,13 @@ void fb_get_put_pages_count(fb_t *fb, unsigned *count); fb_t * fb_new(int drm_fd, uint32_t crtc_id, uint32_t *connectors, int n_connectors, drmModeModeInfoPtr mode, int n_pages); void fb_fragment_divide(fb_fragment_t *fragment, unsigned n_fragments, fb_fragment_t fragments[]); +static inline int fb_fragment_contains(fb_fragment_t *fragment, int x, int y) +{ + if (x < fragment->x || x >= fragment->x + fragment->width || + y < fragment->y || y >= fragment->y + fragment->height) + return 0; + + return 1; +} + #endif -- cgit v1.2.3 From 1a330772b827364471dbe02b417c14fb42838c2d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 3 Feb 2017 15:23:50 -0800 Subject: fb: add pixel drawing helpers Modules seem to be duplicating this, just pull it into fb.h since we're already dependent on the fb.h abstractions in the modules. Slippery slope! --- src/fb.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/fb.h') diff --git a/src/fb.h b/src/fb.h index 64f657b..b990ae6 100644 --- a/src/fb.h +++ b/src/fb.h @@ -34,6 +34,8 @@ void fb_get_put_pages_count(fb_t *fb, unsigned *count); fb_t * fb_new(int drm_fd, uint32_t crtc_id, uint32_t *connectors, int n_connectors, drmModeModeInfoPtr mode, int n_pages); void fb_fragment_divide(fb_fragment_t *fragment, unsigned n_fragments, fb_fragment_t fragments[]); + +/* checks if a coordinate is contained within a fragment */ static inline int fb_fragment_contains(fb_fragment_t *fragment, int x, int y) { if (x < fragment->x || x >= fragment->x + fragment->width || @@ -43,4 +45,26 @@ static inline int fb_fragment_contains(fb_fragment_t *fragment, int x, int y) return 1; } + +/* 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; + + /* FIXME this assumes stride is aligned to 4 */ + pixels[(y * (fragment->width + (fragment->stride >> 2))) + x] = pixel; +} + + +/* puts a pixel into the fragment, bounds checking is performed with a draw performed return status */ +static inline int fb_fragment_put_pixel_checked(fb_fragment_t *fragment, int x, int y, uint32_t pixel) +{ + if (!fb_fragment_contains(fragment, x, y)) + return 0; + + fb_fragment_put_pixel_unchecked(fragment, x, y, pixel); + + return 1; +} + #endif -- cgit v1.2.3 From e0619c5dfa3bc90c2c241f8e330bf4a76a5a003d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 3 Feb 2017 16:12:23 -0800 Subject: fb: add fb_fragment_zero() helper Currently just a memset wrapper... but maybe could get noop'd if the flipper thread started supporting pre-zeroing pages in its thread, just need a zeroed state in the fb page. --- src/fb.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/fb.h') diff --git a/src/fb.h b/src/fb.h index b990ae6..e8d818f 100644 --- a/src/fb.h +++ b/src/fb.h @@ -2,6 +2,7 @@ #define _FB_H #include +#include #include #include /* for drmModeModeInfoPtr */ @@ -67,4 +68,11 @@ static inline int fb_fragment_put_pixel_checked(fb_fragment_t *fragment, int x, return 1; } + +/* zero a fragment */ +static inline void fb_fragment_zero(fb_fragment_t *fragment) +{ + memset(fragment->buf, 0, ((fragment->width << 2) + fragment->stride) * fragment->height); +} + #endif -- cgit v1.2.3