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 LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtWaylandClient/private/qwaylanddisplay_p.h>
6#include <QDebug>
7#include <QtOpenGL/QOpenGLTexture>
8#include <QtGui/QOpenGLContext>
9#include <QtGui/QImage>
10#include <QtCore/QSharedMemory>
11
13
14static QOpenGLTexture *createTextureFromShm(const QString &key, int w, int h, int bpl, int format)
15{
16 QT_IGNORE_DEPRECATIONS(QSharedMemory shm(key);)
17 bool ok;
18 ok = shm.attach(QSharedMemory::ReadOnly);
19 if (!ok) {
20 qWarning() << "Could not attach to" << key;
21 return nullptr;
22 }
23 ok = shm.lock();
24 if (!ok) {
25 qWarning() << "Could not lock" << key << "for reading";
26 return nullptr;
27 }
28
29 QImage::Format imageFormat;
30 switch (format) {
31 case QtWayland::qt_shm_emulation_server_buffer::format_RGBA32:
32 imageFormat = QImage::Format_RGBA8888;
33 break;
34 case QtWayland::qt_shm_emulation_server_buffer::format_A8:
35 imageFormat = QImage::Format_Alpha8;
36 break;
37 default:
38 qWarning() << "ShmServerBuffer: unknown format" << format;
39 imageFormat = QImage::Format_RGBA8888;
40 break;
41 }
42
43 QImage image(static_cast<const uchar*>(shm.constData()), w, h, bpl, imageFormat);
44
46 qWarning("ShmServerBuffer: creating texture with no current context");
47
49 shm.unlock();
50 return tex;
51}
52
53
54namespace QtWaylandClient {
55
57 : m_key(key)
58 , m_bpl(bytesPerLine)
59{
61 m_size = size;
62}
63
67
69{
70 if (!m_texture)
71 m_texture = createTextureFromShm(m_key, m_size.width(), m_size.height(), m_bpl, m_format);
72
73 return m_texture;
74}
75
77{
78 m_display = display;
79 display->addRegistryListener(&wlDisplayHandleGlobal, this);
80}
81
83{
84 return static_cast<QWaylandServerBuffer *>(qt_server_buffer_get_user_data(buffer));
85}
86
87void ShmServerBufferIntegration::wlDisplayHandleGlobal(void *data, ::wl_registry *registry, uint32_t id, const QString &interface, uint32_t version)
88{
89 Q_UNUSED(version);
90 if (interface == "qt_shm_emulation_server_buffer") {
91 auto *integration = static_cast<ShmServerBufferIntegration *>(data);
92 integration->QtWayland::qt_shm_emulation_server_buffer::init(registry, id, 1);
93 }
94}
95
96
97void QtWaylandClient::ShmServerBufferIntegration::shm_emulation_server_buffer_server_buffer_created(qt_server_buffer *id, const QString &key, int32_t width, int32_t height, int32_t bytes_per_line, int32_t format)
98{
101 auto *server_buffer = new ShmServerBuffer(key, size, bytes_per_line, fmt);
102 qt_server_buffer_set_user_data(id, server_buffer);
103}
104
105}
106
\inmodule QtGui
Definition qimage.h:37
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_Alpha8
Definition qimage.h:65
@ Format_RGBA8888
Definition qimage.h:59
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
\inmodule QtGui
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void shm_emulation_server_buffer_server_buffer_created(qt_server_buffer *id, const QString &key, int32_t width, int32_t height, int32_t bytes_per_line, int32_t format) override
QWaylandServerBuffer * serverBuffer(struct qt_server_buffer *buffer) override
void initialize(QWaylandDisplay *display) override
ShmServerBuffer(const QString &key, const QSize &size, int bytesPerLine, QWaylandServerBuffer::Format format)
static QT_BEGIN_NAMESPACE QOpenGLTexture * createTextureFromShm(const QString &key, int w, int h, int bpl, int format)
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
Definition image.cpp:4
#define QT_IGNORE_DEPRECATIONS(statement)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char * interface
#define qWarning
Definition qlogging.h:166
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
GLint GLsizei width
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
#define Q_UNUSED(x)
unsigned char uchar
Definition qtypes.h:32
QVideoFrameFormat::PixelFormat fmt