From f9b026fc4d74a1fb725c2b246bd94121be2fcf31 Mon Sep 17 00:00:00 2001 From: jdgordon Date: Tue, 16 Feb 2010 05:24:27 +0000 Subject: [PATCH] Reuse the backdrop buffers if 2 skins use the same backdrop (on the same screen of course) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24690 a1c6a512-1295-4272-9138-f99709370657 --- apps/SOURCES | 1 + apps/gui/skin_engine/skin_backdrops.c | 119 ++++++++++++++++++++++++++++++++++ apps/gui/skin_engine/skin_engine.h | 6 ++ apps/gui/skin_engine/skin_parser.c | 43 +----------- apps/gui/skin_engine/wps_internals.h | 3 +- apps/settings.c | 1 + 6 files changed, 132 insertions(+), 41 deletions(-) create mode 100644 apps/gui/skin_engine/skin_backdrops.c diff --git a/apps/SOURCES b/apps/SOURCES index cd7cde763..d86bb11fa 100644 --- a/apps/SOURCES +++ b/apps/SOURCES @@ -87,6 +87,7 @@ gui/statusbar-skinned.c gui/yesno.c gui/viewport.c +gui/skin_engine/skin_backdrops.c gui/skin_engine/skin_buffer.c gui/skin_engine/wps_debug.c gui/skin_engine/skin_display.c diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c new file mode 100644 index 000000000..b05793524 --- /dev/null +++ b/apps/gui/skin_engine/skin_backdrops.c @@ -0,0 +1,119 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: skin_tokens.c 24526 2010-02-05 23:58:53Z jdgordon $ + * + * Copyright (C) 2010 Jonathan Gordon + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include +#include +#include + +#include "settings.h" +#include "skin_buffer.h" +#include "wps_internals.h" +#include "skin_engine.h" + +#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) + +static struct skin_backdrop { + char name[MAX_FILENAME+1]; + char *buffer; + enum screen_type screen; +} backdrops[SKINNABLE_SCREENS_COUNT*NB_SCREENS]; + +void skin_backdrop_init(void) +{ + int i; + for(i=0;i 1) + if (screen == SCREEN_REMOTE) + buf_size = REMOTE_LCD_BACKDROP_BYTES; + else +#endif + buf_size = LCD_BACKDROP_BYTES; + + if (backdrop[0] == '-') + { +#if NB_SCREENS > 1 + if (screen == SCREEN_REMOTE) + { + return NULL; /* remotes don't have a backdrop setting (yet!) */ + } + else +#endif + { + if (!global_settings.backdrop_file[0]) + { + return NULL; /* backdrop setting not set */ + } + snprintf(filename, sizeof(filename), "%s/%s.bmp", + BACKDROP_DIR, global_settings.backdrop_file); + } + } + else + { + get_image_filename(backdrop, bmpdir, filename, sizeof(filename)); + } + + for(i=0;ibuffer = skin_buffer_alloc(buf_size); + if (!bdrop->buffer) + return NULL; + loaded = screens[screen].backdrop_load(filename, bdrop->buffer); + bdrop->screen = screen; + strlcpy(bdrop->name, backdrop, MAX_FILENAME+1); + bdrop->name[MAX_FILENAME] = '\0'; + + return loaded ? bdrop->buffer : NULL; +} +#else + +void skin_backdrop_init(void) +{ +} +#endif + diff --git a/apps/gui/skin_engine/skin_engine.h b/apps/gui/skin_engine/skin_engine.h index c5afe3e9f..642f15aaa 100644 --- a/apps/gui/skin_engine/skin_engine.h +++ b/apps/gui/skin_engine/skin_engine.h @@ -60,4 +60,10 @@ void skin_data_init(struct wps_data *wps_data); /* call this in statusbar toggle handlers if needed */ void skin_statusbar_changed(struct gui_wps*); + + +/* load a backdrop into the skin buffer. + * reuse buffers if the file is already loaded */ +char* skin_backdrop_load(char* backdrop, char *bmpdir, enum screen_type screen); +void skin_backdrop_init(void); #endif diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 034ff532f..fe68c7c57 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -567,7 +567,7 @@ static int get_image_id(int c) return -1; } -static char *get_image_filename(const char *start, const char* bmpdir, +char *get_image_filename(const char *start, const char* bmpdir, char *buf, int buf_size) { const char *end = strchr(start, '|'); @@ -2045,45 +2045,8 @@ static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir) */ if (wps_data->backdrop) { - char img_path[MAX_PATH]; - bool loaded = false; - size_t buf_size; -#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) - if (curr_screen == SCREEN_REMOTE) - buf_size = REMOTE_LCD_BACKDROP_BYTES; - else -#endif - buf_size = LCD_BACKDROP_BYTES; - if (wps_data->backdrop[0] == '-') - { -#if NB_SCREENS > 1 - if (curr_screen == SCREEN_REMOTE) - { - wps_data->backdrop = NULL; - return true; - } - else -#endif - { - if (!global_settings.backdrop_file[0]) - { - wps_data->backdrop = NULL; - return true; - } - snprintf(img_path, sizeof(img_path), "%s/%s.bmp", - BACKDROP_DIR, global_settings.backdrop_file); - } - } - else - { - get_image_filename(wps_data->backdrop, bmpdir, - img_path, sizeof(img_path)); - } - char *buffer = skin_buffer_alloc(buf_size); - if (!buffer) - return false; - loaded = screens[curr_screen].backdrop_load(img_path, buffer); - wps_data->backdrop = loaded ? buffer : NULL; + wps_data->backdrop = skin_backdrop_load(wps_data->backdrop, + bmpdir, curr_screen); } #endif /* has backdrop support */ diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index e659f08d3..04a295a44 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h @@ -353,7 +353,8 @@ struct gui_wps /* gui_wps end */ - +char *get_image_filename(const char *start, const char* bmpdir, + char *buf, int buf_size); /***** wps_tokens.c ******/ const char *get_token_value(struct gui_wps *gwps, diff --git a/apps/settings.c b/apps/settings.c index 574aa2715..536e5e90e 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -741,6 +741,7 @@ void settings_apply_skins(void) /* re-initialize the skin buffer before we start reloading skins */ skin_buffer_init(); #ifdef HAVE_LCD_BITMAP + skin_backdrop_init(); skin_font_init(); if ( global_settings.sbs_file[0] && global_settings.sbs_file[0] != 0xff ) -- 2.11.4.GIT