2016-01-11 22:55:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "amiga/os3support.h"
|
2016-01-11 23:12:14 +03:00
|
|
|
#include <string.h>
|
2016-01-11 22:55:37 +03:00
|
|
|
|
|
|
|
#include <proto/timer.h>
|
|
|
|
#include <proto/utility.h>
|
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
|
|
|
|
#include "amiga/font.h"
|
2016-01-16 03:00:57 +03:00
|
|
|
#include "amiga/font_bullet.h"
|
2016-01-11 22:55:37 +03:00
|
|
|
#include "amiga/font_cache.h"
|
|
|
|
#include "amiga/schedule.h"
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
#include "amiga/hash/xxhash.h"
|
|
|
|
#else
|
|
|
|
#include "amiga/object.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
2016-01-11 23:05:15 +03:00
|
|
|
static struct SkipList *ami_font_cache_list = NULL;
|
2016-01-11 22:55:37 +03:00
|
|
|
static struct Hook ami_font_cache_hook;
|
|
|
|
#else
|
2016-01-11 23:05:15 +03:00
|
|
|
static struct MinList *ami_font_cache_list = NULL;
|
2016-01-11 22:55:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
static LONG ami_font_cache_sort(struct Hook *hook, APTR key1, APTR key2)
|
|
|
|
{
|
|
|
|
if(key1 == key2) return 0;
|
|
|
|
if(key1 < key2) return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
2016-01-11 23:05:15 +03:00
|
|
|
static void ami_font_cache_cleanup(struct SkipList *skiplist)
|
2016-01-11 22:55:37 +03:00
|
|
|
{
|
2016-01-11 23:05:15 +03:00
|
|
|
struct ami_font_cache_node *node;
|
|
|
|
struct ami_font_cache_node *nnode;
|
2016-01-11 22:55:37 +03:00
|
|
|
struct TimeVal curtime;
|
|
|
|
|
2016-01-11 23:05:15 +03:00
|
|
|
node = (struct ami_font_cache_node *)GetFirstSkipNode(skiplist);
|
2016-01-11 22:55:37 +03:00
|
|
|
if(node == NULL) return;
|
|
|
|
|
|
|
|
do {
|
2016-01-11 23:05:15 +03:00
|
|
|
nnode = (struct ami_font_cache_node *)GetNextSkipNode(skiplist, (struct SkipNode *)node);
|
2016-01-11 22:55:37 +03:00
|
|
|
GetSysTime(&curtime);
|
|
|
|
SubTime(&curtime, &node->lastused);
|
|
|
|
if(curtime.Seconds > 300)
|
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"Freeing font %p not used for %ld seconds",
|
|
|
|
node->skip_node.sn_Key,
|
|
|
|
curtime.Seconds);
|
2016-01-16 03:00:57 +03:00
|
|
|
ami_font_bullet_close(node);
|
2016-01-11 22:55:37 +03:00
|
|
|
RemoveSkipNode(skiplist, node->skip_node.sn_Key);
|
|
|
|
}
|
|
|
|
} while((node = nnode));
|
|
|
|
|
|
|
|
/* reschedule to run in five minutes */
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_schedule(300000, (void *)ami_font_cache_cleanup, ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
}
|
|
|
|
#else
|
2016-01-11 23:05:15 +03:00
|
|
|
static void ami_font_cache_cleanup(struct MinList *ami_font_cache_list)
|
2016-01-11 22:55:37 +03:00
|
|
|
{
|
|
|
|
struct nsObject *node;
|
|
|
|
struct nsObject *nnode;
|
2016-01-11 23:05:15 +03:00
|
|
|
struct ami_font_cache_node *fnode;
|
2016-01-11 22:55:37 +03:00
|
|
|
struct TimeVal curtime;
|
|
|
|
|
2016-01-11 23:05:15 +03:00
|
|
|
if(IsMinListEmpty(ami_font_cache_list)) return;
|
2016-01-11 22:55:37 +03:00
|
|
|
|
2016-01-11 23:05:15 +03:00
|
|
|
node = (struct nsObject *)GetHead((struct List *)ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nnode=(struct nsObject *)GetSucc((struct Node *)node);
|
|
|
|
fnode = node->objstruct;
|
|
|
|
GetSysTime(&curtime);
|
|
|
|
SubTime(&curtime, &fnode->lastused);
|
|
|
|
if(curtime.Seconds > 300)
|
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"Freeing %s not used for %ld seconds",
|
|
|
|
node->dtz_Node.ln_Name,
|
|
|
|
curtime.Seconds);
|
2016-01-11 22:55:37 +03:00
|
|
|
DelObject(node);
|
|
|
|
}
|
|
|
|
} while((node=nnode));
|
|
|
|
|
|
|
|
/* reschedule to run in five minutes */
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_schedule(300000, (void *)ami_font_cache_cleanup, ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
2016-01-11 23:05:15 +03:00
|
|
|
static void ami_font_cache_del_skiplist(struct SkipList *skiplist)
|
2016-01-11 22:55:37 +03:00
|
|
|
{
|
2016-01-15 22:58:24 +03:00
|
|
|
struct SkipNode *node;
|
2016-01-11 22:55:37 +03:00
|
|
|
struct SkipNode *nnode;
|
|
|
|
|
2016-01-16 03:00:57 +03:00
|
|
|
node = GetFirstSkipNode(skiplist);
|
2016-01-11 22:55:37 +03:00
|
|
|
if(node == NULL) return;
|
|
|
|
|
|
|
|
do {
|
2016-01-16 03:00:57 +03:00
|
|
|
nnode = GetNextSkipNode(skiplist, node);
|
|
|
|
ami_font_bullet_close((struct ami_font_cache_node *)node);
|
2016-01-11 22:55:37 +03:00
|
|
|
|
|
|
|
} while((node = nnode));
|
|
|
|
|
|
|
|
DeleteSkipList(skiplist);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-01-11 23:05:15 +03:00
|
|
|
struct ami_font_cache_node *ami_font_cache_locate(const char *font)
|
2016-01-11 22:55:37 +03:00
|
|
|
{
|
2016-07-10 01:43:17 +03:00
|
|
|
struct ami_font_cache_node *nodedata = NULL;
|
2016-01-11 22:55:37 +03:00
|
|
|
uint32 hash = 0;
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
hash = XXH32(font, strlen(font), 0);
|
2016-01-11 23:05:15 +03:00
|
|
|
nodedata = (struct ami_font_cache_node *)FindSkipNode(ami_font_cache_list, (APTR)hash);
|
2016-01-11 22:55:37 +03:00
|
|
|
#else
|
2016-01-11 23:05:15 +03:00
|
|
|
struct nsObject *node = (struct nsObject *)FindIName((struct List *)ami_font_cache_list, font);
|
2016-01-11 22:55:37 +03:00
|
|
|
if(node) nodedata = node->objstruct;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(nodedata) {
|
|
|
|
GetSysTime(&nodedata->lastused);
|
|
|
|
return nodedata;
|
|
|
|
}
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Font cache miss: %s (%lx)", font, hash);
|
2016-01-11 22:55:37 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:05:15 +03:00
|
|
|
struct ami_font_cache_node *ami_font_cache_alloc_entry(const char *font)
|
2016-01-11 22:55:37 +03:00
|
|
|
{
|
2016-01-11 23:05:15 +03:00
|
|
|
struct ami_font_cache_node *nodedata;
|
2016-01-11 22:55:37 +03:00
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
uint32 hash = XXH32(font, strlen(font), 0);
|
2016-01-11 23:05:15 +03:00
|
|
|
nodedata = (struct ami_font_cache_node *)InsertSkipNode(ami_font_cache_list, (APTR)hash, sizeof(struct ami_font_cache_node));
|
2016-01-11 22:55:37 +03:00
|
|
|
#else
|
2016-11-19 23:44:17 +03:00
|
|
|
nodedata = malloc(sizeof(struct ami_font_cache_node));
|
2016-01-11 22:55:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GetSysTime(&nodedata->lastused);
|
|
|
|
|
|
|
|
return nodedata;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:05:15 +03:00
|
|
|
void ami_font_cache_insert(struct ami_font_cache_node *nodedata, const char *font)
|
2016-01-11 22:55:37 +03:00
|
|
|
{
|
|
|
|
#ifndef __amigaos4__
|
2016-01-11 23:05:15 +03:00
|
|
|
struct nsObject *node = AddObject(ami_font_cache_list, AMINS_FONT);
|
2016-01-11 22:55:37 +03:00
|
|
|
if(node) {
|
2016-01-16 22:37:39 +03:00
|
|
|
ObjectCallback(node, ami_font_bullet_close);
|
2016-01-11 22:55:37 +03:00
|
|
|
node->objstruct = nodedata;
|
|
|
|
node->dtz_Node.ln_Name = strdup(font);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_font_cache_fini(void)
|
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Cleaning up font cache");
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_schedule(-1, (void *)ami_font_cache_cleanup, ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
#ifdef __amigaos4__
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_font_cache_del_skiplist(ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
#else
|
2016-01-11 23:05:15 +03:00
|
|
|
FreeObjList(ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
#endif
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_font_cache_list = NULL;
|
2016-01-11 22:55:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_font_cache_init(void)
|
|
|
|
{
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
ami_font_cache_hook.h_Entry = (HOOKFUNC)ami_font_cache_sort;
|
|
|
|
ami_font_cache_hook.h_Data = 0;
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_font_cache_list = CreateSkipList(&ami_font_cache_hook, 8);
|
2016-01-11 22:55:37 +03:00
|
|
|
#else
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_font_cache_list = NewObjList();
|
2016-01-11 22:55:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* run first cleanup in ten minutes */
|
2016-01-11 23:05:15 +03:00
|
|
|
ami_schedule(600000, (void *)ami_font_cache_cleanup, ami_font_cache_list);
|
2016-01-11 22:55:37 +03:00
|
|
|
}
|
|
|
|
|