diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2011-05-01 11:59:08 +0000 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2011-05-01 11:59:08 +0000 |
commit | 08dcfc0c44eab614eca2072a739ed534a326abb7 (patch) | |
tree | 4e659b76a8a375a055cd0e6841b5e96419f5c5f4 | |
parent | 37854d1575a0038ea6bb4e1fd16d774581bbe93b (diff) | |
download | netsurf-08dcfc0c44eab614eca2072a739ed534a326abb7.tar.gz netsurf-08dcfc0c44eab614eca2072a739ed534a326abb7.tar.bz2 |
Every five minutes, close any fonts not used in the last five minutes
svn path=/trunk/netsurf/; revision=12267
-rw-r--r-- | amiga/font.c | 47 | ||||
-rwxr-xr-x | amiga/gui_options.c | 3 | ||||
-rwxr-xr-x | amiga/object.c | 5 |
3 files changed, 47 insertions, 8 deletions
diff --git a/amiga/font.c b/amiga/font.c index e4f4980a4..5f0f892d5 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -34,6 +34,7 @@ #include <proto/exec.h> #include <proto/graphics.h> #include <proto/Picasso96API.h> +#include <proto/timer.h> #include <proto/utility.h> #include <diskfont/diskfonttag.h> @@ -62,6 +63,7 @@ struct ami_font_node char *bold; char *italic; char *bolditalic; + struct TimeVal lastused; }; struct MinList *ami_font_list = NULL; @@ -69,7 +71,9 @@ ULONG ami_devicedpi; int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 char1, uint16 char2, uint32 x, uint32 y, uint32 emwidth); -struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, BOOL fallback); +struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, + BOOL fallback); +static void ami_font_cleanup(struct MinList *ami_font_list); static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, @@ -313,7 +317,12 @@ struct ami_font_node *ami_font_open(const char *font) struct ami_font_node *nodedata; node = (struct nsObject *)FindIName((struct List *)ami_font_list, font); - if(node) return node->objstruct; + if(node) + { + nodedata = node->objstruct; + GetSysTime(&nodedata->lastused); + return nodedata; + } LOG(("Font cache miss: %s", font)); @@ -351,6 +360,8 @@ struct ami_font_node *ami_font_open(const char *font) else LOG(("Warning: No designed bold-italic font defined for %s", font)); + GetSysTime(&nodedata->lastused); + return nodedata; } @@ -590,6 +601,9 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const void ami_init_fonts(void) { ami_font_list = NewObjList(); + + /* run first cleanup in ten minutes */ + schedule(60000, ami_font_cleanup, ami_font_list); } void ami_close_fonts(void) @@ -606,6 +620,35 @@ void ami_font_close(struct ami_font_node *node) CloseOutlineFont(node->font, NULL); } +static void ami_font_cleanup(struct MinList *ami_font_list) +{ + struct nsObject *node; + struct nsObject *nnode; + struct ami_font_node *fnode; + struct TimeVal curtime; + + if(IsMinListEmpty(ami_font_list)) return; + + node = (struct nsObject *)GetHead((struct List *)ami_font_list); + + do + { + nnode=(struct nsObject *)GetSucc((struct Node *)node); + fnode = node->objstruct; + GetSysTime(&curtime); + SubTime(&curtime, &fnode->lastused); + if(curtime.Seconds > 300) + { + LOG(("Freeing %s not used for %d seconds", + node->dtz_Node.ln_Name, curtime.Seconds)); + DelObject(node); + } + }while(node=nnode); + + /* reschedule to run in five minutes */ + schedule(30000, ami_font_cleanup, ami_font_list); +} + void ami_font_setdevicedpi(int id) { DisplayInfoHandle dih; diff --git a/amiga/gui_options.c b/amiga/gui_options.c index 3d1571d97..2afe5c6eb 100755 --- a/amiga/gui_options.c +++ b/amiga/gui_options.c @@ -1591,9 +1591,6 @@ void ami_gui_opts_use(void) GetAttr(GA_Selected,gow->objects[GID_OPTS_EXPORT_PASSWORD],(ULONG *)&data); if(data) option_enable_PDF_password = true; else option_enable_PDF_password = false; - - ami_close_fonts(); - ami_init_fonts(); } void ami_gui_opts_close(void) diff --git a/amiga/object.c b/amiga/object.c index 440d6559a..a5bdc7f38 100755 --- a/amiga/object.c +++ b/amiga/object.c @@ -19,10 +19,9 @@ #include <proto/exec.h> #include <exec/lists.h> #include <exec/nodes.h> -#include <memory.h> +#include "amiga/font.h" #include "amiga/object.h" -#include "amiga/schedule.h" struct MinList *NewObjList(void) { @@ -53,6 +52,7 @@ struct nsObject *AddObject(struct MinList *objlist, ULONG otype) void DelObjectInternal(struct nsObject *dtzo, BOOL free_obj) { Remove((struct Node *)dtzo); + if(dtzo->Type == AMINS_FONT) ami_font_close(dtzo->objstruct); if(dtzo->objstruct && free_obj) FreeVec(dtzo->objstruct); if(dtzo->dtz_Node.ln_Name) free(dtzo->dtz_Node.ln_Name); FreeVec(dtzo); @@ -80,7 +80,6 @@ void FreeObjList(struct MinList *objlist) do { nnode=(struct nsObject *)GetSucc((struct Node *)node); - if(node->Type == AMINS_FONT) ami_font_close(node->objstruct); DelObject(node); }while(node=nnode); |