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
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
5#include <QtQml/QQmlEngine>
6#include <QQuickWindow>
7#if QT_CONFIG(opengl)
8# include <QOpenGLTextureBlitter>
9# include <QOpenGLTexture>
10# include <QOpenGLFramebufferObject>
11#endif
12#include <QMatrix4x4>
13#include <QRunnable>
14
15#include "qwaylandclient.h"
18#include "qwaylandquickoutput.h"
19#include "qwaylandquickitem.h"
20#include "qwaylandoutput.h"
21#include <QtWaylandCompositor/private/qwaylandcompositor_p.h>
22#include <QtWaylandCompositor/QWaylandViewporter>
24
26
28{
29public:
35protected:
37 {
38 return new QWaylandQuickSurface();
39 }
40private:
41 QScopedPointer<QWaylandViewporter> m_viewporter;
42};
43
48
71{
72 QWaylandCompositor::create();
73}
74
75
80
85
91{
92 if (buffer.isSharedMemory()) {
93 QWaylandCompositor::grabSurface(grabber, buffer);
94 return;
95 }
96
97#if QT_CONFIG(opengl)
98 QWaylandQuickOutput *output = static_cast<QWaylandQuickOutput *>(defaultOutput());
99 if (!output) {
101 return;
102 }
103
104 // We cannot grab the surface now, we need to have a current opengl context, so we
105 // need to be in the render thread
106 class GrabState : public QRunnable
107 {
108 public:
109 QWaylandSurfaceGrabber *grabber = nullptr;
111
112 void run() override
113 {
115 fbo.bind();
116 QOpenGLTextureBlitter blitter;
117 blitter.create();
118
119 glViewport(0, 0, buffer.size().width(), buffer.size().height());
120
121 QOpenGLTextureBlitter::Origin surfaceOrigin =
125
126 auto texture = buffer.toOpenGLTexture();
127 blitter.bind(texture->target());
128 blitter.blit(texture->textureId(), QMatrix4x4(), surfaceOrigin);
129 blitter.release();
130
131 emit grabber->success(fbo.toImage());
132 }
133 };
134
135 GrabState *state = new GrabState;
136 state->grabber = grabber;
137 state->buffer = buffer;
138 static_cast<QQuickWindow *>(output->window())->scheduleRenderJob(state, QQuickWindow::AfterRenderingStage);
139#else
141#endif
142}
143
145
146#include "moc_qwaylandquickcompositor.cpp"
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore
Definition qobject.h:103
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
QImage toImage(bool flipped=true) const
Returns the contents of this framebuffer object as a QImage.
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
The QOpenGLTextureBlitter class provides a convenient way to draw textured quads via OpenGL.
bool create()
Initializes the graphics resources used by the blitter.
Origin
\value OriginBottomLeft Indicates that the data in the texture follows the OpenGL convention of coord...
void blit(GLuint texture, const QMatrix4x4 &targetTransform, Origin sourceOrigin)
Performs the blit with the source texture texture.
void release()
Unbinds the graphics resources used by the blitter.
void bind(GLenum target=GL_TEXTURE_2D)
Binds the graphics resources used by the blitter.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore
Definition qrunnable.h:18
\inmodule QtWaylandCompositor
static QWaylandCompositorPrivate * get(QWaylandCompositor *compositor)
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
QWaylandSurface * createDefaultSurface() override
QWaylandQuickCompositorPrivate(QWaylandCompositor *compositor)
void grabSurface(QWaylandSurfaceGrabber *grabber, const QWaylandBufferRef &buffer) override
Grab the surface content from the given buffer.
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QWaylandQuickCompositor(QObject *parent=nullptr)
void classBegin() override
Invoked after class creation, but before any properties have been set.
void create() override
\qmlproperty list QtWayland.Compositor::WaylandCompositor::extensions
\inmodule QtWaylandCompositor
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
\inmodule QtWaylandCompositor
#define this
Definition dialogs.cpp:9
else opt state
[0]
Combined button and popup list for selecting options.
static QOpenGLCompositor * compositor
GLenum GLuint buffer
GLenum GLuint texture
#define emit
QT_BEGIN_NAMESPACE typedef uchar * output