Use Slim Reader/Writer lock to replace CRITICAL_SECTION (better performance).
[gdipp.git] / gdipp_server / glyph_cache.h
blob1a402232e6b2b817db55c058e12699075f1725cf
1 #pragma once
3 #include "gdipp_lib/lru.h"
4 #include "gdipp_server/glyph_run.h"
6 namespace gdipp
9 class glyph_cache
11 public:
12 typedef uint128_t string_id_type;
13 typedef uint128_t char_id_type;
14 typedef std::pair<string_id_type, uint128_t> glyph_run_id_type;
16 static string_id_type get_string_id(const wchar_t *string, unsigned int count, bool is_glyph_index);
17 static char_id_type get_char_id(uint128_t render_trait, FT_UInt index, bool is_glyph_index);
19 ~glyph_cache();
21 void initialize();
23 const FT_Glyph lookup_glyph(char_id_type char_id);
24 bool store_glyph(char_id_type char_id, const FT_Glyph glyph);
25 const glyph_run *lookup_glyph_run(string_id_type string_id, uint128_t render_trait) const;
26 bool store_glyph_run(string_id_type string_id, uint128_t render_trait, glyph_run *a_glyph_run);
28 private:
29 // std::map from render trait to glyph run
30 typedef std::map<uint128_t, glyph_run *> trait_to_run_map;
32 // std::map from character ID (including character index and render trait) to its glyph
33 std::map<char_id_type, INIT_ONCE> _glyph_store;
34 // std::map from string ID to glyph run
35 // use hierarchical design so that when LRU string is evicted, all associated glyph runs are erased
36 std::map<string_id_type, trait_to_run_map> _glyph_run_store;
38 // least recently used glyph runs, indexed by string ID
39 lru_list<string_id_type> _glyph_run_lru;