diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2017-02-08 20:03:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 20:03:38 -0800 |
commit | 8563edd058bb5e564b5e6c2bafde6636b3fce6ee (patch) | |
tree | d3232ac628eee1517e258d9b512b0f9a838e9f02 /src/fb.h | |
parent | 9d032314e9db794dc88889bc24bf50bbafc3ec8d (diff) | |
parent | b35ba71b6de341f7b87beb3bc078600f3d191612 (diff) |
Consolidate fb_fragment_t interactions
sparkler and stars both cleared fragments and drew individual pixels into fragments, add that functionality to fb.h and cleanup sparkler and stars accordingly.
Diffstat (limited to 'src/fb.h')
-rw-r--r-- | src/fb.h | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -2,6 +2,7 @@ #define _FB_H #include <stdint.h> +#include <string.h> #include <sys/types.h> #include <xf86drmMode.h> /* for drmModeModeInfoPtr */ @@ -34,4 +35,44 @@ 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 || + y < fragment->y || y >= fragment->y + fragment->height) + return 0; + + 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; +} + + +/* 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 |