From 71c5db7476d8deadfa785570ae63732445b10e85 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 27 Aug 2019 11:34:27 -0700 Subject: 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. --- src/stage.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/stage.h') 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); -- cgit v1.2.3