1818#include < stdlib.h>
1919#include " crsetup.h"
2020#include " lvtypes.h"
21+ #include " lvhashtable.h"
22+ #include " ../../include/crlocks.h"
23+ #define GLYPHCACHE_TABLE_SZ 256
2124
2225struct LVFontGlyphCacheItem ;
2326
@@ -50,45 +53,92 @@ class LVFontGlobalGlyphCache {
5053 void clear ();
5154};
5255
53- class LVLocalGlyphCacheStorage
56+ class LVLocalGlyphCacheHashTableStorage
5457{
58+ LVHashTable<lUInt32, struct LVFontGlyphCacheItem *> hashTable;
59+ LVFontGlobalGlyphCache* m_global_cache;
60+ // non-cpyable
61+ LVLocalGlyphCacheHashTableStorage ();
62+ LVLocalGlyphCacheHashTableStorage ( const LVLocalGlyphCacheHashTableStorage& );
63+ LVLocalGlyphCacheHashTableStorage& operator =( const LVLocalGlyphCacheHashTableStorage& );
5564public:
56- LVLocalGlyphCacheStorage (LVFontGlobalGlyphCache *global_cache) :
57- m_global_cache (global_cache) {
58- }
59- virtual ~LVLocalGlyphCacheStorage () {
65+ LVLocalGlyphCacheHashTableStorage (LVFontGlobalGlyphCache *global_cache) :
66+ m_global_cache (global_cache), hashTable(GLYPHCACHE_TABLE_SZ) {}
67+ ~LVLocalGlyphCacheHashTableStorage () {
6068 clear ();
6169 }
62- virtual LVFontGlyphCacheItem* get (lUInt32 ch) = 0;
63- virtual void put (LVFontGlyphCacheItem *item) = 0;
64- virtual void remove (LVFontGlyphCacheItem *item) = 0;
65- virtual void clear () {}
66- protected:
67- LVFontGlobalGlyphCache* m_global_cache;
70+ LVFontGlyphCacheItem* get (lUInt32 ch);
71+ void put (LVFontGlyphCacheItem *item);
72+ void remove (LVFontGlyphCacheItem *item);
73+ void clear ();
6874};
6975
70- class LVFontLocalGlyphCache {
71- private:
72- LVLocalGlyphCacheStorage* m_storage;
76+ class LVLocalGlyphCacheListStorage
77+ {
78+ LVFontGlobalGlyphCache* m_global_cache;
79+ LVFontGlyphCacheItem* head;
80+ LVFontGlyphCacheItem* tail;
81+ // non-cpyable
82+ LVLocalGlyphCacheListStorage ();
83+ LVLocalGlyphCacheListStorage ( const LVLocalGlyphCacheListStorage& );
84+ LVLocalGlyphCacheListStorage& operator =( const LVLocalGlyphCacheListStorage& );
7385public:
74- LVFontLocalGlyphCache (LVFontGlobalGlyphCache *globalCache);
75- ~LVFontLocalGlyphCache () {
76- if ( m_storage )
77- delete m_storage ;
86+ LVLocalGlyphCacheListStorage (LVFontGlobalGlyphCache *global_cache) :
87+ m_global_cache (global_cache), head(), tail() {}
88+ ~LVLocalGlyphCacheListStorage () {
89+ clear () ;
7890 }
79- void clear ();
80- LVFontGlyphCacheItem *get (lUInt32 index);
91+ LVFontGlyphCacheItem* get (lUInt32 ch);
8192 void put (LVFontGlyphCacheItem *item);
8293 void remove (LVFontGlyphCacheItem *item);
94+ void clear ();
8395};
8496
97+ template <class S >
98+ class LVFontLocalGlyphCache_t {
99+ public:
100+ LVFontLocalGlyphCache_t (LVFontGlobalGlyphCache *globalCache) : m_storage(globalCache) {
101+
102+ }
103+ void clear () {
104+ FONT_LOCAL_GLYPH_CACHE_GUARD
105+ m_storage.clear ();
106+ }
107+ LVFontGlyphCacheItem *get (lUInt32 index) {
108+ FONT_LOCAL_GLYPH_CACHE_GUARD
109+ return m_storage.get (index);
110+ }
111+ void put (LVFontGlyphCacheItem *item) {
112+ FONT_LOCAL_GLYPH_CACHE_GUARD
113+ m_storage.put (item);
114+ }
115+ void remove (LVFontGlyphCacheItem *item) {
116+ FONT_LOCAL_GLYPH_CACHE_GUARD
117+ m_storage.remove (item);
118+ }
119+ private:
120+ S m_storage;
121+ };
122+
123+ #if USE_GLYPHCACHE_HASHTABLE == 1
124+ typedef LVFontLocalGlyphCache_t<LVLocalGlyphCacheHashTableStorage> LVFontLocalGlyphCache;
125+ #else
126+ typedef LVFontLocalGlyphCache_t<LVLocalGlyphCacheListStorage> LVFontLocalGlyphCache;
127+ #endif
128+
129+ #if USE_HARFBUZZ == 1
130+ typedef lUInt32 LVFontGlyphCacheKeyType;
131+ #else
132+ typedef lChar16 LVFontGlyphCacheKeyType;
133+ #endif
134+
85135struct LVFontGlyphCacheItem {
86136 LVFontGlyphCacheItem *prev_global;
87137 LVFontGlyphCacheItem *next_global;
88138 LVFontGlyphCacheItem *prev_local;
89139 LVFontGlyphCacheItem *next_local;
90140 LVFontLocalGlyphCache *local_cache;
91- lUInt32 data;
141+ LVFontGlyphCacheKeyType data;
92142 lUInt16 bmp_width;
93143 lUInt16 bmp_height;
94144 lInt16 origin_x;
@@ -101,7 +151,7 @@ struct LVFontGlyphCacheItem {
101151 return sizeof (LVFontGlyphCacheItem)
102152 + (bmp_width * bmp_height - 1 ) * sizeof (lUInt8);
103153 }
104- static LVFontGlyphCacheItem *newItem (LVFontLocalGlyphCache *local_cache, lUInt32 glyph_index , int w, int h);
154+ static LVFontGlyphCacheItem *newItem (LVFontLocalGlyphCache *local_cache, LVFontGlyphCacheKeyType ch_or_index , int w, int h);
105155 static void freeItem (LVFontGlyphCacheItem *item);
106156};
107157#endif // __LV_FONTGLYPHCACHE_H_INCLUDED__
0 commit comments