10#include <QtWaylandCompositor/QWaylandView>
11#include <QtWaylandCompositor/QWaylandQuickItem>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
48
49
50
51
52
53
54
55
56
57
58
59
63
64
65QWaylandPresentationTime::QWaylandPresentationTime(QWaylandCompositor *compositor)
66 : QWaylandCompositorExtensionTemplate(compositor, *
new QWaylandPresentationTimePrivate)
72
73
74QWaylandPresentationTime::QWaylandPresentationTime()
75 : QWaylandCompositorExtensionTemplate(*
new QWaylandPresentationTimePrivate)
80
81
82void QWaylandPresentationTime::initialize()
84 Q_D(QWaylandPresentationTime);
86 if (isInitialized()) {
87 qWarning() <<
"QWaylandPresentationTime is already initialized";
91 QWaylandCompositor *compositor =
this->compositor();
92 if (compositor ==
nullptr) {
93 qWarning() <<
"Failed to find QWaylandCompositor when initializing QWaylandPresentationTime";
97 QWaylandCompositorExtensionTemplate::initialize();
99 d->init(compositor->display(), 1);
102QWaylandCompositor *QWaylandPresentationTime::compositor()
const
104 return qobject_cast<QWaylandCompositor *>(extensionContainer());
108
109
110
111
112
113
114
117
118
119
120
121
122void QWaylandPresentationTime::sendFeedback(QQuickWindow *window, quint64 sequence, quint64 tv_sec, quint32 tv_nsec)
127 quint32 refresh_nsec = window->screen()->refreshRate() != 0 ? 1000000000 / window->screen()->refreshRate() : 0;
129 emit presented(sequence, tv_sec, tv_nsec, refresh_nsec);
133
134
135const struct wl_interface *QWaylandPresentationTime::interface()
137 return QWaylandPresentationTimePrivate::interface();
141
142
143QByteArray QWaylandPresentationTime::interfaceName()
145 return QWaylandPresentationTimePrivate::interfaceName();
148PresentationFeedback::PresentationFeedback(QWaylandPresentationTime *pTime, QWaylandSurface *surface,
struct ::wl_client *client, uint32_t id,
int version)
149 : wp_presentation_feedback(client, id, version)
150 , m_presentationTime(pTime)
165 connect(qwls, &QWaylandSurface::destroyed,
this, &PresentationFeedback::discard);
167 QWaylandView *view = qwls ? qwls->primaryView() :
nullptr;
170 connect(qwls, &QWaylandSurface::hasContentChanged,
this, &
PresentationFeedback::onSurfaceMapped);
174 maybeConnectToWindow(view);
189 QWaylandView *view =
m_surface->primaryView();
191 qWarning() <<
"The mapped surface has no view";
196 maybeConnectToWindow(view);
201 QWaylandQuickItem *item = view ? qobject_cast<QWaylandQuickItem *>(view->renderObject()) :
nullptr;
203 qWarning() <<
"QWaylandPresentationTime only works with QtQuick compositors" << view;
210 if (!item->window()) {
214 connectToWindow(item->window());
219 QWaylandQuickItem *item = qobject_cast<QWaylandQuickItem *>(sender());
220 QQuickWindow *window = item ? item->window() :
nullptr;
223 qWarning() <<
"QWaylandPresentationTime only works with QtQuick compositors" << item;
226
227
235 connectToWindow(window);
253 QQuickWindow *window = qobject_cast<QQuickWindow *>(sender());
264 QQuickWindow *window = qobject_cast<QQuickWindow *>(sender());
268 connect(m_presentationTime, &QWaylandPresentationTime::presented,
this, &PresentationFeedback::sendPresented);
280 QWaylandCompositor *compositor = presentationTime()->compositor();
282 qWarning() <<
"No compositor container to send sync_output";
286 QWaylandView *view =
surface()->primaryView();
287 QWaylandOutput *output = view ? view->output() :
nullptr;
288 struct ::wl_resource *r = output ? output->resourceForClient(QWaylandClient::fromWlClient(compositor, resource()->client())) :
nullptr;
294void PresentationFeedback::sendPresented(quint64 sequence, quint64 tv_sec, quint32 tv_nsec, quint32 refresh_nsec)
298 send_presented(tv_sec >> 32, tv_sec, tv_nsec, refresh_nsec, sequence >> 32, sequence,
299 QtWaylandServer::wp_presentation_feedback::kind_vsync
300 | QtWaylandServer::wp_presentation_feedback::kind_hw_clock
301 | QtWaylandServer::wp_presentation_feedback::kind_hw_completion);
308 wl_resource_destroy(resource()->handle);
323 send_clock_id(resource->handle, CLOCK_MONOTONIC);
328 Q_Q(QWaylandPresentationTime);
330 QWaylandSurface *qwls = QWaylandSurface::fromResource(surface);
334 new PresentationFeedback(q, qwls, resource->client(), callback, 1);
339#include "moc_qwaylandpresentationtime_p_p.cpp"
341#include "moc_qwaylandpresentationtime_p.cpp"
void setSurface(QWaylandSurface *)
void wp_presentation_feedback_destroy_resource(Resource *resource) override
QWaylandSurface * surface()
QWaylandSurface * m_surface
QQuickWindow * m_connectedWindow
void wp_presentation_bind_resource(Resource *resource) override