File: imagetexturescache.h

package info (click to toggle)
artikulate 4%3A20.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,888 kB
  • sloc: cpp: 11,923; xml: 3,116; makefile: 5; sh: 5
file content (47 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download
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
/*
 *   SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *
 *   SPDX-License-Identifier: LGPL-2.0-or-later
 */

#ifndef IMAGETEXTURESCACHE_H
#define IMAGETEXTURESCACHE_H

#include <QQuickWindow>
#include <QSharedPointer>

class QImage;
class QSGTexture;
struct ImageTexturesCachePrivate;

/**
 * @short Helps to manage textures by creating images and reference counts them.
 *
 * Use this class as a factory for textures, when creating them from a QImage
 * instance.
 * Keeps track of all the created textures in a map between the QImage::cacheKey() and
 * the cached texture until it gets de-referenced.
 *
 * @see ManagedTextureNode
 */
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.
     */
    QSharedPointer<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options);

    QSharedPointer<QSGTexture> loadTexture(QQuickWindow *window, const QImage &image);

private:
    QScopedPointer<ImageTexturesCachePrivate> d;
};

#endif // IMAGETEXTURESCACHE_H