Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandquickcompositor.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#include <QtQml/QQmlEngine>
7#include <QQuickWindow>
8#if QT_CONFIG(opengl)
9# include <QOpenGLTextureBlitter>
10# include <QOpenGLTexture>
11# include <QOpenGLFramebufferObject>
12#endif
13#include <QMatrix4x4>
14#include <QRunnable>
15
16#include "qwaylandclient.h"
21#include "qwaylandoutput.h"
22#include <QtWaylandCompositor/private/qwaylandcompositor_p.h>
23#include <QtWaylandCompositor/QWaylandViewporter>
25
27
29{
30public:
31 explicit QWaylandQuickCompositorPrivate(QWaylandCompositor *compositor)
34 {
35 }
36protected:
37 QWaylandSurface *createDefaultSurface() override
38 {
39 return new QWaylandQuickSurface();
40 }
41private:
42 QScopedPointer<QWaylandViewporter> m_viewporter;
43};
44
45QWaylandQuickCompositor::QWaylandQuickCompositor(QObject *parent)
46 : QWaylandCompositor(*new QWaylandQuickCompositorPrivate(this), parent)
47{
48}
49
50/*!
51 * \qmlproperty list QtWayland.Compositor::WaylandCompositor::extensions
52 *
53 * A list of extensions that the compositor advertises to its clients. For
54 * any Wayland extension the compositor should support, instantiate its component,
55 * and add it to the list of extensions. However, it is generally not necessary to
56 * reference this property, as all direct child items are automatically assigned to
57 * it.
58 *
59 * For instance, the following code would allow the clients to request \c xdg_shell
60 * surfaces in the compositor using the \c xdg_shell interface.
61 *
62 * \qml
63 * import QtWayland.Compositor
64 * import QtWayland.Compositor.XdgShell
65 *
66 * WaylandCompositor {
67 * XdgShell {
68 * // ...
69 * }
70 * }
71 * \endqml
72 */
73
74void QWaylandQuickCompositor::create()
75{
76 QWaylandCompositor::create();
77}
78
79
80void QWaylandQuickCompositor::classBegin()
81{
82 QWaylandCompositorPrivate::get(this)->preInit();
83}
84
85void QWaylandQuickCompositor::componentComplete()
86{
87 create();
88}
89
90/*!
91 * \internal
92 * Grab the surface content from the given \a buffer.
93 * Reimplemented from QWaylandCompositor::grabSurface.
94 */
95void QWaylandQuickCompositor::grabSurface(QWaylandSurfaceGrabber *grabber, const QWaylandBufferRef &buffer)
96{
97 if (buffer.isSharedMemory()) {
98 QWaylandCompositor::grabSurface(grabber, buffer);
99 return;
100 }
101
102#if QT_CONFIG(opengl)
103 QWaylandQuickOutput *output = static_cast<QWaylandQuickOutput *>(defaultOutput());
104 if (!output) {
105 emit grabber->failed(QWaylandSurfaceGrabber::RendererNotReady);
106 return;
107 }
108
109 // We cannot grab the surface now, we need to have a current opengl context, so we
110 // need to be in the render thread
111 class GrabState : public QRunnable
112 {
113 public:
114 QWaylandSurfaceGrabber *grabber = nullptr;
115 QWaylandBufferRef buffer;
116
117 void run() override
118 {
119 QOpenGLFramebufferObject fbo(buffer.size());
120 fbo.bind();
121 QOpenGLTextureBlitter blitter;
122 blitter.create();
123
124 glViewport(0, 0, buffer.size().width(), buffer.size().height());
125
126 QOpenGLTextureBlitter::Origin surfaceOrigin =
127 buffer.origin() == QWaylandSurface::OriginTopLeft
128 ? QOpenGLTextureBlitter::OriginTopLeft
129 : QOpenGLTextureBlitter::OriginBottomLeft;
130
131 auto texture = buffer.toOpenGLTexture();
132 blitter.bind(texture->target());
133 blitter.blit(texture->textureId(), QMatrix4x4(), surfaceOrigin);
134 blitter.release();
135
136 emit grabber->success(fbo.toImage());
137 }
138 };
139
140 GrabState *state = new GrabState;
141 state->grabber = grabber;
142 state->buffer = buffer;
143 static_cast<QQuickWindow *>(output->window())->scheduleRenderJob(state, QQuickWindow::AfterRenderingStage);
144#else
145 emit grabber->failed(QWaylandSurfaceGrabber::UnknownBufferType);
146#endif
147}
148
149QT_END_NAMESPACE
150
151#include "moc_qwaylandquickcompositor.cpp"
QWaylandSurface * createDefaultSurface() override
QWaylandQuickCompositorPrivate(QWaylandCompositor *compositor)
Combined button and popup list for selecting options.