summaryrefslogtreecommitdiff
path: root/src/modules/roto
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-05 17:49:29 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-05 17:49:29 -0700
commit2ab12c50fc7fa83905ee5668a725e16e3b29705f (patch)
treeca163726c6c5d51d8a5de137f6e5a4b576751383 /src/modules/roto
parent2fd7ee3a6bd25af499556810e185bffe9a6a9de3 (diff)
modules/roto: til_module_setup_full() for fill_module=
Switch to the generic til_module_setup_full() and rely on the "none" builtin's NULL res_setup on finalize to indicate when no fill_module is desired. This gets rid of the need for a separate til_module_t* handle for the fill_module, since til_setup_t.creator can be used for that, and the NULL til_setup_t* to indicate no fill_module. Basically discards some busy work style code, there's more cleanups needed surrounding this stuff though. More or less identical to the previous change to modules/checkers.
Diffstat (limited to 'src/modules/roto')
-rw-r--r--src/modules/roto/roto.c85
1 files changed, 33 insertions, 52 deletions
diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c
index d60629c..f69d010 100644
--- a/src/modules/roto/roto.c
+++ b/src/modules/roto/roto.c
@@ -20,7 +20,8 @@
#define FIXED_NEW(_i) ((_i) << FIXED_BITS)
#define FIXED_TO_INT(_f) ((_f) >> FIXED_BITS)
-#define ROTO_TEXTURE_SIZE 256
+#define ROTO_TEXTURE_SIZE 256
+#define ROTO_DEFAULT_FILL_MODULE "none"
typedef struct color_t {
int r, g, b;
@@ -37,7 +38,6 @@ typedef struct roto_context_t {
typedef struct roto_setup_t {
til_setup_t til_setup;
- const til_module_t *fill_module;
til_setup_t *fill_module_setup;
} roto_setup_t;
@@ -88,8 +88,8 @@ static til_module_context_t * roto_create_context(const til_module_t *module, ti
if (!ctxt)
return NULL;
- if (((roto_setup_t *)setup)->fill_module) {
- const til_module_t *module = ((roto_setup_t *)setup)->fill_module;
+ if (((roto_setup_t *)setup)->fill_module_setup) {
+ const til_module_t *module = ((roto_setup_t *)setup)->fill_module_setup->creator;
if (til_module_create_contexts(module,
stream,
@@ -419,6 +419,19 @@ static void roto_setup_free(til_setup_t *setup)
}
+static int roto_fill_module_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
+{
+ return til_module_setup_full(settings,
+ res_setting,
+ res_desc,
+ res_setup,
+ "Fill module name",
+ ROTO_DEFAULT_FILL_MODULE,
+ (TIL_MODULE_EXPERIMENTAL | TIL_MODULE_HERMETIC),
+ NULL);
+}
+
+
static int roto_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
@@ -436,9 +449,8 @@ til_module_t roto_module = {
static int roto_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
- const char *fill_module, *fill_module_name;
+ const char *fill_module;
const til_settings_t *fill_module_settings;
- til_setting_t *fill_module_setting;
const char *fill_module_values[] = {
"none",
"blinds",
@@ -473,41 +485,13 @@ static int roto_setup(const til_settings_t *settings, til_setting_t **res_settin
assert((*res_setting)->value_as_nested_settings);
fill_module_settings = (*res_setting)->value_as_nested_settings;
- fill_module_name = til_settings_get_value_by_idx(fill_module_settings, 0, &fill_module_setting);
-
- if (!fill_module_name || !fill_module_setting->desc) {
- r = til_setting_desc_new(fill_module_settings,
- &(til_setting_spec_t){
- .name = "Fill module name",
- .preferred = "none",
- .as_label = 1,
- },
- res_desc);
- if (r < 0)
- return r;
-
- *res_setting = fill_module_name ? fill_module_setting : NULL;
-
- return 1;
- }
-
- if (strcasecmp(fill_module_name, "none")) {
- const til_module_t *mod = til_lookup_module(fill_module_name);
-
- if (!mod) {
- *res_setting = fill_module_setting;
-
- return -EINVAL;
- }
-
- if (mod->setup) {
- r = mod->setup(fill_module_settings, res_setting, res_desc, NULL);
- if (r)
- return r;
- }
- }
-
+ r = roto_fill_module_setup(fill_module_settings,
+ res_setting,
+ res_desc,
+ NULL); /* XXX: note no res_setup, must defer finalize */
+ if (r)
+ return r;
if (res_setup) {
roto_setup_t *setup;
@@ -516,20 +500,17 @@ static int roto_setup(const til_settings_t *settings, til_setting_t **res_settin
if (!setup)
return -ENOMEM;
- if (strcasecmp(fill_module_name, "none")) {
- setup->fill_module = til_lookup_module(fill_module_name);
- if (!setup->fill_module) {
- til_setup_free(&setup->til_setup);
- return -EINVAL;
- }
-
- r = til_module_setup_finalize(setup->fill_module, fill_module_settings, &setup->fill_module_setup);
- if (r < 0) {
- til_setup_free(&setup->til_setup);
- return r;
- }
+ r = roto_fill_module_setup(fill_module_settings,
+ res_setting,
+ res_desc,
+ &setup->fill_module_setup); /* finalize! */
+ if (r < 0) {
+ til_setup_free(&setup->til_setup);
+ return r;
}
+ assert(r == 0);
+
*res_setup = &setup->til_setup;
}
© All Rights Reserved