Kirigami2

managedtexturenode.cpp
1 /*
2  * SPDX-FileCopyrightText: 2011 Marco Martin <[email protected]>
3  * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <[email protected]>
4  * SPDX-FileCopyrightText: 2020 Carson Black <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.0-or-later
7  */
8 
9 #include "managedtexturenode.h"
10 
11 ManagedTextureNode::ManagedTextureNode()
12 {
13 }
14 
15 void ManagedTextureNode::setTexture(std::shared_ptr<QSGTexture> texture)
16 {
17  m_texture = texture;
19 }
20 
21 ImageTexturesCache::ImageTexturesCache()
22  : d(new ImageTexturesCachePrivate)
23 {
24 }
25 
26 ImageTexturesCache::~ImageTexturesCache()
27 {
28 }
29 
30 std::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 
58 std::shared_ptr<QSGTexture> ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image)
59 {
60  return loadTexture(window, image, {});
61 }
typedef CreateTextureOptions
qint64 cacheKey() const const
QSGTexture * texture() const const
int remove(const Key &key)
bool isEmpty() const const
QSharedPointer< QSGTexture > loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options)
void setTexture(QSGTexture *texture)
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:14:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.