summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kde.org>2015-01-08 17:11:43 +0200
committerBogDan Vatra <bogdan@kde.org>2015-01-10 16:43:01 +0100
commita0737f65a62a5d72f15f5f1196b86f16605d936b (patch)
tree63cb34931401d6086390388a063a8d71f4bf8c60 /src/plugins/platforms
parent05d39ec9c0428696d3d523e6b024df59d456fc59 (diff)
Fixes for surface creation/destruction
- After reset a surface we must call makeCurrent before we are usign swapBuffers. - No need to set the surface in QPA when surfaceCreated are called in QtSurface.java, some time the OpenGL surface is not fully initialized at this stage. Is better to wait for surfaceChanged which is always fired at least once. - DO NOT reset m_surfaceId to 1 when there is no surface. The problem is that if we have one surface and when we distory it we don't (need to) wait for its surfaceChanged/surfaceDestroyed notifications, and if we create another one quicly it will have the same id (1). Task-number: QTBUG-39712 Change-Id: I2aa31e5b59d81ef3b03624d4636a4381eea6d543 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp2
-rw-r--r--src/plugins/platforms/android/qandroidplatformopenglcontext.cpp6
-rw-r--r--src/plugins/platforms/android/qandroidplatformopenglwindow.cpp20
-rw-r--r--src/plugins/platforms/android/qandroidplatformopenglwindow.h4
-rw-r--r--src/plugins/platforms/android/qandroidplatformscreen.cpp2
5 files changed, 19 insertions, 15 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index d1e78dfe5d..1c157c79c3 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -376,8 +376,6 @@ namespace QtAndroid
const auto &it = m_surfaces.find(surfaceId);
if (it != m_surfaces.end())
m_surfaces.remove(surfaceId);
- if (m_surfaces.isEmpty())
- m_surfaceId = 1;
QJNIEnvironmentPrivate env;
if (!env)
diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
index 5781f0d7c6..4c38178343 100644
--- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
+++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
@@ -50,8 +50,10 @@ QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceForma
void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface)
{
- if (surface->surface()->surfaceClass() == QSurface::Window)
- static_cast<QAndroidPlatformOpenGLWindow *>(surface)->checkNativeSurface(eglConfig());
+ if (surface->surface()->surfaceClass() == QSurface::Window &&
+ static_cast<QAndroidPlatformOpenGLWindow *>(surface)->checkNativeSurface(eglConfig())) {
+ QEGLPlatformContext::makeCurrent(surface);
+ }
QEGLPlatformContext::swapBuffers(surface);
}
diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp
index 8dc8e84f0a..de7f1f6990 100644
--- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp
+++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp
@@ -138,19 +138,19 @@ EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config)
return m_eglSurface;
}
-void QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config)
+bool QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config)
{
QMutexLocker lock(&m_surfaceMutex);
if (m_nativeSurfaceId == -1 || !m_androidSurfaceObject.isValid())
- return;
+ return false; // makeCurrent is NOT needed.
createEgl(config);
-
// we've create another surface, the window should be repainted
QRect availableGeometry = screen()->availableGeometry();
if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0)
QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size())));
+ return true; // makeCurrent is needed!
}
void QAndroidPlatformOpenGLWindow::applicationStateChanged(Qt::ApplicationState state)
@@ -209,15 +209,19 @@ void QAndroidPlatformOpenGLWindow::surfaceChanged(JNIEnv *jniEnv, jobject surfac
Q_UNUSED(jniEnv);
Q_UNUSED(w);
Q_UNUSED(h);
+
lockSurface();
m_androidSurfaceObject = surface;
- m_surfaceWaitCondition.wakeOne();
+ if (surface) // wait until we have a valid surface to draw into
+ m_surfaceWaitCondition.wakeOne();
unlockSurface();
- // repaint the window
- QRect availableGeometry = screen()->availableGeometry();
- if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0)
- QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size())));
+ if (surface) {
+ // repaint the window, when we have a valid surface
+ QRect availableGeometry = screen()->availableGeometry();
+ if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0)
+ QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size())));
+ }
}
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.h b/src/plugins/platforms/android/qandroidplatformopenglwindow.h
index 71787edee1..6d6548fc6a 100644
--- a/src/plugins/platforms/android/qandroidplatformopenglwindow.h
+++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.h
@@ -54,7 +54,7 @@ public:
EGLSurface eglSurface(EGLConfig config);
QSurfaceFormat format() const;
- void checkNativeSurface(EGLConfig config);
+ bool checkNativeSurface(EGLConfig config);
void applicationStateChanged(Qt::ApplicationState);
@@ -66,7 +66,7 @@ protected:
void clearEgl();
private:
- EGLDisplay m_eglDisplay;
+ EGLDisplay m_eglDisplay = EGL_NO_DISPLAY;
EGLSurface m_eglSurface = EGL_NO_SURFACE;
EGLNativeWindowType m_nativeWindow = nullptr;
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp
index b70f936be1..092ade2e4a 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.cpp
+++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp
@@ -391,7 +391,7 @@ Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const
void QAndroidPlatformScreen::surfaceChanged(JNIEnv *env, jobject surface, int w, int h)
{
lockSurface();
- if (surface && w && h) {
+ if (surface && w > 0 && h > 0) {
releaseSurface();
m_nativeSurface = ANativeWindow_fromSurface(env, surface);
QMetaObject::invokeMethod(this, "setDirty", Qt::QueuedConnection, Q_ARG(QRect, QRect(0, 0, w, h)));