From fc4a73aa544bf03d881ddb7e2eb8ebd47d7da7b8 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Tue, 25 Aug 2020 11:32:58 +0300 Subject: Add QOffScreenSurface platform API abstraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This follows the work done in 6ff79478a44fce12ca18832a56db4a370a9ff417. The API is available by including qoffscreensurface.h, scoped in the QPlatformInterface namespace. The namespace exposes platform specific type-safe interfaces that provide: a) Factory functions for adopting native contexts, e.g. QAndroidPlatformOffscreenSurface::fromNative(ANativeWindow); b) Access to underlying native handles, e.g. surface->platformInterface() ->nativeSurface() Fixes: QTBUG-85874 Change-Id: I29c459866e0355a52320d5d473e8b147e050acb3 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/kernel.pri | 2 + src/gui/kernel/qoffscreensurface.cpp | 81 +++++------------------- src/gui/kernel/qoffscreensurface.h | 8 ++- src/gui/kernel/qoffscreensurface_p.h | 95 +++++++++++++++++++++++++++++ src/gui/kernel/qoffscreensurface_platform.h | 67 ++++++++++++++++++++ src/gui/kernel/qplatformoffscreensurface.h | 25 +++++++- 6 files changed, 206 insertions(+), 72 deletions(-) create mode 100644 src/gui/kernel/qoffscreensurface_p.h create mode 100644 src/gui/kernel/qoffscreensurface_platform.h (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 011e0ce00d..48fd18f8d2 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -6,6 +6,8 @@ PRECOMPILED_HEADER = kernel/qt_gui_pch.h KERNEL_P= kernel HEADERS += \ + kernel/qoffscreensurface_p.h \ + kernel/qoffscreensurface_platform.h \ kernel/qtguiglobal.h \ kernel/qtguiglobal_p.h \ kernel/qgenericpluginfactory.h \ diff --git a/src/gui/kernel/qoffscreensurface.cpp b/src/gui/kernel/qoffscreensurface.cpp index fbd5c6a079..9875911d30 100644 --- a/src/gui/kernel/qoffscreensurface.cpp +++ b/src/gui/kernel/qoffscreensurface.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -42,7 +42,7 @@ #include "qguiapplication_p.h" #include "qscreen.h" #include "qplatformintegration.h" -#include "qplatformoffscreensurface.h" +#include "qoffscreensurface_p.h" #include "qwindow.h" #include "qplatformwindow.h" @@ -50,6 +50,18 @@ QT_BEGIN_NAMESPACE + +/*! + \fn T QOffScreenSurface::platformInterface() + + Returns a platform interface of type T for the surface. + + This function provides access to platform specific functionality + of QOffScreenSurface, as defined in the QPlatformInterface namespace. + + If the requested interface is not available a \nullptr is returned. +*/ + /*! \class QOffscreenSurface \inmodule QtGui @@ -91,36 +103,6 @@ QT_BEGIN_NAMESPACE native surface. For the use cases of QOffscreenSurface (rendering to FBOs, texture upload) this is not a problem. */ -class Q_GUI_EXPORT QOffscreenSurfacePrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QOffscreenSurface) - -public: - QOffscreenSurfacePrivate() - : QObjectPrivate() - , surfaceType(QSurface::OpenGLSurface) - , platformOffscreenSurface(nullptr) - , offscreenWindow(nullptr) - , requestedFormat(QSurfaceFormat::defaultFormat()) - , screen(nullptr) - , size(1, 1) - , nativeHandle(nullptr) - { - } - - ~QOffscreenSurfacePrivate() - { - } - - QSurface::SurfaceType surfaceType; - QPlatformOffscreenSurface *platformOffscreenSurface; - QWindow *offscreenWindow; - QSurfaceFormat requestedFormat; - QScreen *screen; - QSize size; - void *nativeHandle; -}; - /*! \since 5.10 @@ -228,8 +210,6 @@ void QOffscreenSurface::destroy() delete d->offscreenWindow; d->offscreenWindow = nullptr; } - - d->nativeHandle = nullptr; } /*! @@ -343,26 +323,6 @@ void QOffscreenSurface::setScreen(QScreen *newScreen) } } -/*! - Sets the native handle to which the offscreen surface is connected to \a handle. - - The native handle will be resolved in the create() function. Calling - this function after create() will not re-create a native surface. - - \note The interpretation of the native handle is platform specific. Only - some platforms will support adopting native handles of offscreen surfaces - and platforms that do not implement this support will ignore the handle. - - \since 5.9 - \sa nativeHandle() -*/ - -void QOffscreenSurface::setNativeHandle(void *handle) -{ - Q_D(QOffscreenSurface); - d->nativeHandle = handle; -} - /*! Called when the offscreen surface's screen is destroyed. @@ -394,19 +354,6 @@ QPlatformOffscreenSurface *QOffscreenSurface::handle() const return d->platformOffscreenSurface; } -/*! - Returns an optional native handle to which the offscreen surface is connected. - - \since 5.9 - \sa setNativeHandle() -*/ - -void *QOffscreenSurface::nativeHandle() const -{ - Q_D(const QOffscreenSurface); - return d->nativeHandle; -} - /*! Returns the platform surface corresponding to the offscreen surface. diff --git a/src/gui/kernel/qoffscreensurface.h b/src/gui/kernel/qoffscreensurface.h index 1a3c476244..fe8db44633 100644 --- a/src/gui/kernel/qoffscreensurface.h +++ b/src/gui/kernel/qoffscreensurface.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -79,8 +79,8 @@ public: QPlatformOffscreenSurface *handle() const; - void *nativeHandle() const; - void setNativeHandle(void *handle); + template + T *platformInterface() const; Q_SIGNALS: void screenChanged(QScreen *screen); @@ -97,4 +97,6 @@ private: QT_END_NAMESPACE +#include + #endif // QOFFSCREENSURFACE_H diff --git a/src/gui/kernel/qoffscreensurface_p.h b/src/gui/kernel/qoffscreensurface_p.h new file mode 100644 index 0000000000..5b41e71c29 --- /dev/null +++ b/src/gui/kernel/qoffscreensurface_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module 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 QOFFSCREENSURFACE_P_H +#define QOFFSCREENSURFACE_P_H + +// +// 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. +// + +#include "qplatformoffscreensurface.h" + +#include + +QT_BEGIN_NAMESPACE + +class Q_GUI_EXPORT QOffscreenSurfacePrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QOffscreenSurface) + +public: + QOffscreenSurfacePrivate() + : QObjectPrivate() + , surfaceType(QSurface::OpenGLSurface) + , platformOffscreenSurface(nullptr) + , offscreenWindow(nullptr) + , requestedFormat(QSurfaceFormat::defaultFormat()) + , screen(nullptr) + , size(1, 1) + { + } + + ~QOffscreenSurfacePrivate() + { + } + + static QOffscreenSurfacePrivate *get(QOffscreenSurface *surface) + { + return surface ? surface->d_func() : nullptr; + } + + QSurface::SurfaceType surfaceType; + QPlatformOffscreenSurface *platformOffscreenSurface; + QWindow *offscreenWindow; + QSurfaceFormat requestedFormat; + QScreen *screen; + QSize size; +}; + +QT_END_NAMESPACE + +#endif // QOFFSCREENSURFACE_P_H diff --git a/src/gui/kernel/qoffscreensurface_platform.h b/src/gui/kernel/qoffscreensurface_platform.h new file mode 100644 index 0000000000..87e6b453a7 --- /dev/null +++ b/src/gui/kernel/qoffscreensurface_platform.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module 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 QOFFSCREENSURFACE_PLATFORM_H +#define QOFFSCREENSURFACE_PLATFORM_H + +#include +#include + +#if defined(Q_OS_ANDROID) +QT_FORWARD_DECLARE_CLASS(ANativeWindow); +#endif + +QT_BEGIN_NAMESPACE + +namespace QPlatformInterface { + +#if defined(Q_OS_ANDROID) +struct Q_GUI_EXPORT QAndroidPlatformOffscreenSurface +{ + QT_DECLARE_PLATFORM_INTERFACE(QAndroidPlatformOffscreenSurface) + static QOffscreenSurface *fromNative(ANativeWindow *nativeSurface); + virtual ANativeWindow *nativeSurface() const = 0; +}; +#endif + +} // QPlatformInterface + +QT_END_NAMESPACE + +#endif // QOFFSCREENSURFACE_PLATFORM_H diff --git a/src/gui/kernel/qplatformoffscreensurface.h b/src/gui/kernel/qplatformoffscreensurface.h index cef0fab7e1..1d06336956 100644 --- a/src/gui/kernel/qplatformoffscreensurface.h +++ b/src/gui/kernel/qplatformoffscreensurface.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -49,8 +49,9 @@ // source and binary incompatible with future versions of Qt. // -#include #include "qplatformsurface.h" + +#include #include QT_BEGIN_NAMESPACE @@ -75,10 +76,30 @@ public: protected: QScopedPointer d_ptr; + friend class QOffscreenSurfacePrivate; private: Q_DISABLE_COPY(QPlatformOffscreenSurface) }; +template +T *QOffscreenSurface::platformInterface() const +{ + return dynamic_cast(surfaceHandle()); +} + +namespace QPlatformInterface::Private { + +#if defined(Q_OS_ANDROID) +struct Q_GUI_EXPORT QAndroidOffScreenIntegration +{ + QT_DECLARE_PLATFORM_INTERFACE(QAndroidOffScreenIntegration) + virtual QOffscreenSurface *createOffscreenSurface(ANativeWindow *nativeSurface) const = 0; +}; +#endif + +} // QPlatformInterface::Private + + QT_END_NAMESPACE #endif // QPLATFORMOFFSCREENSURFACE_H -- cgit v1.2.3