From 8d54ec8249add0942e5cc989d1cb1b4d9a9aba2e Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 14 Sep 2017 17:48:42 -0700 Subject: fb: implement a tiling fragmenter --- src/fb.c | 34 ++++++++++++++++++++++++++++++++++ src/fb.h | 1 + 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/fb.c b/src/fb.c index c3ed1ed..250bd37 100644 --- a/src/fb.c +++ b/src/fb.c @@ -342,3 +342,37 @@ int fb_fragment_divide_single(const fb_fragment_t *fragment, unsigned n_fragment return 1; } + + +int fb_fragment_tile_single(const fb_fragment_t *fragment, unsigned tile_size, unsigned num, fb_fragment_t *res_fragment) +{ + unsigned w = fragment->width / tile_size, h = fragment->height / tile_size; + unsigned pitch = (fragment->width * 4) + fragment->stride; + unsigned x, y, xoff, yoff; + + if (w * tile_size < fragment->width) + w++; + + if (h * tile_size < fragment->height) + h++; + + y = num / w; + if (y >= h) + return 0; + + x = num - (y * w); + + xoff = x * tile_size; + yoff = y * tile_size; + + res_fragment->buf = (void *)fragment->buf + (yoff * pitch) + (xoff * 4); + res_fragment->x = fragment->x + xoff; + res_fragment->y = fragment->y + yoff; + res_fragment->width = MIN(fragment->width - xoff, tile_size); + res_fragment->height = MIN(fragment->height - yoff, tile_size); + res_fragment->frame_width = fragment->frame_width; + res_fragment->frame_height = fragment->frame_height; + res_fragment->stride = fragment->stride + ((fragment->width - res_fragment->width) * 4); + + return 1; +} diff --git a/src/fb.h b/src/fb.h index 35d5865..055c609 100644 --- a/src/fb.h +++ b/src/fb.h @@ -37,6 +37,7 @@ 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[]); int fb_fragment_divide_single(const fb_fragment_t *fragment, unsigned n_fragments, unsigned num, fb_fragment_t *res_fragment); +int fb_fragment_tile_single(const fb_fragment_t *fragment, unsigned tile_size, unsigned num, fb_fragment_t *res_fragment); /* checks if a coordinate is contained within a fragment */ -- cgit v1.2.1