1 /************************************************************************/
4 /************************************************************************/
5 #ifndef __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__
6 #define __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__
10 #include "flyweight_base_types.h"
12 template<class CahcheKey
>
13 class XyCacheKeyTraits
:public CElementTraits
<CahcheKey
>
16 static inline ULONG
Hash(const CahcheKey
& key
)
18 return key
.GetHashValue();
20 static inline bool CompareElements(
21 const CahcheKey
& element1
,
22 const CahcheKey
& element2
)
24 return ( (element1
==element2
)!=0 );
28 class TextInfoCacheKey
31 XyFwStringW::IdType m_str_id
;
36 bool operator==(const TextInfoCacheKey
& key
)const;
38 ULONG
UpdateHashValue();
39 inline ULONG
GetHashValue()const
45 class PathDataCacheKey
48 PathDataCacheKey(const CWord
& word
):m_style(word
.m_style
)
50 const CPolygon
*tmp
= dynamic_cast<const CPolygon
*>(&word
);
53 m_scalex
= tmp
->m_scalex
;
54 m_scaley
= tmp
->m_scaley
;
61 m_str_id
= word
.m_str
.GetId();
63 PathDataCacheKey(const PathDataCacheKey
& key
)
64 :m_str_id(key
.m_str_id
)
65 ,m_scalex(key
.m_scalex
)
66 ,m_scaley(key
.m_scaley
)
68 ,m_hash_value(key
.m_hash_value
){}
69 bool operator==(const PathDataCacheKey
& key
)const
71 return m_str_id
==key
.m_str_id
72 && fabs(m_scalex
-key
.m_scalex
)<0.000001
73 && fabs(m_scaley
-key
.m_scaley
)<0.000001
74 && ( m_style
==key
.m_style
|| CompareSTSStyle(m_style
, key
.m_style
) );
76 bool operator==(const CWord
& key
)const
78 return operator==(PathDataCacheKey(key
));
81 static bool CompareSTSStyle(const STSStyle
& lhs
, const STSStyle
& rhs
);
83 ULONG
UpdateHashValue();
84 inline ULONG
GetHashValue()const
91 double m_scalex
, m_scaley
;//for CPolygon
92 XyFwStringW::IdType m_str_id
;
96 class ScanLineData2CacheKey
: public PathDataCacheKey
99 ScanLineData2CacheKey(const CWord
& word
, const POINT
& org
):PathDataCacheKey(word
),m_org(org
) { }
100 ScanLineData2CacheKey(const ScanLineData2CacheKey
& key
)
101 :PathDataCacheKey(key
)
103 ,m_hash_value(key
.m_hash_value
) { }
105 bool operator==(const ScanLineData2CacheKey
& key
)const;
107 ULONG
UpdateHashValue();
108 inline ULONG
GetHashValue()const
117 class OverlayNoBlurKey
: public ScanLineData2CacheKey
120 OverlayNoBlurKey(const CWord
& word
, const POINT
& p
, const POINT
& org
):ScanLineData2CacheKey(word
,org
),m_p(p
) {}
121 OverlayNoBlurKey(const OverlayNoBlurKey
& key
):ScanLineData2CacheKey(key
),m_p(key
.m_p
),m_hash_value(key
.m_hash_value
) {}
123 bool operator==(const OverlayNoBlurKey
& key
)const;
125 ULONG
UpdateHashValue();
126 inline ULONG
GetHashValue()const
135 class OverlayKey
: public OverlayNoBlurKey
138 OverlayKey(const CWord
& word
, const POINT
& p
, const POINT
& org
):OverlayNoBlurKey(word
, p
, org
) {}
139 OverlayKey(const OverlayKey
& key
):OverlayNoBlurKey(key
), m_hash_value(key
.m_hash_value
) {}
141 bool operator==(const OverlayKey
& key
)const;
143 ULONG
UpdateHashValue();
144 inline ULONG
GetHashValue()const
152 class ScanLineDataCacheKey
155 ScanLineDataCacheKey(const SharedPtrConstPathData
& path_data
):m_path_data(path_data
){}
156 bool operator==(const ScanLineDataCacheKey
& key
)const;
158 ULONG
UpdateHashValue();
159 inline ULONG
GetHashValue()const
165 SharedPtrConstPathData m_path_data
;
168 class OverlayNoOffsetKey
:public ScanLineDataCacheKey
171 OverlayNoOffsetKey(const SharedPtrConstPathData
& path_data
, int xsub
, int ysub
, int border_x
, int border_y
)
172 : ScanLineDataCacheKey(path_data
)
173 , m_border( border_x
+(border_y
<<16) )
174 , m_rasterize_sub( xsub
+(ysub
<<16) ){}
175 bool operator==(const OverlayNoOffsetKey
& key
)const;
177 ULONG
UpdateHashValue();
178 inline ULONG
GetHashValue()const
189 class ClipperAlphaMaskCacheKey
192 ClipperAlphaMaskCacheKey(const SharedPtrCClipper
& clipper
):m_clipper(clipper
){}
193 bool operator==(const ClipperAlphaMaskCacheKey
& key
)const;
195 ULONG
UpdateHashValue();
196 inline ULONG
GetHashValue()const
203 SharedPtrCClipper m_clipper
;
207 class DrawItemHashKey
210 DrawItemHashKey(const DrawItem
& draw_item
);
211 bool operator==(const DrawItemHashKey
& hash_key
) const;
213 ULONG
UpdateHashValue();
214 inline ULONG
GetHashValue()const
221 typedef ::boost::shared_ptr
<OverlayKey
> SharedOverlayKey
;
222 SharedOverlayKey m_overlay_key
;
223 ClipperAlphaMaskCacheKey m_clipper_key
;
227 DWORD m_switchpts
[6];
232 class GroupedDrawItemsHashKey
235 bool operator==(const GroupedDrawItemsHashKey
& key
) const;
237 ULONG
UpdateHashValue();
238 inline ULONG
GetHashValue()const
245 typedef ::boost::shared_ptr
<DrawItemHashKey
> PKey
;
246 typedef CAtlArray
<PKey
> Keys
;
247 typedef ::boost::shared_ptr
<Keys
> PKeys
;
252 friend struct GroupedDrawItems
;
255 class PathDataTraits
:public CElementTraits
<PathData
>
258 static ULONG
Hash(const PathData
& key
);
261 class ClipperTraits
:public CElementTraits
<CClipper
>
264 static ULONG
Hash(const CClipper
& key
);
267 typedef EnhancedXyMru
<
269 CText::SharedPtrTextInfo
,
270 XyCacheKeyTraits
<TextInfoCacheKey
>
273 typedef EnhancedXyMru
<
275 CRenderedTextSubtitle::SharedPtrConstAssTagList
,
276 CStringElementTraits
<CStringW
>
277 > AssTagListMruCache
;
279 typedef EnhancedXyMru
<PathDataCacheKey
, SharedPtrConstPathData
, XyCacheKeyTraits
<PathDataCacheKey
>> PathDataMruCache
;
281 typedef EnhancedXyMru
<ScanLineData2CacheKey
, SharedPtrConstScanLineData2
, XyCacheKeyTraits
<ScanLineData2CacheKey
>> ScanLineData2MruCache
;
283 typedef EnhancedXyMru
<OverlayNoBlurKey
, SharedPtrOverlay
, XyCacheKeyTraits
<OverlayNoBlurKey
>> OverlayNoBlurMruCache
;
285 typedef EnhancedXyMru
<OverlayKey
, SharedPtrOverlay
, XyCacheKeyTraits
<OverlayKey
>> OverlayMruCache
;
287 typedef EnhancedXyMru
<ScanLineDataCacheKey
, SharedPtrConstScanLineData
, XyCacheKeyTraits
<ScanLineDataCacheKey
>> ScanLineDataMruCache
;
289 typedef EnhancedXyMru
<OverlayNoOffsetKey
, OverlayNoBlurKey
, XyCacheKeyTraits
<OverlayNoOffsetKey
>> OverlayNoOffsetMruCache
;
291 typedef EnhancedXyMru
<ClipperAlphaMaskCacheKey
, SharedPtrGrayImage2
, XyCacheKeyTraits
<ClipperAlphaMaskCacheKey
>> ClipperAlphaMaskMruCache
;
294 typedef ::boost::shared_ptr
<XyBitmap
> SharedPtrXyBitmap
;
295 typedef EnhancedXyMru
<std::size_t, SharedPtrXyBitmap
> BitmapMruCache
;
300 static const int BITMAP_MRU_CACHE_ITEM_NUM
= 64;//for test only
301 static const int CLIPPER_MRU_CACHE_ITEM_NUM
= 48;
303 static const int TEXT_INFO_CACHE_ITEM_NUM
= 2048;
304 static const int ASS_TAG_LIST_CACHE_ITEM_NUM
= 2048;
305 static const int SUBPIXEL_VARIANCE_CACHE_ITEM_NUM
= 256;
306 static const int OVERLAY_CACHE_ITEM_NUM
= 256;
308 static const int OVERLAY_NO_BLUR_CACHE_ITEM_NUM
= 256;
309 static const int SCAN_LINE_DATA_CACHE_ITEM_NUM
= 512;
310 static const int PATH_CACHE_ITEM_NUM
= 512;
311 static const int WORD_CACHE_ITEM_NUM
= 512;
313 static BitmapMruCache
* GetBitmapMruCache();
315 static ClipperAlphaMaskMruCache
* GetClipperAlphaMaskMruCache();
316 static TextInfoMruCache
* GetTextInfoCache();
317 static AssTagListMruCache
* GetAssTagListMruCache();
319 static ScanLineDataMruCache
* GetScanLineDataMruCache();
320 static OverlayNoOffsetMruCache
* GetOverlayNoOffsetMruCache();
322 static OverlayMruCache
* GetSubpixelVarianceCache();
323 static OverlayMruCache
* GetOverlayMruCache();
324 static OverlayNoBlurMruCache
* GetOverlayNoBlurMruCache();
325 static ScanLineData2MruCache
* GetScanLineData2MruCache();
326 static PathDataMruCache
* GetPathDataMruCache();
330 typedef XyFlyWeight
<GroupedDrawItemsHashKey
, CacheManager::BITMAP_MRU_CACHE_ITEM_NUM
, XyCacheKeyTraits
<GroupedDrawItemsHashKey
>> XyFwGroupedDrawItemsHashKey
;
332 #endif // end of __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__