Coverage Report

Created: 2026-05-16 07:21

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