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
qwltextureorphanage.cpp
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwltextureorphanage_p.h"
6
7
#
include
<
QOpenGLContext
>
8
#
include
<
QOpenGLTexture
>
9
#
include
<
QDebug
>
10
#
include
<
QtTypeTraits
>
11
#
include
<
QMutexLocker
>
12
13
QT_BEGIN_NAMESPACE
14
15
Q_LOGGING_CATEGORY(qLcWTO,
"qt.waylandcompositor.orphanage"
)
16
17
Q_GLOBAL_STATIC(QtWayland::QWaylandTextureOrphanage, inst)
18
19
namespace
QtWayland
{
20
21
QWaylandTextureOrphanage
::~
QWaylandTextureOrphanage
()
22
{
23
QMutexLocker
locker
(&
m_containerLock
);
24
if
(!
m_orphanedTextures
.
isEmpty
()) {
25
qCWarning
(
qLcWTO
) <<
Q_FUNC_INFO
<<
"m_orphanedTextures container isn't empty! content:"
26
<<
m_orphanedTextures
;
27
}
28
}
29
30
QWaylandTextureOrphanage
*
QWaylandTextureOrphanage
::
instance
()
31
{
32
return
inst
;
33
}
34
35
void
QWaylandTextureOrphanage
::
admitTexture
(
QOpenGLTexture
*
tex
,
QOpenGLContext
*
ctx
)
36
{
37
qCDebug
(
qLcWTO
) <<
Q_FUNC_INFO
<<
"got a texture ("
<< (
void
*)
tex
38
<<
") ready to be deleted! It's ctx:"
<<
ctx
;
39
40
{
41
QMutexLocker
locker
(&
m_containerLock
);
42
m_orphanedTextures
.
insert
(
ctx
,
tex
);
43
}
44
45
connect
(
ctx
, &
QOpenGLContext
::
aboutToBeDestroyed
,
this
,
46
[
this
,
ctx
]() {
this
->
onContextAboutToBeDestroyed
(
ctx
); },
47
Qt
::
ConnectionType
(
Qt
::
DirectConnection
));
48
}
49
50
void
QWaylandTextureOrphanage
::
deleteTextures
()
51
{
52
QOpenGLContext
*
cCtx
=
QOpenGLContext
::
currentContext
();
53
54
if
(
cCtx
==
nullptr
) {
55
qCWarning
(
qLcWTO
) <<
Q_FUNC_INFO
<<
"cannot delete textures without current OpenGL context"
;
56
return
;
57
}
58
59
{
60
QMutexLocker
locker
(&
m_containerLock
);
61
62
const
auto
contexts
=
m_orphanedTextures
.
keys
();
63
for
(
QOpenGLContext
*
aCtx
:
contexts
) {
64
if
(
QOpenGLContext
::
areSharing
(
cCtx
,
aCtx
)) {
65
66
qCDebug
(
qLcWTO
) <<
Q_FUNC_INFO
<<
"currentContext ("
<<
cCtx
67
<<
") and ctx of orphane(s) ("
<<
aCtx
68
<<
") are shared! => deleteTexturesByContext"
;
69
70
deleteTexturesByContext
(
aCtx
);
71
}
72
}
73
}
74
}
75
76
void
QWaylandTextureOrphanage
::
onContextAboutToBeDestroyed
(
QOpenGLContext
*
ctx
)
77
{
78
Q_ASSERT
(
ctx
!=
nullptr
);
79
80
qCDebug
(
qLcWTO
) <<
Q_FUNC_INFO
<<
" ctx ("
<<
ctx
81
<<
") fired aboutToBeDestroyed => deleteTexturesByContext(ctx)"
;
82
83
{
84
QMutexLocker
locker
(&
m_containerLock
);
85
deleteTexturesByContext
(
ctx
);
86
}
87
}
88
89
void
QWaylandTextureOrphanage
::
deleteTexturesByContext
(
QOpenGLContext
*
ctx
)
90
{
91
// NOTE: We are (by class-internal design) locked (m_containerLock)
92
// when we enter this function!
93
// If not (e.g.: someone changes something in/around this class),
94
// then in a debug-build we will fail below:
95
Q_ASSERT
(!
m_containerLock
.
tryLock
());
96
97
const
QList
<
QOpenGLTexture
*>
texturesToDelete
=
m_orphanedTextures
.
values
(
ctx
);
98
m_orphanedTextures
.
remove
(
ctx
);
99
100
for
(
QOpenGLTexture
*
tex
:
texturesToDelete
) {
101
delete
tex
;
102
qCDebug
(
qLcWTO
) <<
Q_FUNC_INFO
<<
" texture ("
<< (
void
*)
tex
<<
") got deleted"
;
103
}
104
}
105
106
}
// namespace QtWayland
107
108
QT_END_NAMESPACE
109
110
#
include
"moc_qwltextureorphanage_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtWayland
Definition
qwaylanddisplay_p.h:54
qtwayland
src
compositor
hardware_integration
qwltextureorphanage.cpp
Generated on
for Qt by
1.16.1