diff options
Diffstat (limited to 'src/hardwareintegration/client/wayland-egl')
14 files changed, 425 insertions, 737 deletions
diff --git a/src/hardwareintegration/client/wayland-egl/CMakeLists.txt b/src/hardwareintegration/client/wayland-egl/CMakeLists.txt new file mode 100644 index 000000000..967dd3cab --- /dev/null +++ b/src/hardwareintegration/client/wayland-egl/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Generated from wayland-egl.pro. + +##################################################################### +## WaylandEglClientHwIntegrationPrivate Module: +##################################################################### +qt_find_package(EGL) # special case + +qt_internal_add_module(WaylandEglClientHwIntegrationPrivate + CONFIG_MODULE_NAME wayland_egl_client_hw_integration + INTERNAL_MODULE + SOURCES + qwaylandeglclientbufferintegration.cpp qwaylandeglclientbufferintegration_p.h + qwaylandeglinclude_p.h + qwaylandeglwindow.cpp qwaylandeglwindow_p.h + qwaylandglcontext.cpp qwaylandglcontext_p.h + INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC_LIBRARIES + ${CMAKE_DL_LIBS} + EGL::EGL + Qt::Core + Qt::Gui + Qt::OpenGLPrivate + Qt::WaylandClientPrivate + Wayland::Client + Wayland::Egl + NO_GENERATE_CPP_EXPORTS +) + +#### Keys ignored in scope 1:.:.:wayland-egl.pro:<TRUE>: +# MODULE = "wayland_egl_client_hw_integration" diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp index 596911ad3..3b97aef20 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp @@ -1,46 +1,10 @@ -/**************************************************************************** -** -** 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 "qwaylandeglclientbufferintegration.h" - -#include "qwaylandeglwindow.h" -#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 "qwaylandeglclientbufferintegration_p.h" + +#include "qwaylandeglwindow_p.h" +#include "qwaylandglcontext_p.h" #include <wayland-client-core.h> @@ -76,6 +40,9 @@ QWaylandEglClientBufferIntegration::~QWaylandEglClientBufferIntegration() void QWaylandEglClientBufferIntegration::initialize(QWaylandDisplay *display) { +#if QT_CONFIG(egl_extension_platform_wayland) + m_eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_EXT, display->wl_display(), nullptr); +#else if (q_hasEglExtension(EGL_NO_DISPLAY, "EGL_EXT_platform_base")) { if (q_hasEglExtension(EGL_NO_DISPLAY, "EGL_KHR_platform_wayland") || q_hasEglExtension(EGL_NO_DISPLAY, "EGL_EXT_platform_wayland") || @@ -98,6 +65,7 @@ void QWaylandEglClientBufferIntegration::initialize(QWaylandDisplay *display) m_eglDisplay = eglGetDisplay((EGLNativeDisplayType) display->wl_display()); } +#endif m_display = display; @@ -124,6 +92,13 @@ void QWaylandEglClientBufferIntegration::initialize(QWaylandDisplay *display) break; } } + + // On desktop NVIDIA resizing QtQuick freezes them when using threaded rendering QTBUG-95817 + // In order to support threaded rendering on embedded platforms where resizing is not needed + // we check if XDG_CURRENT_DESKTOP is set which desktop environments should set + if (qstrcmp(vendor, "NVIDIA") == 0 && qEnvironmentVariableIsSet("XDG_CURRENT_DESKTOP")) { + m_supportsThreading = false; + } } bool QWaylandEglClientBufferIntegration::isValid() const @@ -143,12 +118,15 @@ bool QWaylandEglClientBufferIntegration::supportsWindowDecoration() const QWaylandWindow *QWaylandEglClientBufferIntegration::createEglWindow(QWindow *window) { - return new QWaylandEglWindow(window); + return new QWaylandEglWindow(window, m_display); } QPlatformOpenGLContext *QWaylandEglClientBufferIntegration::createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const { - return new QWaylandGLContext(m_eglDisplay, m_display, glFormat, share); + QSurfaceFormat fmt = glFormat; + if (m_display->supportsWindowDecoration()) + fmt.setAlphaBufferSize(8); + return new QWaylandGLContext(m_eglDisplay, m_display, fmt, share); } void *QWaylandEglClientBufferIntegration::nativeResource(NativeResource resource) diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h deleted file mode 100644 index 0c5326230..000000000 --- a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QWAYLANDEGLINTEGRATION_H -#define QWAYLANDEGLINTEGRATION_H - -#include <QtWaylandClient/private/qwaylandclientbufferintegration_p.h> - -#include "qwaylandeglinclude.h" - -QT_BEGIN_NAMESPACE - -class QWindow; - -namespace QtWaylandClient { - -class QWaylandWindow; - -class QWaylandEglClientBufferIntegration : public QWaylandClientBufferIntegration -{ -public: - QWaylandEglClientBufferIntegration(); - ~QWaylandEglClientBufferIntegration() override; - - void initialize(QWaylandDisplay *display) override; - bool isValid() const override; - bool supportsThreadedOpenGL() const override; - bool supportsWindowDecoration() const override; - - QWaylandWindow *createEglWindow(QWindow *window) override; - QPlatformOpenGLContext *createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const override; - - void *nativeResource(NativeResource resource) override; - void *nativeResourceForContext(NativeResource resource, QPlatformOpenGLContext *context) override; - - EGLDisplay eglDisplay() const; - -private: - QWaylandDisplay *m_display = nullptr; - - EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; - bool m_supportsThreading = false; -}; - -QT_END_NAMESPACE - -} - -#endif // QWAYLANDEGLINTEGRATION_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration_p.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration_p.h new file mode 100644 index 000000000..ed8fdec2d --- /dev/null +++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration_p.h @@ -0,0 +1,60 @@ +// 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 + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QWAYLANDEGLINTEGRATION_H +#define QWAYLANDEGLINTEGRATION_H + +#include <QtWaylandClient/private/qwaylandclientbufferintegration_p.h> + +#include "qwaylandeglinclude_p.h" + +QT_BEGIN_NAMESPACE + +class QWindow; + +namespace QtWaylandClient { + +class QWaylandWindow; + +class Q_WAYLANDCLIENT_EXPORT QWaylandEglClientBufferIntegration : public QWaylandClientBufferIntegration +{ +public: + QWaylandEglClientBufferIntegration(); + ~QWaylandEglClientBufferIntegration() override; + + void initialize(QWaylandDisplay *display) override; + bool isValid() const override; + bool supportsThreadedOpenGL() const override; + bool supportsWindowDecoration() const override; + + QWaylandWindow *createEglWindow(QWindow *window) override; + QPlatformOpenGLContext *createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const override; + + void *nativeResource(NativeResource resource) override; + void *nativeResourceForContext(NativeResource resource, QPlatformOpenGLContext *context) override; + + EGLDisplay eglDisplay() const; + +private: + QWaylandDisplay *m_display = nullptr; + + EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; + bool m_supportsThreading = false; +}; + +QT_END_NAMESPACE + +} + +#endif // QWAYLANDEGLINTEGRATION_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h b/src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h deleted file mode 100644 index ac0d96791..000000000 --- a/src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QWAYLANDEGLWINDOW_H -#define QWAYLANDEGLWINDOW_H - -#include <QtWaylandClient/qwaylanddisplay.h> - -#include "qwaylandeglintegration.h" - -QT_BEGIN_NAMESPACE - -namespace QtWaylandClient { - -class QWaylandEglDisplay : public QWaylandDisplay -{ -public: - - QWaylandEglDisplay() - : QWaylandDisplay() - { } -}; - -} - -QT_END_NAMESPACE diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h deleted file mode 100644 index e9998b832..000000000 --- a/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QWAYLANDEGLINCLUDE_H -#define QWAYLANDEGLINCLUDE_H - -#include <string.h> -#include <wayland-client-core.h> - -#include <wayland-egl.h> - -#define EGL_EGLEXT_PROTOTYPES -#include <QtEglSupport/private/qt_egl_p.h> - -#endif // QWAYLANDEGLINCLUDE_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude_p.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude_p.h new file mode 100644 index 000000000..eb52ce8ee --- /dev/null +++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude_p.h @@ -0,0 +1,27 @@ +// 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 + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QWAYLANDEGLINCLUDE_H +#define QWAYLANDEGLINCLUDE_H + +#include <string.h> +#include <wayland-client-core.h> + +#include <wayland-egl.h> + +#define EGL_EGLEXT_PROTOTYPES +#include <QtGui/private/qt_egl_p.h> + +#endif // QWAYLANDEGLINCLUDE_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp index 030422c56..0b014cd5c 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp @@ -1,48 +1,13 @@ -/**************************************************************************** -** -** 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 "qwaylandeglwindow.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 "qwaylandeglwindow_p.h" #include <QtWaylandClient/private/qwaylandscreen_p.h> -#include "qwaylandglcontext.h" +#include <QtWaylandClient/private/qwaylandsurface_p.h> +#include "qwaylandglcontext_p.h" -#include <QtEglSupport/private/qeglconvenience_p.h> +#include <QtGui/private/qeglconvenience_p.h> #include <QDebug> #include <QtGui/QWindow> @@ -54,20 +19,15 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -QWaylandEglWindow::QWaylandEglWindow(QWindow *window) - : QWaylandWindow(window) +QWaylandEglWindow::QWaylandEglWindow(QWindow *window, QWaylandDisplay *display) + : QWaylandWindow(window, display) , m_clientBufferIntegration(static_cast<QWaylandEglClientBufferIntegration *>(mDisplay->clientBufferIntegration())) + , m_format(window->requestedFormat()) { - QSurfaceFormat fmt = window->requestedFormat(); - if (mDisplay->supportsWindowDecoration()) - fmt.setAlphaBufferSize(8); - m_eglConfig = q_configFromGLFormat(m_clientBufferIntegration->eglDisplay(), fmt); - m_format = q_glFormatFromConfig(m_clientBufferIntegration->eglDisplay(), m_eglConfig, fmt); - - // Do not create anything from here. This platform window may belong to a - // RasterGLSurface window which may have pure raster content. In this case, where the - // window is never actually made current, creating a wl_egl_window and EGL surface - // should be avoided. + connect(display, &QWaylandDisplay::connected, this, [this] { + m_clientBufferIntegration = static_cast<QWaylandEglClientBufferIntegration *>( + mDisplay->clientBufferIntegration()); + }); } QWaylandEglWindow::~QWaylandEglWindow() @@ -105,7 +65,7 @@ void QWaylandEglWindow::setGeometry(const QRect &rect) void QWaylandEglWindow::updateSurface(bool create) { - QMargins margins = frameMargins(); + QMargins margins = clientSideMargins(); QRect rect = geometry(); QSize sizeWithMargins = (rect.size() + QSize(margins.left() + margins.right(), margins.top() + margins.bottom())) * scale(); @@ -124,6 +84,7 @@ void QWaylandEglWindow::updateSurface(bool create) } mOffset = QPoint(); } else { + QReadLocker locker(&mSurfaceLock); if (m_waylandEglWindow) { int current_width, current_height; static bool disableResizeCheck = qgetenv("QT_WAYLAND_DISABLE_RESIZECHECK").toInt(); @@ -131,19 +92,26 @@ void QWaylandEglWindow::updateSurface(bool create) if (!disableResizeCheck) { wl_egl_window_get_attached_size(m_waylandEglWindow, ¤t_width, ¤t_height); } - if (disableResizeCheck || (current_width != sizeWithMargins.width() || current_height != sizeWithMargins.height())) { + if (disableResizeCheck || (current_width != sizeWithMargins.width() || current_height != sizeWithMargins.height()) || m_requestedSize != sizeWithMargins) { wl_egl_window_resize(m_waylandEglWindow, sizeWithMargins.width(), sizeWithMargins.height(), mOffset.x(), mOffset.y()); + m_requestedSize = sizeWithMargins; mOffset = QPoint(); m_resize = true; } - } else if (create && wlSurface()) { - m_waylandEglWindow = wl_egl_window_create(wlSurface(), sizeWithMargins.width(), sizeWithMargins.height()); + } else if (create && mSurface) { + m_waylandEglWindow = wl_egl_window_create(mSurface->object(), sizeWithMargins.width(), sizeWithMargins.height()); + m_requestedSize = sizeWithMargins; } if (!m_eglSurface && m_waylandEglWindow && create) { EGLNativeWindowType eglw = (EGLNativeWindowType) m_waylandEglWindow; - m_eglSurface = eglCreateWindowSurface(m_clientBufferIntegration->eglDisplay(), m_eglConfig, eglw, 0); + QSurfaceFormat fmt = window()->requestedFormat(); + if (mDisplay->supportsWindowDecoration()) + fmt.setAlphaBufferSize(8); + EGLConfig eglConfig = q_configFromGLFormat(m_clientBufferIntegration->eglDisplay(), fmt); + m_format = q_glFormatFromConfig(m_clientBufferIntegration->eglDisplay(), eglConfig, fmt); + m_eglSurface = eglCreateWindowSurface(m_clientBufferIntegration->eglDisplay(), eglConfig, eglw, 0); if (Q_UNLIKELY(m_eglSurface == EGL_NO_SURFACE)) qCWarning(lcQpaWayland, "Could not create EGL surface (EGL error 0x%x)\n", eglGetError()); } @@ -153,7 +121,7 @@ void QWaylandEglWindow::updateSurface(bool create) QRect QWaylandEglWindow::contentsRect() const { QRect r = geometry(); - QMargins m = frameMargins(); + QMargins m = clientSideMargins(); return QRect(m.left(), m.bottom(), r.width(), r.height()); } @@ -162,13 +130,6 @@ QSurfaceFormat QWaylandEglWindow::format() const return m_format; } -void QWaylandEglWindow::setVisible(bool visible) -{ - QWaylandWindow::setVisible(visible); - if (!visible) - invalidateSurface(); -} - void QWaylandEglWindow::invalidateSurface() { if (m_eglSurface) { @@ -179,6 +140,8 @@ void QWaylandEglWindow::invalidateSurface() wl_egl_window_destroy(m_waylandEglWindow); m_waylandEglWindow = nullptr; } + delete m_contentFBO; + m_contentFBO = nullptr; } EGLSurface QWaylandEglWindow::eglSurface() const @@ -219,3 +182,5 @@ void QWaylandEglWindow::bindContentFBO() } QT_END_NAMESPACE + +#include "moc_qwaylandeglwindow_p.cpp" diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.h deleted file mode 100644 index 9e6cb876c..000000000 --- a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QWAYLANDEGLWINDOW_H -#define QWAYLANDEGLWINDOW_H - -#include <QtWaylandClient/private/qwaylandwindow_p.h> -#include "qwaylandeglinclude.h" -#include "qwaylandeglclientbufferintegration.h" - -QT_BEGIN_NAMESPACE - -class QOpenGLFramebufferObject; - -namespace QtWaylandClient { - -class QWaylandGLContext; - -class QWaylandEglWindow : public QWaylandWindow -{ - Q_OBJECT -public: - QWaylandEglWindow(QWindow *window); - ~QWaylandEglWindow(); - WindowType windowType() const override; - void ensureSize() override; - - void updateSurface(bool create); - void setGeometry(const QRect &rect) override; - QRect contentsRect() const; - - EGLSurface eglSurface() const; - GLuint contentFBO() const; - GLuint contentTexture() const; - bool needToUpdateContentFBO() const { return decoration() && (m_resize || !m_contentFBO); } - - QSurfaceFormat format() const override; - - void bindContentFBO(); - - void invalidateSurface() override; - void setVisible(bool visible) override; - -private: - QWaylandEglClientBufferIntegration *m_clientBufferIntegration = nullptr; - struct wl_egl_window *m_waylandEglWindow = nullptr; - - const QWaylandWindow *m_parentWindow = nullptr; - - EGLSurface m_eglSurface = EGL_NO_SURFACE; - EGLConfig m_eglConfig; - mutable bool m_resize = false; - mutable QOpenGLFramebufferObject *m_contentFBO = nullptr; - - QSurfaceFormat m_format; -}; - -} - -QT_END_NAMESPACE - -#endif // QWAYLANDEGLWINDOW_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow_p.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow_p.h new file mode 100644 index 000000000..5b9aa9874 --- /dev/null +++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow_p.h @@ -0,0 +1,70 @@ +// 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 + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QWAYLANDEGLWINDOW_H +#define QWAYLANDEGLWINDOW_H + +#include <QtWaylandClient/private/qwaylandwindow_p.h> +#include "qwaylandeglinclude_p.h" +#include "qwaylandeglclientbufferintegration_p.h" + +QT_BEGIN_NAMESPACE + +class QOpenGLFramebufferObject; + +namespace QtWaylandClient { + +class QWaylandGLContext; + +class Q_WAYLANDCLIENT_EXPORT QWaylandEglWindow : public QWaylandWindow +{ + Q_OBJECT +public: + QWaylandEglWindow(QWindow *window, QWaylandDisplay *display); + ~QWaylandEglWindow(); + WindowType windowType() const override; + void ensureSize() override; + + void updateSurface(bool create); + void setGeometry(const QRect &rect) override; + QRect contentsRect() const; + + EGLSurface eglSurface() const; + GLuint contentFBO() const; + GLuint contentTexture() const; + bool needToUpdateContentFBO() const { return decoration() && (m_resize || !m_contentFBO); } + + QSurfaceFormat format() const override; + + void bindContentFBO(); + + void invalidateSurface() override; + +private: + QWaylandEglClientBufferIntegration *m_clientBufferIntegration = nullptr; + struct wl_egl_window *m_waylandEglWindow = nullptr; + + EGLSurface m_eglSurface = EGL_NO_SURFACE; + mutable bool m_resize = false; + mutable QOpenGLFramebufferObject *m_contentFBO = nullptr; + + QSurfaceFormat m_format; + QSize m_requestedSize; +}; + +} + +QT_END_NAMESPACE + +#endif // QWAYLANDEGLWINDOW_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp index 5bd2760d0..02789b305 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp @@ -1,60 +1,24 @@ -/**************************************************************************** -** -** 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 <QtEglSupport/private/qeglconvenience_p.h> +#include <QtGui/private/qeglconvenience_p.h> #include <QtGui/private/qopenglcontext_p.h> -#include <QtGui/private/qopengltexturecache_p.h> +#include <QtOpenGL/private/qopengltexturecache_p.h> #include <QtGui/private/qguiapplication_p.h> #include <qpa/qplatformopenglcontext.h> #include <QtGui/QSurfaceFormat> -#include <QtGui/QOpenGLShaderProgram> +#include <QtOpenGL/QOpenGLShaderProgram> #include <QtGui/QOpenGLFunctions> #include <QOpenGLBuffer> @@ -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); @@ -226,179 +191,105 @@ public: int m_textureWrap; }; - - -QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *display, const QSurfaceFormat &format, QPlatformOpenGLContext *share) - : QPlatformOpenGLContext() - , m_eglDisplay(eglDisplay) - , m_display(display) +QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *display, + const QSurfaceFormat &fmt, QPlatformOpenGLContext *share) + : QEGLPlatformContext(fmt, share, eglDisplay), m_display(display) { - QSurfaceFormat fmt = format; - if (static_cast<QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration())->display()->supportsWindowDecoration()) - fmt.setAlphaBufferSize(8); - m_config = q_configFromGLFormat(m_eglDisplay, fmt); - m_format = q_glFormatFromConfig(m_eglDisplay, m_config, fmt); - m_shareEGLContext = share ? static_cast<QWaylandGLContext *>(share)->eglContext() : EGL_NO_CONTEXT; - - QVector<EGLint> eglContextAttrs; - eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); - eglContextAttrs.append(format.majorVersion()); - const bool hasKHRCreateContext = q_hasEglExtension(m_eglDisplay, "EGL_KHR_create_context"); - if (hasKHRCreateContext) { - eglContextAttrs.append(EGL_CONTEXT_MINOR_VERSION_KHR); - eglContextAttrs.append(format.minorVersion()); - int flags = 0; - // The debug bit is supported both for OpenGL and OpenGL ES. - if (format.testOption(QSurfaceFormat::DebugContext)) - flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; - // The fwdcompat bit is only for OpenGL 3.0+. - if (m_format.renderableType() == QSurfaceFormat::OpenGL - && format.majorVersion() >= 3 - && !format.testOption(QSurfaceFormat::DeprecatedFunctions)) - flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; - if (flags) { - eglContextAttrs.append(EGL_CONTEXT_FLAGS_KHR); - eglContextAttrs.append(flags); - } - // Profiles are OpenGL only and mandatory in 3.2+. The value is silently ignored for < 3.2. - if (m_format.renderableType() == QSurfaceFormat::OpenGL) { - switch (format.profile()) { - case QSurfaceFormat::NoProfile: - break; - case QSurfaceFormat::CoreProfile: - eglContextAttrs.append(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR); - eglContextAttrs.append(EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR); - break; - case QSurfaceFormat::CompatibilityProfile: - eglContextAttrs.append(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR); - eglContextAttrs.append(EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR); - break; - } - } - } - eglContextAttrs.append(EGL_NONE); + m_reconnectionWatcher = QObject::connect(m_display, &QWaylandDisplay::connected, + m_display, [this] { invalidateContext(); }); - switch (m_format.renderableType()) { + switch (format().renderableType()) { case QSurfaceFormat::OpenVG: m_api = EGL_OPENVG_API; break; #ifdef EGL_VERSION_1_4 -# if !defined(QT_OPENGL_ES_2) - case QSurfaceFormat::DefaultRenderableType: -# endif case QSurfaceFormat::OpenGL: m_api = EGL_OPENGL_API; break; -#endif - case QSurfaceFormat::OpenGLES: +#endif // EGL_VERSION_1_4 default: m_api = EGL_OPENGL_ES_API; break; } - eglBindAPI(m_api); - - m_context = eglCreateContext(m_eglDisplay, m_config, m_shareEGLContext, eglContextAttrs.constData()); - - if (m_context == EGL_NO_CONTEXT) { - m_context = eglCreateContext(m_eglDisplay, m_config, EGL_NO_CONTEXT, eglContextAttrs.constData()); - m_shareEGLContext = EGL_NO_CONTEXT; - } - - EGLint error = eglGetError(); - if (error != EGL_SUCCESS) { - qWarning("QWaylandGLContext: failed to create EGLContext, error=%x", error); - return; - } // Create an EGL context for the decorations blitter. By using a dedicated context we don't need to make sure to not // change the context state and we also use OpenGL ES 2 API independently to what the app is using to draw. - QVector<EGLint> eglDecorationsContextAttrs = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; - m_decorationsContext = eglCreateContext(m_eglDisplay, m_config, m_context, eglDecorationsContextAttrs.constData()); + QList<EGLint> eglDecorationsContextAttrs = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + m_decorationsContext = eglCreateContext(eglDisplay, eglConfig(), eglContext(), + eglDecorationsContextAttrs.constData()); if (m_decorationsContext == EGL_NO_CONTEXT) qWarning("QWaylandGLContext: Failed to create the decorations EGLContext. Decorations will not be drawn."); EGLint a = EGL_MIN_SWAP_INTERVAL; EGLint b = EGL_MAX_SWAP_INTERVAL; - if (!eglGetConfigAttrib(m_eglDisplay, m_config, a, &a) || - !eglGetConfigAttrib(m_eglDisplay, m_config, b, &b) || - a > 0) { - mSupportNonBlockingSwap = false; + if (!eglGetConfigAttrib(eglDisplay, eglConfig(), a, &a) + || !eglGetConfigAttrib(eglDisplay, eglConfig(), b, &b) || a > 0) { + m_supportNonBlockingSwap = false; } - if (!mSupportNonBlockingSwap) { + { + bool ok; + int supportNonBlockingSwap = qEnvironmentVariableIntValue("QT_WAYLAND_FORCE_NONBLOCKING_SWAP_SUPPORT", &ok); + if (ok) + m_supportNonBlockingSwap = supportNonBlockingSwap != 0; + } + if (!m_supportNonBlockingSwap) { qWarning(lcQpaWayland) << "Non-blocking swap buffers not supported." << "Subsurface rendering can be affected." << "It may also cause the event loop to freeze in some situations"; } +} - updateGLFormat(); +EGLSurface QWaylandGLContext::createTemporaryOffscreenSurface() +{ + m_wlSurface = m_display->createSurface(nullptr); + m_eglWindow = wl_egl_window_create(m_wlSurface, 1, 1); +#if QT_CONFIG(egl_extension_platform_wayland) + EGLSurface eglSurface = + eglCreatePlatformWindowSurface(eglDisplay(), eglConfig(), m_eglWindow, nullptr); +#else + EGLSurface eglSurface = eglCreateWindowSurface(eglDisplay(), eglConfig(), m_eglWindow, nullptr); +#endif + return eglSurface; } -void QWaylandGLContext::updateGLFormat() +void QWaylandGLContext::destroyTemporaryOffscreenSurface(EGLSurface eglSurface) { - // Have to save & restore to prevent QOpenGLContext::currentContext() from becoming - // inconsistent after QOpenGLContext::create(). - EGLDisplay prevDisplay = eglGetCurrentDisplay(); - if (prevDisplay == EGL_NO_DISPLAY) // when no context is current - prevDisplay = m_eglDisplay; - EGLContext prevContext = eglGetCurrentContext(); - EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); - EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ); - - wl_surface *wlSurface = m_display->createSurface(nullptr); - wl_egl_window *eglWindow = wl_egl_window_create(wlSurface, 1, 1); - EGLSurface eglSurface = eglCreateWindowSurface(m_eglDisplay, m_config, eglWindow, 0); - - if (eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_context)) { - if (m_format.renderableType() == QSurfaceFormat::OpenGL - || m_format.renderableType() == QSurfaceFormat::OpenGLES) { - const GLubyte *s = glGetString(GL_VERSION); - if (s) { - QByteArray version = QByteArray(reinterpret_cast<const char *>(s)); - int major, minor; - if (QPlatformOpenGLContext::parseOpenGLVersion(version, major, minor)) { - m_format.setMajorVersion(major); - m_format.setMinorVersion(minor); - } - } - m_format.setProfile(QSurfaceFormat::NoProfile); - m_format.setOptions(QSurfaceFormat::FormatOptions()); - if (m_format.renderableType() == QSurfaceFormat::OpenGL) { - // Check profile and options. - if (m_format.majorVersion() < 3) { - m_format.setOption(QSurfaceFormat::DeprecatedFunctions); - } else { - GLint value = 0; - glGetIntegerv(GL_CONTEXT_FLAGS, &value); - if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)) - m_format.setOption(QSurfaceFormat::DeprecatedFunctions); - if (value & GL_CONTEXT_FLAG_DEBUG_BIT) - m_format.setOption(QSurfaceFormat::DebugContext); - if (m_format.version() >= qMakePair(3, 2)) { - value = 0; - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); - if (value & GL_CONTEXT_CORE_PROFILE_BIT) - m_format.setProfile(QSurfaceFormat::CoreProfile); - else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) - m_format.setProfile(QSurfaceFormat::CompatibilityProfile); - } - } - } - } - eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext); - } - eglDestroySurface(m_eglDisplay, eglSurface); - wl_egl_window_destroy(eglWindow); - wl_surface_destroy(wlSurface); + eglDestroySurface(eglDisplay(), eglSurface); + wl_egl_window_destroy(m_eglWindow); + m_eglWindow = nullptr; + wl_surface_destroy(m_wlSurface); + m_wlSurface = nullptr; } QWaylandGLContext::~QWaylandGLContext() { + QObject::disconnect(m_reconnectionWatcher); delete m_blitter; - eglDestroyContext(m_eglDisplay, m_context); + 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" @@ -408,44 +299,42 @@ 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 (!eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_context)) { - qWarning("QWaylandGLContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this); + if (!m_currentWindow->needToUpdateContentFBO() && (eglSurface != EGL_NO_SURFACE)) { + if (!eglMakeCurrent(eglDisplay(), eglSurface, eglSurface, eglContext())) { + 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(m_eglDisplay, eglSurface, eglSurface, m_context)) { - qWarning("QWaylandGLContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this); - window->setCanResize(true); + if (!eglMakeCurrent(eglDisplay(), eglSurface, eglSurface, eglContext())) { + 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; } void QWaylandGLContext::doneCurrent() { - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglMakeCurrent(eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } void QWaylandGLContext::swapBuffers(QPlatformSurface *surface) @@ -463,7 +352,7 @@ void QWaylandGLContext::swapBuffers(QPlatformSurface *surface) EGLContext currentContext = eglGetCurrentContext(); EGLSurface currentSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); EGLSurface currentSurfaceRead = eglGetCurrentSurface(EGL_READ); - eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_decorationsContext); + eglMakeCurrent(eglDisplay(), eglSurface, eglSurface, m_decorationsContext); if (!m_blitter) m_blitter = new DecorationsBlitter(this); @@ -474,15 +363,16 @@ void QWaylandGLContext::swapBuffers(QPlatformSurface *surface) eglMakeCurrent(currentDisplay, currentSurfaceDraw, currentSurfaceRead, currentContext); } - int swapInterval = mSupportNonBlockingSwap ? 0 : m_format.swapInterval(); - eglSwapInterval(m_eglDisplay, swapInterval); - if (swapInterval == 0 && m_format.swapInterval() > 0) { + int swapInterval = m_supportNonBlockingSwap ? 0 : format().swapInterval(); + eglSwapInterval(eglDisplay(), swapInterval); + if (swapInterval == 0 && format().swapInterval() > 0) { // Emulating a blocking swap glFlush(); // Flush before waiting so we can swap more quickly when the frame event arrives window->waitForFrameSync(100); } window->handleUpdate(); - eglSwapBuffers(m_eglDisplay, eglSurface); + if (!eglSwapBuffers(eglDisplay(), eglSurface)) + qCWarning(lcQpaWayland, "eglSwapBuffers failed with %#x, surface: %p", eglGetError(), eglSurface); window->setCanResize(true); } @@ -492,16 +382,6 @@ GLuint QWaylandGLContext::defaultFramebufferObject(QPlatformSurface *surface) co return static_cast<QWaylandEglWindow *>(surface)->contentFBO(); } -bool QWaylandGLContext::isSharing() const -{ - return m_shareEGLContext != EGL_NO_CONTEXT; -} - -bool QWaylandGLContext::isValid() const -{ - return m_context != EGL_NO_CONTEXT; -} - QFunctionPointer QWaylandGLContext::getProcAddress(const char *procName) { QFunctionPointer proc = (QFunctionPointer) eglGetProcAddress(procName); @@ -510,9 +390,9 @@ QFunctionPointer QWaylandGLContext::getProcAddress(const char *procName) return proc; } -EGLConfig QWaylandGLContext::eglConfig() const +EGLSurface QWaylandGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface) { - return m_config; + return static_cast<QWaylandEglWindow *>(surface)->eglSurface(); } } diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h deleted file mode 100644 index 0e86ca4f5..000000000 --- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QWAYLANDGLCONTEXT_H -#define QWAYLANDGLCONTEXT_H - -#include <QtWaylandClient/private/qwaylanddisplay_p.h> - -#include <qpa/qplatformopenglcontext.h> - -#include "qwaylandeglinclude.h" - -QT_BEGIN_NAMESPACE - -class QOpenGLShaderProgram; -class QOpenGLTextureCache; - -namespace QtWaylandClient { - -class QWaylandWindow; -class QWaylandGLWindowSurface; -class DecorationsBlitter; - -class QWaylandGLContext : public QPlatformOpenGLContext -{ -public: - QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *display, const QSurfaceFormat &format, QPlatformOpenGLContext *share); - ~QWaylandGLContext(); - - void swapBuffers(QPlatformSurface *surface) override; - - bool makeCurrent(QPlatformSurface *surface) override; - void doneCurrent() override; - - GLuint defaultFramebufferObject(QPlatformSurface *surface) const override; - - bool isSharing() const override; - bool isValid() const override; - - QFunctionPointer getProcAddress(const char *procName) override; - - QSurfaceFormat format() const override { return m_format; } - - EGLConfig eglConfig() const; - EGLContext eglContext() const { return m_context; } - -private: - void updateGLFormat(); - - EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; - QWaylandDisplay *m_display = nullptr; - EGLContext m_context; - EGLContext m_shareEGLContext; - EGLContext m_decorationsContext; - EGLConfig m_config; - QSurfaceFormat m_format; - DecorationsBlitter *m_blitter = nullptr; - uint m_api; - bool mSupportNonBlockingSwap = true; -}; - -} - -QT_END_NAMESPACE - -#endif // QWAYLANDGLCONTEXT_H diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext_p.h b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext_p.h new file mode 100644 index 000000000..b985c6675 --- /dev/null +++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext_p.h @@ -0,0 +1,72 @@ +// 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 + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QWAYLANDGLCONTEXT_H +#define QWAYLANDGLCONTEXT_H + +#include "qwaylandeglinclude_p.h" //must be first + +#include <QtWaylandClient/private/qwaylanddisplay_p.h> +#include <QtGui/private/qeglplatformcontext_p.h> +#include <qpa/qplatformopenglcontext.h> + +QT_BEGIN_NAMESPACE + +class QOpenGLShaderProgram; +class QOpenGLTextureCache; + +namespace QtWaylandClient { + +class QWaylandEglWindow; +class DecorationsBlitter; + +class Q_WAYLANDCLIENT_EXPORT QWaylandGLContext : public QEGLPlatformContext +{ +public: + QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *display, const QSurfaceFormat &format, QPlatformOpenGLContext *share); + ~QWaylandGLContext(); + void swapBuffers(QPlatformSurface *surface) override; + + bool makeCurrent(QPlatformSurface *surface) override; + void doneCurrent() override; + + void beginFrame() override; + void endFrame() override; + + GLuint defaultFramebufferObject(QPlatformSurface *surface) const override; + + QFunctionPointer getProcAddress(const char *procName) override; + +protected: + EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override; + EGLSurface createTemporaryOffscreenSurface() override; + void destroyTemporaryOffscreenSurface(EGLSurface surface) override; + +private: + QWaylandDisplay *m_display = nullptr; + EGLContext m_decorationsContext; + DecorationsBlitter *m_blitter = nullptr; + bool m_supportNonBlockingSwap = true; + EGLenum m_api; + wl_surface *m_wlSurface = nullptr; + wl_egl_window *m_eglWindow = nullptr; + QWaylandEglWindow *m_currentWindow = nullptr; + QMetaObject::Connection m_reconnectionWatcher; +}; + +} + +QT_END_NAMESPACE + +#endif // QWAYLANDGLCONTEXT_H diff --git a/src/hardwareintegration/client/wayland-egl/wayland-egl.pri b/src/hardwareintegration/client/wayland-egl/wayland-egl.pri index d7634b150..5d0d0204b 100644 --- a/src/hardwareintegration/client/wayland-egl/wayland-egl.pri +++ b/src/hardwareintegration/client/wayland-egl/wayland-egl.pri @@ -1,14 +1,14 @@ INCLUDEPATH += $$PWD -QMAKE_USE += egl wayland-client wayland-egl +QMAKE_USE += egl wayland-client wayland-egl libdl -QT += egl_support-private +QT += opengl-private SOURCES += $$PWD/qwaylandeglclientbufferintegration.cpp \ $$PWD/qwaylandglcontext.cpp \ $$PWD/qwaylandeglwindow.cpp -HEADERS += $$PWD/qwaylandeglclientbufferintegration.h \ - $$PWD/qwaylandglcontext.h \ - $$PWD/qwaylandeglwindow.h \ - $$PWD/qwaylandeglinclude.h +HEADERS += $$PWD/qwaylandeglclientbufferintegration_p.h \ + $$PWD/qwaylandglcontext_p.h \ + $$PWD/qwaylandeglwindow_p.h \ + $$PWD/qwaylandeglinclude_p.h |