From 80b6fbc2d9dfc753d6570e971aa4cf4f3420585c Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 21 May 2014 16:30:50 +0200 Subject: Android: Support offscreen surfaces on pbuffers This is pretty much the same thing that eglfs does. Task-number: QTBUG-38960 Change-Id: Ibf310ca8e3a4e31e5310ab3a3d3e851eae31a4ad Reviewed-by: Laszlo Agocs --- .../platforms/android/qandroidplatformintegration.cpp | 14 ++++++++++++++ .../platforms/android/qandroidplatformintegration.h | 1 + .../platforms/android/qandroidplatformopenglcontext.cpp | 5 ++++- .../platforms/android/qandroidplatformopenglwindow.cpp | 9 +++++++++ .../platforms/android/qandroidplatformopenglwindow.h | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 7f0f40be0f..213b1bb7e6 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -45,11 +45,14 @@ #include #include #include +#include #include +#include #include #include +#include #include "androidjnimain.h" #include "qabstracteventdispatcher.h" @@ -207,6 +210,17 @@ QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext return new QAndroidPlatformOpenGLContext(format, context->shareHandle(), m_eglDisplay); } +QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const +{ + QSurfaceFormat format(surface->requestedFormat()); + format.setAlphaBufferSize(8); + format.setRedBufferSize(8); + format.setGreenBufferSize(8); + format.setBlueBufferSize(8); + + return new QEGLPbuffer(m_eglDisplay, format, surface); +} + QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const { if (window->type() == Qt::ForeignWindow) diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h index 4a3fe6c766..f8fa1a91dd 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.h +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -82,6 +82,7 @@ public: QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; QAbstractEventDispatcher *createEventDispatcher() const; QAndroidPlatformScreen *screen() { return m_primaryScreen; } + QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const; virtual void setDesktopSize(int width, int height); virtual void setDisplayMetrics(int width, int height); diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 152a06c99d..53047585cf 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -44,6 +44,8 @@ #include "qandroidplatformopenglwindow.h" #include "qandroidplatformintegration.h" +#include + #include #include @@ -98,7 +100,8 @@ EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatform { if (surface->surface()->surfaceClass() == QSurface::Window) return static_cast(surface)->eglSurface(eglConfig()); - return EGL_NO_SURFACE; + else + return static_cast(surface)->pbuffer(); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp index 5a028e8a5b..f0c4a1de2a 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -127,6 +127,7 @@ void QAndroidPlatformOpenGLWindow::createEgl(EGLConfig config) m_nativeWindow = ANativeWindow_fromSurface(env, m_androidSurfaceObject.object()); m_androidSurfaceObject = QJNIObjectPrivate(); m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_nativeWindow, NULL); + m_format = q_glFormatFromConfig(m_eglDisplay, config, window()->requestedFormat()); if (m_eglSurface == EGL_NO_SURFACE) { EGLint error = eglGetError(); eglTerminate(m_eglDisplay); @@ -134,6 +135,14 @@ void QAndroidPlatformOpenGLWindow::createEgl(EGLConfig config) } } +QSurfaceFormat QAndroidPlatformOpenGLWindow::format() const +{ + if (m_nativeWindow == 0) + return window()->requestedFormat(); + else + return m_format; +} + void QAndroidPlatformOpenGLWindow::clearEgl() { eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.h b/src/plugins/platforms/android/qandroidplatformopenglwindow.h index 7af8b722aa..83df15a524 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.h +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.h @@ -60,6 +60,7 @@ public: void setGeometry(const QRect &rect); EGLSurface eglSurface(EGLConfig config); + QSurfaceFormat format() const; void checkNativeSurface(EGLConfig config); @@ -76,6 +77,7 @@ private: int m_nativeSurfaceId = -1; QJNIObjectPrivate m_androidSurfaceObject; QWaitCondition m_surfaceWaitCondition; + QSurfaceFormat m_format; }; QT_END_NAMESPACE -- cgit v1.2.3