summaryrefslogtreecommitdiff
path: root/src/sdl_fb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl_fb.c')
-rw-r--r--src/sdl_fb.c101
1 files changed, 91 insertions, 10 deletions
diff --git a/src/sdl_fb.c b/src/sdl_fb.c
index 77c62bf..80a63dd 100644
--- a/src/sdl_fb.c
+++ b/src/sdl_fb.c
@@ -10,6 +10,9 @@
/* sdl fb backend, everything sdl-specific in rototiller resides here. */
typedef struct sdl_fb_t {
+ unsigned width, height;
+ Uint32 flags;
+
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
@@ -24,25 +27,104 @@ struct sdl_fb_page_t {
int sdl_fb_setup(const settings_t *settings, setting_desc_t **next_setting)
{
- /* TODO: window size? fullscreen? vsync? etc. */
+ const char *fullscreen;
+
+ fullscreen = settings_get_value(settings, "fullscreen");
+ if (!fullscreen) {
+ const char *values[] = {
+ "off",
+ "on",
+ NULL
+ };
+ setting_desc_t *desc;
+
+ desc = setting_desc_new("SDL Fullscreen Mode",
+ "fullscreen",
+ NULL,
+ values[0],
+ values,
+ NULL);
+ if (!desc)
+ return -ENOMEM;
+
+ *next_setting = desc;
+
+ return 1;
+ }
+
+ if (!strcasecmp(fullscreen, "off")) {
+ const char *size;
+
+ size = settings_get_value(settings, "size");
+ if (!size) {
+ setting_desc_t *desc;
+
+ desc = setting_desc_new("SDL Window size",
+ "size",
+ "[1-9][0-9]*[xX][1-9][0-9]*",
+ "640x480",
+ NULL,
+ NULL);
+ if (!desc)
+ return -ENOMEM;
+
+ *next_setting = desc;
+
+ return 1;
+ }
+ }
+
return 0;
}
void * sdl_fb_init(const settings_t *settings)
{
+ const char *fullscreen;
+ const char *size;
sdl_fb_t *c;
+ fullscreen = settings_get_value(settings, "fullscreen");
+ if (!fullscreen)
+ return NULL;
+
+ size = settings_get_value(settings, "size");
+ if (!size && !strcasecmp(fullscreen, "off"))
+ return NULL;
+
c = calloc(1, sizeof(sdl_fb_t));
if (!c)
return NULL;
+ if (!strcasecmp(fullscreen, "on")) {
+ if (!size)
+ c->flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
+ else
+ c->flags = SDL_WINDOW_FULLSCREEN;
+ }
+
+ if (size) /* TODO: errors */
+ sscanf(size, "%u%*[xX]%u", &c->width, &c->height);
+
SDL_SetMainReady();
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
free(c);
return NULL;
}
+ if (c->flags == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ SDL_DisplayMode mode;
+
+ if (SDL_GetDesktopDisplayMode(0, &mode) != 0) {
+ SDL_Quit();
+ free(c);
+ return NULL;
+ }
+
+ c->width = mode.w;
+ c->height = mode.h;
+ }
+
return c;
}
@@ -61,7 +143,7 @@ static int sdl_fb_acquire(void *context, void *page)
sdl_fb_t *c = context;
sdl_fb_page_t *p = page;
- c->window = SDL_CreateWindow("rototiller", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
+ c->window = SDL_CreateWindow("rototiller", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, c->width, c->height, c->flags);
if (!c->window)
return -1;
@@ -69,7 +151,7 @@ static int sdl_fb_acquire(void *context, void *page)
if (!c->renderer)
return -1;
- c->texture = SDL_CreateTexture(c->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 480);
+ c->texture = SDL_CreateTexture(c->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, c->width, c->height);
if (!c->texture)
return -1;
@@ -96,15 +178,14 @@ static void * sdl_fb_page_alloc(void *context, fb_page_t *res_page)
if (!p)
return NULL;
-
- p->surface = SDL_CreateRGBSurfaceWithFormat(0, 640, 480, 32, SDL_PIXELFORMAT_RGB888);
+ p->surface = SDL_CreateRGBSurfaceWithFormat(0, c->width, c->height, 32, SDL_PIXELFORMAT_RGB888);
res_page->fragment.buf = p->surface->pixels;
- res_page->fragment.width = 640;
- res_page->fragment.frame_width = 640;
- res_page->fragment.height = 480;
- res_page->fragment.frame_height = 480;
- res_page->fragment.stride = p->surface->pitch - (640 * 4);
+ res_page->fragment.width = c->width;
+ res_page->fragment.frame_width = c->width;
+ res_page->fragment.height = c->height;
+ res_page->fragment.frame_height = c->height;
+ res_page->fragment.stride = p->surface->pitch - (c->width * 4);
return p;
}
© All Rights Reserved