1 | /* |
2 | SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef IMAGETEXTURESCACHE_H |
8 | #define IMAGETEXTURESCACHE_H |
9 | |
10 | #include <QQuickWindow> |
11 | #include <QSharedPointer> |
12 | |
13 | class QImage; |
14 | class QSGTexture; |
15 | class ImageTexturesCachePrivate; |
16 | |
17 | /** |
18 | * @class ImageTexturesCache imagetexturescache.h KQuickAddons/ImageTexturesCache |
19 | * |
20 | * @short Helps to manage textures by creating images and reference counts them. |
21 | * |
22 | * Use this class as a factory for textures, when creating them from a QImage |
23 | * instance. Keeps track of all the created textures in a map between the |
24 | * QImage::cacheKey() and the cached texture until it gets de-referenced. |
25 | * |
26 | * @see ManagedTextureNode |
27 | */ |
28 | class ImageTexturesCache |
29 | { |
30 | public: |
31 | ImageTexturesCache(); |
32 | ~ImageTexturesCache(); |
33 | |
34 | /** |
35 | * @returns the texture for a given @p window and @p image. |
36 | * |
37 | * If @p image id is the same as one already provided before, we will not |
38 | * create a new texture, and will instead return a shared pointer to the existing texture. |
39 | */ |
40 | QSharedPointer<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options); |
41 | |
42 | QSharedPointer<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image); |
43 | |
44 | private: |
45 | QScopedPointer<ImageTexturesCachePrivate> d; |
46 | }; |
47 | |
48 | #endif // IMAGETEXTURESCACHE_H |
49 | |