summaryrefslogtreecommitdiff
path: root/src/modules/snow/snow.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/snow/snow.c')
-rw-r--r--src/modules/snow/snow.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c
index bf0aee0..767459e 100644
--- a/src/modules/snow/snow.c
+++ b/src/modules/snow/snow.c
@@ -4,52 +4,48 @@
#include "til.h"
#include "til_fb.h"
+#include "til_module_context.h"
/* Copyright (C) 2019 - Vito Caputo <vcaputo@pengaru.com> */
/* This implements white noise / snow just using rand() */
typedef union snow_seed_t {
- char __padding[256]; /* prevent seeds sharing a cache-line */
- unsigned seed;
+ char __padding[256]; /* prevent seeds sharing a cache-line */
+ unsigned seed;
} snow_seed_t;
typedef struct snow_context_t {
- unsigned unused;
- snow_seed_t seeds[];
+ til_module_context_t til_module_context;
+ unsigned unused;
+ snow_seed_t seeds[];
} snow_context_t;
-static void * snow_create_context(unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup)
+static til_module_context_t * snow_create_context(unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup)
{
snow_context_t *ctxt;
- ctxt = calloc(1, sizeof(snow_context_t) + n_cpus * sizeof(snow_seed_t));
+ ctxt = til_module_context_new(sizeof(snow_context_t) + n_cpus * sizeof(snow_seed_t), seed, n_cpus);
if (!ctxt)
return NULL;
for (unsigned i = 0; i < n_cpus; i++)
ctxt->seeds[i].seed = rand_r(&seed);
- return ctxt;
+ return &ctxt->til_module_context;
}
-static void snow_destroy_context(void *context)
-{
- free(context);
-}
-
-
-static void snow_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter)
+static void snow_prepare_frame(til_module_context_t *context, unsigned ticks, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter)
{
*res_fragmenter = til_fragmenter_slice_per_cpu;
}
-static void snow_render_fragment(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment)
+static void snow_render_fragment(til_module_context_t *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment)
{
- snow_context_t *ctxt = context;
+ snow_context_t *ctxt = (snow_context_t *)context;
unsigned *seed = &ctxt->seeds[cpu].seed;
for (unsigned y = fragment->y; y < fragment->y + fragment->height; y++) {
@@ -68,7 +64,6 @@ static void snow_render_fragment(void *context, unsigned ticks, unsigned cpu, ti
til_module_t snow_module = {
.create_context = snow_create_context,
- .destroy_context = snow_destroy_context,
.prepare_frame = snow_prepare_frame,
.render_fragment = snow_render_fragment,
.name = "snow",
© All Rights Reserved