Every five minutes, close any fonts not used in the last five minutes

svn path=/trunk/netsurf/; revision=12267
This commit is contained in:
Chris Young 2011-05-01 11:59:08 +00:00
parent 37854d1575
commit 08dcfc0c44
3 changed files with 47 additions and 8 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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);