diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2017-04-22 15:29:49 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2017-04-22 15:29:49 -0700 |
commit | d28ceb85a6b43a503c608116798945baab0e060f (patch) | |
tree | 1a96ae21cbab1ef8fdf831d588fd2c9477fb3f92 /src/rototiller.c | |
parent | 1ff4632e895202c4485818f6e748e773b6fd2859 (diff) |
*: add module context machinery
introduces create_context() and destroy_context() methods, and adds a
'void *context' first parameter to the module methods.
If a module doesn't supply create_context() then NULL is simply passed
around as the context, so trivial modules can continue to only implement
render_fragment().
A subsequent commit will update the modules to encapsulate their global
state in module-specific contexts.
Diffstat (limited to 'src/rototiller.c')
-rw-r--r-- | src/rototiller.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/rototiller.c b/src/rototiller.c index f9cfece..4d84c91 100644 --- a/src/rototiller.c +++ b/src/rototiller.c @@ -57,24 +57,24 @@ static void module_select(int *module) } -static void module_render_page_threaded(rototiller_module_t *module, threads_t *threads, fb_page_t *page) +static void module_render_page_threaded(rototiller_module_t *module, void *context, threads_t *threads, fb_page_t *page) { rototiller_frame_t frame; unsigned i; - module->prepare_frame(threads_num_threads(threads), &page->fragment, &frame); + module->prepare_frame(context, threads_num_threads(threads), &page->fragment, &frame); - threads_frame_submit(threads, &frame, module->render_fragment); + threads_frame_submit(threads, &frame, module->render_fragment, context); threads_wait_idle(threads); } -static void module_render_page(rototiller_module_t *module, threads_t *threads, fb_page_t *page) +static void module_render_page(rototiller_module_t *module, void *context, threads_t *threads, fb_page_t *page) { if (!module->prepare_frame) - return module->render_fragment(&page->fragment); + return module->render_fragment(context, &page->fragment); - module_render_page_threaded(module, threads, page); + module_render_page_threaded(module, context, threads, page); } @@ -87,6 +87,7 @@ int main(int argc, const char *argv[]) threads_t *threads; int module; fb_t *fb; + void *context = NULL; drm_setup(&drm_fd, &drm_crtc_id, &drm_connector_id, &drm_mode); module_select(&module); @@ -97,6 +98,10 @@ int main(int argc, const char *argv[]) pexit_if(!fps_setup(), "unable to setup fps counter"); + exit_if(modules[module]->create_context && + !(context = modules[module]->create_context()), + "unable to create module context"); + pexit_if(!(threads = threads_create()), "unable to create threads"); @@ -106,11 +111,15 @@ int main(int argc, const char *argv[]) fps_print(fb); page = fb_page_get(fb); - module_render_page(modules[module], threads, page); + module_render_page(modules[module], context, threads, page); fb_page_put(fb, page); } threads_destroy(threads); + + if (context) + modules[module]->destroy_context(context); + fb_free(fb); close(drm_fd); |