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
qwaylandviewporter.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include <QtWaylandCompositor/QWaylandSurface>
7#include <QtWaylandCompositor/QWaylandCompositor>
8
9#include <QtWaylandCompositor/private/qwaylandsurface_p.h>
10
12
32
40
45{
47
49 auto *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
50 if (!compositor) {
51 qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandViewporter";
52 return;
53 }
54 d->init(compositor->display(), 1);
55}
56
60const wl_interface *QWaylandViewporter::interface()
61{
62 return QWaylandViewporterPrivate::interface();
63}
64
66{
67 // Viewport objects are allowed ot outlive the viewporter
68 wl_resource_destroy(resource->handle);
69}
70
71void QWaylandViewporterPrivate::wp_viewporter_get_viewport(Resource *resource, uint id, wl_resource *surfaceResource)
72{
73 auto *surface = QWaylandSurface::fromResource(surfaceResource);
74 if (!surface) {
75 qWarning() << "Couldn't find surface for viewporter";
76 return;
77 }
78
79 auto *surfacePrivate = QWaylandSurfacePrivate::get(surface);
80 if (surfacePrivate->viewport) {
81 wl_resource_post_error(resource->handle, WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS,
82 "viewport already exists for surface");
83 return;
84 }
85
86 surfacePrivate->viewport = new Viewport(surface, resource->client(), id);
87}
88
90 : QtWaylandServer::wp_viewport(client, id, /*version*/ 1)
91 , m_surface(surface)
92{
93 Q_ASSERT(surface);
94}
95
97{
98 if (m_surface) {
99 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface);
100 Q_ASSERT(surfacePrivate->viewport == this);
101 surfacePrivate->viewport = nullptr;
102 }
103}
104
105// This function has to be called immediately after a surface is committed, before no
106// other client events have been dispatched, or we may incorrectly error out on an
107// incomplete pending state. See comment below.
109{
110 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface);
111
112 // We can't use the current state for destination/source when checking,
113 // as that has fallbacks to the buffer size so we can't distinguish
114 // between the set/unset case. We use the pending state because no other
115 // requests has modified it yet.
116 QSize destination = surfacePrivate->pending.destinationSize;
117 QRectF source = surfacePrivate->pending.sourceGeometry;
118
119 if (!destination.isValid() && source.size() != source.size().toSize()) {
120 wl_resource_post_error(resource()->handle, error_bad_size,
121 "non-integer size (%fx%f) with unset destination",
122 source.width(), source.height());
123 return;
124 }
125
126 if (m_surface->bufferSize().isValid()) {
127 QRectF max = QRectF(QPointF(), m_surface->bufferSize() / m_surface->bufferScale());
128 // We can't use QRectF.contains, because that would return false for values on the border
129 if (max.united(source) != max) {
130 wl_resource_post_error(resource()->handle, error_out_of_buffer,
131 "source %f,%f, %fx%f extends outside attached buffer %fx%f",
132 source.x(), source.y(), source.width(), source.height(),
133 max.width(), max.height());
134 return;
135 }
136 }
137}
138
139
141{
142 Q_UNUSED(resource);
143 delete this;
144}
145
147{
148 if (m_surface) {
149 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface);
150 surfacePrivate->pending.destinationSize = QSize();
151 surfacePrivate->pending.sourceGeometry = QRectF();
152 }
153 wl_resource_destroy(resource->handle);
154}
155
156void QWaylandViewporterPrivate::Viewport::wp_viewport_set_source(QtWaylandServer::wp_viewport::Resource *resource, wl_fixed_t x, wl_fixed_t y, wl_fixed_t width, wl_fixed_t height)
157{
158 Q_UNUSED(resource);
159
160 if (!m_surface) {
161 wl_resource_post_error(resource->handle, error_no_surface,
162 "set_source requested for destroyed surface");
163 return;
164 }
165
166 QPointF position(wl_fixed_to_double(x), wl_fixed_to_double(y));
167 QSizeF size(wl_fixed_to_double(width), wl_fixed_to_double(height));
168 QRectF sourceGeometry(position, size);
169
170 if (sourceGeometry == QRectF(-1, -1, -1, -1)) {
171 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface);
172 surfacePrivate->pending.sourceGeometry = QRectF();
173 return;
174 }
175
176 if (position.x() < 0 || position.y() < 0) {
177 wl_resource_post_error(resource->handle, error_bad_value,
178 "negative position in set_source");
179 return;
180 }
181
182 if (!size.isValid()) {
183 wl_resource_post_error(resource->handle, error_bad_value,
184 "negative size in set_source");
185 return;
186 }
187
188 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface);
189 surfacePrivate->pending.sourceGeometry = sourceGeometry;
190}
191
192void QWaylandViewporterPrivate::Viewport::wp_viewport_set_destination(QtWaylandServer::wp_viewport::Resource *resource, int32_t width, int32_t height)
193{
194 Q_UNUSED(resource);
195
196 if (!m_surface) {
197 wl_resource_post_error(resource->handle, error_no_surface,
198 "set_destination requested for destroyed surface");
199 return;
200 }
201
202 QSize destinationSize(width, height);
203 if (!destinationSize.isValid() && destinationSize != QSize(-1, -1)) {
204 wl_resource_post_error(resource->handle, error_bad_value,
205 "negative size in set_destination");
206 return;
207 }
208 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface);
209 surfacePrivate->pending.destinationSize = destinationSize;
210}
211
213
214#include "moc_qwaylandviewporter.cpp"
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
QRectF united(const QRectF &other) const noexcept
Definition qrect.h:852
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:127
virtual void initialize()
Initializes the QWaylandCompositorExtension.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
static QWaylandSurfacePrivate * get(QWaylandSurface *surface)
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
static QWaylandSurface * fromResource(::wl_resource *resource)
Returns the QWaylandSurface corresponding to the Wayland resource resource.
void wp_viewport_set_source(Resource *resource, wl_fixed_t x, wl_fixed_t y, wl_fixed_t width, wl_fixed_t height) override
void wp_viewport_set_destination(Resource *resource, int32_t width, int32_t height) override
Viewport(QWaylandSurface *surface, wl_client *client, int id)
void wp_viewport_destroy_resource(Resource *resource) override
void wp_viewport_destroy(Resource *resource) override
void wp_viewporter_get_viewport(Resource *resource, uint32_t id, wl_resource *surface) override
void wp_viewporter_destroy(Resource *resource) override
\inmodule QtWaylandCompositor
QWaylandViewporter()
Constructs a QWaylandViewporter object.
static const struct wl_interface * interface()
Returns the Wayland interface for the QWaylandViewporter.
void initialize() override
Initializes the extension.
Combined button and popup list for selecting options.
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 const char return DBusMessage return DBusMessage const char * destination
#define qWarning
Definition qlogging.h:166
static QOpenGLCompositor * compositor
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint id
[7]
GLint GLsizei width
GLint y
GLsizei GLsizei GLchar * source
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34