File: managedtexturenode.h

package info (click to toggle)
syncthingtray 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 34,081; xml: 1,705; java: 1,258; sh: 97; javascript: 54; makefile: 25
file content (55 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download | duplicates (2)
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
/*
 *  SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org>
 *  SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *  SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
 *  SPDX-FileCopyrightText: 2024 Martchus <martchus@gmx.net>
 *
 *  SPDX-License-Identifier: LGPL-2.0-or-later
 */

#pragma once
#include <QImage>
#include <QQuickWindow>
#include <QSGSimpleTextureNode>
#include <QSGTexture>
#include <memory>

namespace QtGui {

class ManagedTextureNode : public QSGSimpleTextureNode {
    Q_DISABLE_COPY(ManagedTextureNode)
public:
    ManagedTextureNode();

    void setTexture(std::shared_ptr<QSGTexture> texture);

private:
    std::shared_ptr<QSGTexture> m_texture;
};

typedef QHash<qint64, QHash<QWindow *, std::weak_ptr<QSGTexture>>> TexturesCache;

struct ImageTexturesCachePrivate {
    TexturesCache cache;
};

class ImageTexturesCache {
public:
    ImageTexturesCache();
    ~ImageTexturesCache();

    /**
     * @returns the texture for a given @p window and @p image.
     *
     * If an @p image id is the same as one already provided before, we won't create
     * a new texture and return a shared pointer to the existing texture.
     */
    std::shared_ptr<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options);

    std::shared_ptr<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image);

private:
    std::unique_ptr<ImageTexturesCachePrivate> d;
};

} // namespace QtGui