From 4c81b4d185eddba20b514cebd8b0afd6567f603a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 1 May 2022 10:46:32 -0700 Subject: til: introduce "blank" built-in module rtv special-cased handling a nil module to mean clear the fragment, and called this "none" But it really makes more sense for rtv to treat "none" as not doing anything at all for its snow_module - not even blanking. And it would be nice to have a consistent way to express a blank module throughout rototiller, so this introduces a concept of built-in modules accessible only via explicit lookup by name which don't get enumerated via til_get_modules(), as they're inherently uninteresting more utility-oriented modules for use by other modules. For now it's only "blank" that constitutes the built-ins list, but expanding this is only a matter of introducing more modules there. Future commits will rework rtv to use "blank" in place of its current "none", and rtv's "none" will be reworked to represent no snow mechanism at all, obviating the need to specify snow_duration=0,snow_module=none required today. --- src/til.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/til.c b/src/til.c index ce880b3..08a574c 100644 --- a/src/til.c +++ b/src/til.c @@ -103,13 +103,52 @@ void til_shutdown(void) } +static void _blank_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter) +{ + *res_fragmenter = til_fragmenter_slice_per_cpu; +} + + +static void _blank_render_fragment(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment) +{ + til_fb_fragment_clear(fragment); +} + + +static til_module_t _blank_module = { + .prepare_frame = _blank_prepare_frame, + .render_fragment = _blank_render_fragment, + .name = "blank", + .description = "built-in blanker", + .author = "built-in", +}; + + const til_module_t * til_lookup_module(const char *name) { + static const til_module_t *builtins[] = { + &_blank_module, + }; + static struct { + const til_module_t **modules; + size_t n_modules; + } module_lists[] = { + { + builtins, + nelems(builtins), + }, + { modules, + nelems(modules), + } + }; + assert(name); - for (size_t i = 0; i < nelems(modules); i++) { - if (!strcasecmp(name, modules[i]->name)) - return modules[i]; + for (size_t n = 0; n < nelems(module_lists); n++) { + for (size_t i = 0; i < module_lists[n].n_modules; i++) { + if (!strcasecmp(name, module_lists[n].modules[i]->name)) + return module_lists[n].modules[i]; + } } return NULL; -- cgit v1.2.3