diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-10-03 21:13:00 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-10-03 21:13:00 +0200 |
commit | d7609640e7cb9d213b9d3cbcf9394c677719d369 (patch) | |
tree | 1487faa310e5f6dd91a5d033644abb470b8f3719 /arch/sandbox/os | |
parent | d1e65d2a7bd9162e7009da870adb15c70b620320 (diff) | |
parent | 9d73b518fc3c61640123f8499aab7f8373e41dbd (diff) | |
download | barebox-d7609640e7cb9d213b9d3cbcf9394c677719d369.tar.gz barebox-d7609640e7cb9d213b9d3cbcf9394c677719d369.tar.xz |
Merge branch 'for-next/sandbox'
Conflicts:
arch/sandbox/mach-sandbox/include/mach/linux.h
Diffstat (limited to 'arch/sandbox/os')
-rw-r--r-- | arch/sandbox/os/Makefile | 2 | ||||
-rw-r--r-- | arch/sandbox/os/common.c | 33 | ||||
-rw-r--r-- | arch/sandbox/os/sdl.c | 108 |
3 files changed, 140 insertions, 3 deletions
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile index dc211d94cd..2e65be5eed 100644 --- a/arch/sandbox/os/Makefile +++ b/arch/sandbox/os/Makefile @@ -13,3 +13,5 @@ NOSTDINC_FLAGS := obj-y = common.o tap.o +CFLAGS_sdl.o = $(shell pkg-config sdl --cflags) +obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index 0a4b96a63e..0dedfe19f4 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -49,6 +49,9 @@ #include <mach/linux.h> #include <mach/hostfile.h> +int sdl_xres; +int sdl_yres; + static struct termios term_orig, term_vi; static char erase_char; /* the users erase character */ @@ -275,10 +278,12 @@ static struct option long_options[] = { {"env", 1, 0, 'e'}, {"stdout", 1, 0, 'O'}, {"stdin", 1, 0, 'I'}, + {"xres", 1, 0, 'x'}, + {"yres", 1, 0, 'y'}, {0, 0, 0, 0}, }; -static const char optstring[] = "hm:i:e:O:I:"; +static const char optstring[] = "hm:i:e:O:I:x:y:"; int main(int argc, char *argv[]) { @@ -303,6 +308,8 @@ int main(int argc, char *argv[]) case 'm': malloc_size = strtoul(optarg, NULL, 0); break; + case 'i': + break; case 'e': sprintf(str, "env%d", envno); ret = add_image(optarg, str); @@ -328,6 +335,12 @@ int main(int argc, char *argv[]) barebox_register_console("cin", fd, -1); break; + case 'x': + sdl_xres = strtoul(optarg, NULL, 0); + break; + case 'y': + sdl_yres = strtoul(optarg, NULL, 0); + break; default: exit(1); } @@ -340,7 +353,11 @@ int main(int argc, char *argv[]) } mem_malloc_init(ram, ram + malloc_size - 1); - /* reset getopt */ + /* + * Reset getopt. + * We need to run a second getopt to count -i parameters. + * This is for /dev/fd# devices. + */ optind = 1; while (1) { @@ -396,7 +413,9 @@ static void print_usage(const char *prgname) " -O, --stdout=<file> Register a file as a console capable of doing stdout.\n" " <file> can be a regular file or a FIFO.\n" " -I, --stdin=<file> Register a file as a console capable of doing stdin.\n" -" <file> can be a regular file or a FIFO.\n", +" <file> can be a regular file or a FIFO.\n" +" -x, --xres=<res> SDL width.\n" +" -y, --yres=<res> SDL height.\n", prgname ); } @@ -436,6 +455,14 @@ static void print_usage(const char *prgname) * Register \<file\> as a console capable of doing stdin. \<file\> can be a regular * file or a fifo. * + * -x, --xres \<res\> + * + * Specify SDL width + * + * -y, --yres \<res\> + * + * Specify SDL height + * * @section simu_dbg How to debug barebox simulator * */ diff --git a/arch/sandbox/os/sdl.c b/arch/sandbox/os/sdl.c new file mode 100644 index 0000000000..ec538e9af9 --- /dev/null +++ b/arch/sandbox/os/sdl.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> + * + * GPL v2 + */ + +#include <stdio.h> +#include <SDL.h> +#include <time.h> +#include <signal.h> +#include <mach/linux.h> +#include <unistd.h> +#include <pthread.h> + +struct fb_bitfield { + uint32_t offset; /* beginning of bitfield */ + uint32_t length; /* length of bitfield */ + uint32_t msb_right; /* != 0 : Most significant bit is */ + /* right */ +}; + +static SDL_Surface *real_screen; +static void *buffer = NULL; +pthread_t th; + +int sdl_init(void) +{ + return SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); +} + +static void sdl_copy_buffer(SDL_Surface *screen) +{ + if (SDL_MUSTLOCK(screen)) { + if (SDL_LockSurface(screen) < 0) + return; + } + + memcpy(screen->pixels, buffer, screen->pitch * screen->h); + + if(SDL_MUSTLOCK(screen)) + SDL_UnlockSurface(screen); +} + +static void *threadStart(void *ptr) +{ + while (1) { + usleep(1000 * 100); + + sdl_copy_buffer(real_screen); + SDL_Flip(real_screen); + } + + return 0; +} + +void sdl_start_timer(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_create(&th, &attr, threadStart, NULL); +} + +void sdl_stop_timer(void) +{ + pthread_cancel(th); +} + +void sdl_get_bitfield_rgba(struct fb_bitfield *r, struct fb_bitfield *g, + struct fb_bitfield *b, struct fb_bitfield *a) +{ + SDL_Surface *screen = real_screen; + + r->length = 8 - screen->format->Rloss; + r->offset = screen->format->Rshift; + g->length = 8 - screen->format->Gloss; + g->offset = screen->format->Gshift; + b->length = 8 - screen->format->Bloss; + b->offset = screen->format->Bshift; + a->length = 8 - screen->format->Aloss; + a->offset = screen->format->Ashift; +} + +int sdl_open(int xres, int yres, int bpp, void* buf) +{ + int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; + + if (sdl_init() < 0) { + printf("Could not initialize SDL: %s.\n", SDL_GetError()); + return -1; + } + + real_screen = SDL_SetVideoMode(xres, yres, bpp, flags); + if (!real_screen) { + sdl_close(); + fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); + return -1; + } + + buffer = buf; + + return 0; +} + +void sdl_close(void) +{ + sdl_stop_timer(); + SDL_Quit(); +} |