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 m_str_id
= word
.m_str
.GetId();
52 PathDataCacheKey(const PathDataCacheKey
& key
)
53 :m_str_id(key
.m_str_id
)
55 ,m_hash_value(key
.m_hash_value
){}
56 PathDataCacheKey(const FwSTSStyle
& style
, XyFwStringW::IdType str_id
):m_style(style
)
60 bool operator==(const PathDataCacheKey
& key
)const
62 return m_str_id
==key
.m_str_id
&& ( m_style
==key
.m_style
|| CompareSTSStyle(m_style
, key
.m_style
) );
64 bool operator==(const CWord
& key
)const
66 return m_str_id
==key
.m_str
.GetId() && ( m_style
==key
.m_style
|| CompareSTSStyle(m_style
.get(), key
.m_style
.get()) );
69 static bool CompareSTSStyle(const STSStyle
& lhs
, const STSStyle
& rhs
);
71 ULONG
UpdateHashValue();
72 inline ULONG
GetHashValue()const
79 XyFwStringW::IdType m_str_id
;
83 class ScanLineData2CacheKey
: public PathDataCacheKey
86 ScanLineData2CacheKey(const CWord
& word
, const POINT
& org
):PathDataCacheKey(word
),m_org(org
) { }
87 ScanLineData2CacheKey(const ScanLineData2CacheKey
& key
)
88 :PathDataCacheKey(key
)
90 ,m_hash_value(key
.m_hash_value
) { }
91 ScanLineData2CacheKey(const FwSTSStyle
& style
, XyFwStringW::IdType str_id
, const POINT
& org
)
92 :PathDataCacheKey(style
, str_id
),m_org(org
) { }
93 bool operator==(const ScanLineData2CacheKey
& key
)const;
95 ULONG
UpdateHashValue();
96 inline ULONG
GetHashValue()const
105 class OverlayNoBlurKey
: public ScanLineData2CacheKey
108 OverlayNoBlurKey(const CWord
& word
, const POINT
& p
, const POINT
& org
):ScanLineData2CacheKey(word
,org
),m_p(p
) {}
109 OverlayNoBlurKey(const OverlayNoBlurKey
& key
):ScanLineData2CacheKey(key
),m_p(key
.m_p
),m_hash_value(key
.m_hash_value
) {}
110 OverlayNoBlurKey(const FwSTSStyle
& style
, XyFwStringW::IdType str_id
, const POINT
& p
, const POINT
& org
)
111 :ScanLineData2CacheKey(style
, str_id
, org
),m_p(p
) {}
112 bool operator==(const OverlayNoBlurKey
& key
)const;
114 ULONG
UpdateHashValue();
115 inline ULONG
GetHashValue()const
124 class OverlayKey
: public OverlayNoBlurKey
127 OverlayKey(const CWord
& word
, const POINT
& p
, const POINT
& org
):OverlayNoBlurKey(word
, p
, org
) {}
128 OverlayKey(const OverlayKey
& key
):OverlayNoBlurKey(key
), m_hash_value(key
.m_hash_value
) {}
130 bool operator==(const OverlayKey
& key
)const;
132 ULONG
UpdateHashValue();
133 inline ULONG
GetHashValue()const
141 class ScanLineDataCacheKey
144 ScanLineDataCacheKey(const SharedPtrConstPathData
& path_data
):m_path_data(path_data
){}
145 bool operator==(const ScanLineDataCacheKey
& key
)const;
147 ULONG
UpdateHashValue();
148 inline ULONG
GetHashValue()const
154 SharedPtrConstPathData m_path_data
;
157 class OverlayNoOffsetKey
:public ScanLineDataCacheKey
160 OverlayNoOffsetKey(const SharedPtrConstPathData
& path_data
, int xsub
, int ysub
, int border_x
, int border_y
)
161 : ScanLineDataCacheKey(path_data
)
162 , m_border( border_x
+(border_y
<<16) )
163 , m_rasterize_sub( xsub
+(ysub
<<16) ){}
164 bool operator==(const OverlayNoOffsetKey
& key
)const;
166 ULONG
UpdateHashValue();
167 inline ULONG
GetHashValue()const
178 class ClipperAlphaMaskCacheKey
181 ClipperAlphaMaskCacheKey(const SharedPtrCClipper
& clipper
):m_clipper(clipper
){}
182 bool operator==(const ClipperAlphaMaskCacheKey
& key
)const;
184 ULONG
UpdateHashValue();
185 inline ULONG
GetHashValue()const
192 SharedPtrCClipper m_clipper
;
196 class DrawItemHashKey
199 DrawItemHashKey(const DrawItem
& draw_item
);
200 bool operator==(const DrawItemHashKey
& hash_key
) const;
202 ULONG
UpdateHashValue();
203 inline ULONG
GetHashValue()const
210 typedef ::boost::shared_ptr
<OverlayKey
> SharedOverlayKey
;
211 SharedOverlayKey m_overlay_key
;
212 ClipperAlphaMaskCacheKey m_clipper_key
;
216 DWORD m_switchpts
[6];
221 class GroupedDrawItemsHashKey
224 bool operator==(const GroupedDrawItemsHashKey
& key
) const;
226 ULONG
UpdateHashValue();
227 inline ULONG
GetHashValue()const
234 typedef ::boost::shared_ptr
<DrawItemHashKey
> PKey
;
235 typedef CAtlArray
<PKey
> Keys
;
236 typedef ::boost::shared_ptr
<Keys
> PKeys
;
241 friend struct GroupedDrawItems
;
244 class PathDataTraits
:public CElementTraits
<PathData
>
247 static ULONG
Hash(const PathData
& key
);
250 class ClipperTraits
:public CElementTraits
<CClipper
>
253 static ULONG
Hash(const CClipper
& key
);
256 typedef EnhancedXyMru
<
258 CText::SharedPtrTextInfo
,
259 XyCacheKeyTraits
<TextInfoCacheKey
>
262 typedef EnhancedXyMru
<
264 CRenderedTextSubtitle::SharedPtrConstAssTagList
,
265 CStringElementTraits
<CStringW
>
266 > AssTagListMruCache
;
268 typedef EnhancedXyMru
<PathDataCacheKey
, SharedPtrConstPathData
, XyCacheKeyTraits
<PathDataCacheKey
>> PathDataMruCache
;
270 typedef EnhancedXyMru
<ScanLineData2CacheKey
, SharedPtrConstScanLineData2
, XyCacheKeyTraits
<ScanLineData2CacheKey
>> ScanLineData2MruCache
;
272 typedef EnhancedXyMru
<OverlayNoBlurKey
, SharedPtrOverlay
, XyCacheKeyTraits
<OverlayNoBlurKey
>> OverlayNoBlurMruCache
;
274 typedef EnhancedXyMru
<OverlayKey
, SharedPtrOverlay
, XyCacheKeyTraits
<OverlayKey
>> OverlayMruCache
;
276 typedef EnhancedXyMru
<ScanLineDataCacheKey
, SharedPtrConstScanLineData
, XyCacheKeyTraits
<ScanLineDataCacheKey
>> ScanLineDataMruCache
;
278 typedef EnhancedXyMru
<OverlayNoOffsetKey
, OverlayNoBlurKey
, XyCacheKeyTraits
<OverlayNoOffsetKey
>> OverlayNoOffsetMruCache
;
280 typedef EnhancedXyMru
<ClipperAlphaMaskCacheKey
, SharedPtrGrayImage2
, XyCacheKeyTraits
<ClipperAlphaMaskCacheKey
>> ClipperAlphaMaskMruCache
;
283 typedef ::boost::shared_ptr
<XyBitmap
> SharedPtrXyBitmap
;
284 typedef EnhancedXyMru
<std::size_t, SharedPtrXyBitmap
> BitmapMruCache
;
289 static const int BITMAP_MRU_CACHE_ITEM_NUM
= 64;//for test only
290 static const int CLIPPER_MRU_CACHE_ITEM_NUM
= 48;
292 static const int TEXT_INFO_CACHE_ITEM_NUM
= 2048;
293 static const int ASS_TAG_LIST_CACHE_ITEM_NUM
= 256;
294 static const int SUBPIXEL_VARIANCE_CACHE_ITEM_NUM
= 256;
295 static const int OVERLAY_CACHE_ITEM_NUM
= 256;
297 static const int OVERLAY_NO_BLUR_CACHE_ITEM_NUM
= 256;
298 static const int SCAN_LINE_DATA_CACHE_ITEM_NUM
= 512;
299 static const int PATH_CACHE_ITEM_NUM
= 512;
300 static const int WORD_CACHE_ITEM_NUM
= 512;
302 static BitmapMruCache
* GetBitmapMruCache();
304 static ClipperAlphaMaskMruCache
* GetClipperAlphaMaskMruCache();
305 static TextInfoMruCache
* GetTextInfoCache();
306 static AssTagListMruCache
* GetAssTagListMruCache();
308 static ScanLineDataMruCache
* GetScanLineDataMruCache();
309 static OverlayNoOffsetMruCache
* GetOverlayNoOffsetMruCache();
311 static OverlayMruCache
* GetSubpixelVarianceCache();
312 static OverlayMruCache
* GetOverlayMruCache();
313 static OverlayNoBlurMruCache
* GetOverlayNoBlurMruCache();
314 static ScanLineData2MruCache
* GetScanLineData2MruCache();
315 static PathDataMruCache
* GetPathDataMruCache();
319 typedef XyFlyWeight
<GroupedDrawItemsHashKey
, CacheManager::BITMAP_MRU_CACHE_ITEM_NUM
, XyCacheKeyTraits
<GroupedDrawItemsHashKey
>> XyFwGroupedDrawItemsHashKey
;
321 #endif // end of __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__