Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
shmserverbufferintegration.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:critical reason:network-protocol
4
5
#
include
"shmserverbufferintegration.h"
6
7
#
include
<
QtOpenGL
/
QOpenGLTexture
>
8
#
include
<
QtGui
/
QOpenGLContext
>
9
#
include
<
QtCore
/
QSharedMemory
>
10
11
#
include
<
QtCore
/
QDebug
>
12
13
QT_BEGIN_NAMESPACE
14
15
ShmServerBuffer
::
ShmServerBuffer
(ShmServerBufferIntegration *integration,
const
QImage &qimage, QtWayland::ServerBuffer::Format format)
16
: QtWayland::ServerBuffer(qimage.size(),format)
17
, m_integration(integration)
18
, m_width(qimage.width())
19
, m_height(qimage.height())
20
, m_bpl(qimage.bytesPerLine())
21
{
22
m_format = format;
23
switch
(m_format) {
24
case
RGBA32:
25
m_shm_format = QtWaylandServer::qt_shm_emulation_server_buffer::format_RGBA32;
26
break
;
27
case
A8:
28
m_shm_format = QtWaylandServer::qt_shm_emulation_server_buffer::format_A8;
29
break
;
30
default
:
31
qWarning(
"ShmServerBuffer: unsupported format"
);
32
m_shm_format = QtWaylandServer::qt_shm_emulation_server_buffer::format_RGBA32;
33
break
;
34
}
35
36
QString key =
"qt_shm_emulation_"
+ QString::number(qimage.cacheKey());
37
// ### Use proper native keys the next time we can break protocol compatibility
38
QT_IGNORE_DEPRECATIONS(m_shm =
new
QSharedMemory(key);)
39
qsizetype shm_size = qimage.sizeInBytes();
40
bool
ok = m_shm->create(shm_size) && m_shm->lock();
41
if
(ok) {
42
memcpy(m_shm->data(), qimage.constBits(), shm_size);
43
m_shm->unlock();
44
}
else
{
45
qWarning() <<
"Could not create shared memory"
<< key << shm_size;
46
}
47
}
48
49
ShmServerBuffer
::~
ShmServerBuffer
()
50
{
51
delete
m_shm;
52
}
53
54
struct
::wl_resource *
ShmServerBuffer
::resourceForClient(
struct
::wl_client *client)
55
{
56
auto
*bufferResource = resourceMap().value(client);
57
if
(!bufferResource) {
58
auto
integrationResource = m_integration->resourceMap().value(client);
59
if
(!integrationResource) {
60
qWarning(
"ShmServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the shm_emulation interface"
);
61
return
nullptr
;
62
}
63
struct
::wl_resource *shm_integration_resource = integrationResource->handle;
64
Resource *resource = add(client, 1);
65
QT_IGNORE_DEPRECATIONS(
const
QString shmKey = m_shm->key();)
66
m_integration->send_server_buffer_created(shm_integration_resource, resource->handle, shmKey, m_width, m_height, m_bpl, m_shm_format);
67
return
resource->handle;
68
}
69
return
bufferResource->handle;
70
}
71
72
bool
ShmServerBuffer
::
bufferInUse
()
73
{
74
return
resourceMap().size() > 0;
75
}
76
77
QOpenGLTexture
*
ShmServerBuffer
::
toOpenGlTexture
()
78
{
79
if
(!m_texture) {
80
qWarning(
"ShmServerBuffer::toOpenGlTexture: no texture defined"
);
81
}
82
return
m_texture;
83
}
84
85
ShmServerBufferIntegration
::
ShmServerBufferIntegration
()
86
{
87
}
88
89
ShmServerBufferIntegration
::~
ShmServerBufferIntegration
()
90
{
91
}
92
93
bool
ShmServerBufferIntegration
::
initializeHardware
(QWaylandCompositor *compositor)
94
{
95
Q_ASSERT(QGuiApplication::platformNativeInterface());
96
97
QtWaylandServer::qt_shm_emulation_server_buffer::init(compositor->display(), 1);
98
return
true
;
99
}
100
101
bool
ShmServerBufferIntegration
::
supportsFormat
(QtWayland::ServerBuffer::Format format)
const
102
{
103
switch
(format) {
104
case
QtWayland::ServerBuffer::RGBA32:
105
return
true
;
106
case
QtWayland::ServerBuffer::A8:
107
return
true
;
108
default
:
109
return
false
;
110
}
111
}
112
113
QtWayland
::
ServerBuffer
*
ShmServerBufferIntegration
::
createServerBufferFromImage
(
const
QImage &qimage, QtWayland::ServerBuffer::Format format)
114
{
115
return
new
ShmServerBuffer
(
this
, qimage, format);
116
}
117
118
QT_END_NAMESPACE
ShmServerBufferIntegration
Definition
shmserverbufferintegration.h:49
ShmServerBufferIntegration::initializeHardware
bool initializeHardware(QWaylandCompositor *) override
Definition
shmserverbufferintegration.cpp:93
ShmServerBufferIntegration::supportsFormat
bool supportsFormat(QtWayland::ServerBuffer::Format format) const override
Definition
shmserverbufferintegration.cpp:101
ShmServerBufferIntegration::createServerBufferFromImage
QtWayland::ServerBuffer * createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override
Definition
shmserverbufferintegration.cpp:113
ShmServerBufferIntegration::ShmServerBufferIntegration
ShmServerBufferIntegration()
Definition
shmserverbufferintegration.cpp:85
ShmServerBufferIntegration::~ShmServerBufferIntegration
~ShmServerBufferIntegration() override
Definition
shmserverbufferintegration.cpp:89
ShmServerBuffer
Definition
shmserverbufferintegration.h:26
ShmServerBuffer::~ShmServerBuffer
~ShmServerBuffer() override
Definition
shmserverbufferintegration.cpp:49
ShmServerBuffer::bufferInUse
bool bufferInUse() override
Definition
shmserverbufferintegration.cpp:72
ShmServerBuffer::toOpenGlTexture
QOpenGLTexture * toOpenGlTexture() override
Definition
shmserverbufferintegration.cpp:77
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtwayland
src
hardwareintegration
compositor
shm-emulation-server
shmserverbufferintegration.cpp
Generated on
for Qt by
1.18.0