1 | /* |
2 | * SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> |
3 | * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> |
4 | * SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #pragma once |
10 | #include <QImage> |
11 | #include <QQuickWindow> |
12 | #include <QSGSimpleTextureNode> |
13 | #include <QSGTexture> |
14 | #include <memory> |
15 | |
16 | class ManagedTextureNode : public QSGSimpleTextureNode |
17 | { |
18 | Q_DISABLE_COPY(ManagedTextureNode) |
19 | public: |
20 | ManagedTextureNode(); |
21 | |
22 | void setTexture(std::shared_ptr<QSGTexture> texture); |
23 | |
24 | private: |
25 | std::shared_ptr<QSGTexture> m_texture; |
26 | }; |
27 | |
28 | typedef QHash<qint64, QHash<QWindow *, std::weak_ptr<QSGTexture>>> TexturesCache; |
29 | |
30 | struct ImageTexturesCachePrivate { |
31 | TexturesCache cache; |
32 | }; |
33 | |
34 | class ImageTexturesCache |
35 | { |
36 | public: |
37 | ImageTexturesCache(); |
38 | ~ImageTexturesCache(); |
39 | |
40 | /** |
41 | * @returns the texture for a given @p window and @p image. |
42 | * |
43 | * If an @p image id is the same as one already provided before, we won't create |
44 | * a new texture and return a shared pointer to the existing texture. |
45 | */ |
46 | std::shared_ptr<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options); |
47 | |
48 | std::shared_ptr<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image); |
49 | |
50 | private: |
51 | std::unique_ptr<ImageTexturesCachePrivate> d; |
52 | }; |
53 | |