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 <laszlo.agocs@digia.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2014-05-21 16:30:50 +02:00 committed by The Qt Project
parent 90808ead98
commit 80b6fbc2d9
5 changed files with 30 additions and 1 deletions

View File

@ -45,11 +45,14 @@
#include <QGuiApplication>
#include <QOpenGLContext>
#include <QThread>
#include <QOffscreenSurface>
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
#include <QtPlatformSupport/private/qeglpbuffer_p.h>
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformoffscreensurface.h>
#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)

View File

@ -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);

View File

@ -44,6 +44,8 @@
#include "qandroidplatformopenglwindow.h"
#include "qandroidplatformintegration.h"
#include <QtPlatformSupport/private/qeglpbuffer_p.h>
#include <QSurface>
#include <QtGui/private/qopenglcontext_p.h>
@ -98,7 +100,8 @@ EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatform
{
if (surface->surface()->surfaceClass() == QSurface::Window)
return static_cast<QAndroidPlatformOpenGLWindow *>(surface)->eglSurface(eglConfig());
return EGL_NO_SURFACE;
else
return static_cast<QEGLPbuffer *>(surface)->pbuffer();
}
QT_END_NAMESPACE

View File

@ -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);

View File

@ -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