summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-11-30 11:34:15 -0800
committerVito Caputo <vcaputo@pengaru.com>2023-11-30 11:44:14 -0800
commit28d12a899645be09dae7e4cb8c293bf7fc64d6ad (patch)
treead195d50f3d488521add9f81f7fd291fc7d92743
parent97b3dd17c1499c7ffd6d429a01d64ceaed233df2 (diff)
til: wire up til_video_setup_t throughout *_fb
Preparatory commit for aspect ratio settings at the fb layer. This slightly reworks how main::setup_video() integrates the selected fb backend's setup_func to better resemble how the module setup_funcs work now, with more clearly separated settings-building and setup-baking/finalizing phases. Which makes inserting the ratio setting in the middle of the front-end and back-end setup_funcs fairly trivial. Not a fan of all the casts, but there will probably be more helpers introduced to take care of that and make til_video_setup_t more of a first-class thing facilitating the fb stuff.
-rw-r--r--src/drm_fb.c7
-rw-r--r--src/main.c56
-rw-r--r--src/mem_fb.c9
-rw-r--r--src/sdl_fb.c15
-rw-r--r--src/til_fb.c5
-rw-r--r--src/til_fb.h5
6 files changed, 56 insertions, 41 deletions
diff --git a/src/drm_fb.c b/src/drm_fb.c
index 5d7f259..2dd4f98 100644
--- a/src/drm_fb.c
+++ b/src/drm_fb.c
@@ -14,6 +14,7 @@
#include "til_fb.h"
#include "til_settings.h"
#include "til_util.h"
+#include "til_video_setup.h"
/* drm fb backend, everything drm-specific in rototiller resides here. */
typedef struct drm_fb_page_t drm_fb_page_t;
@@ -37,7 +38,7 @@ typedef struct drm_fb_t {
} drm_fb_t;
typedef struct drm_fb_setup_t {
- til_setup_t til_setup;
+ til_video_setup_t til_video_setup;
const char *dev;
const char *connector;
const char *mode;
@@ -330,7 +331,7 @@ static drmModeModeInfo * lookup_mode(drmModeConnector *connector, const char *mo
/* prepare the drm context for use with the supplied settings */
-static int drm_fb_init(const char *title, const til_setup_t *setup, void **res_context)
+static int drm_fb_init(const char *title, const til_video_setup_t *setup, void **res_context)
{
drm_fb_setup_t *s = (drm_fb_setup_t *)setup;
drm_fb_t *c;
@@ -598,7 +599,7 @@ static int drm_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
if (!setup)
return -ENOMEM;
- return til_settings_apply_desc_generators(settings, generators, nelems(generators), &setup->til_setup, res_setting, res_desc, res_setup);
+ return til_settings_apply_desc_generators(settings, generators, nelems(generators), &setup->til_video_setup.til_setup, res_setting, res_desc, res_setup);
}
diff --git a/src/main.c b/src/main.c
index c4e4c4e..df2d219 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,6 +17,7 @@
#include "til_settings.h"
#include "til_stream.h"
#include "til_util.h"
+#include "til_video_setup.h"
#include "fps.h"
#include "setup.h"
@@ -80,14 +81,14 @@ static rototiller_t rototiller;
typedef struct setup_t {
- til_settings_t *module_settings;
- til_setup_t *module_setup;
- til_settings_t *audio_settings;
- til_setup_t *audio_setup;
- til_settings_t *video_settings;
- til_setup_t *video_setup;
- unsigned seed;
- const char *title;
+ til_settings_t *module_settings;
+ til_setup_t *module_setup;
+ til_settings_t *audio_settings;
+ til_setup_t *audio_setup;
+ til_settings_t *video_settings;
+ til_video_setup_t *video_setup;
+ unsigned seed;
+ const char *title;
} setup_t;
/* FIXME: this is unnecessarily copy-pasta, i think modules should just be made
@@ -153,6 +154,7 @@ static int setup_video(const til_settings_t *settings, til_setting_t **res_setti
{
til_setting_t *setting;
const char *video;
+ int r;
video = til_settings_get_value_by_idx(settings, 0, &setting);
if (!video || !setting->desc) {
@@ -166,7 +168,6 @@ static int setup_video(const til_settings_t *settings, til_setting_t **res_setti
#endif
NULL,
};
- int r;
r = til_setting_desc_new( settings,
&(til_setting_spec_t){
@@ -189,26 +190,35 @@ static int setup_video(const til_settings_t *settings, til_setting_t **res_setti
/* XXX: this is kind of hacky for now */
#ifdef HAVE_DRM
- if (!strcasecmp(video, "drm")) {
+ if (!strcasecmp(video, "drm"))
fb_ops = &drm_fb_ops;
-
- return drm_fb_ops.setup(settings, res_setting, res_desc, res_setup);
- }
#endif
- if (!strcasecmp(video, "mem")) {
+ if (!strcasecmp(video, "mem"))
fb_ops = &mem_fb_ops;
-
- return mem_fb_ops.setup(settings, res_setting, res_desc, res_setup);
- }
#ifdef HAVE_SDL
- if (!strcasecmp(video, "sdl")) {
+ if (!strcasecmp(video, "sdl"))
fb_ops = &sdl_fb_ops;
+#endif
+ if (!fb_ops) {
+ *res_setting = setting;
+ return -EINVAL;
+ }
- return sdl_fb_ops.setup(settings, res_setting, res_desc, res_setup);
+ r = fb_ops->setup(settings, res_setting, res_desc, NULL);
+ if (r)
+ return r;
+
+ if (res_setup) { /* now to finalize/bake the setup */
+ til_video_setup_t *setup;
+
+ r = fb_ops->setup(settings, res_setting, res_desc, (til_setup_t **)&setup);
+ if (r)
+ return r;
+
+ *res_setup = &setup->til_setup;
}
-#endif
- return -EINVAL;
+ return 0;
}
@@ -319,7 +329,7 @@ static int setup_from_args(til_args_t *args, setup_t *res_setup, const char **re
if (r)
changes = 1;
- r = setup_interactively(setup.video_settings, setup_video, args->use_defaults, &setup.video_setup, res_failed_desc_path);
+ r = setup_interactively(setup.video_settings, setup_video, args->use_defaults, (til_setup_t **)&setup.video_setup, res_failed_desc_path);
if (r < 0)
goto _err;
if (r)
@@ -531,7 +541,7 @@ int main(int argc, const char *argv[])
{ /* free setup (move to function? and disambiguate from til_setup_t w/rename? TODO) */
free((void *)setup.title);
- til_setup_free(setup.video_setup);
+ til_setup_free(&setup.video_setup->til_setup);
til_settings_free(setup.video_settings);
til_setup_free(setup.audio_setup);
til_settings_free(setup.audio_settings);
diff --git a/src/mem_fb.c b/src/mem_fb.c
index 94566d7..72de1e5 100644
--- a/src/mem_fb.c
+++ b/src/mem_fb.c
@@ -4,6 +4,7 @@
#include "til_fb.h"
#include "til_settings.h"
#include "til_util.h"
+#include "til_video_setup.h"
/* dummy mem_fb backend; render to anonymous memory */
/* useful for testing/debugging, and benchmarking systems even if headless */
@@ -16,7 +17,7 @@ struct mem_fb_page_t {
};
typedef struct mem_fb_setup_t {
- til_setup_t til_setup;
+ til_video_setup_t til_video_setup;
unsigned width, height;
} mem_fb_setup_t;
@@ -26,7 +27,7 @@ typedef struct mem_fb_t {
} mem_fb_t;
-static int mem_fb_init(const char *title, const til_setup_t *setup, void **res_context)
+static int mem_fb_init(const char *title, const til_video_setup_t *setup, void **res_context)
{
mem_fb_t *c;
int r;
@@ -169,9 +170,9 @@ static int mem_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
return -ENOMEM;
if (sscanf(size->value, "%ux%u", &setup->width, &setup->height) != 2)
- return til_setup_free_with_failed_setting_ret_err(&setup->til_setup, size, res_setting, -EINVAL);
+ return til_setup_free_with_failed_setting_ret_err(&setup->til_video_setup.til_setup, size, res_setting, -EINVAL);
- *res_setup = &setup->til_setup;
+ *res_setup = &setup->til_video_setup.til_setup;
}
return 0;
diff --git a/src/sdl_fb.c b/src/sdl_fb.c
index 64ea593..d2d4d70 100644
--- a/src/sdl_fb.c
+++ b/src/sdl_fb.c
@@ -6,15 +6,16 @@
#include "til_fb.h"
#include "til_settings.h"
+#include "til_video_setup.h"
/* sdl fb backend, everything sdl-specific in rototiller resides here. */
typedef struct sdl_fb_setup_t {
- til_setup_t til_setup;
- int fullscreen:1;
- int vsync:1;
- unsigned width, height;
+ til_video_setup_t til_video_setup;
+ int fullscreen:1;
+ int vsync:1;
+ unsigned width, height;
} sdl_fb_setup_t;
typedef struct sdl_fb_page_t sdl_fb_page_t;
@@ -54,7 +55,7 @@ static int sdl_err_to_errno(int err)
}
}
-static int sdl_fb_init(const char *title, const til_setup_t *setup, void **res_context)
+static int sdl_fb_init(const char *title, const til_video_setup_t *setup, void **res_context)
{
sdl_fb_setup_t *s = (sdl_fb_setup_t *)setup;
sdl_fb_t *c;
@@ -374,9 +375,9 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
setup->vsync = 1;
if (size && sscanf(size->value, "%u%*[xX]%u", &setup->width, &setup->height) != 2)
- return til_setup_free_with_failed_setting_ret_err(&setup->til_setup, size, res_setting, -EINVAL);
+ return til_setup_free_with_failed_setting_ret_err(&setup->til_video_setup.til_setup, size, res_setting, -EINVAL);
- *res_setup = &setup->til_setup;
+ *res_setup = &setup->til_video_setup.til_setup;
}
return 0;
diff --git a/src/til_fb.c b/src/til_fb.c
index a802c40..3c19ae5 100644
--- a/src/til_fb.c
+++ b/src/til_fb.c
@@ -8,6 +8,7 @@
#include "til_fb.h"
#include "til_settings.h"
#include "til_util.h"
+#include "til_video_setup.h"
/* Copyright (C) 2016-2017 Vito Caputo <vcaputo@pengaru.com> */
@@ -550,7 +551,7 @@ til_fb_t * til_fb_free(til_fb_t *fb)
/* create a new fb instance */
-int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_setup_t *setup, int n_pages, til_fb_t **res_fb)
+int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_video_setup_t *setup, int n_pages, til_fb_t **res_fb)
{
_til_fb_page_t *page;
til_fb_t *fb;
@@ -560,7 +561,7 @@ int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_setup_t *se
assert(ops->page_alloc);
assert(ops->page_free);
assert(ops->page_flip);
- assert(!setup || setup->creator == ops);
+ assert(!setup && setup->til_setup.creator == ops);
assert(n_pages > 1);
assert(res_fb);
diff --git a/src/til_fb.h b/src/til_fb.h
index af17025..935b310 100644
--- a/src/til_fb.h
+++ b/src/til_fb.h
@@ -11,6 +11,7 @@
typedef struct til_fb_fragment_t til_fb_fragment_t;
typedef struct til_fb_fragment_ops_t til_fb_fragment_ops_t;
+typedef struct til_video_setup_t til_video_setup_t;
#define TIL_FB_DRAW_FLAG_TEXTURABLE 0x1
@@ -38,7 +39,7 @@ typedef struct til_fb_t til_fb_t;
/* Supply this struct to fb_new() with the appropriate context */
typedef struct til_fb_ops_t {
int (*setup)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
- int (*init)(const char *title, const til_setup_t *setup, void **res_context);
+ int (*init)(const char *title, const til_video_setup_t *setup, void **res_context);
void (*shutdown)(til_fb_t *fb, void *context);
int (*acquire)(til_fb_t *fb, void *context, void *page);
void (*release)(til_fb_t *fb, void *context);
@@ -53,7 +54,7 @@ til_fb_fragment_t * til_fb_fragment_snapshot(til_fb_fragment_t **fragment_ptr, i
til_fb_fragment_t * til_fb_fragment_reclaim(til_fb_fragment_t *fragment);
til_fb_t * til_fb_free(til_fb_t *fb);
void til_fb_get_put_pages_count(til_fb_t *fb, unsigned *count);
-int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_setup_t *setup, int n_pages, til_fb_t **res_fb);
+int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_video_setup_t *setup, int n_pages, til_fb_t **res_fb);
void til_fb_rebuild(til_fb_t *fb);
void til_fb_halt(til_fb_t *fb);
void * til_fb_context(til_fb_t *fb);
© All Rights Reserved