Kirigami2

managedtexturenode.cpp
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#include "managedtexturenode.h"
10
11ManagedTextureNode::ManagedTextureNode()
12{
13}
14
15void ManagedTextureNode::setTexture(std::shared_ptr<QSGTexture> texture)
16{
17 m_texture = texture;
19}
20
21ImageTexturesCache::ImageTexturesCache()
22 : d(new ImageTexturesCachePrivate)
23{
24}
25
26ImageTexturesCache::~ImageTexturesCache()
27{
28}
29
30std::shared_ptr<QSGTexture> ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options)
31{
32 qint64 id = image.cacheKey();
33 std::shared_ptr<QSGTexture> texture = d->cache.value(id).value(window).lock();
34
35 if (!texture) {
36 auto cleanAndDelete = [this, window, id](QSGTexture *texture) {
37 QHash<QWindow *, std::weak_ptr<QSGTexture>> &textures = (d->cache)[id];
38 textures.remove(window);
39 if (textures.isEmpty()) {
40 d->cache.remove(id);
41 }
42 delete texture;
43 };
44 texture = std::shared_ptr<QSGTexture>(window->createTextureFromImage(image, options), cleanAndDelete);
45 (d->cache)[id][window] = texture;
46 }
47
48 // if we have a cache in an atlas but our request cannot use an atlassed texture
49 // create a new texture and use that
50 // don't use removedFromAtlas() as that requires keeping a reference to the non atlased version
51 if (!(options & QQuickWindow::TextureCanUseAtlas) && texture->isAtlasTexture()) {
52 texture = std::shared_ptr<QSGTexture>(window->createTextureFromImage(image, options));
53 }
54
55 return texture;
56}
57
58std::shared_ptr<QSGTexture> ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image)
59{
60 return loadTexture(window, image, {});
61}
QSharedPointer< QSGTexture > loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options)
QWidget * window(QObject *job)
bool isEmpty() const const
bool remove(const Key &key)
qint64 cacheKey() const const
typedef CreateTextureOptions
void setTexture(QSGTexture *texture)
QSGTexture * texture() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.