Add text info cache to eliminate GDI calls.
[xy_vsfilter.git] / src / subtitles / cache_manager.h
blob622d1c42dcfc9321bbe1f6bdb1dc82b6dc89b351
1 /************************************************************************/
2 /* author: xy */
3 /* date: 20110926 */
4 /************************************************************************/
5 #ifndef __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__
6 #define __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__
8 #include "RTS.h"
10 class TextInfoCacheKey
12 public:
13 CStringW m_str;
14 FwSTSStyle m_style;
15 bool operator==(const TextInfoCacheKey& key)const;
18 class CWordCacheKey
20 public:
21 CWordCacheKey(const CWord& word);
22 CWordCacheKey(const CWordCacheKey& key);
23 CWordCacheKey(const FwSTSStyle& style, const CStringW& str, int ktype, int kstart, int kend);
24 bool operator==(const CWordCacheKey& key)const;
25 bool operator==(const CWord& key)const;
27 CStringW m_str;
28 FwSTSStyle m_style;
29 int m_ktype, m_kstart, m_kend;
32 class PathDataCacheKey
34 public:
35 PathDataCacheKey(const CWord& word):m_str(word.m_str),m_style(word.m_style){}
36 PathDataCacheKey(const PathDataCacheKey& key):m_str(key.m_str),m_style(key.m_style){}
37 PathDataCacheKey(const FwSTSStyle& style, const CStringW& str):m_str(str),m_style(style){}
38 bool operator==(const PathDataCacheKey& key)const
40 return m_str==key.m_str && ( m_style==key.m_style || CompareSTSStyle(m_style, key.m_style) );
42 bool operator==(const CWord& key)const
44 return m_str==key.m_str && ( m_style==key.m_style || CompareSTSStyle(m_style.get(), key.m_style.get()) );
47 static bool CompareSTSStyle(const STSStyle& lhs, const STSStyle& rhs);
48 protected:
49 CStringW m_str;
50 FwSTSStyle m_style;
52 friend std::size_t hash_value(const PathDataCacheKey& key);
55 class ScanLineDataCacheKey: public PathDataCacheKey
57 public:
58 ScanLineDataCacheKey(const CWord& word, const POINT& org):PathDataCacheKey(word),m_org(org) { }
59 ScanLineDataCacheKey(const ScanLineDataCacheKey& key):PathDataCacheKey(key),m_org(key.m_org) { }
60 ScanLineDataCacheKey(const FwSTSStyle& style, const CStringW& str, const POINT& org)
61 :PathDataCacheKey(style, str),m_org(org) { }
62 bool operator==(const ScanLineDataCacheKey& key)const;
64 POINT m_org;
67 class OverlayNoBlurKey: public ScanLineDataCacheKey
69 public:
70 OverlayNoBlurKey(const CWord& word, const POINT& p, const POINT& org):ScanLineDataCacheKey(word,org),m_p(p) { }
71 OverlayNoBlurKey(const OverlayNoBlurKey& key):ScanLineDataCacheKey(key),m_p(key.m_p) { }
72 OverlayNoBlurKey(const FwSTSStyle& style, const CStringW& str, const POINT& p, const POINT& org)
73 :ScanLineDataCacheKey(style, str, org),m_p(p) { }
74 bool operator==(const OverlayNoBlurKey& key)const;
76 POINT m_p;
79 class OverlayKey: public OverlayNoBlurKey
81 public:
82 OverlayKey(const CWord& word, const POINT& p, const POINT& org):OverlayNoBlurKey(word, p, org) { }
83 OverlayKey(const OverlayKey& key):OverlayNoBlurKey(key){ }
85 bool operator==(const OverlayKey& key)const;
87 friend std::size_t hash_value(const OverlayKey& key);
90 std::size_t hash_value(const TextInfoCacheKey& key);
91 std::size_t hash_value(const CWord& key);
92 std::size_t hash_value(const PathDataCacheKey& key);
93 std::size_t hash_value(const ScanLineDataCacheKey& key);
94 std::size_t hash_value(const OverlayNoBlurKey& key);
95 std::size_t hash_value(const OverlayKey& key);
96 std::size_t hash_value(const CWordCacheKey& key);
98 //shouldn't use std::pair, or else VC complaining error C2440
99 //typedef std::pair<OverlayKey, SharedPtrOverlay> OverlayMruItem;
100 struct AssTagListMruItem
102 CStringW script;
103 CRenderedTextSubtitle::SharedPtrConstAssTagList tag_list;
106 struct OverlayMruItem
108 OverlayMruItem(const OverlayKey& overlay_key_, const SharedPtrOverlay& overlay_):overlay_key(overlay_key_),overlay(overlay_){}
110 OverlayKey overlay_key;
111 SharedPtrOverlay overlay;
114 struct TextInfoMruItem
116 TextInfoMruItem(const TextInfoCacheKey& text_info_key_, const CText::SharedPtrTextInfo& text_info_ )
117 :text_info_key(text_info_key_), text_info(text_info_){}
119 TextInfoCacheKey text_info_key;
120 CText::SharedPtrTextInfo text_info;
123 struct CWordMruItem
125 CWordMruItem(const CWordCacheKey& word_key_, const SharedPtrCWord& word_):word_key(word_key_),word(word_){}
127 CWordCacheKey word_key;
128 SharedPtrCWord word;
131 struct PathDataMruItem
133 PathDataMruItem(const PathDataCacheKey& path_data_key_, const SharedPtrConstPathData& path_data_):
134 path_data_key(path_data_key_),path_data(path_data_){}
136 PathDataCacheKey path_data_key;
137 SharedPtrConstPathData path_data;
140 struct ScanLineDataMruItem
142 ScanLineDataMruItem(const ScanLineDataCacheKey& scan_line_data_key_, const SharedPtrConstScanLineData& scan_line_data_):
143 scan_line_data_key(scan_line_data_key_),scan_line_data(scan_line_data_){}
145 ScanLineDataCacheKey scan_line_data_key;
146 SharedPtrConstScanLineData scan_line_data;
149 struct OverlayNoBlurMruItem
151 OverlayNoBlurMruItem(const OverlayNoBlurKey& key_, const SharedPtrOverlay& overlay_)
152 :key(key_),overlay(overlay_){}
154 OverlayNoBlurKey key;
155 SharedPtrOverlay overlay;
158 typedef enhanced_mru_list<
159 TextInfoMruItem,
160 boost::multi_index::member<TextInfoMruItem,
161 TextInfoCacheKey,
162 &TextInfoMruItem::text_info_key
164 > TextInfoMruCache;
166 typedef enhanced_mru_list<
167 AssTagListMruItem,
168 boost::multi_index::member<AssTagListMruItem,
169 CStringW,
170 &AssTagListMruItem::script
172 > AssTagListMruCache;
174 typedef enhanced_mru_list<
175 OverlayMruItem,
176 boost::multi_index::member<OverlayMruItem,
177 OverlayKey,
178 &OverlayMruItem::overlay_key
180 > OverlayMruCache;
182 typedef enhanced_mru_list<
183 CWordMruItem,
184 boost::multi_index::member<CWordMruItem,
185 CWordCacheKey,
186 &CWordMruItem::word_key
188 > CWordMruCache;
190 typedef enhanced_mru_list<
191 PathDataMruItem,
192 boost::multi_index::member<PathDataMruItem,
193 PathDataCacheKey,
194 &PathDataMruItem::path_data_key
196 > PathDataMruCache;
198 typedef enhanced_mru_list<
199 ScanLineDataMruItem,
200 boost::multi_index::member<ScanLineDataMruItem,
201 ScanLineDataCacheKey,
202 &ScanLineDataMruItem::scan_line_data_key
204 > ScanLineDataMruCache;
206 typedef enhanced_mru_list<
207 OverlayNoBlurMruItem,
208 boost::multi_index::member<OverlayNoBlurMruItem,
209 OverlayNoBlurKey,
210 &OverlayNoBlurMruItem::key
212 > OverlayNoBlurMruCache;
214 class CacheManager
216 public:
217 static const int TEXT_INFO_CACHE_ITEM_NUM = 2048;
218 static const int ASS_TAG_LIST_CACHE_ITEM_NUM = 256;
219 static const int SUBPIXEL_VARIANCE_CACHE_ITEM_NUM = 256;
220 static const int OVERLAY_CACHE_ITEM_NUM = 256;
222 static const int OVERLAY_NO_BLUR_CACHE_ITEM_NUM = 256;
223 static const int SCAN_LINE_DATA_CACHE_ITEM_NUM = 256;
224 static const int PATH_CACHE_ITEM_NUM = 256;
225 static const int WORD_CACHE_ITEM_NUM = 512;
227 static TextInfoMruCache* GetTextInfoCache();
228 static AssTagListMruCache* GetAssTagListMruCache();
229 static OverlayMruCache* GetSubpixelVarianceCache();
230 static OverlayMruCache* GetOverlayMruCache();
231 static OverlayNoBlurMruCache* GetOverlayNoBlurMruCache();
232 static ScanLineDataMruCache* GetScanLineDataMruCache();
233 static PathDataMruCache* GetPathDataMruCache();
234 static CWordMruCache* GetCWordMruCache();
235 private:
236 static TextInfoMruCache* s_text_info_cache;
237 static AssTagListMruCache* s_ass_tag_list_cache;
238 static OverlayMruCache* s_subpixel_variance_cache;
239 static OverlayMruCache* s_overlay_mru_cache;
240 static OverlayNoBlurMruCache* s_overlay_no_blur_mru_cache;
241 static PathDataMruCache* s_path_data_mru_cache;
242 static ScanLineDataMruCache* s_scan_line_data_mru_cache;
243 static CWordMruCache* s_word_mru_cache;
246 #endif // end of __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__