Coverage Report

Created: 2026-03-31 07:41

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