Skip to content

Commit

Permalink
SDL: Migrate to SDL2
Browse files Browse the repository at this point in the history
Incorporates large portions of g#5879 g#5282 g#5285 g#5286 g#5287

Differences from the above patches:

 * Removed all MacOS-specific stuff
 * Removed support for SDL1 entirely
 * Properly implement mousewheel support
 * Bumped up minimum stack size for sigalstack threading
 * Check for overflow before enqueing scrollwheel events

Tested on:

 * sdl application (Linux)
 * Simulator (x86_64, Linux) -- xduoox3/ipod4g/sansafuze
 * Simulator (i686, Windows) -- xduoox3
 * Simulator (arm64, Linux)

Change-Id: Ia3012dd1be123feb2888798a42d5b7cc149f382b
  • Loading branch information
speachy committed Oct 6, 2024
1 parent d13029e commit 7927423
Show file tree
Hide file tree
Showing 49 changed files with 709 additions and 717 deletions.
4 changes: 2 additions & 2 deletions firmware/asm/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 9 additions & 17 deletions firmware/target/hosted/sdl/app/button-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,64 +40,56 @@ 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;
#if (CONFIG_PLATFORM & PLATFORM_MAEMO|PLATFORM_PANDORA)
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;
Expand Down
86 changes: 45 additions & 41 deletions firmware/target/hosted/sdl/button-sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -362,7 +382,7 @@ static void button_event(int key, bool pressed)
}
return;
#endif

#ifdef HAS_REMOTE_BUTTON_HOLD
case SDLK_j:
if(pressed)
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -496,5 +501,4 @@ int button_read_device(void)

void button_init_device(void)
{
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
}
12 changes: 6 additions & 6 deletions firmware/target/hosted/sdl/kernel-sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand All @@ -175,7 +175,7 @@ Uint32 tick_timer(Uint32 interval, void *param)

sim_exit_irq_handler();
}

return interval;
}

Expand All @@ -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
{
Expand Down
9 changes: 5 additions & 4 deletions firmware/target/hosted/sdl/lcd-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions firmware/target/hosted/sdl/lcd-sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions firmware/target/hosted/sdl/lcd-sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
Expand All @@ -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,
Expand All @@ -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__ */

Loading

0 comments on commit 7927423

Please sign in to comment.