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ø --- .../android/qandroidplatformintegration.cpp | 21 ++++++++++------ .../android/qandroidplatformintegration.h | 12 ++++----- .../android/qandroidplatformoffscreensurface.cpp | 29 +++++++++------------- .../android/qandroidplatformoffscreensurface.h | 15 +++++++---- .../android/qandroidplatformopenglcontext.cpp | 5 ++-- 5 files changed, 44 insertions(+), 38 deletions(-) (limited to 'src/plugins') 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