From ce13609598d814875a232fd4d48b8c9f6217c1f3 Mon Sep 17 00:00:00 2001 From: xy Date: Sun, 5 Aug 2012 19:16:23 +0800 Subject: [PATCH] Xy Flyweight. [Part 4] --- .../transform/vsfilter/DirectVobSubFilter.cpp | 2 ++ src/filters/transform/vsfilter/plugins.cpp | 2 ++ src/subtitles/cache_manager.h | 27 ++++++++++++---------- src/subtitles/draw_item.cpp | 23 +++++++++--------- src/subtitles/draw_item.h | 2 +- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/filters/transform/vsfilter/DirectVobSubFilter.cpp b/src/filters/transform/vsfilter/DirectVobSubFilter.cpp index 19ea437..f561ccc 100644 --- a/src/filters/transform/vsfilter/DirectVobSubFilter.cpp +++ b/src/filters/transform/vsfilter/DirectVobSubFilter.cpp @@ -703,7 +703,9 @@ void CDirectVobSubFilter::InitSubPicQueue() CacheManager::GetOverlayNoBlurMruCache()->SetMaxItemNum(m_xy_int_opt[INT_OVERLAY_NO_BLUR_CACHE_MAX_ITEM_NUM]); CacheManager::GetOverlayMruCache()->SetMaxItemNum(m_xy_int_opt[INT_OVERLAY_CACHE_MAX_ITEM_NUM]); + XyFwGroupedDrawItemsHashKey::GetCacher()->SetMaxItemNum(m_xy_int_opt[INT_BITMAP_MRU_CACHE_ITEM_NUM]); CacheManager::GetBitmapMruCache()->SetMaxItemNum(m_xy_int_opt[INT_BITMAP_MRU_CACHE_ITEM_NUM]); + CacheManager::GetClipperAlphaMaskMruCache()->SetMaxItemNum(m_xy_int_opt[INT_CLIPPER_MRU_CACHE_ITEM_NUM]); CacheManager::GetTextInfoCache()->SetMaxItemNum(m_xy_int_opt[INT_TEXT_INFO_CACHE_ITEM_NUM]); CacheManager::GetAssTagListMruCache()->SetMaxItemNum(m_xy_int_opt[INT_ASS_TAG_LIST_CACHE_ITEM_NUM]); diff --git a/src/filters/transform/vsfilter/plugins.cpp b/src/filters/transform/vsfilter/plugins.cpp index 0ad1816..9f3c3fb 100644 --- a/src/filters/transform/vsfilter/plugins.cpp +++ b/src/filters/transform/vsfilter/plugins.cpp @@ -67,7 +67,9 @@ public: CacheManager::GetOverlayNoBlurMruCache()->SetMaxItemNum(m_xy_int_opt[INT_OVERLAY_NO_BLUR_CACHE_MAX_ITEM_NUM]); CacheManager::GetOverlayMruCache()->SetMaxItemNum(m_xy_int_opt[INT_OVERLAY_CACHE_MAX_ITEM_NUM]); + XyFwGroupedDrawItemsHashKey::GetCacher()->SetMaxItemNum(m_xy_int_opt[INT_BITMAP_MRU_CACHE_ITEM_NUM]); CacheManager::GetBitmapMruCache()->SetMaxItemNum(m_xy_int_opt[INT_BITMAP_MRU_CACHE_ITEM_NUM]); + CacheManager::GetClipperAlphaMaskMruCache()->SetMaxItemNum(m_xy_int_opt[INT_CLIPPER_MRU_CACHE_ITEM_NUM]); CacheManager::GetTextInfoCache()->SetMaxItemNum(m_xy_int_opt[INT_TEXT_INFO_CACHE_ITEM_NUM]); CacheManager::GetAssTagListMruCache()->SetMaxItemNum(m_xy_int_opt[INT_ASS_TAG_LIST_CACHE_ITEM_NUM]); diff --git a/src/subtitles/cache_manager.h b/src/subtitles/cache_manager.h index d24fa26..6936d70 100644 --- a/src/subtitles/cache_manager.h +++ b/src/subtitles/cache_manager.h @@ -7,6 +7,17 @@ #include "RTS.h" #include "mru_cache.h" +#include "flyweight_base_types.h" + +template +class XyCacheKeyTraits:public CElementTraits +{ +public: + static ULONG Hash(const CahcheKey& key) + { + return key.GetHashValue(); + } +}; class TextInfoCacheKey { @@ -223,16 +234,6 @@ private: friend struct GroupedDrawItems; }; - -template -class XyCacheKeyTraits:public CElementTraits -{ -public: - static ULONG Hash(const CahcheKey& key) - { - return key.GetHashValue(); - } -}; class PathDataTraits:public CElementTraits { @@ -274,8 +275,7 @@ typedef EnhancedXyMru SharedPtrXyBitmap; -typedef EnhancedXyMru> BitmapMruCache; - +typedef EnhancedXyMru BitmapMruCache; class CacheManager { @@ -309,5 +309,8 @@ public: static PathDataMruCache* GetPathDataMruCache(); }; + +typedef XyFlyWeight> XyFwGroupedDrawItemsHashKey; + #endif // end of __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__ diff --git a/src/subtitles/draw_item.cpp b/src/subtitles/draw_item.cpp index f136ea4..7d5f582 100644 --- a/src/subtitles/draw_item.cpp +++ b/src/subtitles/draw_item.cpp @@ -424,12 +424,12 @@ void MergeRects(const XyRectExList& input, XyRectExList* output) void GroupedDrawItems::Draw( SharedPtrXyBitmap *bitmap, int *bitmap_identity_num ) { - static int id=0; - ASSERT(bitmap && bitmap_identity_num); BitmapMruCache *bitmap_cache = CacheManager::GetBitmapMruCache(); - GroupedDrawItemsHashKey key = GetHashKey(); - POSITION pos = bitmap_cache->Lookup(key); + GroupedDrawItemsHashKey *key = new GroupedDrawItemsHashKey(); + CreateHashKey(key); + XyFwGroupedDrawItemsHashKey::IdType key_id = XyFwGroupedDrawItemsHashKey(key).GetId(); + POSITION pos = bitmap_cache->Lookup( key_id ); if (pos==NULL) { POSITION pos = draw_item_list.GetHeadPosition(); @@ -439,30 +439,29 @@ void GroupedDrawItems::Draw( SharedPtrXyBitmap *bitmap, int *bitmap_identity_num { DrawItem::Draw(tmp, *draw_item_list.GetNext(pos), clip_rect); } - bitmap_cache->UpdateCache(key, *bitmap); + bitmap_cache->UpdateCache(key_id, *bitmap); } else { *bitmap = bitmap_cache->GetAt(pos); bitmap_cache->UpdateCache(pos); } - *bitmap_identity_num = id++;//fix me: not really support id yet + *bitmap_identity_num = key_id; } -GroupedDrawItemsHashKey GroupedDrawItems::GetHashKey() +void GroupedDrawItems::CreateHashKey(GroupedDrawItemsHashKey *key) { - GroupedDrawItemsHashKey key; - key.m_clip_rect = clip_rect; + ASSERT(key); + key->m_clip_rect = clip_rect; GroupedDrawItemsHashKey::Keys *inner_key = new GroupedDrawItemsHashKey::Keys(); ASSERT(inner_key); - key.m_key.reset(inner_key); + key->m_key.reset(inner_key); inner_key->SetCount(draw_item_list.GetCount()); POSITION pos = draw_item_list.GetHeadPosition(); for (unsigned i=0;iGetCount();i++) { inner_key->GetAt(i) = draw_item_list.GetNext(pos)->GetHashKey(); } - key.UpdateHashValue(); - return key; + key->UpdateHashValue(); } diff --git a/src/subtitles/draw_item.h b/src/subtitles/draw_item.h index b6b91ca..29b3076 100644 --- a/src/subtitles/draw_item.h +++ b/src/subtitles/draw_item.h @@ -72,7 +72,7 @@ public: public: void Draw(SharedPtrXyBitmap *bitmap, int *bitmap_identity_num); - GroupedDrawItemsHashKey GetHashKey(); + void CreateHashKey(GroupedDrawItemsHashKey *key); }; #endif // __DRAW_ITEM_21D18040_C396_4CA5_BFCE_5616A63F2C56_H__ -- 2.11.4.GIT