blob: 5c4eab8e63d27797dfbe0576d4b6e3a1099f46be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
}
}
|