From cb4a46e7fbe62d788e66ed6121c717a2d22a4d7c Mon Sep 17 00:00:00 2001 From: watcherhd Date: Thu, 21 Apr 2011 14:14:52 +0000 Subject: svn.miranda.im is moving to a new home! git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@7 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- skinengine/src/bitmap_cache.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 skinengine/src/bitmap_cache.cpp (limited to 'skinengine/src/bitmap_cache.cpp') diff --git a/skinengine/src/bitmap_cache.cpp b/skinengine/src/bitmap_cache.cpp new file mode 100644 index 0000000..5c4eab8 --- /dev/null +++ b/skinengine/src/bitmap_cache.cpp @@ -0,0 +1,53 @@ +#include "headers.h" + +CBitmapCache g_BitmapCache; + +CBitmapCache::CBitmapCache(): m_cache(5, CacheNode::cmp) +{ +} + +CBitmapCache::~CBitmapCache() +{ + for (int i = 0; i < m_cache.getCount(); ++i) + { + delete m_cache[i].bitmap; + free(m_cache[i].path); + } +} + +HBITMAP CBitmapCache::LoadBitmap(const TCHAR *path) +{ + CacheNode search = {0}; + search.path = (TCHAR *)path; + CacheNode *newNode = m_cache.find(&search); + if (newNode) + { + newNode->refCount++; + return newNode->bitmap; + } + + newNode = new CacheNode; + newNode->path = _tcsdup(path); + char *s = mir_t2a(path); + newNode->bitmap = (HBITMAP)CallService(MS_UTILS_LOADBITMAP, 0, (LPARAM)s); + mir_free(s); + newNode->refCount = 1; + m_cache.insert(newNode); + + return newNode->bitmap; +} + +void CBitmapCache::UnloadBitmap(HBITMAP bmp) +{ + for (int i = 0; i < m_cache.getCount(); ++i) + if (m_cache[i].bitmap == bmp) + { + if (--m_cache[i].refCount == 0) + { + DeleteObject(m_cache[i].bitmap); + free(m_cache[i].path); + m_cache.remove(i); + } + return; + } +} -- cgit v1.2.3