Skip to content

Commit

Permalink
ps3: Preload system fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Apr 17, 2011
1 parent c74cbea commit ef2c525
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
1 change: 1 addition & 0 deletions configure.ps3
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ done
setup_env "$@"


enable libfreetype
enable spidermonkey
enable trex
enable emu_thread_specifics
Expand Down
2 changes: 2 additions & 0 deletions src/arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ void arch_set_default_paths(int argc, char **argv);
int64_t arch_cache_avail_bytes(void);

void trap_init(void);

void arch_preload_fonts(void);
9 changes: 9 additions & 0 deletions src/arch/arch_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,12 @@ arch_get_seed(void)
v = (v << 32) ^ time(NULL);
return v;
}


/**
*
*/
void
arch_preload_fonts(void)
{
}
16 changes: 16 additions & 0 deletions src/arch/arch_ps3.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "showtime.h"
#include "service.h"
#include "misc/callout.h"
#include "text/text.h"

#if ENABLE_PS3_VDEC
#include "video/ps3_vdec.h"
Expand Down Expand Up @@ -478,3 +479,18 @@ arch_get_seed(void)
{
return mftb();
}



/**
*
*/
void
arch_preload_fonts(void)
{
freetype_load_font("file:https:///dev_flash/data/font/SCE-PS3-VR-R-LATIN2.TTF");
freetype_load_font("file:https:///dev_flash/data/font/SCE-PS3-NR-R-JPN.TTF");
freetype_load_font("file:https:///dev_flash/data/font/SCE-PS3-YG-R-KOR.TTF");
freetype_load_font("file:https:///dev_flash/data/font/SCE-PS3-DH-R-CGB.TTF");
freetype_load_font("file:https:///dev_flash/data/font/SCE-PS3-CP-R-KANA.TTF");
}
41 changes: 30 additions & 11 deletions src/text/freetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "misc/queue.h"
#include "misc/pixmap.h"
#include "text.h"
#include "arch/arch.h"

#include "fileaccess/fileaccess.h"

Expand All @@ -46,7 +47,7 @@ static hts_mutex_t text_mutex;
#define GLYPH_HASH_MASK (GLYPH_HASH_SIZE-1)
TAILQ_HEAD(glyph_queue, glyph);
LIST_HEAD(glyph_list, glyph);
LIST_HEAD(face_list, face);
TAILQ_HEAD(face_queue, face);

#define STYLE_BOLD 0x1
#define STYLE_ITALIC 0x2
Expand All @@ -55,7 +56,7 @@ LIST_HEAD(face_list, face);
//------------------------- Faces -----------------------

typedef struct face {
LIST_ENTRY(face) link;
TAILQ_ENTRY(face) link;

FT_Face face;
char *url;
Expand All @@ -67,7 +68,7 @@ typedef struct face {

} face_t;

static struct face_list faces;
static struct face_queue faces;


//------------------------- Glyph cache -----------------------
Expand Down Expand Up @@ -101,7 +102,7 @@ static void
face_destroy(face_t *f)
{
TRACE(TRACE_DEBUG, "Freetype", "Unloading %s", f->url);
LIST_REMOVE(f, link);
TAILQ_REMOVE(&faces, f, link);
free(f->url);
free(f->family);
FT_Done_Face(f->face);
Expand All @@ -116,8 +117,8 @@ static void
faces_purge(void)
{
face_t *f, *n;
for(f = LIST_FIRST(&faces); f != NULL; f = n) {
n = LIST_NEXT(f, link);
for(f = TAILQ_FIRST(&faces); f != NULL; f = n) {
n = TAILQ_NEXT(f, link);
if(f->refcount == 0)
face_destroy(f);
}
Expand Down Expand Up @@ -200,7 +201,7 @@ face_create(const char *path)

FT_Select_Charmap(face->face, FT_ENCODING_UNICODE);

LIST_INSERT_HEAD(&faces, face, link);
TAILQ_INSERT_TAIL(&faces, face, link);
return face;
}

Expand Down Expand Up @@ -236,7 +237,7 @@ face_clone(face_t *src, const char *family)

dst->family = strdup(family);
dst->style = src->style;
LIST_INSERT_HEAD(&faces, dst, link);
TAILQ_INSERT_TAIL(&faces, dst, link);
return dst;
}

Expand All @@ -252,7 +253,7 @@ face_find(int uc, uint8_t style, const char *family)
uint8_t actualstyle;

// Try already loaded faces
LIST_FOREACH(f, &faces, link) {
TAILQ_FOREACH(f, &faces, link) {
if((family == NULL || !strcmp(family, f->family ?: "" )) &&
f->style == style && FT_Get_Char_Index(f->face, uc))
return f;
Expand All @@ -261,7 +262,7 @@ face_find(int uc, uint8_t style, const char *family)
if(face_resovle(uc, style, family, url, sizeof(url), &actualstyle))
return NULL;

LIST_FOREACH(f, &faces, link) {
TAILQ_FOREACH(f, &faces, link) {
if(!strcmp(f->url, url)) {
if(family == NULL || !strcmp(family, f->family ?: ""))
return f;
Expand Down Expand Up @@ -818,8 +819,26 @@ freetype_init(void)
TRACE(TRACE_ERROR, "Freetype", "Freetype init error\n");
return -1;
}

TAILQ_INIT(&faces);
TAILQ_INIT(&allglyphs);
hts_mutex_init(&text_mutex);
arch_preload_fonts();
return 0;
}


/**
*
*/
void
freetype_load_font(const char *url)
{
face_t *f;
hts_mutex_lock(&text_mutex);

f = face_create(url);
if(f != NULL)
f->refcount++; // Make sure it never is unloaded

hts_mutex_unlock(&text_mutex);
}
2 changes: 2 additions & 0 deletions src/text/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ text_render(const uint32_t *uc, int len, int flags, int size,

#if ENABLE_LIBFREETYPE
int freetype_init(void);

void freetype_load_font(const char *url);
#endif

0 comments on commit ef2c525

Please sign in to comment.