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
qwaylandview.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qwaylandview.h"
5#include "qwaylandview_p.h"
6#include "qwaylandsurface.h"
7#include <QtWaylandCompositor/QWaylandSeat>
8#include <QtWaylandCompositor/QWaylandCompositor>
9
10#include <QtWaylandCompositor/private/qwaylandsurface_p.h>
11#include <QtWaylandCompositor/private/qwaylandoutput_p.h>
12
13#include <QtCore/QMutex>
14#include <QtCore/qpointer.h>
15
17
19{
20 Q_Q(QWaylandView);
21 Q_ASSERT(surface == this->surface);
22
23 setSurface(nullptr);
24 QPointer<QWaylandView> deleteGuard(q);
25 emit q->surfaceDestroyed();
26 if (!deleteGuard.isNull())
28}
29
57 : QObject(*new QWaylandViewPrivate(),parent)
58{
59 d_func()->renderObject = renderObject;
60}
61
66{
67 Q_D(QWaylandView);
68 if (d->surface) {
69 if (d->output)
70 QWaylandOutputPrivate::get(d->output)->removeView(this, d->surface);
71
72 QWaylandSurfacePrivate::get(d->surface)->derefView(this);
73 }
74
75}
76
82{
83 Q_D(const QWaylandView);
84 return d->renderObject;
85}
86
99{
100 Q_D(const QWaylandView);
101 return d->surface;
102}
103
104
106{
107 Q_Q(QWaylandView);
108 if (surface) {
110 if (output)
112 }
113
114 surface = newSurface;
115
117 nextBufferCommitted = false;
119
120 if (surface) {
122 if (output)
124 }
125}
126
134
136{
137 Q_D(QWaylandView);
138 if (d->surface == newSurface)
139 return;
140
141 d->setSurface(newSurface);
142 d->clearFrontBuffer();
144}
145
158{
159 Q_D(const QWaylandView);
160 return d->output;
161}
162
164{
165 Q_D(QWaylandView);
166 if (d->output == newOutput)
167 return;
168
169 if (d->output && d->surface)
170 QWaylandOutputPrivate::get(d->output)->removeView(this, d->surface);
171
172 d->output = newOutput;
173
174 if (d->output && d->surface)
175 QWaylandOutputPrivate::get(d->output)->addView(this, d->surface);
176
178}
179
189{
190 Q_D(QWaylandView);
191 QMutexLocker locker(&d->bufferMutex);
192 d->nextBuffer = buffer;
193 d->nextDamage = damage;
194 d->nextBufferCommitted = true;
195}
196
205{
206 Q_D(QWaylandView);
207
208 if (!d->nextBufferCommitted && !d->forceAdvanceSucceed)
209 return false;
210
211 if (d->bufferLocked)
212 return false;
213
214 if (d->surface && d->surface->primaryView() == this) {
215 const auto views = d->surface->views();
216 for (QWaylandView *view : views) {
217 if (view != this && view->allowDiscardFrontBuffer() && view->d_func()->currentBuffer == d->currentBuffer)
218 view->discardCurrentBuffer();
219 }
220 }
221
222 QMutexLocker locker(&d->bufferMutex);
223 d->forceAdvanceSucceed = false;
224 d->nextBufferCommitted = false;
225 d->currentBuffer = d->nextBuffer;
226 d->currentDamage = d->nextDamage;
227 return true;
228}
229
234{
235 Q_D(QWaylandView);
236 QMutexLocker locker(&d->bufferMutex);
237 d->currentBuffer = QWaylandBufferRef();
238 d->forceAdvanceSucceed = true;
239}
240
245{
246 Q_D(QWaylandView);
247 QMutexLocker locker(&d->bufferMutex);
248 return d->currentBuffer;
249}
250
255{
256 Q_D(QWaylandView);
257 QMutexLocker locker(&d->bufferMutex);
258 return d->currentDamage;
259}
260
281{
282 Q_D(const QWaylandView);
283 return d->bufferLocked;
284}
285
287{
288 Q_D(QWaylandView);
289 if (d->bufferLocked == locked)
290 return;
291 d->bufferLocked = locked;
293}
314{
315 Q_D(const QWaylandView);
316 return d->allowDiscardFrontBuffer;
317}
318
320{
321 Q_D(QWaylandView);
322 if (d->allowDiscardFrontBuffer == discard)
323 return;
324 d->allowDiscardFrontBuffer = discard;
326}
327
336{
337 Q_D(QWaylandView);
338 if (d->surface)
339 d->surface->setPrimaryView(this);
340 else
341 qWarning("Calling setPrimary() on a QWaylandView without a surface has no effect.");
342}
343
350{
351 Q_D(const QWaylandView);
352 return d->surface && d->surface->primaryView() == this;
353}
354
358struct wl_resource *QWaylandView::surfaceResource() const
359{
360 Q_D(const QWaylandView);
361 if (!d->surface)
362 return nullptr;
363 return d->surface->resource();
364}
365
367
368#include "moc_qwaylandview.cpp"
\inmodule QtCore
Definition qmutex.h:313
\inmodule QtCore
Definition qobject.h:103
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtWaylandCompositor
static QWaylandOutputPrivate * get(QWaylandOutput *output)
\qmltype WaylandOutput \instantiates QWaylandOutput \inqmlmodule QtWayland.Compositor
static QWaylandSurfacePrivate * get(QWaylandSurface *surface)
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
void setSurface(QWaylandSurface *newSurface)
QWaylandOutput * output
QWaylandSurface * surface
QWaylandBufferRef nextBuffer
QWaylandBufferRef currentBuffer
void markSurfaceAsDestroyed(QWaylandSurface *surface)
\qmltype WaylandView \instantiates QWaylandView \inqmlmodule QtWayland.Compositor
virtual bool advance()
Updates the current buffer and damage region to the latest version committed by the client.
virtual void discardCurrentBuffer()
Force the view to discard its current buffer, to allow it to be reused on the client side.
virtual QRegion currentDamage()
Returns the current damage region of this view.
bool isBufferLocked() const
struct wl_resource * surfaceResource() const
Returns the Wayland surface resource for this QWaylandView.
void allowDiscardFrontBufferChanged()
bool isPrimary() const
Returns true if this QWaylandView is the primary view for the QWaylandSurface.
QObject * renderObject
QWaylandOutput * output
\qmlproperty WaylandOutput QtWayland.Compositor::WaylandView::output
void setSurface(QWaylandSurface *surface)
QWaylandView(QObject *renderObject=nullptr, QObject *parent=nullptr)
Constructs a QWaylandView with the given renderObject and parent.
bool allowDiscardFrontBuffer
\qmlproperty bool QtWayland.Compositor::WaylandView::allowDiscardFrontBuffer
virtual QWaylandBufferRef currentBuffer()
Returns a reference to this view's current buffer.
void setOutput(QWaylandOutput *output)
QWaylandSurface * surface
\qmlproperty WaylandSurface QtWayland.Compositor::WaylandView::surface
void bufferLockedChanged()
~QWaylandView() override
Destroys the QWaylandView.
virtual void bufferCommitted(const QWaylandBufferRef &buffer, const QRegion &damage)
This function is called when a new buffer is committed to this view's surface.
void outputChanged()
void setPrimary()
Makes this QWaylandView the primary view for the surface.
void setAllowDiscardFrontBuffer(bool discard)
void setBufferLocked(bool locked)
void surfaceChanged()
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
GLenum GLuint buffer
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QQuickView * view
[0]