From 164b7fcc797e8ae58845db4e4f129ccdaccb41fa Mon Sep 17 00:00:00 2001 From: kugel Date: Thu, 6 Aug 2009 00:14:40 +0000 Subject: [PATCH] Add backdrop functions to the multiscreen api and add a enum backdrop_type parameter for different backdrops (main, wps), symplifying calls and removing dozens of #ifdefs (stubs added for non-backdrop displays that can't do backdrops). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22176 a1c6a512-1295-4272-9138-f99709370657 --- apps/bookmark.c | 10 ++- apps/filetree.c | 4 +- apps/gui/backdrop.c | 141 ++++++++++++++++++++++++------------- apps/gui/backdrop.h | 59 ++++++++++++---- apps/gui/skin_engine/wps_display.c | 9 +-- apps/gui/skin_engine/wps_parser.c | 19 ++--- apps/gui/wps.c | 38 +++------- apps/menus/theme_menu.c | 4 +- apps/onplay.c | 4 +- apps/screen_access.c | 11 ++- apps/screen_access.h | 4 ++ apps/screens.c | 7 +- apps/settings.c | 19 ++--- 13 files changed, 185 insertions(+), 144 deletions(-) diff --git a/apps/bookmark.c b/apps/bookmark.c index 892a3d35b..5b9276779 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c @@ -164,6 +164,7 @@ bool bookmark_autobookmark(void) char* bookmark; if (!system_check()) return false; + int i; audio_pause(); /* first pause playback */ bookmark = create_bookmark(); @@ -191,12 +192,9 @@ bool bookmark_autobookmark(void) str(LANG_CONFIRM_WITH_BUTTON)}; const struct text_message message={lines, 2}; #endif -#if LCD_DEPTH > 1 - show_main_backdrop(); /* switch to main backdrop as we may come from wps */ -#endif -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - show_remote_main_backdrop(); -#endif + FOR_NB_SCREENS(i) + screens[i].backdrop_show(BACKDROP_MAIN); + if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) { if (global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK) diff --git a/apps/filetree.c b/apps/filetree.c index e6be09ad6..6a7da4067 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -482,7 +482,7 @@ int ft_enter(struct tree_context* c) case FILE_ATTR_WPS: splash(0, ID2P(LANG_WAIT)); #if LCD_DEPTH > 1 - unload_wps_backdrop(); + backdrop_unload(BACKDROP_SKIN_WPS); #endif wps_data_load(SCREEN_MAIN, buf, true); set_file(buf, (char *)global_settings.wps_file, @@ -494,7 +494,7 @@ int ft_enter(struct tree_context* c) case FILE_ATTR_RWPS: splash(0, ID2P(LANG_WAIT)); #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - unload_remote_wps_backdrop(); + remote_backdrop_unload(BACKDROP_SKIN_WPS); #endif wps_data_load(SCREEN_REMOTE, buf, true); set_file(buf, (char *)global_settings.rwps_file, diff --git a/apps/gui/backdrop.c b/apps/gui/backdrop.c index c95fda902..28216da4e 100644 --- a/apps/gui/backdrop.c +++ b/apps/gui/backdrop.c @@ -27,21 +27,19 @@ #endif #include "backdrop.h" -#if LCD_DEPTH >= 8 -static fb_data main_backdrop[LCD_HEIGHT][LCD_WIDTH] __attribute__ ((aligned (16))); -static fb_data wps_backdrop[LCD_HEIGHT][LCD_WIDTH] __attribute__ ((aligned (16))); -#elif LCD_DEPTH == 2 -static fb_data main_backdrop[LCD_FBHEIGHT][LCD_FBWIDTH]; -static fb_data wps_backdrop[LCD_FBHEIGHT][LCD_FBWIDTH]; -#endif +static fb_data main_backdrop[LCD_FBHEIGHT][LCD_FBHEIGHT] + __attribute__ ((aligned (16))); +static fb_data skin_backdrop[LCD_FBHEIGHT][LCD_FBHEIGHT] + __attribute__ ((aligned (16))); #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 -static fb_remote_data remote_wps_backdrop[LCD_REMOTE_FBHEIGHT][LCD_REMOTE_FBWIDTH]; -static bool remote_wps_backdrop_valid = false; +static fb_remote_data +remote_skin_backdrop[LCD_REMOTE_FBHEIGHT][LCD_REMOTE_FBWIDTH]; +static bool remote_skin_backdrop_valid = false; #endif static bool main_backdrop_valid = false; -static bool wps_backdrop_valid = false; +static bool skin_backdrop_valid = false; /* load a backdrop into a buffer */ static bool load_backdrop(const char* filename, fb_data* backdrop_buffer) @@ -54,49 +52,43 @@ static bool load_backdrop(const char* filename, fb_data* backdrop_buffer) ret = read_bmp_file(filename, &bm, sizeof(main_backdrop), FORMAT_NATIVE | FORMAT_DITHER, NULL); - if ((ret > 0) && (bm.width == LCD_WIDTH) && (bm.height == LCD_HEIGHT)) - { - return true; - } - else - { - return false; - } + return ((ret > 0) + && (bm.width == LCD_WIDTH) && (bm.height == LCD_HEIGHT)); } -bool load_main_backdrop(const char* filename) +static bool load_main_backdrop(const char* filename) { main_backdrop_valid = load_backdrop(filename, &main_backdrop[0][0]); return main_backdrop_valid; } -bool load_wps_backdrop(const char* filename) +static inline bool load_skin_backdrop(const char* filename) { - wps_backdrop_valid = load_backdrop(filename, &wps_backdrop[0][0]); - return wps_backdrop_valid; + skin_backdrop_valid = load_backdrop(filename, &skin_backdrop[0][0]); + return skin_backdrop_valid; } -void unload_main_backdrop(void) +static inline void unload_main_backdrop(void) { main_backdrop_valid = false; } -void unload_wps_backdrop(void) +static inline void unload_skin_backdrop(void) { - wps_backdrop_valid = false; + skin_backdrop_valid = false; } -void show_main_backdrop(void) +static inline void show_main_backdrop(void) { lcd_set_backdrop(main_backdrop_valid ? &main_backdrop[0][0] : NULL); } -void show_wps_backdrop(void) +static void show_skin_backdrop(void) { /* if no wps backdrop, fall back to main backdrop */ - if(wps_backdrop_valid) + if(skin_backdrop_valid) { - lcd_set_backdrop(&wps_backdrop[0][0]); + lcd_set_backdrop(&skin_backdrop[0][0]); } else { @@ -104,9 +96,39 @@ void show_wps_backdrop(void) } } +/* api functions */ + +bool backdrop_load(enum backdrop_type bdrop, const char* filename) +{ + if (bdrop == BACKDROP_MAIN) + return load_main_backdrop(filename); + else if (bdrop == BACKDROP_SKIN_WPS) + return load_skin_backdrop(filename); + else + return false; +} + +void backdrop_unload(enum backdrop_type bdrop) +{ + if (bdrop == BACKDROP_MAIN) + unload_main_backdrop(); + else if (bdrop == BACKDROP_SKIN_WPS) + unload_skin_backdrop(); +} + +void backdrop_show(enum backdrop_type bdrop) +{ + if (bdrop == BACKDROP_MAIN) + show_main_backdrop(); + else if (bdrop == BACKDROP_SKIN_WPS) + show_skin_backdrop(); +} + + #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 -static bool load_remote_backdrop(const char* filename, fb_remote_data* backdrop_buffer) +static bool load_remote_backdrop(const char* filename, + fb_remote_data* backdrop_buffer) { struct bitmap bm; int ret; @@ -116,33 +138,29 @@ static bool load_remote_backdrop(const char* filename, fb_remote_data* backdrop_ ret = read_bmp_file(filename, &bm, sizeof(main_backdrop), FORMAT_NATIVE | FORMAT_DITHER | FORMAT_REMOTE, NULL); - if ((ret > 0) && (bm.width == LCD_REMOTE_WIDTH) && (bm.height == LCD_REMOTE_HEIGHT)) - { - return true; - } - else - { - return false; - } + return ((ret > 0) + && (bm.width == LCD_REMOTE_WIDTH) + && (bm.height == LCD_REMOTE_HEIGHT)); } -bool load_remote_wps_backdrop(const char* filename) +static inline bool load_remote_skin_backdrop(const char* filename) { - remote_wps_backdrop_valid = load_remote_backdrop(filename, &remote_wps_backdrop[0][0]); - return remote_wps_backdrop_valid; + remote_skin_backdrop_valid = + load_remote_backdrop(filename, &remote_skin_backdrop[0][0]); + return remote_skin_backdrop_valid; } -void unload_remote_wps_backdrop(void) +static inline void unload_remote_skin_backdrop(void) { - remote_wps_backdrop_valid = false; + remote_skin_backdrop_valid = false; } -void show_remote_wps_backdrop(void) +static inline void show_remote_skin_backdrop(void) { /* if no wps backdrop, fall back to main backdrop */ - if(remote_wps_backdrop_valid) + if(remote_skin_backdrop_valid) { - lcd_remote_set_backdrop(&remote_wps_backdrop[0][0]); + lcd_remote_set_backdrop(&remote_skin_backdrop[0][0]); } else { @@ -150,8 +168,37 @@ void show_remote_wps_backdrop(void) } } -void show_remote_main_backdrop(void) +static line void show_remote_main_backdrop(void) { lcd_remote_set_backdrop(NULL); } + + +/* api functions */ +bool remote_backdrop_load(enum backdrop_type bdrop, + const char *filename) +{ + if (bdrop == BACKDROP_SKIN_WPS) + return load_remote_skin_backdrop(filename); + else if (bdrop == BACKDROP_MAIN) + return true; + else + return false; +} + +void remote_backrop_show(enum backdrop_type bdrop) +{ + if (bdrop == BACKDROP_MAIN) + show_remote_main_backdrop(); + else if (bdrop == BACKDROP_SKIN_WPS) + show_remote_skin_backdrop(); +} + +void remote_backdrop_unload(enum backdrop_type bdrop) +{ + if (bdrop != BACKDROP_MAIN) + unload_remote_skin_backdrop(); +} + + #endif diff --git a/apps/gui/backdrop.h b/apps/gui/backdrop.h index dc9805f07..f3ef1d768 100644 --- a/apps/gui/backdrop.h +++ b/apps/gui/backdrop.h @@ -22,27 +22,62 @@ #ifndef _BACKDROP_H #define _BACKDROP_H +enum backdrop_type { + BACKDROP_MAIN, + BACKDROP_SKIN_WPS, +}; + #if LCD_DEPTH > 1 #include "lcd.h" #include "bmp.h" -bool load_main_backdrop(const char* filename); -bool load_wps_backdrop(const char* filename); +bool backdrop_load(enum backdrop_type bdrop, const char*); +void backdrop_unload(enum backdrop_type bdrop); +void backdrop_show(enum backdrop_type bdrop); + +#else /* LCD_DEPTH > 1 */ + +static inline +bool backdrop_load(enum backdrop_type bdrop, const char* filename) +{ + (void)filename; (void)bdrop; return true; +} -void unload_main_backdrop(void); -void unload_wps_backdrop(void); +static inline void backdrop_unload(enum backdrop_type bdrop) +{ + (void)bdrop; +} +static inline void backdrop_show(enum backdrop_type bdrop) +{ + (void)bdrop; +} -void show_main_backdrop(void); -void show_wps_backdrop(void); +#endif + +#if defined(HAVE_REMOTE_LCD) +/* no main backdrop, stubs! */ +#if LCD_REMOTE_DEPTH > 1 +bool remote_backdrop_load(enum backdrop_type bdrop,const char* filename); +void remote_backdropunload(enum backdrop_type bdrop); +void remote_backdrop_show(enum backdrop_type bdrop); +#else +static inline +bool remote_backdrop_load(enum backdrop_type bdrop,const char* filename) +{ + (void)filename; (void)bdrop; return true; +} -#endif /* LCD_DEPTH > 1 */ +static inline void remote_backdrop_unload(enum backdrop_type bdrop) +{ + (void)bdrop; +} -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 -bool load_remote_wps_backdrop(const char* filename); -void unload_remote_wps_backdrop(void); -void show_remote_wps_backdrop(void); -void show_remote_main_backdrop(void); /* only clears the wps backdrop */ +static inline void remote_backdrop_show(enum backdrop_type bdrop) +{ + (void)bdrop; +} +#endif #endif #endif /* _BACKDROP_H */ diff --git a/apps/gui/skin_engine/wps_display.c b/apps/gui/skin_engine/wps_display.c index 98050093c..6a94c6a94 100644 --- a/apps/gui/skin_engine/wps_display.c +++ b/apps/gui/skin_engine/wps_display.c @@ -82,14 +82,7 @@ bool gui_wps_display(struct gui_wps *gwps) } #endif display->clear_display(); -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - if (display->screen_type == SCREEN_REMOTE) - show_remote_wps_backdrop(); - else if (display->screen_type == SCREEN_MAIN) -#endif -#if LCD_DEPTH > 1 - show_wps_backdrop(); -#endif + display->backdrop_show(BACKDROP_SKIN_WPS); return gui_wps_redraw(gwps, WPS_REFRESH_ALL); } diff --git a/apps/gui/skin_engine/wps_parser.c b/apps/gui/skin_engine/wps_parser.c index 1a903c98e..c37cd786e 100644 --- a/apps/gui/skin_engine/wps_parser.c +++ b/apps/gui/skin_engine/wps_parser.c @@ -1635,26 +1635,15 @@ static bool load_wps_bitmaps(struct wps_data *wps_data, char *bmpdir) #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) if (bmp_names[BACKDROP_BMP]) { + int screen = SCREEN_MAIN; get_image_filename(bmp_names[BACKDROP_BMP], bmpdir, img_path, sizeof(img_path)); - #if defined(HAVE_REMOTE_LCD) /* We only need to check LCD type if there is a remote LCD */ - if (!wps_data->remote_wps) -#endif - { - /* Load backdrop for the main LCD */ - if (!load_wps_backdrop(img_path)) - return false; - } -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - else - { - /* Load backdrop for the remote LCD */ - if (!load_remote_wps_backdrop(img_path)) - return false; - } + if (wps_data->remote_wps) + screen = SCREEN_REMOTE; #endif + screens[screen].backdrop_load(BACKDROP_SKIN_WPS, img_path); } #endif /* has backdrop support */ diff --git a/apps/gui/wps.c b/apps/gui/wps.c index bce4db2b8..bbf169ff9 100644 --- a/apps/gui/wps.c +++ b/apps/gui/wps.c @@ -92,7 +92,8 @@ static void nextid3available_callback(void* param); void wps_data_load(enum screen_type screen, const char *buf, bool isfile) { - bool loaded_ok = buf && skin_data_load(gui_wps[screen].data, &screens[screen], buf, isfile); + bool loaded_ok = buf && skin_data_load(gui_wps[screen].data, + &screens[screen], buf, isfile); if (!loaded_ok) /* load the hardcoded default */ { char *skin_buf[NB_SCREENS] = { @@ -115,24 +116,9 @@ void wps_data_load(enum screen_type screen, const char *buf, bool isfile) "%pb\n", #endif }; + screens[screen].backdrop_unload(BACKDROP_SKIN_WPS); skin_data_load(gui_wps[screen].data, &screens[screen], skin_buf[screen], false); - /* set the default wps for the main-screen */ - if(screen == SCREEN_MAIN) - { -#if LCD_DEPTH > 1 - unload_wps_backdrop(); -#endif - } -#ifdef HAVE_REMOTE_LCD - /* set the default wps for the remote-screen */ - else if(screen == SCREEN_REMOTE) - { -#if LCD_REMOTE_DEPTH > 1 - unload_remote_wps_backdrop(); -#endif - } -#endif } #ifdef HAVE_REMOVE_LCD gui_wps[screen].data->remote_wps = !(screen == SCREEN_MAIN); @@ -564,16 +550,13 @@ static void gwps_leave_wps(void) int i, oldbars = VP_SB_HIDE_ALL; FOR_NB_SCREENS(i) + { gui_wps[i].display->stop_scroll(); + gui_wps[i].display->backdrop_show(BACKDROP_MAIN); + } if (global_settings.statusbar) oldbars = VP_SB_ALLSCREENS; -#if LCD_DEPTH > 1 - show_main_backdrop(); -#endif -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - show_remote_main_backdrop(); -#endif viewportmanager_set_statusbar(oldbars); #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) /* Play safe and unregister the hook */ @@ -1237,23 +1220,18 @@ void gui_sync_wps_init(void) wps_datas[i].wps_uses_albumart = 0; #endif #ifdef HAVE_REMOTE_LCD - wps_datas[i].remote_wps = (i != 0); + wps_datas[i].remote_wps = (i == SCREEN_REMOTE); #endif gui_wps[i].data = &wps_datas[i]; gui_wps[i].display = &screens[i]; /* Currently no seperate wps_state needed/possible so use the only available ( "global" ) one */ gui_wps[i].state = &wps_state; + gui_wps[i].display->backdrop_unload(BACKDROP_SKIN_WPS); } #ifdef HAVE_LCD_BITMAP add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler); #endif -#if LCD_DEPTH > 1 - unload_wps_backdrop(); -#endif -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - unload_remote_wps_backdrop(); -#endif } #ifdef HAVE_ALBUMART diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c index 25b18244a..f96a6ced4 100644 --- a/apps/menus/theme_menu.c +++ b/apps/menus/theme_menu.c @@ -46,8 +46,8 @@ static int clear_main_backdrop(void) { global_settings.backdrop_file[0]=0; - unload_main_backdrop(); - show_main_backdrop(); + backdrop_unload(BACKDROP_MAIN); + backdrop_show(BACKDROP_MAIN); settings_save(); return 0; } diff --git a/apps/onplay.c b/apps/onplay.c index ad71f7302..3052f8dfd 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -560,11 +560,11 @@ static bool delete_dir(void) static bool set_backdrop(void) { /* load the image */ - if(load_main_backdrop(selected_file)) { + if(backdrop_load(BACKDROP_MAIN, selected_file)) { splash(HZ, str(LANG_BACKDROP_LOADED)); set_file(selected_file, (char *)global_settings.backdrop_file, MAX_FILENAME); - show_main_backdrop(); + backdrop_show(BACKDROP_MAIN); return true; } else { splash(HZ, str(LANG_BACKDROP_FAILED)); diff --git a/apps/screen_access.c b/apps/screen_access.c index 2f928b736..d0b483f3f 100644 --- a/apps/screen_access.c +++ b/apps/screen_access.c @@ -31,6 +31,7 @@ #include #include "screen_access.h" +#include "backdrop.h" /* some helper functions to calculate metrics on the fly */ static int screen_helper_getcharwidth(void) @@ -197,8 +198,11 @@ struct screen screens[NB_SCREENS] = .backlight_off=&backlight_off, .is_backlight_on=&is_backlight_on, .backlight_set_timeout=&backlight_set_timeout, + .backdrop_load=&backdrop_load, + .backdrop_unload=&backdrop_unload, + .backdrop_show=&backdrop_show, #ifdef HAVE_BUTTONBAR - .has_buttonbar=false + .has_buttonbar=false, #endif }, #if NB_SCREENS == 2 @@ -278,7 +282,10 @@ struct screen screens[NB_SCREENS] = .backlight_on=&remote_backlight_on, .backlight_off=&remote_backlight_off, .is_backlight_on=&is_remote_backlight_on, - .backlight_set_timeout=&remote_backlight_set_timeout + .backlight_set_timeout=&remote_backlight_set_timeout, + .backdrop_load=&remote_backdrop_load, + .backdrop_unload=&remote_backdrop_unload, + .backdrop_show=&remote_backdrop_show, } #endif /* HAVE_REMOTE_LCD */ }; diff --git a/apps/screen_access.h b/apps/screen_access.h index c76d2b1c8..f0fed0172 100644 --- a/apps/screen_access.h +++ b/apps/screen_access.h @@ -24,6 +24,7 @@ #include "lcd.h" #include "buttonbar.h" +#include "backdrop.h" enum screen_type { SCREEN_MAIN @@ -152,6 +153,9 @@ struct screen void (*backlight_off)(void); bool (*is_backlight_on)(bool ignore_always_off); void (*backlight_set_timeout)(int index); + bool (*backdrop_load)(enum backdrop_type bdrop, const char* filename); + void (*backdrop_unload)(enum backdrop_type bdrop); + void (*backdrop_show)(enum backdrop_type bdrop); }; #if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) diff --git a/apps/screens.c b/apps/screens.c index 9a986716f..9f1596cb7 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -183,14 +183,9 @@ void usb_screen(void) int i; bool statusbar = global_settings.statusbar; /* force the statusbar */ global_settings.statusbar = true; -#if LCD_DEPTH > 1 - show_main_backdrop(); -#endif -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - show_remote_main_backdrop(); -#endif FOR_NB_SCREENS(i) { + screens[i].backdrop_show(BACKDROP_MAIN); screens[i].backlight_on(); screens[i].clear_display(); #if NB_SCREENS > 1 diff --git a/apps/settings.c b/apps/settings.c index 423e6ed17..6a761ecdd 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -730,6 +730,7 @@ void settings_apply(bool read_disk) #if CONFIG_CODEC == SWCODEC int i; #endif + int screen; sound_settings_apply(); @@ -838,12 +839,7 @@ void settings_apply(bool read_disk) else load_kbd(NULL); #endif -#if LCD_DEPTH > 1 - unload_wps_backdrop(); -#endif -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - unload_remote_wps_backdrop(); -#endif + if ( global_settings.wps_file[0] && global_settings.wps_file[0] != 0xff ) { snprintf(buf, sizeof buf, WPS_DIR "/%s.wps", @@ -861,16 +857,15 @@ void settings_apply(bool read_disk) global_settings.backdrop_file[0] != 0xff ) { snprintf(buf, sizeof buf, BACKDROP_DIR "/%s.bmp", global_settings.backdrop_file); - load_main_backdrop(buf); + backdrop_load(BACKDROP_MAIN, buf); } else { - unload_main_backdrop(); + backdrop_unload(BACKDROP_MAIN); } - show_main_backdrop(); -#endif -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - show_remote_main_backdrop(); #endif + FOR_NB_SCREENS(screen) + screens[screen].backdrop_show(BACKDROP_MAIN); + #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) if ( global_settings.rwps_file[0]) { snprintf(buf, sizeof buf, WPS_DIR "/%s.rwps", -- 2.11.4.GIT