diff options
| author | Vito Caputo <vcaputo@pengaru.com> | 2019-08-27 11:34:27 -0700 |
|---|---|---|
| committer | Vito Caputo <vcaputo@pengaru.com> | 2019-08-27 11:34:27 -0700 |
| commit | 71c5db7476d8deadfa785570ae63732445b10e85 (patch) | |
| tree | e39c31097505eb59daed6d675126bf619e356a0b /src/stage.h | |
| parent | 83a324a7d4a2c3e0a75148c918171b14f77dd371 (diff) | |
libstage: encapsulate stage funs in an ops struct
Introduces stage_ops_t, tidying up stage_new() users.
For now the stage_t simply references the passed in ops struct, so the
caller must ensure its lifetime survives the referencing stages. That
may be annoying if callers tend to construct them as compound literals
at the call site, but I don't expect that to be too onerous to avoid.
Diffstat (limited to 'src/stage.h')
| -rw-r--r-- | src/stage.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/stage.h b/src/stage.h index 86d2311..a73a5d9 100644 --- a/src/stage.h +++ b/src/stage.h @@ -27,22 +27,25 @@ typedef void (stage_render_func_t)(const stage_t *stage, void *object, float alp typedef void (stage_free_func_t)(const stage_t *stage, void *object); typedef stage_t * (stage_lookup_func_t)(const stage_t *stage, void *object, void *key); +typedef struct stage_ops_t { + stage_prepare_func_t *prepare_func; /* pre-render object */ + stage_render_func_t *render_func; /* render object */ + stage_free_func_t *free_func; /* free object */ + stage_lookup_func_t *lookup_func; /* lookup object against key */ +} stage_ops_t; + typedef struct stage_conf_t { stage_t *parent; int layer; const char *name; - void *object; - stage_prepare_func_t *prepare_func; - stage_render_func_t *render_func; - stage_free_func_t *free_func; - stage_lookup_func_t *lookup_func; float alpha; unsigned active:1; unsigned locked:1; } stage_conf_t; -stage_t * stage_new(const stage_conf_t *conf); -void stage_replace(stage_t *stage, const char *name, void *object, stage_prepare_func_t *prepare_func, stage_render_func_t *render_func, stage_free_func_t *free_func, stage_lookup_func_t *lookup_func); +stage_t * stage_new(const stage_conf_t *conf, const stage_ops_t *ops, void *object); +void stage_replace(stage_t *stage, const char *name, const stage_ops_t *ops, void *object); + stage_t * stage_free(stage_t *stage); int stage_render(stage_t *stage, void *render_ctxt); void stage_dirty(stage_t *stage); |
