fix sdl_fb.c to support gcc under linux

This commit is contained in:
prife 2013-01-22 15:49:49 +08:00
parent 236099e3ec
commit 7c3f2fd6c7
1 changed files with 26 additions and 2 deletions

View File

@ -1,6 +1,10 @@
#include <rtthread.h> #include <rtthread.h>
#ifdef _WIN32
#include <sdl.h> #include <sdl.h>
#else
#include <SDL/SDL.h>
#endif
#include <rtdevice.h> #include <rtdevice.h>
#include <rtgui/driver.h> #include <rtgui/driver.h>
@ -104,7 +108,7 @@ static void sdlfb_hw_init(void)
//_putenv("SDL_VIDEODRIVER=windib"); //_putenv("SDL_VIDEODRIVER=windib");
//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) if (SDL_Init(SDL_INIT_VIDEO) < 0)
{ {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1); exit(1);
@ -132,16 +136,24 @@ static void sdlfb_hw_init(void)
sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO); sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO);
} }
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#else
#include <pthread.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <sdl.h>
#include <rtgui/event.h> #include <rtgui/event.h>
#include <rtgui/kbddef.h> #include <rtgui/kbddef.h>
#include <rtgui/rtgui_server.h> #include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#ifdef _WIN32
static DWORD WINAPI sdl_loop(LPVOID lpParam) static DWORD WINAPI sdl_loop(LPVOID lpParam)
#else
static void *sdl_loop(void *lpParam)
#endif
{ {
int quit = 0; int quit = 0;
SDL_Event event; SDL_Event event;
@ -284,6 +296,7 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
/* start sdl thread */ /* start sdl thread */
void rt_hw_sdl_start(void) void rt_hw_sdl_start(void)
{ {
#ifdef _WIN32
HANDLE thread; HANDLE thread;
DWORD thread_id; DWORD thread_id;
@ -301,4 +314,15 @@ void rt_hw_sdl_start(void)
return; return;
} }
ResumeThread(thread); ResumeThread(thread);
#else
/* Linux */
pthread_t pid;
int res;
res = pthread_create(&pid, NULL, &sdl_loop, NULL);
if (res)
{
printf("pthread create sdl thread faild, <%d>\n", res);
exit(EXIT_FAILURE);
}
#endif
} }