summaryrefslogtreecommitdiff
path: root/skinengine/src/bitmap_cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'skinengine/src/bitmap_cache.cpp')
-rw-r--r--skinengine/src/bitmap_cache.cpp53
1 files changed, 53 insertions, 0 deletions
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;
+ }
+}