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.tar.gz
rockbox-7d1117fe4f594c9ef8c7faef3dea701db0526255.zip
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 b32deba479..9b32b862ff 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -75,6 +75,15 @@ static char* skip_utf8_bom(char* buf)
75 * a..z and A..Z 75 * a..z and A..Z
76 */ 76 */
77#ifdef HAVE_LCD_BITMAP 77#ifdef HAVE_LCD_BITMAP
78struct bmp_cache_entry {
79 char filename[MAX_PATH];
80 int width;
81 int height;
82 int size;
83};
84static int bmp_cache_fd = -1;
85static bool bmp_cache_write;
86
78static int get_image_id(int c) 87static int get_image_id(int c)
79{ 88{
80 if(c >= 'a' && c <= 'z') 89 if(c >= 'a' && c <= 'z')
@@ -83,7 +92,60 @@ static int get_image_id(int c)
83 c = c - 'A' + 26; 92 c = c - 'A' + 26;
84 return c; 93 return c;
85} 94}
95
96void wps_initialize_bmp_cache(const char *file)
97{
98 bmp_cache_fd = open(file, O_RDONLY);
99 bmp_cache_write = 0;
100 if (bmp_cache_fd < 0)
101 {
102 bmp_cache_fd = open(file, O_WRONLY | O_CREAT);
103 bmp_cache_write = 1;
104 }
105}
106
107void wps_close_bmp_cache(const char *file)
108{
109 if (bmp_cache_fd >= 0)
110 {
111 close(bmp_cache_fd);
112 bmp_cache_fd = -1;
113 return ;
114 }
115
116 /* Remove the file if cache read failed. */
117 remove(file);
118}
119
120static int read_bmp_from_cache(const char *filename, struct bitmap *bm,
121 int buflen)
122{
123 struct bmp_cache_entry c;
124 int rc;
125
126 if (!bmp_cache_fd || bmp_cache_write)
127 return -1;
128
129 rc = read(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
130 if (rc != sizeof(struct bmp_cache_entry))
131 return -2;
132
133 if (buflen < c.size)
134 return -3;
135
136 if (strcasecmp(filename, c.filename))
137 return -4;
138
139 bm->width = c.width;
140 bm->height = c.height;
141 rc = read(bmp_cache_fd, bm->data, c.size);
142 if (rc != c.size)
143 return -4;
144
145 return c.size;
146}
86#endif 147#endif
148
87/* 149/*
88 * parse the given buffer for following static tags: 150 * parse the given buffer for following static tags:
89 * %x - load image for always display 151 * %x - load image for always display
@@ -217,11 +279,35 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf,
217 279
218 /* load the image */ 280 /* load the image */
219 data->img[n].bm.data = data->img_buf_ptr; 281 data->img[n].bm.data = data->img_buf_ptr;
220 ret = read_bmp_file(imgname, &data->img[n].bm, 282 ret = read_bmp_from_cache(imgname, &data->img[n].bm,
221 data->img_buf_free, 283 data->img_buf_free);
222 FORMAT_ANY|FORMAT_TRANSPARENT); 284
285 if (ret < 0)
286 {
287 if (!bmp_cache_write)
288 {
289 close(bmp_cache_fd);
290 bmp_cache_fd = -1;
291 }
292
293 ret = read_bmp_file(imgname, &data->img[n].bm,
294 data->img_buf_free,
295 FORMAT_ANY|FORMAT_TRANSPARENT);
296 }
297
223 if (ret > 0) 298 if (ret > 0)
224 { 299 {
300 if (bmp_cache_write && bmp_cache_fd >= 0)
301 {
302 struct bmp_cache_entry c;
303 strncpy(c.filename, imgname, sizeof(c.filename)-1);
304 c.width = data->img[n].bm.width;
305 c.height = data->img[n].bm.height;
306 c.size = ret;
307 write(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
308 write(bmp_cache_fd, data->img_buf_ptr, ret);
309 }
310
225 data->img_buf_ptr += ret; 311 data->img_buf_ptr += ret;
226 data->img_buf_free -= ret; 312 data->img_buf_free -= ret;
227 data->img[n].loaded = true; 313 data->img[n].loaded = true;
diff --git a/apps/gui/gwps-common.h b/apps/gui/gwps-common.h
index ecda1d47ea..b106203f98 100644
--- a/apps/gui/gwps-common.h
+++ b/apps/gui/gwps-common.h
@@ -23,6 +23,9 @@
23 23
24#include "gwps.h" 24#include "gwps.h"
25 25
26void wps_initialize_bmp_cache(const char *file);
27void wps_close_bmp_cache(const char *file);
28
26void gui_wps_format_time(char* buf, int buf_size, long time); 29void gui_wps_format_time(char* buf, int buf_size, long time);
27void fade(bool fade_in); 30void fade(bool fade_in);
28void gui_wps_format(struct wps_data *data); 31void gui_wps_format(struct wps_data *data);
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c
index d7d436c089..e7ae67266f 100644
--- a/apps/gui/gwps.c
+++ b/apps/gui/gwps.c
@@ -862,6 +862,7 @@ bool wps_data_load(struct wps_data *wps_data,
862 wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */ 862 wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */
863 863
864 wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */ 864 wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */
865 wps_initialize_bmp_cache(ROCKBOX_DIR "/.wpscache");
865#endif 866#endif
866 while( ( read_line(fd, &wps_data->format_buffer[start], 867 while( ( read_line(fd, &wps_data->format_buffer[start],
867 sizeof(wps_data->format_buffer)-start) ) > 0 ) 868 sizeof(wps_data->format_buffer)-start) ) > 0 )
@@ -880,6 +881,10 @@ bool wps_data_load(struct wps_data *wps_data,
880 } 881 }
881 } 882 }
882 883
884#ifdef HAVE_LCD_BITMAP
885 wps_close_bmp_cache(ROCKBOX_DIR "/.wpscache");
886#endif
887
883 if (start > 0) 888 if (start > 0)
884 { 889 {
885 gui_wps_format(wps_data); 890 gui_wps_format(wps_data);