Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickpixmapcache_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQUICKPIXMAPCACHE_H
6#define QQUICKPIXMAPCACHE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qmutex.h>
20#include <QtCore/qurl.h>
21#include <QtQuick/qquickimageprovider.h>
22#include <private/qquickpixmap_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QQuickPixmapData;
27
28/*! \internal
29 A composite key to identify a QQuickPixmapData instance in a QHash.
30*/
31struct Q_AUTOTEST_EXPORT QQuickPixmapKey
32{
33 const QUrl *url;
34 const QRect *region;
35 const QSize *size;
36 int frame;
37 QQuickImageProviderOptions options;
38};
39
40/*! \internal
41 A singleton managing the storage and garbage collection of QQuickPixmapData
42 instances. It's exported only for the sake of autotests, and should not be
43 manipulated outside qquickpixmap.cpp and qquickpixmapcache.cpp.
44*/
45class Q_AUTOTEST_EXPORT QQuickPixmapCache : public QObject
46{
47 Q_OBJECT
48
49public:
50 static QQuickPixmapCache *instance();
51 ~QQuickPixmapCache() override;
52
53 void unreferencePixmap(QQuickPixmapData *);
54 void referencePixmap(QQuickPixmapData *);
55
56 void purgeCache();
57
58protected:
59 void timerEvent(QTimerEvent *) override;
60
61private:
62 QQuickPixmapCache() = default;
63 Q_DISABLE_COPY(QQuickPixmapCache)
64
65 void shrinkCache(int remove);
66 int destroyCache();
67 qsizetype referencedCost() const;
68
69private:
70 QHash<QQuickPixmapKey, QQuickPixmapData *> m_cache;
71 mutable QMutex m_cacheMutex; // avoid simultaneous iteration and modification
72
73 QQuickPixmapData *m_unreferencedPixmaps = nullptr;
74 QQuickPixmapData *m_lastUnreferencedPixmap = nullptr;
75
76 int m_unreferencedCost = 0;
77 int m_timerId = -1;
78 bool m_destroying = false;
79
80 friend class QQuickPixmap;
81 friend class QQuickPixmapData;
82 friend class tst_qquickpixmapcache;
83 friend class tst_qquicktext;
84 friend class tst_qquicktextedit;
85};
86
87QT_END_NAMESPACE
88
89#endif // QQUICKPIXMAPCACHE_H