summaryrefslogtreecommitdiff
path: root/src/sdl_fb.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-07-15 15:09:01 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-07-15 15:09:01 -0700
commit8bd50ffd4ba81cb9c5197bcae926e177cc7a8987 (patch)
tree0a2c50fed2c7b800fade874fd33ce99806d90fb7 /src/sdl_fb.c
parentf1e59ffe5607ae8b84f03f153cacb27bc3024bac (diff)
til_fb: switch til_fb_ops_t.init() to use til_setup_t
Until now the fb init has been receiving a til_settings_t to access its setup. Now that there's a til_setup_t for representing the fully baked setup, let's bring the fb stuff up to speed so their init() behaves more like til_module_t.create_context() WRT settings/setup. This involves some reworking of how settings are handled in {drm,sdl}_fb.c but nothing majorly different. The only real funcitonal change that happened in the course of this work is I made it possible now to actually instruct SDL to do a more legacy SDL_WINDOW_FULLSCREEN vs. SDL_WINDOW_FULLSCREEN_DESKTOP where SDL will attempt to switch the video mode. This is triggered by specifying both a size=WxH and fullscreen=on for video=sdl. Be careful though, I've observed some broken display states when specifying goofy sizes, which look like Xorg bugs.
Diffstat (limited to 'src/sdl_fb.c')
-rw-r--r--src/sdl_fb.c75
1 files changed, 55 insertions, 20 deletions
diff --git a/src/sdl_fb.c b/src/sdl_fb.c
index b260091..8ce133d 100644
--- a/src/sdl_fb.c
+++ b/src/sdl_fb.c
@@ -10,6 +10,12 @@
/* sdl fb backend, everything sdl-specific in rototiller resides here. */
+typedef struct sdl_fb_setup_t {
+ til_setup_t til_setup;
+ int fullscreen;
+ unsigned width, height;
+} sdl_fb_setup_t;
+
typedef struct sdl_fb_t {
unsigned width, height;
Uint32 flags;
@@ -34,6 +40,7 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
NULL
};
const char *fullscreen;
+ const char *size;
int r;
r = til_settings_get_and_describe_value(settings,
@@ -52,8 +59,6 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
return r;
if (!strcasecmp(fullscreen, "off")) {
- const char *size;
-
r = til_settings_get_and_describe_value(settings,
&(til_setting_desc_t){
.name = "SDL window size",
@@ -68,6 +73,45 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
res_desc);
if (r)
return r;
+ } else if ((size = til_settings_get_value(settings, "size", res_setting)) && !(*res_setting)->desc) {
+ /* if fullscreen=on AND size=WxH is specified, we'll do a more legacy style SDL fullscreen
+ * where it tries to change the video mode. But if size is unspecified, it'll be a desktop
+ * style fullscreen where it just uses a fullscreen window in the existing video mode, and
+ * we won't forcibly require a size= be specified.
+ */
+ /* FIXME TODO: this is all copy-n-pasta grossness that wouldn't need to exist if
+ * til_settings_get_and_describe_value() just supported optional settings we only
+ * describe when they're already present. It just needs something like an optional flag,
+ * to be added in a future commit which will remove this hack.
+ */
+ r = til_setting_desc_clone( &(til_setting_desc_t){
+ .name = "SDL window size",
+ .key = "size",
+ .regex = "[1-9][0-9]*[xX][1-9][0-9]*",
+ .preferred = "640x480",
+ .values = NULL,
+ .annotations = NULL
+ }, res_desc);
+ if (r < 0)
+ return r;
+
+ return 1;
+ }
+
+ if (res_setup) {
+ sdl_fb_setup_t *setup;
+
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
+ if (!setup)
+ return -ENOMEM;
+
+ if (!strcasecmp(fullscreen, "on"))
+ setup->fullscreen = 1;
+
+ if (size)
+ sscanf(size, "%u%*[xX]%u", &setup->width, &setup->height);
+
+ *res_setup = &setup->til_setup;
}
return 0;
@@ -89,37 +133,28 @@ static int sdl_err_to_errno(int err)
}
}
-static int sdl_fb_init(const til_settings_t *settings, void **res_context)
+static int sdl_fb_init(const til_setup_t *setup, void **res_context)
{
- const char *fullscreen;
- const char *size;
+ sdl_fb_setup_t *s = (sdl_fb_setup_t *)setup;
sdl_fb_t *c;
int r;
- assert(settings);
+ assert(setup);
assert(res_context);
- fullscreen = til_settings_get_value(settings, "fullscreen", NULL);
- if (!fullscreen)
- return -EINVAL;
-
- size = til_settings_get_value(settings, "size", NULL);
- if (!size && !strcasecmp(fullscreen, "off"))
- return -EINVAL;
-
c = calloc(1, sizeof(sdl_fb_t));
if (!c)
return -ENOMEM;
- if (!strcasecmp(fullscreen, "on")) {
- if (!size)
- c->flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
- else
+ if (s->fullscreen) {
+ if (s->width && s->height)
c->flags = SDL_WINDOW_FULLSCREEN;
+ else
+ c->flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
- if (size) /* TODO: errors */
- sscanf(size, "%u%*[xX]%u", &c->width, &c->height);
+ c->width = s->width;
+ c->height = s->height;
SDL_SetMainReady();
r = SDL_Init(SDL_INIT_VIDEO);
© All Rights Reserved