-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagetexturecache.h
67 lines (50 loc) · 1.82 KB
/
imagetexturecache.h
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
61
62
63
64
65
66
67
#pragma once
#include <QObject>
#include <QQuickWindow>
#include <memory>
class QSGTexture;
class ImageTextureCacheData;
class ImageTextureCacheEntry;
class ImageTextureCachePrivate;
// ImageTextureCacheEntry represents an entry in the image texture cache,
// holds a reference to that entry to ensure its lifetime.
class ImageTextureCacheEntry
{
friend class ImageTextureCache;
public:
ImageTextureCacheEntry();
ImageTextureCacheEntry(const ImageTextureCacheEntry &o);
~ImageTextureCacheEntry();
ImageTextureCacheEntry &operator=(const ImageTextureCacheEntry &o);
bool isNull() const { return !d; }
bool isEmpty() const { return image().isNull() && !texture() && error().isEmpty(); }
void reset();
QImage image() const;
QString error() const;
QSize loadedSize() const;
QSize imageSize() const;
QSGTexture *texture() const;
private:
std::shared_ptr<ImageTextureCacheData> d;
ImageTextureCacheEntry(const std::shared_ptr<ImageTextureCacheData> &dp);
};
class ImageTextureCache : public QObject
{
Q_OBJECT
public:
static std::shared_ptr<ImageTextureCache> forWindow(QQuickWindow *window);
virtual ~ImageTextureCache();
// Query the cache with the given key, and return a CacheEntry with the
// result and a strong reference to this entry in the cache.
//
// Even if the key does not exist or has no result, an entry will be added
// to the cache. If the key is later inserted, the entry will be updated.
ImageTextureCacheEntry get(const QString &key);
void insert(const QString &key, const QImage &image, const QSize &imageSize);
void insert(const QString &key, const QString &error);
signals:
void changed(const QString &key);
private:
std::shared_ptr<ImageTextureCachePrivate> d;
explicit ImageTextureCache(QQuickWindow *window);
};