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
4#include "qimagepixmapcleanuphooks_p.h"
5#include <qpa/qplatformpixmap.h>
6#include "private/qimage_p.h"
7
8
9QT_BEGIN_NAMESPACE
10
11Q_GLOBAL_STATIC(QImagePixmapCleanupHooks, qt_image_and_pixmap_cleanup_hooks)
12
13QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance()
14{
15 return qt_image_and_pixmap_cleanup_hooks();
16}
17
18void QImagePixmapCleanupHooks::addPlatformPixmapModificationHook(_qt_pixmap_cleanup_hook_pmd hook)
19{
20 pixmapModificationHooks.append(t: hook);
21}
22
23void QImagePixmapCleanupHooks::addPlatformPixmapDestructionHook(_qt_pixmap_cleanup_hook_pmd hook)
24{
25 pixmapDestructionHooks.append(t: hook);
26}
27
28
29void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook)
30{
31 imageHooks.append(t: hook);
32}
33
34void QImagePixmapCleanupHooks::removePlatformPixmapModificationHook(_qt_pixmap_cleanup_hook_pmd hook)
35{
36 pixmapModificationHooks.removeAll(t: hook);
37}
38
39void QImagePixmapCleanupHooks::removePlatformPixmapDestructionHook(_qt_pixmap_cleanup_hook_pmd hook)
40{
41 pixmapDestructionHooks.removeAll(t: hook);
42}
43
44void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
45{
46 imageHooks.removeAll(t: hook);
47}
48
49void QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(QPlatformPixmap* pmd)
50{
51 const QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
52 // the global destructor for the pixmap and image hooks might have
53 // been called already if the app is "leaking" global
54 // pixmaps/images
55 if (!h)
56 return;
57 for (auto hook : h->pixmapModificationHooks)
58 hook(pmd);
59}
60
61void QImagePixmapCleanupHooks::executePlatformPixmapDestructionHooks(QPlatformPixmap* pmd)
62{
63 const QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
64 // the global destructor for the pixmap and image hooks might have
65 // been called already if the app is "leaking" global
66 // pixmaps/images
67 if (!h)
68 return;
69 for (auto hook : h->pixmapDestructionHooks)
70 hook(pmd);
71}
72
73void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
74{
75 const QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
76 // the global destructor for the pixmap and image hooks might have
77 // been called already if the app is "leaking" global
78 // pixmaps/images
79 if (!h)
80 return;
81 for (auto hook : h->imageHooks)
82 hook(key);
83}
84
85
86void QImagePixmapCleanupHooks::enableCleanupHooks(QPlatformPixmap *handle)
87{
88 handle->is_cached = true;
89}
90
91void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
92{
93 enableCleanupHooks(handle: const_cast<QPixmap &>(pixmap).data_ptr().data());
94}
95
96void QImagePixmapCleanupHooks::enableCleanupHooks(const QImage &image)
97{
98 const_cast<QImage &>(image).data_ptr()->is_cached = true;
99}
100
101bool QImagePixmapCleanupHooks::isImageCached(const QImage &image)
102{
103 return const_cast<QImage &>(image).data_ptr()->is_cached;
104}
105
106bool QImagePixmapCleanupHooks::isPixmapCached(const QPixmap &pixmap)
107{
108 return const_cast<QPixmap&>(pixmap).data_ptr().data()->is_cached;
109}
110
111
112
113QT_END_NAMESPACE
114

source code of qtbase/src/gui/image/qimagepixmapcleanuphooks.cpp