summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-01-29 14:16:30 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-01-29 14:16:30 +0000
commit7d1117fe4f594c9ef8c7faef3dea701db0526255 (patch)
treeeb8e196e566937fc1352919e5ebea3bbbd66e4a4
parentc87730e9e3a79e4eb0b8774428ae822a04189b6b (diff)
downloadrockbox-7d1117fe4f594c9ef8c7faef3dea701db0526255.zip
rockbox-7d1117fe4f594c9ef8c7faef3dea701db0526255.tar.gz
rockbox-7d1117fe4f594c9ef8c7faef3dea701db0526255.tar.bz2
rockbox-7d1117fe4f594c9ef8c7faef3dea701db0526255.tar.xz
Cache wps image files to allow really fast boot.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8483 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/gwps-common.c92
-rw-r--r--apps/gui/gwps-common.h3
-rw-r--r--apps/gui/gwps.c5
3 files changed, 97 insertions, 3 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index b32deba..9b32b86 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -75,6 +75,15 @@ static char* skip_utf8_bom(char* buf)
* a..z and A..Z
*/
#ifdef HAVE_LCD_BITMAP
+struct bmp_cache_entry {
+ char filename[MAX_PATH];
+ int width;
+ int height;
+ int size;
+};
+static int bmp_cache_fd = -1;
+static bool bmp_cache_write;
+
static int get_image_id(int c)
{
if(c >= 'a' && c <= 'z')
@@ -83,7 +92,60 @@ static int get_image_id(int c)
c = c - 'A' + 26;
return c;
}
+
+void wps_initialize_bmp_cache(const char *file)
+{
+ bmp_cache_fd = open(file, O_RDONLY);
+ bmp_cache_write = 0;
+ if (bmp_cache_fd < 0)
+ {
+ bmp_cache_fd = open(file, O_WRONLY | O_CREAT);
+ bmp_cache_write = 1;
+ }
+}
+
+void wps_close_bmp_cache(const char *file)
+{
+ if (bmp_cache_fd >= 0)
+ {
+ close(bmp_cache_fd);
+ bmp_cache_fd = -1;
+ return ;
+ }
+
+ /* Remove the file if cache read failed. */
+ remove(file);
+}
+
+static int read_bmp_from_cache(const char *filename, struct bitmap *bm,
+ int buflen)
+{
+ struct bmp_cache_entry c;
+ int rc;
+
+ if (!bmp_cache_fd || bmp_cache_write)
+ return -1;
+
+ rc = read(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
+ if (rc != sizeof(struct bmp_cache_entry))
+ return -2;
+
+ if (buflen < c.size)
+ return -3;
+
+ if (strcasecmp(filename, c.filename))
+ return -4;
+
+ bm->width = c.width;
+ bm->height = c.height;
+ rc = read(bmp_cache_fd, bm->data, c.size);
+ if (rc != c.size)
+ return -4;
+
+ return c.size;
+}
#endif
+
/*
* parse the given buffer for following static tags:
* %x - load image for always display
@@ -217,11 +279,35 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf,
/* load the image */
data->img[n].bm.data = data->img_buf_ptr;
- ret = read_bmp_file(imgname, &data->img[n].bm,
- data->img_buf_free,
- FORMAT_ANY|FORMAT_TRANSPARENT);
+ ret = read_bmp_from_cache(imgname, &data->img[n].bm,
+ data->img_buf_free);
+
+ if (ret < 0)
+ {
+ if (!bmp_cache_write)
+ {
+ close(bmp_cache_fd);
+ bmp_cache_fd = -1;
+ }
+
+ ret = read_bmp_file(imgname, &data->img[n].bm,
+ data->img_buf_free,
+ FORMAT_ANY|FORMAT_TRANSPARENT);
+ }
+
if (ret > 0)
{
+ if (bmp_cache_write && bmp_cache_fd >= 0)
+ {
+ struct bmp_cache_entry c;
+ strncpy(c.filename, imgname, sizeof(c.filename)-1);
+ c.width = data->img[n].bm.width;
+ c.height = data->img[n].bm.height;
+ c.size = ret;
+ write(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
+ write(bmp_cache_fd, data->img_buf_ptr, ret);
+ }
+
data->img_buf_ptr += ret;
data->img_buf_free -= ret;
data->img[n].loaded = true;
diff --git a/apps/gui/gwps-common.h b/apps/gui/gwps-common.h
index ecda1d4..b106203 100644
--- a/apps/gui/gwps-common.h
+++ b/apps/gui/gwps-common.h
@@ -23,6 +23,9 @@
#include "gwps.h"
+void wps_initialize_bmp_cache(const char *file);
+void wps_close_bmp_cache(const char *file);
+
void gui_wps_format_time(char* buf, int buf_size, long time);
void fade(bool fade_in);
void gui_wps_format(struct wps_data *data);
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c
index d7d436c..e7ae672 100644
--- a/apps/gui/gwps.c
+++ b/apps/gui/gwps.c
@@ -862,6 +862,7 @@ bool wps_data_load(struct wps_data *wps_data,
wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */
wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */
+ wps_initialize_bmp_cache(ROCKBOX_DIR "/.wpscache");
#endif
while( ( read_line(fd, &wps_data->format_buffer[start],
sizeof(wps_data->format_buffer)-start) ) > 0 )
@@ -880,6 +881,10 @@ bool wps_data_load(struct wps_data *wps_data,
}
}
+#ifdef HAVE_LCD_BITMAP
+ wps_close_bmp_cache(ROCKBOX_DIR "/.wpscache");
+#endif
+
if (start > 0)
{
gui_wps_format(wps_data);