File indexing completed on 2024-04-28 03:55:59
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> 0003 * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0004 * SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 #include <QImage> 0011 #include <QQuickWindow> 0012 #include <QSGSimpleTextureNode> 0013 #include <QSGTexture> 0014 #include <memory> 0015 0016 class ManagedTextureNode : public QSGSimpleTextureNode 0017 { 0018 Q_DISABLE_COPY(ManagedTextureNode) 0019 public: 0020 ManagedTextureNode(); 0021 0022 void setTexture(std::shared_ptr<QSGTexture> texture); 0023 0024 private: 0025 std::shared_ptr<QSGTexture> m_texture; 0026 }; 0027 0028 typedef QHash<qint64, QHash<QWindow *, std::weak_ptr<QSGTexture>>> TexturesCache; 0029 0030 struct ImageTexturesCachePrivate { 0031 TexturesCache cache; 0032 }; 0033 0034 class ImageTexturesCache 0035 { 0036 public: 0037 ImageTexturesCache(); 0038 ~ImageTexturesCache(); 0039 0040 /** 0041 * @returns the texture for a given @p window and @p image. 0042 * 0043 * If an @p image id is the same as one already provided before, we won't create 0044 * a new texture and return a shared pointer to the existing texture. 0045 */ 0046 std::shared_ptr<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options); 0047 0048 std::shared_ptr<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image); 0049 0050 private: 0051 std::unique_ptr<ImageTexturesCachePrivate> d; 0052 };