diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2017-02-03 15:23:50 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@gnugeneration.com> | 2017-02-03 15:23:50 -0800 |
commit | 1a330772b827364471dbe02b417c14fb42838c2d (patch) | |
tree | 335708f23c689988f22fc972dea592ee77bc31d4 | |
parent | 91e5956932d17de17c0c75be20c834cf7a6c6ed9 (diff) |
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!
-rw-r--r-- | src/fb.h | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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 |