From 6d79a0a6e2ca21e2edad552c0c5de2868b5aad4b Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 7 Feb 2021 15:47:52 -0800 Subject: modules/plasma: trivial cleanups - move LUT initialization to context create - minor syntactic changes --- src/modules/plasma/plasma.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/modules/plasma') diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c index 20dc942..04e5b2c 100644 --- a/src/modules/plasma/plasma.c +++ b/src/modules/plasma/plasma.c @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include "fb.h" @@ -29,6 +29,7 @@ typedef struct plasma_context_t { unsigned n_cpus; } plasma_context_t; + static inline uint32_t color2pixel(color_t *color) { return (FIXED_TO_INT(color->r) << 16) | (FIXED_TO_INT(color->g) << 8) | FIXED_TO_INT(color->b); @@ -37,10 +38,8 @@ static inline uint32_t color2pixel(color_t *color) static void init_plasma(int32_t *costab, int32_t *sintab) { - int i; - /* Generate fixed-point cos & sin LUTs. */ - for (i = 0; i < FIXED_TRIG_LUT_SIZE; i++) { + for (int i = 0; i < FIXED_TRIG_LUT_SIZE; i++) { costab[i] = ((cos((double)2*M_PI*i/FIXED_TRIG_LUT_SIZE))*FIXED_EXP); sintab[i] = ((sin((double)2*M_PI*i/FIXED_TRIG_LUT_SIZE))*FIXED_EXP); } @@ -49,6 +48,14 @@ static void init_plasma(int32_t *costab, int32_t *sintab) static void * plasma_create_context(unsigned ticks, unsigned num_cpus) { + static int initialized; + + if (!initialized) { + initialized = 1; + + init_plasma(costab, sintab); + } + return calloc(1, sizeof(plasma_context_t)); } @@ -71,13 +78,6 @@ static int plasma_fragmenter(void *context, const fb_fragment_t *fragment, unsig static void plasma_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter) { plasma_context_t *ctxt = context; - static int initialized; - - if (!initialized) { - initialized = 1; - - init_plasma(costab, sintab); - } *res_fragmenter = plasma_fragmenter; ctxt->n_cpus = n_cpus; @@ -152,6 +152,7 @@ static void plasma_render_fragment(void *context, unsigned ticks, unsigned cpu, } } + rototiller_module_t plasma_module = { .create_context = plasma_create_context, .destroy_context = plasma_destroy_context, -- cgit v1.2.3