diff options
Diffstat (limited to 'src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp')
-rw-r--r-- | src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp | 118 |
1 files changed, 53 insertions, 65 deletions
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp index c0c86a6dd..02789b305 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp @@ -1,50 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwaylandglcontext.h" +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qwaylandglcontext_p.h" #include <QtWaylandClient/private/qwaylanddisplay_p.h> #include <QtWaylandClient/private/qwaylandwindow_p.h> #include <QtWaylandClient/private/qwaylandsubsurface_p.h> #include <QtWaylandClient/private/qwaylandabstractdecoration_p.h> #include <QtWaylandClient/private/qwaylandintegration_p.h> -#include "qwaylandeglwindow.h" +#include "qwaylandeglwindow_p.h" #include <QDebug> #include <QtGui/private/qeglconvenience_p.h> @@ -192,22 +156,23 @@ public: } void blit(QWaylandEglWindow *window) { - Q_ASSERT(window->wlSurface()); QOpenGLTextureCache *cache = QOpenGLTextureCache::cacheForContext(m_context->context()); QSize surfaceSize = window->surfaceSize(); - int scale = window->scale() ; + qreal scale = window->scale() ; glViewport(0, 0, surfaceSize.width() * scale, surfaceSize.height() * scale); //Draw Decoration - m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_inverseSquareVerticesOffset, 2); - QImage decorationImage = window->decoration()->contentImage(); - cache->bindTexture(m_context->context(), decorationImage); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_textureWrap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_textureWrap); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + if (auto *decoration = window->decoration()) { + m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_inverseSquareVerticesOffset, 2); + QImage decorationImage = decoration->contentImage(); + cache->bindTexture(m_context->context(), decorationImage); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_textureWrap); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_textureWrap); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } //Draw Content m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_squareVerticesOffset, 2); @@ -230,6 +195,9 @@ QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *dis const QSurfaceFormat &fmt, QPlatformOpenGLContext *share) : QEGLPlatformContext(fmt, share, eglDisplay), m_display(display) { + m_reconnectionWatcher = QObject::connect(m_display, &QWaylandDisplay::connected, + m_display, [this] { invalidateContext(); }); + switch (format().renderableType()) { case QSurfaceFormat::OpenVG: m_api = EGL_OPENVG_API; @@ -295,12 +263,33 @@ void QWaylandGLContext::destroyTemporaryOffscreenSurface(EGLSurface eglSurface) QWaylandGLContext::~QWaylandGLContext() { + QObject::disconnect(m_reconnectionWatcher); delete m_blitter; m_blitter = nullptr; + if (m_decorationsContext != EGL_NO_CONTEXT) + eglDestroyContext(eglDisplay(), m_decorationsContext); +} + +void QWaylandGLContext::beginFrame() +{ + Q_ASSERT(m_currentWindow != nullptr); + if (m_supportNonBlockingSwap) + m_currentWindow->beginFrame(); +} + +void QWaylandGLContext::endFrame() +{ + Q_ASSERT(m_currentWindow != nullptr); + if (m_supportNonBlockingSwap) + m_currentWindow->endFrame(); } bool QWaylandGLContext::makeCurrent(QPlatformSurface *surface) { + if (!isValid()) { + return false; + } + // in QWaylandGLContext() we called eglBindAPI with the correct value. However, // eglBindAPI's documentation says: // "eglBindAPI defines the current rendering API for EGL in the thread it is called from" @@ -310,37 +299,35 @@ bool QWaylandGLContext::makeCurrent(QPlatformSurface *surface) eglBindAPI(m_api); } - QWaylandEglWindow *window = static_cast<QWaylandEglWindow *>(surface); - EGLSurface eglSurface = window->eglSurface(); + m_currentWindow = static_cast<QWaylandEglWindow *>(surface); + EGLSurface eglSurface = m_currentWindow->eglSurface(); - if (!window->needToUpdateContentFBO() && (eglSurface != EGL_NO_SURFACE)) { + if (!m_currentWindow->needToUpdateContentFBO() && (eglSurface != EGL_NO_SURFACE)) { if (!eglMakeCurrent(eglDisplay(), eglSurface, eglSurface, eglContext())) { - qWarning("QWaylandGLContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this); + qWarning("QWaylandGLContext::makeCurrent: eglError: %#x, this: %p \n", eglGetError(), this); return false; } return true; } - if (window->isExposed()) - window->setCanResize(false); - if (m_decorationsContext != EGL_NO_CONTEXT && !window->decoration()) - window->createDecoration(); + if (m_currentWindow->isExposed()) + m_currentWindow->setCanResize(false); if (eglSurface == EGL_NO_SURFACE) { - window->updateSurface(true); - eglSurface = window->eglSurface(); + m_currentWindow->updateSurface(true); + eglSurface = m_currentWindow->eglSurface(); } if (!eglMakeCurrent(eglDisplay(), eglSurface, eglSurface, eglContext())) { - qWarning("QWaylandGLContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this); - window->setCanResize(true); + qWarning("QWaylandGLContext::makeCurrent: eglError: %#x, this: %p \n", eglGetError(), this); + m_currentWindow->setCanResize(true); return false; } //### setCurrentContext will be called in QOpenGLContext::makeCurrent after this function // returns, but that's too late, as we need a current context in order to bind the content FBO. QOpenGLContextPrivate::setCurrentContext(context()); - window->bindContentFBO(); + m_currentWindow->bindContentFBO(); return true; } @@ -384,7 +371,8 @@ void QWaylandGLContext::swapBuffers(QPlatformSurface *surface) window->waitForFrameSync(100); } window->handleUpdate(); - eglSwapBuffers(eglDisplay(), eglSurface); + if (!eglSwapBuffers(eglDisplay(), eglSurface)) + qCWarning(lcQpaWayland, "eglSwapBuffers failed with %#x, surface: %p", eglGetError(), eglSurface); window->setCanResize(true); } |