diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2017-04-22 12:18:01 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2017-04-22 12:25:56 -0700 |
commit | ce124fe9d2621e52d57fa4d602708bd6ef3b2780 (patch) | |
tree | 0e18058b049c13be2ff4088f0ca2ecb569fb7688 /src/modules/plasma | |
parent | a41ef4dc8a518cb1b07aab1c60176a56fe91abd1 (diff) |
plasma: enable threaded rendering
Same general procedure as the previous commit made to the julia module.
Diffstat (limited to 'src/modules/plasma')
-rw-r--r-- | src/modules/plasma/plasma.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c index 26b38c2..8c3e921 100644 --- a/src/modules/plasma/plasma.c +++ b/src/modules/plasma/plasma.c @@ -21,6 +21,8 @@ typedef struct color_t { int r, g, b; } color_t; +static int32_t costab[FIXED_TRIG_LUT_SIZE], sintab[FIXED_TRIG_LUT_SIZE]; +static unsigned rr; static inline uint32_t color2pixel(color_t *color) { @@ -40,24 +42,34 @@ static void init_plasma(int32_t *costab, int32_t *sintab) } +/* Prepare a frame for concurrent drawing of fragment using multiple fragments */ +static void plasma_prepare_frame(unsigned n_cpus, fb_fragment_t *fragment, rototiller_frame_t *res_frame) +{ + static int initialized; + + if (!initialized) { + initialized = 1; + + init_plasma(costab, sintab); + } + + res_frame->n_fragments = n_cpus; + fb_fragment_divide(fragment, n_cpus, res_frame->fragments); + + rr += 3; +} + + /* Draw a plasma effect */ static void plasma_render_fragment(fb_fragment_t *fragment) { - static int32_t costab[FIXED_TRIG_LUT_SIZE], sintab[FIXED_TRIG_LUT_SIZE]; - static int initialized; - static unsigned rr, rr2, rr6, rr8, rr16, rr20, rr12; unsigned stride = fragment->stride / 4, width = fragment->width, height = fragment->height; int fw2 = FIXED_NEW(width / 2), fh2 = FIXED_NEW(height / 2); int x, y, cx, cy, dx2, dy2; uint32_t *buf = fragment->buf; color_t c = { .r = 0, .g = 0, .b = 0 }, cscale; - - if (!initialized) { - initialized = 1; - - init_plasma(costab, sintab); - } + unsigned rr2, rr6, rr8, rr16, rr20, rr12; rr2 = rr * 2; rr6 = rr * 6; @@ -74,14 +86,14 @@ static void plasma_render_fragment(fb_fragment_t *fragment) cx = FIXED_TO_INT(FIXED_MULT(FIXED_COS(rr), fw2) + fw2); cy = FIXED_TO_INT(FIXED_MULT(FIXED_SIN(rr2), fh2) + fh2); - for (y = 0; y < height; y++) { + for (y = fragment->y; y < fragment->y + height; y++) { int y2 = y << 1; int y4 = y << 2; dy2 = cy - y; dy2 *= dy2; - for (x = 0; x < width; x++, buf++) { + for (x = fragment->x; x < fragment->x + width; x++, buf++) { int v; int hyp; @@ -113,14 +125,13 @@ static void plasma_render_fragment(fb_fragment_t *fragment) buf += stride; } - - rr += 3; } rototiller_module_t plasma_module = { + .prepare_frame = plasma_prepare_frame, .render_fragment = plasma_render_fragment, .name = "plasma", - .description = "Oldskool plasma effect", + .description = "Oldskool plasma effect (threaded)", .author = "Vito Caputo <vcaputo@pengaru.com>", .license = "GPLv2", }; |