Skip to content

Commit b3db949

Browse files
committed
- Moved GlyphCache storage classes declaration for cpp file to a header.
- LVFontGlyphCacheItem.data field type now depends on USE_HARFBUZZ macro
1 parent 65821c1 commit b3db949

File tree

2 files changed

+74
-93
lines changed

2 files changed

+74
-93
lines changed

crengine/src/private/lvfontglyphcache.cpp

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,6 @@
1313
*/
1414

1515
#include "lvfontglyphcache.h"
16-
#include "../../include/crlocks.h"
17-
#include "lvhashtable.h"
18-
#define GLYPHCACHE_TABLE_SZ 256
19-
20-
class LVLocalGlyphCacheHashTableStorage : public LVLocalGlyphCacheStorage
21-
{
22-
LVHashTable<lUInt32, struct LVFontGlyphCacheItem*> hashTable;
23-
public:
24-
LVLocalGlyphCacheHashTableStorage(LVFontGlobalGlyphCache *global_cache, int size) :
25-
LVLocalGlyphCacheStorage(global_cache), hashTable(size) {
26-
}
27-
LVFontGlyphCacheItem* get(lUInt32 ch);
28-
void put(LVFontGlyphCacheItem *item);
29-
void remove(LVFontGlyphCacheItem *item);
30-
void clear();
31-
};
32-
33-
class LVLocalGlyphCacheListStorage : public LVLocalGlyphCacheStorage
34-
{
35-
LVFontGlyphCacheItem* head;
36-
LVFontGlyphCacheItem* tail;
37-
public:
38-
LVLocalGlyphCacheListStorage(LVFontGlobalGlyphCache *global_cache) :
39-
LVLocalGlyphCacheStorage(global_cache), head(), tail() {}
40-
~LVLocalGlyphCacheListStorage() {
41-
clear();
42-
}
43-
LVFontGlyphCacheItem* get(lUInt32 ch);
44-
void put(LVFontGlyphCacheItem *item);
45-
void remove(LVFontGlyphCacheItem *item);
46-
void clear();
47-
};
4816

4917
void LVFontGlobalGlyphCache::refresh(LVFontGlyphCacheItem *item) {
5018
FONT_GLYPH_CACHE_GUARD
@@ -112,12 +80,12 @@ void LVFontGlobalGlyphCache::clear() {
11280
}
11381
}
11482

115-
LVFontGlyphCacheItem *LVFontGlyphCacheItem::newItem(LVFontLocalGlyphCache* local_cache, lUInt32 glyph_index, int w, int h)
83+
LVFontGlyphCacheItem *LVFontGlyphCacheItem::newItem(LVFontLocalGlyphCache* local_cache, LVFontGlyphCacheKeyType ch_or_index, int w, int h)
11684
{
11785
LVFontGlyphCacheItem *item = (LVFontGlyphCacheItem *) malloc(sizeof(LVFontGlyphCacheItem)
11886
+ (w * h - 1) * sizeof(lUInt8));
11987
if (item) {
120-
item->data = glyph_index;
88+
item->data = ch_or_index;
12189
item->bmp_width = (lUInt16) w;
12290
item->bmp_height = (lUInt16) h;
12391
item->origin_x = 0;
@@ -217,40 +185,3 @@ void LVLocalGlyphCacheListStorage::clear()
217185
LVFontGlyphCacheItem::freeItem(ptr);
218186
}
219187
}
220-
void LVFontLocalGlyphCache::clear()
221-
{
222-
FONT_LOCAL_GLYPH_CACHE_GUARD
223-
224-
m_storage->clear();
225-
}
226-
227-
LVFontGlyphCacheItem *LVFontLocalGlyphCache::get(lUInt32 index)
228-
{
229-
FONT_LOCAL_GLYPH_CACHE_GUARD
230-
return m_storage->get(index);
231-
}
232-
233-
void LVFontLocalGlyphCache::put(LVFontGlyphCacheItem *item)
234-
{
235-
FONT_LOCAL_GLYPH_CACHE_GUARD
236-
m_storage->put(item);
237-
}
238-
239-
void LVFontLocalGlyphCache::remove(LVFontGlyphCacheItem *item)
240-
{
241-
FONT_LOCAL_GLYPH_CACHE_GUARD
242-
m_storage->remove(item);
243-
}
244-
245-
#if USE_GLYPHCACHE_HASHTABLE == 1
246-
LVFontLocalGlyphCache::LVFontLocalGlyphCache(LVFontGlobalGlyphCache *globalCache)
247-
{
248-
m_storage = new LVLocalGlyphCacheHashTableStorage(globalCache, GLYPHCACHE_TABLE_SZ);
249-
}
250-
#else
251-
LVFontLocalGlyphCache::LVFontLocalGlyphCache(LVFontGlobalGlyphCache *globalCache)
252-
{
253-
m_storage = new LVLocalGlyphCacheListStorage(globalCache);
254-
}
255-
#endif
256-

crengine/src/private/lvfontglyphcache.h

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
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

2225
struct 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& );
5564
public:
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& );
7385
public:
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+
85135
struct 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

Comments
 (0)