4#include <QtOpenGL/QOpenGLFramebufferObject>
5#include <QtGui/QOpenGLContext>
6#include <QtGui/QWindow>
8#include <qpa/qplatformbackingstore.h>
43QOpenGLCompositor::QOpenGLCompositor()
49 m_updateTimer.setSingleShot(
true);
50 m_updateTimer.setInterval(0);
54QOpenGLCompositor::~QOpenGLCompositor()
76 m_rotationMatrix.
rotate(degrees, 0, 0, 1);
82 m_updateTimer.
start();
87 Q_ASSERT(m_context && m_targetWindow);
96 if (fbo->
size() != m_nativeTargetGeometry.
size()
107void QOpenGLCompositor::handleRenderAllRequest()
109 Q_ASSERT(m_context && m_targetWindow);
119 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
120 glViewport(0, 0, m_nativeTargetGeometry.
width(), m_nativeTargetGeometry.
height());
127 for (
int i = 0;
i < m_windows.
size(); ++
i)
130 for (
int i = 0;
i < m_windows.
size(); ++
i)
131 render(m_windows.
at(
i), origin);
139 for (
int i = 0;
i < m_windows.
size(); ++
i)
152 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
168 return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1,
169 topLeftRect.width(), topLeftRect.height());
173 const QRect &sourceWindowRect,
const QRect &targetWindowRect,
182 const QRect clippedRectInWindow = rectInWindow & clipRect.
translated(rectInWindow.topLeft());
192 const uint textureId =
textures->texture(idx)->nativeTexture().object;
202 const QRect targetWindowRect(
QPoint(0, 0), m_targetWindow->geometry().
size());
203 float currentOpacity = 1.0f;
205 const QRect sourceWindowRect =
window->sourceWindow()->geometry();
211 const float opacity =
window->sourceWindow()->opacity();
212 if (opacity != currentOpacity) {
213 currentOpacity = opacity;
224 }
else if (
textures->count() == 1) {
226 const bool translucent =
window->sourceWindow()->requestedFormat().alphaBufferSize() > 0;
227 blend.
set(translucent);
236 m_rotation ? &m_rotationMatrix :
nullptr, clippedBlitSourceOrigin);
244 m_rotation ? &m_rotationMatrix :
nullptr, clippedBlitSourceOrigin);
268 ensureCorrectZOrder();
290 ensureCorrectZOrder();
299 if (idx != -1 && idx != newIdx) {
300 m_windows.
move(idx, newIdx);
301 ensureCorrectZOrder();
307void QOpenGLCompositor::ensureCorrectZOrder()
309 const auto originalOrder = m_windows;
311 std::sort(m_windows.
begin(), m_windows.
end(),
313 QWindow *w1 = cw1->sourceWindow();
314 QWindow *w2 = cw2->sourceWindow();
318 if (w1 == m_targetWindow || w2 == m_targetWindow)
319 return w1 == m_targetWindow;
322 if (w2->isAncestorOf(w1)) {
327 if (
w1->isAncestorOf(
w2)) {
346 if (isPurePopup1 != isPurePopup2)
347 return !isPurePopup1;
350 if (isTool1 != isTool2)
354 return originalOrder.indexOf(cw1) < originalOrder.indexOf(cw2);
360#include "moc_qopenglcompositor_p.cpp"
qsizetype size() const noexcept
bool isEmpty() const noexcept
const T & constLast() const noexcept
bool removeOne(const AT &t)
const_reference at(qsizetype i) const noexcept
void move(qsizetype from, qsizetype to)
void append(parameter_type t)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void rotate(float angle, const QVector3D &vector)
Multiples this matrix by another that rotates coordinates through angle degrees about vector.
void setToIdentity()
Sets this matrix to the identity.
virtual void endCompositing()
virtual void beginCompositing()
A generic OpenGL-based compositor.
QRect nativeTargetGeometry() const
void setTargetContext(QOpenGLContext *context)
void removeWindow(QOpenGLCompositorWindow *window)
static QOpenGLCompositor * instance()
void setTargetWindow(QWindow *window, const QRect &nativeTargetGeometry)
void moveToTop(QOpenGLCompositorWindow *window)
void setRotation(int degrees)
QOpenGLContext * context() const
QWindow * targetWindow() const
void topWindowChanged(QOpenGLCompositorWindow *window)
void addWindow(QOpenGLCompositorWindow *window)
bool grabToFrameBufferObject(QOpenGLFramebufferObject *fbo, GrabOrientation orientation=Flipped)
void changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx)
bool makeCurrent(QSurface *surface)
Makes the context current in the current thread, against the given surface.
void swapBuffers(QSurface *surface)
Swap the back and front buffers of surface.
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
QOpenGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
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.
void destroy()
Frees all graphics resources held by the blitter.
Origin
\value OriginBottomLeft Indicates that the data in the texture follows the OpenGL convention of coord...
void setOpacity(float opacity)
Changes the opacity to opacity.
void blit(GLuint texture, const QMatrix4x4 &targetTransform, Origin sourceOrigin)
Performs the blit with the source texture texture.
static QMatrix3x3 sourceTransform(const QRectF &subTexture, const QSize &textureSize, Origin origin)
Calculates a 3x3 matrix suitable as the input to blit().
void release()
Unbinds the graphics resources used by the blitter.
static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport)
Calculates a target transform suitable for blit().
void bind(GLenum target=GL_TEXTURE_2D)
Binds the graphics resources used by the blitter.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Combined button and popup list for selecting options.
static QOpenGLCompositor * compositor
static QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)
static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &sourceWindowRect, const QRect &targetWindowRect, QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix, QOpenGLTextureBlitter::Origin sourceOrigin)
GLuint const GLuint GLuint const GLuint * textures
GLbitfield GLuint64 timeout
[4]
GLsizei GLsizei GLchar * source
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
if(qFloatDistance(a, b)<(1<< 7))
[0]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept