1 /************************************************************************/
4 /************************************************************************/
6 #include "cache_manager.h"
8 ULONG
TextInfoCacheKeyTraits::Hash( const TextInfoCacheKey
& key
)
10 ULONG hash
= CStringElementTraits
<CString
>::Hash(key
.m_str
);
12 hash
+= hash_value( static_cast<const STSStyleBase
&>(key
.m_style
.get()) );
14 hash
+= hash_value( key
.m_style
.get().fontScaleX
);
16 hash
+= hash_value( key
.m_style
.get().fontScaleY
);
18 hash
+= hash_value( key
.m_style
.get().fontSpacing
);
22 ULONG
CWordCacheKeyTraits::Hash( const CWordCacheKey
& key
)
24 return( CStringElementTraits
<CString
>::Hash(key
.m_str
) );//fix me
27 ULONG
PathDataCacheKeyTraits::Hash( const PathDataCacheKey
& key
)
29 return( CStringElementTraits
<CString
>::Hash(key
.m_str
) );
32 ULONG
ScanLineData2CacheKeyTraits::Hash( const ScanLineData2CacheKey
& key
)
34 //return hash_value(static_cast<PathDataCacheKey>(key)) ^ key.m_org.x ^ key.m_org.y;
35 size_t hash
= PathDataCacheKeyTraits::Hash(static_cast<const PathDataCacheKey
&>(key
));
43 ULONG
OverlayNoBlurKeyTraits::Hash( const OverlayNoBlurKey
& key
)
45 ULONG hash
= ScanLineData2CacheKeyTraits::Hash(static_cast<const ScanLineData2CacheKey
&>(key
));
53 ULONG
OverlayKeyTraits::Hash( const OverlayKey
& key
)
55 ULONG hash
= OverlayNoBlurKeyTraits::Hash(static_cast<const OverlayNoBlurKey
&>(key
));
57 hash
+= key
.m_style
.get().fBlur
;
59 hash
+= hash_value(key
.m_style
.get().fGaussianBlur
);
64 ULONG
PathDataTraits::Hash( const PathData
& key
)
68 hash
+= key
.mPathPoints
;
69 for (int i
=0;i
<key
.mPathPoints
;i
++)
72 hash
+= key
.mpPathTypes
[i
];
74 for (int i
=0;i
<key
.mPathPoints
;i
++)
77 hash
+= key
.mpPathPoints
[i
].x
;
79 hash
+= key
.mpPathPoints
[i
].y
;
84 ULONG
ScanLineDataCacheKeyTraits::Hash( const ScanLineDataCacheKey
& key
)
86 return PathDataTraits::Hash(*key
.m_path_data
);
89 ULONG
ClipperAlphaMaskCacheKeyTraits::Hash( const ClipperAlphaMaskCacheKey
& key
)
91 return Hash(*key
.m_clipper
);
94 ULONG
ClipperAlphaMaskCacheKeyTraits::Hash( const CClipper
& key
)
96 ULONG hash
= CStringElementTraits
<CString
>::Hash(key
.m_polygon
->m_str
);;
98 hash
+= key
.m_inverse
;
100 hash
+= key
.m_effectType
;
102 hash
+= key
.m_size
.cx
;
104 hash
+= key
.m_size
.cy
;
106 hash
+= hash_value(key
.m_polygon
->m_scalex
);
108 hash
+= hash_value(key
.m_polygon
->m_scaley
);
110 for (int i
=0;i
<sizeof(key
.m_effect
.param
)/sizeof(key
.m_effect
.param
[0]);i
++)
113 hash
+= key
.m_effect
.param
[i
];
115 for (int i
=0;i
<sizeof(key
.m_effect
.t
)/sizeof(key
.m_effect
.t
[0]);i
++)
118 hash
+= key
.m_effect
.t
[i
];
123 //////////////////////////////////////////////////////////////////////////////////////////////
127 bool TextInfoCacheKey::operator==( const TextInfoCacheKey
& key
) const
129 return m_str
== key
.m_str
130 && static_cast<const STSStyleBase
&>(m_style
).operator==(key
.m_style
)
131 && m_style
.get().fontScaleX
== key
.m_style
.get().fontScaleX
132 && m_style
.get().fontScaleY
== key
.m_style
.get().fontScaleY
133 && m_style
.get().fontSpacing
== key
.m_style
.get().fontSpacing
;
136 //////////////////////////////////////////////////////////////////////////////////////////////
140 CWordCacheKey::CWordCacheKey( const CWord
& word
)
143 m_style
= word
.m_style
;
144 m_ktype
= word
.m_ktype
;
145 m_kstart
= word
.m_kstart
;
146 m_kend
= word
.m_kend
;
149 CWordCacheKey::CWordCacheKey( const CWordCacheKey
& key
)
152 m_style
= key
.m_style
;
153 m_ktype
= key
.m_ktype
;
154 m_kstart
= key
.m_kstart
;
158 CWordCacheKey::CWordCacheKey( const FwSTSStyle
& style
, const CStringW
& str
, int ktype
, int kstart
, int kend
)
159 :m_style(style
),m_str(str
),m_ktype(ktype
),m_kstart(kstart
),m_kend(m_kend
)
164 bool CWordCacheKey::operator==( const CWordCacheKey
& key
) const
166 return (m_str
== key
.m_str
&&
167 m_style
== key
.m_style
&&
168 m_ktype
== key
.m_ktype
&&
169 m_kstart
== key
.m_kstart
&&
170 m_kend
== key
.m_kend
);
173 bool CWordCacheKey::operator==(const CWord
& key
)const
175 return (m_str
== key
.m_str
&&
176 m_style
== key
.m_style
&&
177 m_ktype
== key
.m_ktype
&&
178 m_kstart
== key
.m_kstart
&&
179 m_kend
== key
.m_kend
);
182 //////////////////////////////////////////////////////////////////////////////////////////////
186 bool PathDataCacheKey::CompareSTSStyle( const STSStyle
& lhs
, const STSStyle
& rhs
)
188 return lhs
.charSet
==rhs
.charSet
&&
189 lhs
.fontName
==rhs
.fontName
&&
190 lhs
.fontSize
==rhs
.fontSize
&&
191 lhs
.fontSpacing
==rhs
.fontSpacing
&&
192 lhs
.fontWeight
==rhs
.fontWeight
&&
193 lhs
.fItalic
==rhs
.fItalic
&&
194 lhs
.fUnderline
==rhs
.fUnderline
&&
195 lhs
.fStrikeOut
==rhs
.fStrikeOut
;
198 //////////////////////////////////////////////////////////////////////////////////////////////
200 // ScanLineData2CacheKey
202 bool ScanLineData2CacheKey::operator==( const ScanLineData2CacheKey
& key
) const
204 return //(static_cast<PathDataCacheKey>(*this)==static_cast<PathDataCacheKey>(key))
205 PathDataCacheKey::operator==(key
) //static_cast will call copy constructer to construct a tmp obj
206 && this->m_style
.get().borderStyle
== key
.m_style
.get().borderStyle
207 && fabs(this->m_style
.get().outlineWidthX
- key
.m_style
.get().outlineWidthX
) < 0.000001
208 && fabs(this->m_style
.get().outlineWidthY
- key
.m_style
.get().outlineWidthY
) < 0.000001
209 && fabs(this->m_style
.get().fontScaleX
- key
.m_style
.get().fontScaleX
) < 0.000001
210 && fabs(this->m_style
.get().fontScaleY
- key
.m_style
.get().fontScaleY
) < 0.000001
211 && fabs(this->m_style
.get().fontAngleX
- key
.m_style
.get().fontAngleX
) < 0.000001
212 && fabs(this->m_style
.get().fontAngleY
- key
.m_style
.get().fontAngleY
) < 0.000001
213 && fabs(this->m_style
.get().fontAngleZ
- key
.m_style
.get().fontAngleZ
) < 0.000001
214 && fabs(this->m_style
.get().fontShiftX
- key
.m_style
.get().fontShiftX
) < 0.000001
215 && fabs(this->m_style
.get().fontShiftY
- key
.m_style
.get().fontShiftY
) < 0.000001
216 && (m_org
.x
==key
.m_org
.x
) && (m_org
.y
==key
.m_org
.y
);
219 //////////////////////////////////////////////////////////////////////////////////////////////
223 bool OverlayNoBlurKey::operator==( const OverlayNoBlurKey
& key
) const
225 //static_cast will call copy constructer to construct a tmp obj
226 //return (static_cast<ScanLineDataCacheKey>(*this)==static_cast<ScanLineDataCacheKey>(key))
227 // && (m_p.x==key.m_p.x) && (m_p.y==key.m_p.y);
228 return ScanLineData2CacheKey::operator==(key
) && (m_p
.x
==key
.m_p
.x
) && (m_p
.y
==key
.m_p
.y
);
231 //////////////////////////////////////////////////////////////////////////////////////////////
235 bool OverlayKey::operator==( const OverlayKey
& key
) const
237 return OverlayNoBlurKey::operator==(key
)
238 && fabs(this->m_style
.get().fGaussianBlur
- key
.m_style
.get().fGaussianBlur
) < 0.000001
239 && this->m_style
.get().fBlur
== key
.m_style
.get().fBlur
;
240 //static_cast will call copy constructer to construct a tmp obj
241 //return ((CWordCacheKey)(*this)==(CWordCacheKey)key) && (m_p.x==key.m_p.x) && (m_p.y==key.m_p.y)
242 // && (m_org.x==key.m_org.x) && (m_org.y==key.m_org.y);
245 //////////////////////////////////////////////////////////////////////////////////////////////
247 // ScanLineDataCacheKey
249 bool ScanLineDataCacheKey::operator==( const ScanLineDataCacheKey
& key
) const
251 return (m_path_data
&& key
.m_path_data
) ? *m_path_data
==*key
.m_path_data
: m_path_data
==key
.m_path_data
;
254 //////////////////////////////////////////////////////////////////////////////////////////////
256 // ClipperAlphaMaskCacheKey
258 bool ClipperAlphaMaskCacheKey::operator==( const ClipperAlphaMaskCacheKey
& key
) const
261 if (m_clipper
==key
.m_clipper
)
265 else if ( m_clipper
!=NULL
&& key
.m_clipper
!=NULL
)
267 const CClipper
& lhs
= *m_clipper
;
268 const CClipper
& rhs
= *key
.m_clipper
;
269 result
= (lhs
.m_polygon
->m_str
== rhs
.m_polygon
->m_str
270 && fabs(lhs
.m_polygon
->m_scalex
- rhs
.m_polygon
->m_scalex
) < 0.000001
271 && fabs(lhs
.m_polygon
->m_scaley
- rhs
.m_polygon
->m_scaley
) < 0.000001
272 && lhs
.m_size
== rhs
.m_size
273 && lhs
.m_inverse
== rhs
.m_inverse
274 && lhs
.m_effectType
== rhs
.m_effectType
275 && lhs
.m_effect
== rhs
.m_effect
);//fix me: unsafe code
280 //////////////////////////////////////////////////////////////////////////////////////////////
289 s_clipper_alpha_mask_cache
= NULL
;
291 s_text_info_cache
= NULL
;
292 s_word_mru_cache
= NULL
;
293 s_path_data_mru_cache
= NULL
;
294 s_scan_line_data_2_mru_cache
= NULL
;
295 s_overlay_no_blur_mru_cache
= NULL
;
296 s_overlay_mru_cache
= NULL
;
298 s_scan_line_data_mru_cache
= NULL
;
300 s_subpixel_variance_cache
= NULL
;
301 s_ass_tag_list_cache
= NULL
;
305 delete s_clipper_alpha_mask_cache
;
307 delete s_text_info_cache
;
308 delete s_word_mru_cache
;
309 delete s_path_data_mru_cache
;
310 delete s_scan_line_data_2_mru_cache
;
311 delete s_overlay_no_blur_mru_cache
;
312 delete s_overlay_mru_cache
;
314 delete s_scan_line_data_mru_cache
;
316 delete s_subpixel_variance_cache
;
317 delete s_ass_tag_list_cache
;
320 ClipperAlphaMaskMruCache
* s_clipper_alpha_mask_cache
;
322 TextInfoMruCache
* s_text_info_cache
;
323 AssTagListMruCache
* s_ass_tag_list_cache
;
325 ScanLineDataMruCache
* s_scan_line_data_mru_cache
;
327 OverlayMruCache
* s_subpixel_variance_cache
;
328 OverlayMruCache
* s_overlay_mru_cache
;
329 OverlayNoBlurMruCache
* s_overlay_no_blur_mru_cache
;
330 PathDataMruCache
* s_path_data_mru_cache
;
331 ScanLineData2MruCache
* s_scan_line_data_2_mru_cache
;
332 CWordMruCache
* s_word_mru_cache
;
335 static Caches s_caches
;
337 OverlayMruCache
* CacheManager::GetOverlayMruCache()
339 if(s_caches
.s_overlay_mru_cache
==NULL
)
341 s_caches
.s_overlay_mru_cache
= new OverlayMruCache(OVERLAY_CACHE_ITEM_NUM
);
343 return s_caches
.s_overlay_mru_cache
;
346 PathDataMruCache
* CacheManager::GetPathDataMruCache()
348 if (s_caches
.s_path_data_mru_cache
==NULL
)
350 s_caches
.s_path_data_mru_cache
= new PathDataMruCache(PATH_CACHE_ITEM_NUM
);
352 return s_caches
.s_path_data_mru_cache
;
355 CWordMruCache
* CacheManager::GetCWordMruCache()
357 if(s_caches
.s_word_mru_cache
==NULL
)
359 s_caches
.s_word_mru_cache
= new CWordMruCache(WORD_CACHE_ITEM_NUM
);
361 return s_caches
.s_word_mru_cache
;
364 OverlayNoBlurMruCache
* CacheManager::GetOverlayNoBlurMruCache()
366 if(s_caches
.s_overlay_no_blur_mru_cache
==NULL
)
368 s_caches
.s_overlay_no_blur_mru_cache
= new OverlayNoBlurMruCache(OVERLAY_NO_BLUR_CACHE_ITEM_NUM
);
370 return s_caches
.s_overlay_no_blur_mru_cache
;
373 ScanLineData2MruCache
* CacheManager::GetScanLineData2MruCache()
375 if(s_caches
.s_scan_line_data_2_mru_cache
==NULL
)
377 s_caches
.s_scan_line_data_2_mru_cache
= new ScanLineData2MruCache(SCAN_LINE_DATA_CACHE_ITEM_NUM
);
379 return s_caches
.s_scan_line_data_2_mru_cache
;
382 OverlayMruCache
* CacheManager::GetSubpixelVarianceCache()
384 if(s_caches
.s_subpixel_variance_cache
==NULL
)
386 s_caches
.s_subpixel_variance_cache
= new OverlayMruCache(SUBPIXEL_VARIANCE_CACHE_ITEM_NUM
);
388 return s_caches
.s_subpixel_variance_cache
;
391 ScanLineDataMruCache
* CacheManager::GetScanLineDataMruCache()
393 if(s_caches
.s_scan_line_data_mru_cache
==NULL
)
395 s_caches
.s_scan_line_data_mru_cache
= new ScanLineDataMruCache(SCAN_LINE_DATA_CACHE_ITEM_NUM
);
397 return s_caches
.s_scan_line_data_mru_cache
;
400 AssTagListMruCache
* CacheManager::GetAssTagListMruCache()
402 if(s_caches
.s_ass_tag_list_cache
==NULL
)
404 s_caches
.s_ass_tag_list_cache
= new AssTagListMruCache(ASS_TAG_LIST_CACHE_ITEM_NUM
);
406 return s_caches
.s_ass_tag_list_cache
;
409 TextInfoMruCache
* CacheManager::GetTextInfoCache()
411 if(s_caches
.s_text_info_cache
==NULL
)
413 s_caches
.s_text_info_cache
= new TextInfoMruCache(TEXT_INFO_CACHE_ITEM_NUM
);
415 return s_caches
.s_text_info_cache
;
418 ClipperAlphaMaskMruCache
* CacheManager::GetClipperAlphaMaskMruCache()
420 if(s_caches
.s_clipper_alpha_mask_cache
==NULL
)
422 s_caches
.s_clipper_alpha_mask_cache
= new ClipperAlphaMaskMruCache(CLIPPER_ALPHA_MASK_MRU_CACHE
);
424 return s_caches
.s_clipper_alpha_mask_cache
;