From 6a99f56239d5e9f04188ca96f1c3058ebaf13a72 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 29 May 2020 21:26:27 -0700 Subject: libstage: expose struct stage_t size publicly The existing stage.h has been renamed to stage-public.h, and stage.h is now generated as part of the build. The generated stage.h now declares a padded struct stage_t after including the original stage.h as stage-public.h. The real struct stage_t has moved out of stage.c into stage-private.h, which is very similar to the generated stage.h but declares a the real struct stage_t instaed of the padded one. The internal code while building libstage.a simply includes stage-private.h to get the real struct and everything from stage-public.h. My main annoyance with this approach is it leaves stage.h and libstage.a in @top_builddir@/src, but stage-public.h at @top_srcdir@/src. I generally use this library in a vendored form, without performing any `make install` step. Currently, when I use it, my outer autotools project vendoring this library adds -I@top_srcdir@/libstage/src to get the headers, and it looks like it will need to *add* -I@top_builddir@/libstage/src to get the generated stage.h while keeping the -I@top_srcdir@/libstage/src for stage-public.h. Sigh, there's probably a simple way to make the build simply copy the stage-public.h to @top_builddir@/src. I made some experiments with that, and at least when using the same filename, it seemed to get confused because the file existed in @top_srcdir@/src despite being in BUILT_SOURCES and CLEANFILES, and it tended to clobber the copy in @top_srcdir@/src. Leaving that as a TODO for a future day. --- src/Makefile.am | 13 ++++++++++- src/stage-private.h | 23 +++++++++++++++++++ src/stage-public.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/stage.c | 20 +---------------- src/stage.h | 64 ----------------------------------------------------- 5 files changed, 100 insertions(+), 84 deletions(-) create mode 100644 src/stage-private.h create mode 100644 src/stage-public.h delete mode 100644 src/stage.h diff --git a/src/Makefile.am b/src/Makefile.am index de38d5f..400a0fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,14 @@ noinst_LIBRARIES = libstage.a -libstage_a_SOURCES = ../include/dll_h/dll.h stage.c stage.h +noinst_PROGRAMS = stage-header + +libstage_a_SOURCES = ../include/dll_h/dll.h stage-private.h stage-public.h stage.c libstage_a_CPPFLAGS = -I@top_srcdir@/include + +stage_header_SOURCES = ../include/dll_h/dll.h stage-private.h stage-header.c +stage_header_CPPFLAGS = -I@top_srcdir@/include + +BUILT_SOURCES = stage.h +CLEANFILES = stage.h + +stage.h: Makefile stage-header + @top_builddir@/src/stage-header >$@ diff --git a/src/stage-private.h b/src/stage-private.h new file mode 100644 index 0000000..ac045a4 --- /dev/null +++ b/src/stage-private.h @@ -0,0 +1,23 @@ +#ifndef _STAGE_PRIVATE_H +#define _STAGE_PRIVATE_H + +#include + +#include "stage-public.h" + +struct stage_t { + stage_t *parent; /* NULL when root stage */ + dll_t layer; /* node on parent->layers[layer] when parent != NULL */ + dll_t layers[STAGE_LAYERS_MAX]; + char name[STAGE_NAME_MAX]; + float alpha; /* alpha for the stage */ + unsigned active:1; /* stage is active */ + unsigned locked:1; /* stage is locked */ + unsigned dirty:1; /* stage is dirty (since last render) */ + unsigned allocated:1; /* stage is allocated by libstage, needs freeing. */ + + const stage_ops_t *ops; /* ops for operating on this stage's object */ + void *object; /* this stage's object */ +}; + +#endif diff --git a/src/stage-public.h b/src/stage-public.h new file mode 100644 index 0000000..d7bd4fe --- /dev/null +++ b/src/stage-public.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018-2019 - Vito Caputo - + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _STAGE_PUBLIC_H +#define _STAGE_PUBLIC_H + +#define STAGE_NAME_MAX 16 +#define STAGE_LAYERS_MAX 10 + +typedef struct stage_t stage_t; + +typedef void (stage_prepare_func_t)(stage_t *stage, void *object, float alpha, void *render_ctxt); +typedef void (stage_render_func_t)(const stage_t *stage, void *object, float alpha, void *render_ctxt); +typedef void (stage_free_func_t)(const stage_t *stage, void *object); + +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_ops_t; + +typedef struct stage_conf_t { + stage_t *parent, *stage; + int layer; + const char *name; + float alpha; + unsigned active:1; + unsigned locked:1; + unsigned dirty:1; + unsigned replace:1; +} stage_conf_t; + +stage_t * stage_new(const stage_conf_t *conf, const stage_ops_t *ops, void *object); +stage_t * 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); +void stage_clear(stage_t *stage); +void stage_set_object(stage_t *stage, void *object); +void * stage_get_object(const stage_t *stage); +void stage_set_alpha(stage_t *stage, float alpha); +float stage_get_alpha(const stage_t *stage); +void stage_set_active(stage_t *stage, int active); +int stage_get_active(const stage_t *stage); +void stage_set_locked(stage_t *stage, int locked); +int stage_get_locked(const stage_t *stage); +void stage_set_layer(stage_t *stage, int layer); +stage_t * stage_lookup_name(stage_t *stage, const char *name); + +#endif diff --git a/src/stage.c b/src/stage.c index a714f1f..106186e 100644 --- a/src/stage.c +++ b/src/stage.c @@ -18,25 +18,7 @@ #include #include -#include - -#include "stage.h" - - -struct stage_t { - stage_t *parent; /* NULL when root stage */ - dll_t layer; /* node on parent->layers[layer] when parent != NULL */ - dll_t layers[STAGE_LAYERS_MAX]; - char name[STAGE_NAME_MAX]; - float alpha; /* alpha for the stage */ - unsigned active:1; /* stage is active */ - unsigned locked:1; /* stage is locked */ - unsigned dirty:1; /* stage is dirty (since last render) */ - unsigned allocated:1; /* stage is allocated by libstage, needs freeing. */ - - const stage_ops_t *ops; /* ops for operating on this stage's object */ - void *object; /* this stage's object */ -}; +#include "stage-private.h" /* minimally initialize a stage to carry an object */ diff --git a/src/stage.h b/src/stage.h deleted file mode 100644 index 40f2057..0000000 --- a/src/stage.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2018-2019 - Vito Caputo - - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3 as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef _STAGE_H -#define _STAGE_H - -#define STAGE_NAME_MAX 16 -#define STAGE_LAYERS_MAX 10 - -typedef struct stage_t stage_t; - -typedef void (stage_prepare_func_t)(stage_t *stage, void *object, float alpha, void *render_ctxt); -typedef void (stage_render_func_t)(const stage_t *stage, void *object, float alpha, void *render_ctxt); -typedef void (stage_free_func_t)(const stage_t *stage, void *object); - -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_ops_t; - -typedef struct stage_conf_t { - stage_t *parent, *stage; - int layer; - const char *name; - float alpha; - unsigned active:1; - unsigned locked:1; - unsigned dirty:1; - unsigned replace:1; -} stage_conf_t; - -stage_t * stage_new(const stage_conf_t *conf, const stage_ops_t *ops, void *object); -stage_t * 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); -void stage_clear(stage_t *stage); -void stage_set_object(stage_t *stage, void *object); -void * stage_get_object(const stage_t *stage); -void stage_set_alpha(stage_t *stage, float alpha); -float stage_get_alpha(const stage_t *stage); -void stage_set_active(stage_t *stage, int active); -int stage_get_active(const stage_t *stage); -void stage_set_locked(stage_t *stage, int locked); -int stage_get_locked(const stage_t *stage); -void stage_set_layer(stage_t *stage, int layer); -stage_t * stage_lookup_name(stage_t *stage, const char *name); - -#endif -- cgit v1.2.3