-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageCache.h
More file actions
61 lines (48 loc) · 1.58 KB
/
Copy pathImageCache.h
File metadata and controls
61 lines (48 loc) · 1.58 KB
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
54
55
56
57
58
59
60
#pragma once
#include "ImageRequest.h"
#include <d2d1.h>
#include <wrl/client.h>
#include <unordered_map>
#include <list>
#include <mutex>
#include <memory>
namespace ImageCore
{
// LRU cache entry
// Note: Stores a D2D bitmap, but this is only used in the UI layer.
// Ideally, ImageCore provides decode results as DecodedImage and D2D conversion is handled in the UI layer.
// (Currently maintaining D2D dependency for compatibility with existing structure)
struct ImageCacheEntry
{
Microsoft::WRL::ComPtr<ID2D1Bitmap> bitmap;
size_t memorySize; // Memory usage (bytes)
std::list<ImageRequest>::iterator lruIterator;
ImageCacheEntry()
: memorySize(0)
{
}
};
class ImageCache
{
public:
ImageCache();
~ImageCache();
// Find in cache
bool Find(const ImageRequest& request, Microsoft::WRL::ComPtr<ID2D1Bitmap>& outBitmap);
// Store in cache
void Store(const ImageRequest& request, Microsoft::WRL::ComPtr<ID2D1Bitmap> bitmap);
// Clear cache
void Clear();
// Set cache size limit
void SetSizeLimit(size_t maxBytes);
// Current memory in use
size_t CurrentMemoryUsage() const;
private:
void EvictLRU();
std::unordered_map<ImageRequest, ImageCacheEntry, std::hash<ImageRequest>> m_cache;
std::list<ImageRequest> m_lruList; // LRU order (front = most recently used)
mutable std::mutex m_mutex;
size_t m_maxMemoryBytes;
size_t m_currentMemoryBytes;
};
}