diff options
author | Fred Bauer <fred.w.bauer@gmail.com> | 2011-10-17 13:17:04 +0000 |
---|---|---|
committer | Fred Bauer <fred.w.bauer@gmail.com> | 2011-10-17 13:17:04 +0000 |
commit | 8c9017211e466cde0dc729c1814d813192ffd570 (patch) | |
tree | 567d7332df052e0e5fbef9f4550ff7b44ca3db74 | |
parent | afc42ff7935274b9cee2980635e69985ddaa844b (diff) | |
download | rockbox-8c9017211e466cde0dc729c1814d813192ffd570.tar.gz rockbox-8c9017211e466cde0dc729c1814d813192ffd570.zip |
Faster cached font loading. FS#12333
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30769 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/export/font.h | 2 | ||||
-rw-r--r-- | firmware/font.c | 40 | ||||
-rw-r--r-- | tools/convbdf.c | 2 |
3 files changed, 39 insertions, 5 deletions
diff --git a/firmware/export/font.h b/firmware/export/font.h index 36c6e0a291..02476c17ff 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -100,6 +100,8 @@ struct font { | |||
100 | 100 | ||
101 | /* file, buffer and cache management */ | 101 | /* file, buffer and cache management */ |
102 | int fd; /* fd for the font file. >= 0 if cached */ | 102 | int fd; /* fd for the font file. >= 0 if cached */ |
103 | int fd_width; /* fd for the font file. >= 0 if cached */ | ||
104 | int fd_offset; /* fd for the font file. >= 0 if cached */ | ||
103 | unsigned char *buffer_start; /* buffer to store the font in */ | 105 | unsigned char *buffer_start; /* buffer to store the font in */ |
104 | unsigned char *buffer_position; /* position in the buffer */ | 106 | unsigned char *buffer_position; /* position in the buffer */ |
105 | unsigned char *buffer_end; /* end of the buffer */ | 107 | unsigned char *buffer_end; /* end of the buffer */ |
diff --git a/firmware/font.c b/firmware/font.c index 8b70a7dcb9..943f2e2d06 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -394,7 +394,22 @@ static bool internal_load_font(int font_id, const char *path, char *buf, | |||
394 | return false; | 394 | return false; |
395 | } | 395 | } |
396 | 396 | ||
397 | /* Cheat to get sector cache for different parts of font * | ||
398 | * file while preloading glyphs. Without this the disk head * | ||
399 | * thrashes between the width, offset, and bitmap data * | ||
400 | * in glyph_cache_load(). */ | ||
401 | pf->fd_width = open(path, O_RDONLY|O_BINARY); | ||
402 | pf->fd_offset = open(path, O_RDONLY|O_BINARY); | ||
403 | |||
397 | glyph_cache_load(font_id); | 404 | glyph_cache_load(font_id); |
405 | |||
406 | if(pf->fd_width >= 0) | ||
407 | close(pf->fd_width); | ||
408 | pf->fd_width = -1; | ||
409 | |||
410 | if(pf->fd_offset >= 0) | ||
411 | close(pf->fd_offset); | ||
412 | pf->fd_offset = -1; | ||
398 | } | 413 | } |
399 | else | 414 | else |
400 | { | 415 | { |
@@ -402,6 +417,8 @@ static bool internal_load_font(int font_id, const char *path, char *buf, | |||
402 | pf->buffer_end = pf->buffer_position + size; | 417 | pf->buffer_end = pf->buffer_position + size; |
403 | close(pf->fd); | 418 | close(pf->fd); |
404 | pf->fd = -1; | 419 | pf->fd = -1; |
420 | pf->fd_width = -1; | ||
421 | pf->fd_offset = -1; | ||
405 | 422 | ||
406 | if (!font_load_header(pf)) | 423 | if (!font_load_header(pf)) |
407 | { | 424 | { |
@@ -451,6 +468,8 @@ static int alloc_and_init(int font_idx, const char* name, size_t size) | |||
451 | pdata->refcount = 1; | 468 | pdata->refcount = 1; |
452 | pf->buffer_position = pf->buffer_start = buffer_from_handle(handle); | 469 | pf->buffer_position = pf->buffer_start = buffer_from_handle(handle); |
453 | pf->buffer_size = size; | 470 | pf->buffer_size = size; |
471 | pf->fd_width = -1; | ||
472 | pf->fd_offset = -1; | ||
454 | return handle; | 473 | return handle; |
455 | } | 474 | } |
456 | 475 | ||
@@ -639,14 +658,20 @@ load_cache_entry(struct font_cache_entry* p, void* callback_data) | |||
639 | int handle = pf_to_handle(pf); | 658 | int handle = pf_to_handle(pf); |
640 | unsigned short char_code = p->_char_code; | 659 | unsigned short char_code = p->_char_code; |
641 | unsigned char tmp[2]; | 660 | unsigned char tmp[2]; |
661 | int fd; | ||
642 | 662 | ||
643 | if (handle > 0) | 663 | if (handle > 0) |
644 | lock_font_handle(handle, true); | 664 | lock_font_handle(handle, true); |
645 | if (pf->file_width_offset) | 665 | if (pf->file_width_offset) |
646 | { | 666 | { |
647 | int width_offset = pf->file_width_offset + char_code; | 667 | int width_offset = pf->file_width_offset + char_code; |
648 | lseek(pf->fd, width_offset, SEEK_SET); | 668 | /* load via different fd to get this file section cached */ |
649 | read(pf->fd, &(p->width), 1); | 669 | if(pf->fd_width >=0 ) |
670 | fd = pf->fd_width; | ||
671 | else | ||
672 | fd = pf->fd; | ||
673 | lseek(fd, width_offset, SEEK_SET); | ||
674 | read(fd, &(p->width), 1); | ||
650 | } | 675 | } |
651 | else | 676 | else |
652 | { | 677 | { |
@@ -658,11 +683,16 @@ load_cache_entry(struct font_cache_entry* p, void* callback_data) | |||
658 | if (pf->file_offset_offset) | 683 | if (pf->file_offset_offset) |
659 | { | 684 | { |
660 | int32_t offset = pf->file_offset_offset + char_code * (pf->long_offset ? sizeof(int32_t) : sizeof(int16_t)); | 685 | int32_t offset = pf->file_offset_offset + char_code * (pf->long_offset ? sizeof(int32_t) : sizeof(int16_t)); |
661 | lseek(pf->fd, offset, SEEK_SET); | 686 | /* load via different fd to get this file section cached */ |
662 | read (pf->fd, tmp, 2); | 687 | if(pf->fd_offset >=0 ) |
688 | fd = pf->fd_offset; | ||
689 | else | ||
690 | fd = pf->fd; | ||
691 | lseek(fd, offset, SEEK_SET); | ||
692 | read (fd, tmp, 2); | ||
663 | bitmap_offset = tmp[0] | (tmp[1] << 8); | 693 | bitmap_offset = tmp[0] | (tmp[1] << 8); |
664 | if (pf->long_offset) { | 694 | if (pf->long_offset) { |
665 | read (pf->fd, tmp, 2); | 695 | read (fd, tmp, 2); |
666 | bitmap_offset |= (tmp[0] << 16) | (tmp[1] << 24); | 696 | bitmap_offset |= (tmp[0] << 16) | (tmp[1] << 24); |
667 | } | 697 | } |
668 | } | 698 | } |
diff --git a/tools/convbdf.c b/tools/convbdf.c index d562365ed5..d4f7c3cb9a 100644 --- a/tools/convbdf.c +++ b/tools/convbdf.c | |||
@@ -1401,6 +1401,8 @@ int gen_c_source(struct font* pf, char *path) | |||
1401 | " %d, /* defaultchar */\n" | 1401 | " %d, /* defaultchar */\n" |
1402 | " %d, /* bits_size */\n" | 1402 | " %d, /* bits_size */\n" |
1403 | " -1, /* font fd */\n" | 1403 | " -1, /* font fd */\n" |
1404 | " -1, /* font fd width */\n" | ||
1405 | " -1, /* font fd offset */\n" | ||
1404 | " 0, /* buffer start */\n" | 1406 | " 0, /* buffer start */\n" |
1405 | " 0, /* ^ position */\n" | 1407 | " 0, /* ^ position */\n" |
1406 | " 0, /* ^ end */\n" | 1408 | " 0, /* ^ end */\n" |