Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtOpenGL/QOpenGLTexture>
7#include <QtGui/QOpenGLContext>
8#include <QtCore/QSharedMemory>
9
10#include <QtCore/QDebug>
11
13
15 : QtWayland::ServerBuffer(qimage.size(),format)
16 , m_integration(integration)
17 , m_width(qimage.width())
18 , m_height(qimage.height())
19 , m_bpl(qimage.bytesPerLine())
20{
22 switch (m_format) {
23 case RGBA32:
24 m_shm_format = QtWaylandServer::qt_shm_emulation_server_buffer::format_RGBA32;
25 break;
26 case A8:
27 m_shm_format = QtWaylandServer::qt_shm_emulation_server_buffer::format_A8;
28 break;
29 default:
30 qWarning("ShmServerBuffer: unsupported format");
31 m_shm_format = QtWaylandServer::qt_shm_emulation_server_buffer::format_RGBA32;
32 break;
33 }
34
35 QString key = "qt_shm_emulation_" + QString::number(qimage.cacheKey());
36 // ### Use proper native keys the next time we can break protocol compatibility
37 QT_IGNORE_DEPRECATIONS(m_shm = new QSharedMemory(key);)
38 qsizetype shm_size = qimage.sizeInBytes();
39 bool ok = m_shm->create(shm_size) && m_shm->lock();
40 if (ok) {
41 memcpy(m_shm->data(), qimage.constBits(), shm_size);
42 m_shm->unlock();
43 } else {
44 qWarning() << "Could not create shared memory" << key << shm_size;
45 }
46}
47
49{
50 delete m_shm;
51}
52
53struct ::wl_resource *ShmServerBuffer::resourceForClient(struct ::wl_client *client)
54{
55 auto *bufferResource = resourceMap().value(client);
56 if (!bufferResource) {
57 auto integrationResource = m_integration->resourceMap().value(client);
58 if (!integrationResource) {
59 qWarning("ShmServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the shm_emulation interface");
60 return nullptr;
61 }
62 struct ::wl_resource *shm_integration_resource = integrationResource->handle;
63 Resource *resource = add(client, 1);
64 QT_IGNORE_DEPRECATIONS(const QString shmKey = m_shm->key();)
65 m_integration->send_server_buffer_created(shm_integration_resource, resource->handle, shmKey, m_width, m_height, m_bpl, m_shm_format);
66 return resource->handle;
67 }
68 return bufferResource->handle;
69}
70
72{
73 return resourceMap().size() > 0;
74}
75
77{
78 if (!m_texture) {
79 qWarning("ShmServerBuffer::toOpenGlTexture: no texture defined");
80 }
81 return m_texture;
82}
83
87
91
93{
95
96 QtWaylandServer::qt_shm_emulation_server_buffer::init(compositor->display(), 1);
97 return true;
98}
99
101{
102 switch (format) {
104 return true;
106 return true;
107 default:
108 return false;
109 }
110}
111
116
static QPlatformNativeInterface * platformNativeInterface()
\inmodule QtGui
Definition qimage.h:37
\inmodule QtGui
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
bool initializeHardware(QWaylandCompositor *) override
bool supportsFormat(QtWayland::ServerBuffer::Format format) const override
QtWayland::ServerBuffer * createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override
struct::wl_resource * resourceForClient(struct ::wl_client *) override
QOpenGLTexture * toOpenGlTexture() override
ShmServerBuffer(ShmServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format)
Combined button and popup list for selecting options.
#define QT_IGNORE_DEPRECATIONS(statement)
#define qWarning
Definition qlogging.h:166
static QOpenGLCompositor * compositor
GLuint64 key
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLint GLsizei GLsizei GLenum format
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qsizetype
Definition qtypes.h:165