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/CMakeLists.txt | 7 +- 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 +++++- src/gui/platform/android/android.pri | 1 + .../platform/android/qandroidplatforminterface.cpp | 61 ++++++++++++++ src/gui/platform/platform.pri | 1 + .../android/qandroidplatformintegration.cpp | 21 +++-- .../android/qandroidplatformintegration.h | 12 +-- .../android/qandroidplatformoffscreensurface.cpp | 29 +++---- .../android/qandroidplatformoffscreensurface.h | 15 ++-- .../android/qandroidplatformopenglcontext.cpp | 5 +- 15 files changed, 319 insertions(+), 111 deletions(-) create mode 100644 src/gui/kernel/qoffscreensurface_p.h create mode 100644 src/gui/kernel/qoffscreensurface_platform.h create mode 100644 src/gui/platform/android/android.pri create mode 100644 src/gui/platform/android/qandroidplatforminterface.cpp diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 3396adf23c..89ef65aa31 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -100,7 +100,7 @@ qt_add_module(Gui kernel/qinputmethod.cpp kernel/qinputmethod.h kernel/qinputmethod_p.h kernel/qinternalmimedata.cpp kernel/qinternalmimedata_p.h kernel/qkeymapper.cpp kernel/qkeymapper_p.h - kernel/qoffscreensurface.cpp kernel/qoffscreensurface.h + kernel/qoffscreensurface.cpp kernel/qoffscreensurface.h kernel/qoffscreensurface_p.h kernel/qoffscreensurface_platform.h kernel/qpaintdevicewindow.cpp kernel/qpaintdevicewindow.h kernel/qpaintdevicewindow_p.h kernel/qpalette.cpp kernel/qpalette.h kernel/qpixelformat.cpp kernel/qpixelformat.h @@ -352,6 +352,11 @@ qt_extend_target(Gui CONDITION QT_FEATURE_opengl rhi/qrhigles2_p_p.h ) +qt_extend_target(Gui CONDITION ANDROID + SOURCES + platform/android/qandroidplatforminterface.cpp +) + #### Keys ignored in scope 2:.:.:gui.pro:QT_FEATURE_opengl: # MODULE_CONFIG = "opengl" 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 diff --git a/src/gui/platform/android/android.pri b/src/gui/platform/android/android.pri new file mode 100644 index 0000000000..bdaa4b1279 --- /dev/null +++ b/src/gui/platform/android/android.pri @@ -0,0 +1 @@ +SOURCES += $$PWD/qandroidplatforminterface.cpp diff --git a/src/gui/platform/android/qandroidplatforminterface.cpp b/src/gui/platform/android/qandroidplatforminterface.cpp new file mode 100644 index 0000000000..a3c4a5028d --- /dev/null +++ b/src/gui/platform/android/qandroidplatforminterface.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +using namespace QPlatformInterface::Private; + +#if defined(Q_OS_ANDROID) +QT_DEFINE_PLATFORM_INTERFACE(QAndroidPlatformOffscreenSurface, QOffscreenSurface); +QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QAndroidOffScreenIntegration); + +QOffscreenSurface *QPlatformInterface::QAndroidPlatformOffscreenSurface::fromNative(ANativeWindow *nativeSurface) +{ + return QGuiApplicationPrivate::platformIntegration()->call< + &QAndroidOffScreenIntegration::createOffscreenSurface>(nativeSurface); +} +#endif + +QT_END_NAMESPACE diff --git a/src/gui/platform/platform.pri b/src/gui/platform/platform.pri index 71cffb403e..6240069f09 100644 --- a/src/gui/platform/platform.pri +++ b/src/gui/platform/platform.pri @@ -3,3 +3,4 @@ darwin:include(darwin/darwin.pri) win32:include(windows/windows.pri) unix:include(unix/unix.pri) macos:include(macos/macos.pri) +android:include(android/android.pri) diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 372b32746d..8048bd6cff 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,8 @@ #include "qandroidsystemlocale.h" #include "qandroidplatformoffscreensurface.h" +#include + #if QT_CONFIG(vulkan) #include "qandroidplatformvulkanwindow.h" #include "qandroidplatformvulkaninstance.h" @@ -322,16 +325,20 @@ QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenS format.setGreenBufferSize(8); format.setBlueBufferSize(8); - if (surface->nativeHandle()) { - // Adopt existing offscreen Surface - // The expectation is that nativeHandle is an ANativeWindow* representing - // an android.view.Surface - return new QAndroidPlatformOffscreenSurface(m_eglDisplay, format, surface); - } - return new QEGLPbuffer(m_eglDisplay, format, surface); } +QOffscreenSurface *QAndroidPlatformIntegration::createOffscreenSurface(ANativeWindow *nativeSurface) const +{ + if (!QtAndroid::activity() || !nativeSurface) + return nullptr; + + auto *surface = new QOffscreenSurface; + auto *surfacePrivate = QOffscreenSurfacePrivate::get(surface); + surfacePrivate->platformOffscreenSurface = new QAndroidPlatformOffscreenSurface(nativeSurface, m_eglDisplay, surface); + return surface; +} + QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const { if (!QtAndroid::activity()) diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h index 30ab42ab34..012616839c 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.h +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -40,19 +40,17 @@ #ifndef QANDROIDPLATFORMINTERATION_H #define QANDROIDPLATFORMINTERATION_H -#include +#include "qandroidinputcontext.h" +#include "qandroidplatformscreen.h" +#include #include #include #include #include +#include #include -#include -#include "qandroidinputcontext.h" - -#include "qandroidplatformscreen.h" - #include QT_BEGIN_NAMESPACE @@ -75,6 +73,7 @@ protected: class QAndroidPlatformIntegration : public QPlatformIntegration , QPlatformInterface::Private::QEGLIntegration + , QPlatformInterface::Private::QAndroidOffScreenIntegration { friend class QAndroidPlatformScreen; @@ -94,6 +93,7 @@ public: QAbstractEventDispatcher *createEventDispatcher() const override; QAndroidPlatformScreen *screen() { return m_primaryScreen; } QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override; + QOffscreenSurface *createOffscreenSurface(ANativeWindow *nativeSurface) const override; void setAvailableGeometry(const QRect &availableGeometry); void setPhysicalSize(int width, int height); diff --git a/src/plugins/platforms/android/qandroidplatformoffscreensurface.cpp b/src/plugins/platforms/android/qandroidplatformoffscreensurface.cpp index f9589cea1a..9255ef4446 100644 --- a/src/plugins/platforms/android/qandroidplatformoffscreensurface.cpp +++ b/src/plugins/platforms/android/qandroidplatformoffscreensurface.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 plugins of the Qt Toolkit. @@ -39,28 +39,23 @@ #include "qandroidplatformoffscreensurface.h" -#include #include -#include - QT_BEGIN_NAMESPACE -QAndroidPlatformOffscreenSurface::QAndroidPlatformOffscreenSurface(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface) - : QPlatformOffscreenSurface(offscreenSurface) - , m_format(format) - , m_display(display) - , m_surface(EGL_NO_SURFACE) +QAndroidPlatformOffscreenSurface::QAndroidPlatformOffscreenSurface( + ANativeWindow *nativeSurface, EGLDisplay display, QOffscreenSurface *offscreenSurface) + : QPlatformOffscreenSurface(offscreenSurface), m_display(display), m_surface(EGL_NO_SURFACE) { - // Get native handle - ANativeWindow *surfaceTexture = (ANativeWindow*)offscreenSurface->nativeHandle(); + // FIXME: Read surface format properties from native surface using ANativeWindow_getFormat + m_format.setAlphaBufferSize(8); + m_format.setRedBufferSize(8); + m_format.setGreenBufferSize(8); + m_format.setBlueBufferSize(8); - EGLConfig config = q_configFromGLFormat(m_display, m_format, false); - if (config) { - const EGLint attributes[] = { - EGL_NONE - }; - m_surface = eglCreateWindowSurface(m_display, config, surfaceTexture, attributes); + if (EGLConfig config = q_configFromGLFormat(m_display, m_format, false)) { + const EGLint attributes[] = { EGL_NONE }; + m_surface = eglCreateWindowSurface(m_display, config, nativeSurface, attributes); } } diff --git a/src/plugins/platforms/android/qandroidplatformoffscreensurface.h b/src/plugins/platforms/android/qandroidplatformoffscreensurface.h index 033bc6a03f..3cfeab3bf2 100644 --- a/src/plugins/platforms/android/qandroidplatformoffscreensurface.h +++ b/src/plugins/platforms/android/qandroidplatformoffscreensurface.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 plugins of the Qt Toolkit. @@ -41,21 +41,26 @@ #define QANDROIDPLATFORMOFFSCREENSURFACETEXTURE_H #include -#include +#include + +#include QT_BEGIN_NAMESPACE class QOffscreenSurface; -class QAndroidPlatformOffscreenSurface : public QPlatformOffscreenSurface +class QAndroidPlatformOffscreenSurface : public QPlatformOffscreenSurface, + public QPlatformInterface::QAndroidPlatformOffscreenSurface { public: - QAndroidPlatformOffscreenSurface(EGLDisplay display, const QSurfaceFormat &format, - QOffscreenSurface *offscreenSurface); + QAndroidPlatformOffscreenSurface(ANativeWindow *nativeSurface, EGLDisplay display, QOffscreenSurface *offscreenSurface); ~QAndroidPlatformOffscreenSurface(); QSurfaceFormat format() const override { return m_format; } bool isValid() const override { return m_surface != EGL_NO_SURFACE; } EGLSurface surface() const { return m_surface; } + + ANativeWindow *nativeSurface() const override { return (ANativeWindow *)surface(); }; + private: QSurfaceFormat m_format; EGLDisplay m_display; diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 330330a638..c51fbaf1d3 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -76,9 +76,8 @@ EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatform if (surface->surface()->surfaceClass() == QSurface::Window) { return static_cast(surface)->eglSurface(eglConfig()); } else { - auto platformOffscreenSurface = static_cast(surface); - if (platformOffscreenSurface->offscreenSurface()->nativeHandle()) - return static_cast(surface)->surface(); + if (auto *platformOffscreenSurface = dynamic_cast(surface)) + return platformOffscreenSurface->surface(); else return static_cast(surface)->pbuffer(); } -- cgit v1.2.3