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
This commit is contained in:
Thomas Martitz 2009-08-06 00:14:40 +00:00
parent 4632fc0682
commit 4764ee04c9
13 changed files with 185 additions and 144 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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

View file

@ -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);
void unload_main_backdrop(void);
void unload_wps_backdrop(void);
#else /* LCD_DEPTH > 1 */
void show_main_backdrop(void);
void show_wps_backdrop(void);
static inline
bool backdrop_load(enum backdrop_type bdrop, const char* filename)
{
(void)filename; (void)bdrop; return true;
}
#endif /* LCD_DEPTH > 1 */
static inline void backdrop_unload(enum backdrop_type bdrop)
{
(void)bdrop;
}
static inline void backdrop_show(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 */
#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;
}
static inline void remote_backdrop_unload(enum backdrop_type bdrop)
{
(void)bdrop;
}
static inline void remote_backdrop_show(enum backdrop_type bdrop)
{
(void)bdrop;
}
#endif
#endif
#endif /* _BACKDROP_H */

View file

@ -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);
}

View file

@ -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 */

View file

@ -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

View file

@ -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;
}

View file

@ -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));

View file

@ -31,6 +31,7 @@
#include <icons.h>
#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 */
};

View file

@ -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)

View file

@ -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

View file

@ -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",