diff --git a/firmware/asm/thread.h b/firmware/asm/thread.h index 771338b406..fb7065e6fd 100644 --- a/firmware/asm/thread.h +++ b/firmware/asm/thread.h @@ -50,8 +50,8 @@ struct regs #ifndef MINSIGSTKSZ #define MINSIGSTKSZ 16384 #endif - /* MINSIGSTKSZ for the OS to deliver the signal + 0x3000 for us */ - #define DEFAULT_STACK_SIZE (MINSIGSTKSZ+0x3000) /* Bytes */ + /* MINSIGSTKSZ for the OS to deliver the signal + 0x6000 for us */ + #define DEFAULT_STACK_SIZE (MINSIGSTKSZ+0x6000) /* Bytes */ #elif defined(HAVE_WIN32_FIBER_THREADS) #define DEFAULT_STACK_SIZE 0x1000 /* Bytes */ #endif diff --git a/firmware/target/hosted/sdl/app/button-application.c b/firmware/target/hosted/sdl/app/button-application.c index 9c313b76b1..8071df201a 100644 --- a/firmware/target/hosted/sdl/app/button-application.c +++ b/firmware/target/hosted/sdl/app/button-application.c @@ -40,23 +40,23 @@ int key_to_button(int keyboard_key) #if (CONFIG_PLATFORM & PLATFORM_MAEMO4) case SDLK_ESCAPE: #endif - case SDLK_KP7: + case SDLK_KP_7: new_btn = BUTTON_TOPLEFT; break; - case SDLK_KP8: + case SDLK_KP_8: case SDLK_UP: new_btn = BUTTON_TOPMIDDLE; break; #if (CONFIG_PLATFORM & PLATFORM_MAEMO4) case SDLK_F7: #endif - case SDLK_KP9: + case SDLK_KP_9: new_btn = BUTTON_TOPRIGHT; break; #if (CONFIG_PLATFORM & PLATFORM_PANDORA) case SDLK_RSHIFT: #endif - case SDLK_KP4: + case SDLK_KP_4: case SDLK_LEFT: new_btn = BUTTON_MIDLEFT; break; @@ -64,40 +64,32 @@ int key_to_button(int keyboard_key) case SDLK_RETURN: case SDLK_KP_ENTER: #endif - case SDLK_KP5: + case SDLK_KP_5: new_btn = BUTTON_CENTER; break; #if (CONFIG_PLATFORM & PLATFORM_PANDORA) case SDLK_RCTRL: #endif - case SDLK_KP6: + case SDLK_KP_6: case SDLK_RIGHT: new_btn = BUTTON_MIDRIGHT; break; #if (CONFIG_PLATFORM & PLATFORM_MAEMO4) case SDLK_F6: #endif - case SDLK_KP1: + case SDLK_KP_1: new_btn = BUTTON_BOTTOMLEFT; break; - case SDLK_KP2: + case SDLK_KP_2: case SDLK_DOWN: new_btn = BUTTON_BOTTOMMIDDLE; break; #if (CONFIG_PLATFORM & PLATFORM_MAEMO4) case SDLK_F8: #endif - case SDLK_KP3: + case SDLK_KP_3: new_btn = BUTTON_BOTTOMRIGHT; break; -#ifdef HAVE_SCROLLWHEEL - case SDL_BUTTON_WHEELUP: - new_btn = BUTTON_SCROLL_BACK; - break; - case SDL_BUTTON_WHEELDOWN: - new_btn = BUTTON_SCROLL_FWD; - break; -#endif case SDL_BUTTON_RIGHT: new_btn = BUTTON_MIDLEFT; break; diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c index b5f3720a3b..8af6f3ffaf 100644 --- a/firmware/target/hosted/sdl/button-sdl.c +++ b/firmware/target/hosted/sdl/button-sdl.c @@ -107,6 +107,30 @@ static void touchscreen_event(int x, int y) } #endif +#if defined(HAVE_SCROLLWHEEL) || ((defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK))) +static void scrollwheel_event(int x, int y) +{ + int new_btn = 0; + if (y > 0) + new_btn = BUTTON_SCROLL_BACK; + else if (y < 0) + new_btn = BUTTON_SCROLL_FWD; + else + return; + +#ifdef HAVE_BACKLIGHT + backlight_on(); +#endif +#ifdef HAVE_BUTTON_LIGHT + buttonlight_on(); +#endif + reset_poweroff_timer(); + if (new_btn && !queue_full(&button_queue)) + queue_post(&button_queue, new_btn, 1<<24); + + (void)x; +} +#endif static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) { #define SQUARE(x) ((x)*(x)) @@ -118,10 +142,6 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) if(button_up) { switch ( event->button ) { -#ifdef HAVE_SCROLLWHEEL - case SDL_BUTTON_WHEELUP: - case SDL_BUTTON_WHEELDOWN: -#endif case SDL_BUTTON_MIDDLE: case SDL_BUTTON_RIGHT: button_event( event->button, false ); @@ -145,13 +165,9 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) #endif break; } - } else { /* button down */ + } else { /* button down */ switch ( event->button ) { -#ifdef HAVE_SCROLLWHEEL - case SDL_BUTTON_WHEELUP: - case SDL_BUTTON_WHEELDOWN: -#endif case SDL_BUTTON_MIDDLE: case SDL_BUTTON_RIGHT: button_event( event->button, true ); @@ -215,18 +231,15 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) static bool event_handler(SDL_Event *event) { - SDLKey ev_key; + SDL_Keycode ev_key; switch(event->type) { - case SDL_ACTIVEEVENT: - if (event->active.state & SDL_APPINPUTFOCUS) - { - if (event->active.gain == 1) - sdl_app_has_input_focus = 1; - else - sdl_app_has_input_focus = 0; - } + case SDL_WINDOWEVENT: + if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED) + sdl_app_has_input_focus = 1; + else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST) + sdl_app_has_input_focus = 0; break; case SDL_KEYDOWN: case SDL_KEYUP: @@ -275,6 +288,13 @@ static bool event_handler(SDL_Event *event) mouse_event(mev, event->type == SDL_MOUSEBUTTONUP); break; } +#ifdef HAVE_SCROLLWHEEL + case SDL_MOUSEWHEEL: + { + scrollwheel_event(event->wheel.x, event->wheel.y); + break; + } +#endif case SDL_QUIT: /* Will post SDL_USEREVENT in shutdown_hw() if successful. */ sdl_sys_quit(); @@ -362,7 +382,7 @@ static void button_event(int key, bool pressed) } return; #endif - + #ifdef HAS_REMOTE_BUTTON_HOLD case SDLK_j: if(pressed) @@ -379,7 +399,7 @@ static void button_event(int key, bool pressed) if(pressed) switch(_remote_type) { - case REMOTETYPE_UNPLUGGED: + case REMOTETYPE_UNPLUGGED: _remote_type=REMOTETYPE_H100_LCD; DEBUGF("Changed remote type to H100\n"); break; @@ -399,7 +419,7 @@ static void button_event(int key, bool pressed) break; #endif #ifndef APPLICATION - case SDLK_KP0: + case SDLK_KP_0: case SDLK_F5: if(pressed) { @@ -430,32 +450,17 @@ static void button_event(int key, bool pressed) #endif break; } - /* Call to make up for scrollwheel target implementation. This is - * not handled in the main button.c driver, but on the target - * implementation (look at button-e200.c for example if you are trying to - * figure out why using button_get_data needed a hack before). - */ + #if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK) - if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) && + if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) && pressed) { - /* Clear these buttons from the data - adding them to the queue is - * handled in the scrollwheel drivers for the targets. They do not - * store the scroll forward/back buttons in their button data for - * the button_read call. - */ -#ifdef HAVE_BACKLIGHT - backlight_on(); -#endif -#ifdef HAVE_BUTTON_LIGHT - buttonlight_on(); -#endif - reset_poweroff_timer(); - queue_post(&button_queue, new_btn, 1<<24); + scrollwheel_event(0, new_btn == BUTTON_SCROLL_FWD ? -1 : 1); new_btn &= ~(BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK); } #endif + /* Update global button press state */ if (pressed) btn |= new_btn; else @@ -496,5 +501,4 @@ int button_read_device(void) void button_init_device(void) { - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); } diff --git a/firmware/target/hosted/sdl/kernel-sdl.c b/firmware/target/hosted/sdl/kernel-sdl.c index 5c16f86749..bcad39b4d8 100644 --- a/firmware/target/hosted/sdl/kernel-sdl.c +++ b/firmware/target/hosted/sdl/kernel-sdl.c @@ -153,7 +153,7 @@ void sim_kernel_shutdown(void) SDL_Delay(10); SDL_DestroyMutex(sim_irq_mtx); - SDL_DestroyCond(sim_thread_cond); + SDL_DestroyCond(sim_thread_cond); } Uint32 tick_timer(Uint32 interval, void *param) @@ -162,9 +162,9 @@ Uint32 tick_timer(Uint32 interval, void *param) (void) interval; (void) param; - + new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ); - + while(new_tick != current_tick) { sim_enter_irq_handler(); @@ -175,7 +175,7 @@ Uint32 tick_timer(Uint32 interval, void *param) sim_exit_irq_handler(); } - + return interval; } @@ -187,10 +187,10 @@ void tick_start(unsigned int interval_in_ms) exit(-1); } - if (tick_timer_id != NULL) + if (tick_timer_id != 0) { SDL_RemoveTimer(tick_timer_id); - tick_timer_id = NULL; + tick_timer_id = 0; } else { diff --git a/firmware/target/hosted/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c index ea30afea3b..ef284eeb48 100644 --- a/firmware/target/hosted/sdl/lcd-bitmap.c +++ b/firmware/target/hosted/sdl/lcd-bitmap.c @@ -164,12 +164,12 @@ void sim_backlight(int value) #else /* LCD_DEPTH > 8 */ #if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP) if (!lcd_active()) - SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, 0); + SDL_SetSurfaceAlphaMod(lcd_surface, 0); else - SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, + SDL_SetSurfaceAlphaMod(lcd_surface, MAX(BACKLIGHT_OFF_ALPHA, (value * 255) / 100)); #else - SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, (value * 255) / 100); + SDL_SetSurfaceAlphaMod(lcd_surface, (value * 255) / 100); #endif #endif /* LCD_DEPTH */ @@ -187,6 +187,7 @@ void lcd_init_device(void) SIM_LCD_WIDTH * display_zoom, SIM_LCD_HEIGHT * display_zoom, LCD_DEPTH, 0, 0, 0, 0); + SDL_SetSurfaceBlendMode(lcd_surface, SDL_BLENDMODE_BLEND); #elif LCD_DEPTH <= 8 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, SIM_LCD_WIDTH * display_zoom, @@ -222,7 +223,7 @@ void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height) if (lcd_ex_getpixel) { sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel); - sdl_gui_update(lcd_surface, x_start, y_start, width, + sdl_gui_update(lcd_surface, x_start, y_start, width, height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT, background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0); diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c index 8cbb6c5651..1e9daeffd3 100644 --- a/firmware/target/hosted/sdl/lcd-sdl.c +++ b/firmware/target/hosted/sdl/lcd-sdl.c @@ -115,12 +115,17 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width, (ui_y + y_start) * display_zoom, width * display_zoom, height * display_zoom}; - if (surface->flags & SDL_SRCALPHA) /* alpha needs a black background */ + uint8_t alpha; + if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255) SDL_FillRect(gui_surface, &dest, 0); - SDL_BlitSurface(surface, &src, gui_surface, &dest); + SDL_BlitSurface(surface, &src, gui_surface, &dest); /* alpha needs a black background */ - SDL_Flip(gui_surface); + SDL_Texture *sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, gui_surface); + SDL_RenderClear(sdlRenderer); + SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); + SDL_RenderPresent(sdlRenderer); + SDL_DestroyTexture(sdlTexture); } /* set a range of bitmap indices to a gradient from startcolour to endcolour */ @@ -136,7 +141,7 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, palette[i].b = start->b + (end->b - start->b) * i / (steps - 1); } - SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); + SDL_SetPaletteColors(surface->format->palette, palette, first , steps); } int lcd_get_dpi(void) diff --git a/firmware/target/hosted/sdl/lcd-sdl.h b/firmware/target/hosted/sdl/lcd-sdl.h index a964c9bc40..3f1334e4a2 100644 --- a/firmware/target/hosted/sdl/lcd-sdl.h +++ b/firmware/target/hosted/sdl/lcd-sdl.h @@ -3,7 +3,7 @@ * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * @@ -27,6 +27,7 @@ /* Default display zoom level */ extern SDL_Surface *gui_surface; +extern SDL_Renderer *sdlRenderer; void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, int height, int max_x, int max_y, @@ -39,4 +40,3 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, int first, int steps); #endif /* #ifndef __LCDSDL_H__ */ - diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c index 587b678550..dec12af2f1 100644 --- a/firmware/target/hosted/sdl/pcm-sdl.c +++ b/firmware/target/hosted/sdl/pcm-sdl.c @@ -1,10 +1,10 @@ /*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2005 by Nick Lanham @@ -85,8 +85,43 @@ void pcm_play_unlock(void) SDL_UnlockMutex(audio_lock); } +static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len); static void pcm_dma_apply_settings_nolock(void) { + SDL_AudioSpec wanted_spec; + wanted_spec.freq = pcm_sampr; + wanted_spec.format = AUDIO_S16SYS; + wanted_spec.channels = 2; + wanted_spec.samples = 2048; + wanted_spec.callback = + (void (SDLCALL *)(void *userdata, + Uint8 *stream, int len))sdl_audio_callback; + wanted_spec.userdata = &udata; + SDL_CloseAudio(); + /* Open the audio device and start playing sound! */ + if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) { + DEBUGF("Unable to open audio: %s\n", SDL_GetError()); + return; + } + switch (obtained.format) + { + case AUDIO_U8: + case AUDIO_S8: + pcm_channel_bytes = 1; + break; + case AUDIO_U16LSB: + case AUDIO_S16LSB: + case AUDIO_U16MSB: + case AUDIO_S16MSB: + pcm_channel_bytes = 2; + break; + default: + DEBUGF("Unknown sample format obtained: %u\n", + (unsigned)obtained.format); + return; + } + pcm_sample_bytes = obtained.channels * pcm_channel_bytes; + cvt_status = SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, pcm_sampr, obtained.format, obtained.channels, obtained.freq); @@ -256,9 +291,7 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len) if (delay > 0) { - SDL_UnlockMutex(audio_lock); SDL_Delay(delay); - SDL_LockMutex(audio_lock); if (!pcm_is_playing()) break; @@ -339,7 +372,6 @@ void pcm_play_dma_init(void) return; } - SDL_AudioSpec wanted_spec; #ifdef DEBUG udata.debug = NULL; if (debug_audio) { @@ -347,43 +379,6 @@ void pcm_play_dma_init(void) DEBUGF("Audio debug file open\n"); } #endif - /* Set 16-bit stereo audio at 44Khz */ - wanted_spec.freq = 44100; - wanted_spec.format = AUDIO_S16SYS; - wanted_spec.channels = 2; - wanted_spec.samples = 2048; - wanted_spec.callback = - (void (SDLCALL *)(void *userdata, - Uint8 *stream, int len))sdl_audio_callback; - wanted_spec.userdata = &udata; - - /* Open the audio device and start playing sound! */ - if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) { - DEBUGF("Unable to open audio: %s\n", SDL_GetError()); - return; - } - - switch (obtained.format) - { - case AUDIO_U8: - case AUDIO_S8: - pcm_channel_bytes = 1; - break; - case AUDIO_U16LSB: - case AUDIO_S16LSB: - case AUDIO_U16MSB: - case AUDIO_S16MSB: - pcm_channel_bytes = 2; - break; - default: - DEBUGF("Unknown sample format obtained: %u\n", - (unsigned)obtained.format); - return; - } - - pcm_sample_bytes = obtained.channels * pcm_channel_bytes; - - pcm_dma_apply_settings_nolock(); } void pcm_play_dma_postinit(void) diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index e53643f449..9ec375dd17 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c @@ -1,10 +1,10 @@ /*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2006 by Daniel Everton @@ -50,6 +50,8 @@ #define SIMULATOR_DEFAULT_ROOT "simdisk" SDL_Surface *gui_surface; +SDL_Window *window; +SDL_Renderer *sdlRenderer; bool background = true; /* use backgrounds by default */ #ifdef HAVE_REMOTE_LCD @@ -72,26 +74,12 @@ bool debug_audio = false; bool debug_wps = false; int wps_verbose_level = 3; -/* - * This thread will read the buttons in an interrupt like fashion, and - * also initializes SDL_INIT_VIDEO and the surfaces - * - * it must be done in the same thread (at least on windows) because events only - * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO - * - * This is an SDL thread and relies on preemptive behavoir of the host - **/ -static int sdl_event_thread(void * param) +static void sdl_window_setup(void) { - SDL_InitSubSystem(SDL_INIT_VIDEO); - -#if (CONFIG_PLATFORM & PLATFORM_MAEMO) - SDL_sem *wait_for_maemo_startup; -#endif SDL_Surface *picture_surface = NULL; int width, height; int depth; - Uint32 flags; + Uint32 flags = 0; /* Try and load the background image. If it fails go without */ if (background) { @@ -101,14 +89,14 @@ static int sdl_event_thread(void * param) DEBUGF("warn: %s\n", SDL_GetError()); } } - + /* Set things up */ if (background) { width = UI_WIDTH; height = UI_HEIGHT; - } - else + } + else { #ifdef HAVE_REMOTE_LCD if (showremote) @@ -128,17 +116,47 @@ static int sdl_event_thread(void * param) if (depth < 8) depth = 16; - flags = SDL_HWSURFACE|SDL_DOUBLEBUF; #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) /* Fullscreen mode for maemo app */ - flags |= SDL_FULLSCREEN; + flags |= SDL_WINDOW_FULLSCREEN; #endif - SDL_WM_SetCaption(UI_TITLE, NULL); - - if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, depth, flags)) == NULL) { + if ((window = SDL_CreateWindow(UI_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + width * display_zoom, height * display_zoom , flags)) == NULL) panicf("%s", SDL_GetError()); + if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)) == NULL) + panicf("%s", SDL_GetError()); + if ((gui_surface = SDL_CreateRGBSurface(0, width * display_zoom, height * display_zoom, depth, + 0, 0, 0, 0)) == NULL) + panicf("%s", SDL_GetError()); + + /* If we have a background, blit it over to the display surface */ + if (background && picture_surface) + { + SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); + SDL_FreeSurface(picture_surface); } +} + +/* + * This thread will read the buttons in an interrupt like fashion, and + * also initializes SDL_INIT_VIDEO and the surfaces + * + * it must be done in the same thread (at least on windows) because events only + * work in the thread that called SDL_InitSubSystem(SDL_INIT_VIDEO) + * + * This is an SDL thread and relies on preemptive behavoir of the host + **/ +static int sdl_event_thread(void * param) +{ +#ifdef __WIN32 /* Fails on Linux and MacOS */ + SDL_InitSubSystem(SDL_INIT_VIDEO); + sdl_window_setup(); +#endif + +#if (CONFIG_PLATFORM & PLATFORM_MAEMO) + SDL_sem *wait_for_maemo_startup; +#endif #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) /* SDL touch screen fix: Work around a SDL assumption that returns @@ -152,14 +170,10 @@ static int sdl_event_thread(void * param) SDL_SetCursor(hiddenCursor); #endif - if (background && picture_surface != NULL) - SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); - #if (CONFIG_PLATFORM & PLATFORM_MAEMO) /* start maemo thread: Listen to display on/off events and battery monitoring */ wait_for_maemo_startup = SDL_CreateSemaphore(0); /* 0-count so it blocks */ - SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, wait_for_maemo_startup); - + SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, NULL, wait_for_maemo_startup); SDL_SemWait(wait_for_maemo_startup); SDL_DestroySemaphore(wait_for_maemo_startup); #endif @@ -184,9 +198,6 @@ static int sdl_event_thread(void * param) SDL_FreeCursor(hiddenCursor); #endif - if(picture_surface) - SDL_FreeSurface(picture_surface); - /* Order here is relevent to prevent deadlocks and use of destroyed sync primitives by kernel threads */ #ifdef HAVE_SDL_THREADS @@ -251,15 +262,16 @@ void system_init(void) g_type_init(); #endif - if (SDL_Init(SDL_INIT_TIMER)) + if (SDL_InitSubSystem(SDL_INIT_TIMER)) panicf("%s", SDL_GetError()); +#ifndef __WIN32 /* Fails on Windows */ + SDL_InitSubSystem(SDL_INIT_VIDEO); + sdl_window_setup(); +#endif + s = SDL_CreateSemaphore(0); /* 0-count so it blocks */ - - evt_thread = SDL_CreateThread(sdl_event_thread, s); - - /* wait for sdl_event_thread to run so that it can initialize the surfaces - * and video subsystem needed for SDL events */ + evt_thread = SDL_CreateThread(sdl_event_thread, NULL, s); SDL_SemWait(s); /* cleanup */ SDL_DestroySemaphore(s); @@ -303,29 +315,29 @@ int hostfs_flush(void) void sys_handle_argv(int argc, char *argv[]) { - if (argc >= 1) + if (argc >= 1) { int x; - for (x = 1; x < argc; x++) + for (x = 1; x < argc; x++) { #ifdef DEBUG - if (!strcmp("--debugaudio", argv[x])) + if (!strcmp("--debugaudio", argv[x])) { debug_audio = true; printf("Writing debug audio file.\n"); } - else + else #endif if (!strcmp("--debugwps", argv[x])) { debug_wps = true; printf("WPS debug mode enabled.\n"); - } + } else if (!strcmp("--nobackground", argv[x])) { background = false; printf("Disabling background image.\n"); - } + } #ifdef HAVE_REMOTE_LCD else if (!strcmp("--noremote", argv[x])) { @@ -346,7 +358,7 @@ void sys_handle_argv(int argc, char *argv[]) display_zoom=atof(argv[x]); else display_zoom = 2; - printf("Window zoom is %d\n", display_zoom); + printf("Window zoom is %f\n", display_zoom); } else if (!strcmp("--alarm", argv[x])) { @@ -372,7 +384,7 @@ void sys_handle_argv(int argc, char *argv[]) debug_buttons = true; printf("Printing background button clicks.\n"); } - else + else { printf("rockboxui\n"); printf("Arguments:\n"); diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index 17a0f847b5..abd6339cee 100644 --- a/firmware/target/hosted/sdl/thread-sdl.c +++ b/firmware/target/hosted/sdl/thread-sdl.c @@ -340,7 +340,7 @@ unsigned int create_thread(void (*function)(void), return 0; } - SDL_Thread *t = SDL_CreateThread(runthread, thread); + SDL_Thread *t = SDL_CreateThread(runthread, NULL, thread); if (t == NULL) { DEBUGF("Failed to create SDL thread\n"); @@ -447,7 +447,7 @@ void init_threads(void) thread->context.s = SDL_CreateSemaphore(0); thread->context.t = NULL; /* NULL for the implicit main thread */ __running_self_entry() = thread; - + if (thread->context.s == NULL) { fprintf(stderr, "Failed to create main semaphore\n"); diff --git a/tools/configure b/tools/configure index 43f119ae17..4b4abb03df 100755 --- a/tools/configure +++ b/tools/configure @@ -162,7 +162,7 @@ findtool(){ # scan the $PATH for sdl-config - check whether for a (cross-)win32 # sdl as requested findsdl(){ - files=sdl-config + files=sdl2-config if [ -n "$CROSS_COMPILE" ]; then # sdl-config might (not) be prefixed for cross compiles so try both. files="${CROSS_COMPILE}sdl-config:${files}" @@ -1676,7 +1676,7 @@ cat <