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
16class ManagedTextureNode : public QSGSimpleTextureNode
17{
18 Q_DISABLE_COPY(ManagedTextureNode)
19public:
20 ManagedTextureNode();
21
22 void setTexture(std::shared_ptr<QSGTexture> texture);
23
24private:
25 std::shared_ptr<QSGTexture> m_texture;
26};
27
28typedef QHash<qint64, QHash<QWindow *, std::weak_ptr<QSGTexture>>> TexturesCache;
29
30struct ImageTexturesCachePrivate {
31 TexturesCache cache;
32};
33
34class ImageTexturesCache
35{
36public:
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
50private:
51 std::unique_ptr<ImageTexturesCachePrivate> d;
52};
53

source code of kirigami/src/scenegraph/managedtexturenode.h