This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 2988715637a4e169cf766abe2f777c76600180c7 (commit) from 30ca8e94204a8e1d24346bedc088197b0e877846 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/2988715637a4e169cf766abe2f777c7660018...
commit 2988715637a4e169cf766abe2f777c76600180c7 Author: Cyril Hrubis metan@ucw.cz Date: Sun Feb 19 17:28:24 2012 +0100
libs: backends add simplified generic init.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c index 7fe0e36..18554f2 100644 --- a/demos/fbshow/fbshow.c +++ b/demos/fbshow/fbshow.c @@ -293,21 +293,8 @@ static void sighandler(int signo)
static void init_backend(const char *backend_opts) { - if (!strcmp(backend_opts, "fb")) { - fprintf(stderr, "Initalizing framebuffer backendn"); - backend = GP_BackendLinuxFBInit("/dev/fb0"); - } + backend = GP_BackendInit(backend_opts, stderr); - if (!strcmp(backend_opts, "SDL")) { - fprintf(stderr, "Initalizing SDL backendn"); - backend = GP_BackendSDLInit(800, 600, 0, 0); - } - - if (!strcmp(backend_opts, "SDL:FS")) { - fprintf(stderr, "Initalizing SDL fullscreenn"); - backend = GP_BackendSDLInit(0, 0, 0, GP_SDL_FULLSCREEN); - } - if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", backend_opts); exit(1); diff --git a/include/backends/GP_Backend.h b/include/backends/GP_Backend.h index 2e36bb9..a50065a 100644 --- a/include/backends/GP_Backend.h +++ b/include/backends/GP_Backend.h @@ -28,7 +28,7 @@ The GP_Backend is overall structure for API for managing connection/mmaped memory/... to xserver window/framebuffer/... .
- In contrast to other graphics libraries we do not try to create overall + In contrast to other graphics libraries we do not try to create unified initalization interface that would match specialities for every possible backend. Rather than that we are trying to create API that is the same for all backends, once initalization is done. diff --git a/include/backends/GP_Backends.h b/include/backends/GP_BackendInit.h similarity index 73% copy from include/backends/GP_Backends.h copy to include/backends/GP_BackendInit.h index 284e2d7..3d34687 100644 --- a/include/backends/GP_Backends.h +++ b/include/backends/GP_BackendInit.h @@ -22,22 +22,29 @@
/*
- Catch all header for backends. + Simplified backend initalization interface good enough for most of the cases.
*/
-#ifndef BACKENDS_GP_BACKENDS_H -#define BACKENDS_GP_BACKENDS_H +#ifndef BACKENDS_GP_BACKEND_INIT_H +#define BACKENDS_GP_BACKEND_INIT_H
-/* - * Base backend definitions. - */ -#include "GP_Backend.h" +#include "backends/GP_Backend.h"
/* - * Backends. + * Initalize backend by a string. + * + * The format is: + * + * "backend_name:backend_params" + * + * For example "SDL:FS" is string for fullscreen SDL backend. + * + * Returns initalized backend or NULL in case of failure. + * + * If initialization has failed or params is NULL and help is not NULL, help + * text is printed to a given file. */ -#include "GP_LinuxFB.h" -#include "GP_SDL.h" +GP_Backend *GP_BackendInit(const char *params, FILE *help);
-#endif /* BACKENDS_GP_BACKENDS_H */ +#endif /* BACKENDS_GP_BACKEND_INIT_H */ diff --git a/include/backends/GP_Backends.h b/include/backends/GP_Backends.h index 284e2d7..0cd74f6 100644 --- a/include/backends/GP_Backends.h +++ b/include/backends/GP_Backends.h @@ -32,12 +32,17 @@ /* * Base backend definitions. */ -#include "GP_Backend.h" +#include "backends/GP_Backend.h"
/* * Backends. */ -#include "GP_LinuxFB.h" -#include "GP_SDL.h" +#include "backends/GP_LinuxFB.h" +#include "backends/GP_SDL.h" + +/* + * Simplified backend initalization. + */ +#include "backends/GP_BackendInit.h"
#endif /* BACKENDS_GP_BACKENDS_H */ diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c new file mode 100644 index 0000000..a544600 --- /dev/null +++ b/libs/backends/GP_BackendInit.c @@ -0,0 +1,169 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <string.h> + +#include "core/GP_Debug.h" + +#include "backends/GP_LinuxFB.h" +#include "backends/GP_SDL.h" +#include "backends/GP_BackendInit.h" + +static void backend_sdl_help(FILE *help, const char *err) +{ + if (help == NULL) + return; + + if (err != NULL) + fprintf(help, "ERROR: %sn", err); + + fprintf(help, "libSDL backendn" + "--------------n" + "SDL:[FS]n"); +} + +static GP_Backend *backend_sdl_init(const char *params, FILE *help) +{ + if (params == NULL) + return GP_BackendSDLInit(0, 0, 0, 0); + + if (!strcasecmp(params, "FS")) + return GP_BackendSDLInit(0, 0, 0, GP_SDL_FULLSCREEN); + + backend_sdl_help(help, "SDL: Invalid parameters"); + + return NULL; +} + +static void backend_fb_help(FILE *help, const char *err) +{ + if (help == NULL) + return; + + if (err != NULL) + fprintf(help, "ERROR: %sn", err); + + fprintf(help, "LinuxFB backendn" + "--------------n" + "FB:[/dev/fbX]n"); +} + +static GP_Backend *backend_fb_init(const char *params, FILE *help) +{ + const char *fb = "/dev/fb0"; + + (void) help; + + if (params != NULL) + fb = params; + + return GP_BackendLinuxFBInit(fb); +} + +static const char *backend_names[] = { + "SDL", /* libSDL */ + "FB", /* Linux Framebuffer */ + NULL, +}; + +static GP_Backend *(*backend_inits[])(const char *params, FILE *help) = { + backend_sdl_init, + backend_fb_init, + NULL, +}; + +static void (*backend_helps[])(FILE *help, const char *err) = { + backend_sdl_help, + backend_fb_help, + NULL, +}; + +static void print_help(FILE *help, char *err) +{ + int i; + + if (help == NULL) + return; + + if (err != NULL) { + fprintf(help, "ERROR: %sn", err); + fprintf(help, "n"); + } + + fprintf(help, "Backends usagen" + "--------------nn"); + + for (i = 0; backend_helps[i] != NULL; i++) { + backend_helps[i](help, NULL); + fprintf(help, "n"); + } +} + +static int get_backend(const char *name) +{ + int i; + + for (i = 0; backend_names[i] != 0; i++) + if (!strcasecmp(name, backend_names[i])) + return i; + + return -1; +} + +static GP_Backend *init_backend(const char *name, const char *params, FILE *help) +{ + int i = get_backend(name); + + if (i < 0) { + GP_DEBUG(1, "Invalid backend name '%s'", name); + print_help(help, "Invalid backend name"); + return NULL; + } + + return backend_inits[i](params, help); +} + +GP_Backend *GP_BackendInit(const char *params, FILE *help) +{ + if (params == NULL) { + print_help(help, NULL); + return NULL; + } + + /* parse backend name */ + int i, len = strlen(params); + char buf[len+1], *backend_params = NULL; + + strcpy(buf, params); + + for (i = 0; i < len; i++) { + if (buf[i] == ':') { + buf[i] = '0'; + backend_params = buf + i + 1; + break; + } + } + + GP_DEBUG(1, "Have backend name '%s'", buf); + + return init_backend(buf, backend_params, help); +}
-----------------------------------------------------------------------
Summary of changes: demos/fbshow/fbshow.c | 15 +-- include/backends/GP_Backend.h | 2 +- .../backends/GP_BackendInit.h | 40 +++--- include/backends/GP_Backends.h | 11 +- libs/backends/GP_BackendInit.c | 169 ++++++++++++++++++++ 5 files changed, 199 insertions(+), 38 deletions(-) copy demos/fbshow/cpu_timer.h => include/backends/GP_BackendInit.h (73%) create mode 100644 libs/backends/GP_BackendInit.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.